Skip to content

Commit 632a2bb

Browse files
committed
Merge bitcoin/bitcoin#29215: test: assumeutxo: spend coin from snapshot chainstate after loading
9315754 test: assumeutxo: spend coin from snapshot chainstate after loading (Sebastian Falbesoner) Pull request description: This PR extends the AssumeUTXO functional test by submitting a spending transaction for an UTXO that is only available in a the snapshot chainstate (after loading via `loadtxoutset`), i.e. it hasn't been seen in a block before. With that we can verify that snapshot coins are visible to the mempool. Note that we unfortunately can't use MiniWallet here, as the only available UTXO to spend from the snapshot chainstate is at height 200, where a P2PKH created from the test framework's deterministic private key is used (see `TestNode.generate(...)` and the `PRIV_KEYS` array). Coinbase outputs with smaller heights (<= 199) would be part of the pre-generated chain and hence not qualify for the "UTXO is only in snapshot chainstate and has never been seen in a block" scenario, coinbase outputs with larger heights (>= 201) can't be spent due to immaturity, as the snapshot chainstate block height is 299. One could of course mine a different chain with outputs that MiniWallet supports (e.g. taproot anyone-can-spend), but this would change the hardcoded AssumeUTXO hash, colliding with other PRs like #28838, so I wanted to avoid that. ACKs for top commit: maflcko: lgtm ACK 9315754 jamesob: ACK bitcoin/bitcoin@9315754 Tree-SHA512: 0665868e1e91fe74f408d0a239cc264bbbc11a6b55bcc0e86cc8b4b2ec1f44977884b817dbe9065a7c768332cab464636656858bc8b9c8e7d7810498e0a17d78
2 parents 063a8b8 + 9315754 commit 632a2bb

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

test/functional/feature_assumeutxo.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
1212
## Possible test improvements
1313
14-
- TODO: test submitting a transaction and verifying it appears in mempool
1514
- TODO: test what happens with -reindex and -reindex-chainstate before the
1615
snapshot is validated, and make sure it's deleted successfully.
1716
@@ -35,11 +34,14 @@
3534
"""
3635
from shutil import rmtree
3736

37+
from test_framework.messages import tx_from_hex
3838
from test_framework.test_framework import BitcoinTestFramework
3939
from test_framework.util import (
4040
assert_equal,
4141
assert_raises_rpc_error,
4242
)
43+
from test_framework.wallet import getnewdestination
44+
4345

4446
START_HEIGHT = 199
4547
SNAPSHOT_BASE_HEIGHT = 299
@@ -207,6 +209,22 @@ def run_test(self):
207209

208210
assert_equal(n1.getblockchaininfo()["blocks"], SNAPSHOT_BASE_HEIGHT)
209211

212+
self.log.info("Submit a spending transaction for a snapshot chainstate coin to the mempool")
213+
# spend the coinbase output of the first block that is not available on node1
214+
spend_coin_blockhash = n1.getblockhash(START_HEIGHT + 1)
215+
assert_raises_rpc_error(-1, "Block not found on disk", n1.getblock, spend_coin_blockhash)
216+
prev_tx = n0.getblock(spend_coin_blockhash, 3)['tx'][0]
217+
prevout = {"txid": prev_tx['txid'], "vout": 0, "scriptPubKey": prev_tx['vout'][0]['scriptPubKey']['hex']}
218+
privkey = n0.get_deterministic_priv_key().key
219+
raw_tx = n1.createrawtransaction([prevout], {getnewdestination()[2]: 24.99})
220+
signed_tx = n1.signrawtransactionwithkey(raw_tx, [privkey], [prevout])['hex']
221+
signed_txid = tx_from_hex(signed_tx).rehash()
222+
223+
assert n1.gettxout(prev_tx['txid'], 0) is not None
224+
n1.sendrawtransaction(signed_tx)
225+
assert signed_txid in n1.getrawmempool()
226+
assert not n1.gettxout(prev_tx['txid'], 0)
227+
210228
PAUSE_HEIGHT = FINAL_HEIGHT - 40
211229

212230
self.log.info("Restarting node to stop at height %d", PAUSE_HEIGHT)

0 commit comments

Comments
 (0)