mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 06:52:36 +01:00
test: fix intermittent issue in feature_bip68_sequence
To avoid `bad-txns-premature-spend-of-coinbase` error, when getting a utxo (using `get_utxo`) to create a new transaction `get_utxo` shouldn't return by default immature coinbase.
This commit is contained in:
parent
7be7e62fdf
commit
60ced9007d
3 changed files with 5 additions and 2 deletions
|
@ -47,12 +47,12 @@ class MempoolCompatibilityTest(BitcoinTestFramework):
|
||||||
# unbroadcasted_tx won't pass old_node's `MemPoolAccept::PreChecks`.
|
# unbroadcasted_tx won't pass old_node's `MemPoolAccept::PreChecks`.
|
||||||
self.connect_nodes(0, 1)
|
self.connect_nodes(0, 1)
|
||||||
self.sync_blocks()
|
self.sync_blocks()
|
||||||
self.stop_node(1)
|
|
||||||
|
|
||||||
self.log.info("Add a transaction to mempool on old node and shutdown")
|
self.log.info("Add a transaction to mempool on old node and shutdown")
|
||||||
old_tx_hash = new_wallet.send_self_transfer(from_node=old_node)["txid"]
|
old_tx_hash = new_wallet.send_self_transfer(from_node=old_node)["txid"]
|
||||||
assert old_tx_hash in old_node.getrawmempool()
|
assert old_tx_hash in old_node.getrawmempool()
|
||||||
self.stop_node(0)
|
self.stop_node(0)
|
||||||
|
self.stop_node(1)
|
||||||
|
|
||||||
self.log.info("Move mempool.dat from old to new node")
|
self.log.info("Move mempool.dat from old to new node")
|
||||||
old_node_mempool = os.path.join(old_node.datadir, self.chain, 'mempool.dat')
|
old_node_mempool = os.path.join(old_node.datadir, self.chain, 'mempool.dat')
|
||||||
|
|
|
@ -191,6 +191,7 @@ class MempoolPersistTest(BitcoinTestFramework):
|
||||||
def test_persist_unbroadcast(self):
|
def test_persist_unbroadcast(self):
|
||||||
node0 = self.nodes[0]
|
node0 = self.nodes[0]
|
||||||
self.start_node(0)
|
self.start_node(0)
|
||||||
|
self.start_node(2)
|
||||||
|
|
||||||
# clear out mempool
|
# clear out mempool
|
||||||
self.generate(node0, 1, sync_fun=self.no_op)
|
self.generate(node0, 1, sync_fun=self.no_op)
|
||||||
|
|
|
@ -218,10 +218,12 @@ class MiniWallet:
|
||||||
txid: get the first utxo we find from a specific transaction
|
txid: get the first utxo we find from a specific transaction
|
||||||
"""
|
"""
|
||||||
self._utxos = sorted(self._utxos, key=lambda k: (k['value'], -k['height'])) # Put the largest utxo last
|
self._utxos = sorted(self._utxos, key=lambda k: (k['value'], -k['height'])) # Put the largest utxo last
|
||||||
|
blocks_height = self._test_node.getblockchaininfo()['blocks']
|
||||||
|
mature_coins = list(filter(lambda utxo: not utxo['coinbase'] or COINBASE_MATURITY - 1 <= blocks_height - utxo['height'], self._utxos))
|
||||||
if txid:
|
if txid:
|
||||||
utxo_filter: Any = filter(lambda utxo: txid == utxo['txid'], self._utxos)
|
utxo_filter: Any = filter(lambda utxo: txid == utxo['txid'], self._utxos)
|
||||||
else:
|
else:
|
||||||
utxo_filter = reversed(self._utxos) # By default the largest utxo
|
utxo_filter = reversed(mature_coins) # By default the largest utxo
|
||||||
if vout is not None:
|
if vout is not None:
|
||||||
utxo_filter = filter(lambda utxo: vout == utxo['vout'], utxo_filter)
|
utxo_filter = filter(lambda utxo: vout == utxo['vout'], utxo_filter)
|
||||||
index = self._utxos.index(next(utxo_filter))
|
index = self._utxos.index(next(utxo_filter))
|
||||||
|
|
Loading…
Add table
Reference in a new issue