Skip to content

Commit 0622788

Browse files
committed
merge bitcoin#24941: support skipping mempool checks (feature_fee_estimation.py performance fix)
1 parent 9c93e3a commit 0622788

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

test/functional/feature_csv_activation.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,15 @@ def create_bip112special(self, input, txversion):
120120
tx.nVersion = txversion
121121
self.miniwallet.sign_tx(tx)
122122
tx.vin[0].scriptSig = CScript([-1, OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(CScript(tx.vin[0].scriptSig)))
123+
tx.rehash()
123124
return tx
124125

125126
def create_bip112emptystack(self, input, txversion):
126127
tx = self.create_self_transfer_from_utxo(input)
127128
tx.nVersion = txversion
128129
self.miniwallet.sign_tx(tx)
129130
tx.vin[0].scriptSig = CScript([OP_CHECKSEQUENCEVERIFY] + list(CScript(tx.vin[0].scriptSig)))
131+
tx.rehash()
130132
return tx
131133

132134
def send_generic_input_tx(self, coinbases):
@@ -144,7 +146,6 @@ def create_bip68txs(self, bip68inputs, txversion, locktime_delta=0):
144146
tx.nVersion = txversion
145147
tx.vin[0].nSequence = locktime + locktime_delta
146148
self.miniwallet.sign_tx(tx)
147-
tx.rehash()
148149
txs.append({'tx': tx, 'sdf': sdf, 'stf': stf})
149150

150151
return txs
@@ -350,20 +351,16 @@ def run_test(self):
350351
# BIP 113 tests should now fail regardless of version number if nLockTime isn't satisfied by new rules
351352
bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 # = MTP of prior block (not <) but < time put on current block
352353
self.miniwallet.sign_tx(bip113tx_v1)
353-
bip113tx_v1.rehash()
354354
bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 # = MTP of prior block (not <) but < time put on current block
355355
self.miniwallet.sign_tx(bip113tx_v2)
356-
bip113tx_v2.rehash()
357356
for bip113tx in [bip113tx_v1, bip113tx_v2]:
358357
self.send_blocks([self.create_test_block([bip113tx])], success=False, reject_reason='bad-txns-nonfinal')
359358

360359
# BIP 113 tests should now pass if the locktime is < MTP
361360
bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 - 1 # < MTP of prior block
362361
self.miniwallet.sign_tx(bip113tx_v1)
363-
bip113tx_v1.rehash()
364362
bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 - 1 # < MTP of prior block
365363
self.miniwallet.sign_tx(bip113tx_v2)
366-
bip113tx_v2.rehash()
367364
for bip113tx in [bip113tx_v1, bip113tx_v2]:
368365
self.send_blocks([self.create_test_block([bip113tx])])
369366
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
@@ -488,7 +485,6 @@ def run_test(self):
488485
for tx in [tx['tx'] for tx in bip112txs_vary_OP_CSV_v2 if not tx['sdf'] and tx['stf']]:
489486
tx.vin[0].nSequence = BASE_RELATIVE_LOCKTIME | SEQ_TYPE_FLAG
490487
self.miniwallet.sign_tx(tx)
491-
tx.rehash()
492488
time_txs.append(tx)
493489

494490
self.send_blocks([self.create_test_block(time_txs)])

test/functional/test_framework/wallet.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def sign_tx(self, tx, fixed_length=True):
128128
if not fixed_length:
129129
break
130130
tx.vin[0].scriptSig = CScript([der_sig + bytes(bytearray([SIGHASH_ALL]))])
131+
tx.rehash()
131132

132133
def generate(self, num_blocks, **kwargs):
133134
"""Generate blocks with coinbase outputs to the internal address, and append the outputs to the internal list"""
@@ -241,7 +242,8 @@ def create_self_transfer_multi(
241242
return tx
242243

243244
def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node=None, utxo_to_spend=None, mempool_valid=True, locktime=0, sequence=0):
244-
"""Create and return a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
245+
"""Create and return a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed.
246+
Checking mempool validity via the testmempoolaccept RPC can be skipped by setting mempool_valid to False."""
245247
from_node = from_node or self._test_node
246248
utxo_to_spend = utxo_to_spend or self.get_utxo()
247249
if self._mode in (MiniWalletMode.RAW_OP_TRUE, MiniWalletMode.ADDRESS_OP_TRUE):
@@ -267,12 +269,13 @@ def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node=None, utx
267269
assert False
268270
tx_hex = tx.serialize().hex()
269271

270-
tx_info = from_node.testmempoolaccept([tx_hex])[0]
271-
assert_equal(mempool_valid, tx_info['allowed'])
272272
if mempool_valid:
273+
tx_info = from_node.testmempoolaccept([tx_hex])[0]
274+
assert_equal(tx_info['allowed'], True)
273275
assert_equal(len(tx_hex) // 2, vsize) # 1 byte = 2 character
274276
assert_equal(tx_info['fees']['base'], utxo_to_spend['value'] - Decimal(send_value) / COIN)
275-
return {'txid': tx_info['txid'], 'hex': tx_hex, 'tx': tx}
277+
278+
return {'txid': tx.rehash(), 'hex': tx_hex, 'tx': tx}
276279

277280
def sendrawtransaction(self, *, from_node, tx_hex, maxfeerate=0, **kwargs):
278281
txid = from_node.sendrawtransaction(hexstring=tx_hex, maxfeerate=maxfeerate, **kwargs)

0 commit comments

Comments
 (0)