Skip to content

Commit a498acc

Browse files
committed
test: MiniWallet: skip mempool check if mempool_valid=False
MiniWallet's core method for creating txs (`create_self_transfer`) right now always executes the `testmempoolaccept` RPC to check for mempool validity or invalidity. In some test cases where we use MiniWallet to create a huge number of transactions this can lead to performance issues (e.g. feature_fee_estimation.py where the execution time after MiniWallet usage almost doubled). Providing the possibility to skip the mempool checks is a mitigation for this. master branch: $ time ./test/functional/feature_fee_estimation.py real 3m20.771s user 2m52.360s sys 0m39.340s PR branch: $ time ./test/functional/feature_fee_estimation.py real 2m1.386s user 1m42.510s sys 0m22.980s
1 parent 01552e8 commit a498acc

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

test/functional/test_framework/wallet.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ def create_self_transfer_multi(self, *, from_node, utxos_to_spend=None, num_outp
234234
return tx
235235

236236
def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node=None, utxo_to_spend=None, mempool_valid=True, locktime=0, sequence=0):
237-
"""Create and return a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
237+
"""Create and return a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed.
238+
Checking mempool validity via the testmempoolaccept RPC can be skipped by setting mempool_valid to False."""
238239
from_node = from_node or self._test_node
239240
utxo_to_spend = utxo_to_spend or self.get_utxo()
240241
if self._priv_key is None:
@@ -261,12 +262,13 @@ def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node=None, utx
261262
tx.wit.vtxinwit[0].scriptWitness.stack = [CScript([OP_TRUE]), bytes([LEAF_VERSION_TAPSCRIPT]) + self._internal_key]
262263
tx_hex = tx.serialize().hex()
263264

264-
tx_info = from_node.testmempoolaccept([tx_hex])[0]
265-
assert_equal(mempool_valid, tx_info['allowed'])
266265
if mempool_valid:
266+
tx_info = from_node.testmempoolaccept([tx_hex])[0]
267+
assert_equal(tx_info['allowed'], True)
267268
assert_equal(tx_info['vsize'], vsize)
268269
assert_equal(tx_info['fees']['base'], utxo_to_spend['value'] - Decimal(send_value) / COIN)
269-
return {'txid': tx_info['txid'], 'wtxid': tx_info['wtxid'], 'hex': tx_hex, 'tx': tx}
270+
271+
return {'txid': tx.rehash(), 'wtxid': tx.getwtxid(), 'hex': tx_hex, 'tx': tx}
270272

271273
def sendrawtransaction(self, *, from_node, tx_hex, **kwargs):
272274
txid = from_node.sendrawtransaction(hexstring=tx_hex, **kwargs)

0 commit comments

Comments
 (0)