Skip to content

Commit 4fc15d1

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#22707: test: refactor use of getrawmempool in functional tests for efficiency
47c48b5 test: only use verbose for getrawmempool when necessary in functional tests (Michael Dietz) 7734971 test: use getmempoolentry instead of getrawmempool in functional tests when appropriate (Michael Dietz) 86dbd54 test: improve mempool_updatefrom efficiency by using getmempoolentry for specific txns (Michael Dietz) Pull request description: I don't think this changes the intention of the test. But it does shave ~30 seconds off the time it takes to run. From what I've seen our CI `macOS 11 native [gui] [no depends]` runs `mempool_updatefrom.py` in ~135 seconds. After this PR it should run in ~105 seconds I noticed this improvement should probably be made when testing performance/runtimes of bitcoin/bitcoin#22698. But I wanted to separate this out from that PR so the affects of each is decoupled Edit: The major change in this PR is improving mempool_updatefrom.py's runtime as this is a very long running test. Then made the same efficiency improvements across all the functional tests as it made since to do that here ACKs for top commit: theStack: Tested ACK 47c48b5 Tree-SHA512: 40f553715f3d4649dc18c2738554eafaca9ea800c4b028c099217896cc1c466ff457ae814d59cf8564c782a8964d8fac3eda60c1b6ffb08bbee1439b2d34434b
2 parents 192a959 + 47c48b5 commit 4fc15d1

8 files changed

+48
-51
lines changed

test/functional/mempool_accept_wtxid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def run_test(self):
9090

9191
self.log.info("Submit child_one to the mempool")
9292
txid_submitted = node.sendrawtransaction(child_one.serialize().hex())
93-
assert_equal(node.getrawmempool(True)[txid_submitted]['wtxid'], child_one_wtxid)
93+
assert_equal(node.getmempoolentry(txid_submitted)['wtxid'], child_one_wtxid)
9494

9595
peer_wtxid_relay.wait_for_broadcast([child_one_wtxid])
9696
assert_equal(node.getmempoolinfo()["unbroadcastcount"], 0)

test/functional/mempool_compatibility.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ def run_test(self):
6565
self.log.info("Add unbroadcasted tx to mempool on new node and shutdown")
6666
unbroadcasted_tx_hash = new_wallet.send_self_transfer(from_node=new_node)['txid']
6767
assert unbroadcasted_tx_hash in new_node.getrawmempool()
68-
mempool = new_node.getrawmempool(True)
69-
assert mempool[unbroadcasted_tx_hash]['unbroadcast']
68+
assert new_node.getmempoolentry(unbroadcasted_tx_hash)['unbroadcast']
7069
self.stop_node(1)
7170

7271
self.log.info("Move mempool.dat from new to old node")

test/functional/mempool_package_limits.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_chain_limits_helper(self, mempool_count, package_count):
7474
txid = tx.rehash()
7575
if i < mempool_count:
7676
node.sendrawtransaction(txhex)
77-
assert_equal(node.getrawmempool(verbose=True)[txid]["ancestorcount"], i + 1)
77+
assert_equal(node.getmempoolentry(txid)["ancestorcount"], i + 1)
7878
else:
7979
chain_hex.append(txhex)
8080
chain_txns.append(tx)

test/functional/mempool_package_onemore.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def run_test(self):
5151
(second_chain, second_chain_value) = chain_transaction(self.nodes[0], [utxo[1]['txid']], [utxo[1]['vout']], utxo[1]['amount'], fee, 1)
5252

5353
# Check mempool has MAX_ANCESTORS + 1 transactions in it
54-
assert_equal(len(self.nodes[0].getrawmempool(True)), MAX_ANCESTORS + 1)
54+
assert_equal(len(self.nodes[0].getrawmempool()), MAX_ANCESTORS + 1)
5555

5656
# Adding one more transaction on to the chain should fail.
5757
assert_raises_rpc_error(-26, "too-long-mempool-chain, too many unconfirmed ancestors [limit: 25]", chain_transaction, self.nodes[0], [txid], [0], value, fee, 1)
@@ -74,7 +74,7 @@ def run_test(self):
7474
self.nodes[0].sendrawtransaction(signed_second_tx['hex'])
7575

7676
# Finally, check that we added two transactions
77-
assert_equal(len(self.nodes[0].getrawmempool(True)), MAX_ANCESTORS + 3)
77+
assert_equal(len(self.nodes[0].getrawmempool()), MAX_ANCESTORS + 3)
7878

7979
if __name__ == '__main__':
8080
MempoolPackagesTest().main()

test/functional/mempool_packages.py

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -89,28 +89,28 @@ def run_test(self):
8989
assert_equal(entry, mempool[x])
9090

9191
# Check that the descendant calculations are correct
92-
assert_equal(mempool[x]['descendantcount'], descendant_count)
93-
descendant_fees += mempool[x]['fee']
94-
assert_equal(mempool[x]['modifiedfee'], mempool[x]['fee'])
95-
assert_equal(mempool[x]['fees']['base'], mempool[x]['fee'])
96-
assert_equal(mempool[x]['fees']['modified'], mempool[x]['modifiedfee'])
97-
assert_equal(mempool[x]['descendantfees'], descendant_fees * COIN)
98-
assert_equal(mempool[x]['fees']['descendant'], descendant_fees)
99-
descendant_vsize += mempool[x]['vsize']
100-
assert_equal(mempool[x]['descendantsize'], descendant_vsize)
92+
assert_equal(entry['descendantcount'], descendant_count)
93+
descendant_fees += entry['fee']
94+
assert_equal(entry['modifiedfee'], entry['fee'])
95+
assert_equal(entry['fees']['base'], entry['fee'])
96+
assert_equal(entry['fees']['modified'], entry['modifiedfee'])
97+
assert_equal(entry['descendantfees'], descendant_fees * COIN)
98+
assert_equal(entry['fees']['descendant'], descendant_fees)
99+
descendant_vsize += entry['vsize']
100+
assert_equal(entry['descendantsize'], descendant_vsize)
101101
descendant_count += 1
102102

103103
# Check that ancestor calculations are correct
104-
assert_equal(mempool[x]['ancestorcount'], ancestor_count)
105-
assert_equal(mempool[x]['ancestorfees'], ancestor_fees * COIN)
106-
assert_equal(mempool[x]['ancestorsize'], ancestor_vsize)
107-
ancestor_vsize -= mempool[x]['vsize']
108-
ancestor_fees -= mempool[x]['fee']
104+
assert_equal(entry['ancestorcount'], ancestor_count)
105+
assert_equal(entry['ancestorfees'], ancestor_fees * COIN)
106+
assert_equal(entry['ancestorsize'], ancestor_vsize)
107+
ancestor_vsize -= entry['vsize']
108+
ancestor_fees -= entry['fee']
109109
ancestor_count -= 1
110110

111111
# Check that parent/child list is correct
112-
assert_equal(mempool[x]['spentby'], descendants[-1:])
113-
assert_equal(mempool[x]['depends'], ancestors[-2:-1])
112+
assert_equal(entry['spentby'], descendants[-1:])
113+
assert_equal(entry['depends'], ancestors[-2:-1])
114114

115115
# Check that getmempooldescendants is correct
116116
assert_equal(sorted(descendants), sorted(self.nodes[0].getmempooldescendants(x)))
@@ -153,26 +153,26 @@ def run_test(self):
153153
# Check that ancestor modified fees includes fee deltas from
154154
# prioritisetransaction
155155
self.nodes[0].prioritisetransaction(txid=chain[0], fee_delta=1000)
156-
mempool = self.nodes[0].getrawmempool(True)
157156
ancestor_fees = 0
158157
for x in chain:
159-
ancestor_fees += mempool[x]['fee']
160-
assert_equal(mempool[x]['fees']['ancestor'], ancestor_fees + Decimal('0.00001'))
161-
assert_equal(mempool[x]['ancestorfees'], ancestor_fees * COIN + 1000)
158+
entry = self.nodes[0].getmempoolentry(x)
159+
ancestor_fees += entry['fee']
160+
assert_equal(entry['fees']['ancestor'], ancestor_fees + Decimal('0.00001'))
161+
assert_equal(entry['ancestorfees'], ancestor_fees * COIN + 1000)
162162

163163
# Undo the prioritisetransaction for later tests
164164
self.nodes[0].prioritisetransaction(txid=chain[0], fee_delta=-1000)
165165

166166
# Check that descendant modified fees includes fee deltas from
167167
# prioritisetransaction
168168
self.nodes[0].prioritisetransaction(txid=chain[-1], fee_delta=1000)
169-
mempool = self.nodes[0].getrawmempool(True)
170169

171170
descendant_fees = 0
172171
for x in reversed(chain):
173-
descendant_fees += mempool[x]['fee']
174-
assert_equal(mempool[x]['fees']['descendant'], descendant_fees + Decimal('0.00001'))
175-
assert_equal(mempool[x]['descendantfees'], descendant_fees * COIN + 1000)
172+
entry = self.nodes[0].getmempoolentry(x)
173+
descendant_fees += entry['fee']
174+
assert_equal(entry['fees']['descendant'], descendant_fees + Decimal('0.00001'))
175+
assert_equal(entry['descendantfees'], descendant_fees * COIN + 1000)
176176

177177
# Adding one more transaction on to the chain should fail.
178178
assert_raises_rpc_error(-26, "too-long-mempool-chain", chain_transaction, self.nodes[0], [txid], [vout], value, fee, 1)
@@ -190,16 +190,15 @@ def run_test(self):
190190
self.nodes[1].invalidateblock(self.nodes[1].getbestblockhash())
191191

192192
# Now check that the transaction is in the mempool, with the right modified fee
193-
mempool = self.nodes[0].getrawmempool(True)
194-
195193
descendant_fees = 0
196194
for x in reversed(chain):
197-
descendant_fees += mempool[x]['fee']
195+
entry = self.nodes[0].getmempoolentry(x)
196+
descendant_fees += entry['fee']
198197
if (x == chain[-1]):
199-
assert_equal(mempool[x]['modifiedfee'], mempool[x]['fee']+satoshi_round(0.00002))
200-
assert_equal(mempool[x]['fees']['modified'], mempool[x]['fee']+satoshi_round(0.00002))
201-
assert_equal(mempool[x]['descendantfees'], descendant_fees * COIN + 2000)
202-
assert_equal(mempool[x]['fees']['descendant'], descendant_fees+satoshi_round(0.00002))
198+
assert_equal(entry['modifiedfee'], entry['fee']+satoshi_round(0.00002))
199+
assert_equal(entry['fees']['modified'], entry['fee']+satoshi_round(0.00002))
200+
assert_equal(entry['descendantfees'], descendant_fees * COIN + 2000)
201+
assert_equal(entry['fees']['descendant'], descendant_fees+satoshi_round(0.00002))
203202

204203
# Check that node1's mempool is as expected (-> custom ancestor limit)
205204
mempool0 = self.nodes[0].getrawmempool(False)
@@ -255,7 +254,7 @@ def run_test(self):
255254
# - txs from previous ancestor test (-> custom ancestor limit)
256255
# - parent tx for descendant test
257256
# - txs chained off parent tx (-> custom descendant limit)
258-
self.wait_until(lambda: len(self.nodes[1].getrawmempool(False)) ==
257+
self.wait_until(lambda: len(self.nodes[1].getrawmempool()) ==
259258
MAX_ANCESTORS_CUSTOM + 1 + MAX_DESCENDANTS_CUSTOM, timeout=10)
260259
mempool0 = self.nodes[0].getrawmempool(False)
261260
mempool1 = self.nodes[1].getrawmempool(False)

test/functional/mempool_unbroadcast.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ def test_broadcast(self):
9494

9595
self.log.info("Rebroadcast transaction and ensure it is not added to unbroadcast set when already in mempool")
9696
rpc_tx_hsh = node.sendrawtransaction(txFS["hex"])
97-
mempool = node.getrawmempool(True)
98-
assert rpc_tx_hsh in mempool
99-
assert not mempool[rpc_tx_hsh]['unbroadcast']
97+
assert not node.getmempoolentry(rpc_tx_hsh)['unbroadcast']
10098

10199
def test_txn_removal(self):
102100
self.log.info("Test that transactions removed from mempool are removed from unbroadcast set")

test/functional/mempool_updatefromblock.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def transaction_graph_test(self, size, n_tx_to_mine=None, start_input_txid='', e
8686
unsigned_raw_tx = self.nodes[0].createrawtransaction(inputs, outputs)
8787
signed_raw_tx = self.nodes[0].signrawtransactionwithwallet(unsigned_raw_tx)
8888
tx_id.append(self.nodes[0].sendrawtransaction(signed_raw_tx['hex']))
89-
tx_size.append(self.nodes[0].getrawmempool(True)[tx_id[-1]]['vsize'])
89+
tx_size.append(self.nodes[0].getmempoolentry(tx_id[-1])['vsize'])
9090

9191
if tx_count in n_tx_to_mine:
9292
# The created transactions are mined into blocks by batches.
@@ -109,10 +109,11 @@ def transaction_graph_test(self, size, n_tx_to_mine=None, start_input_txid='', e
109109
self.log.info('Checking descendants/ancestors properties of all of the in-mempool transactions...')
110110
for k, tx in enumerate(tx_id):
111111
self.log.debug('Check transaction #{}.'.format(k))
112-
assert_equal(self.nodes[0].getrawmempool(True)[tx]['descendantcount'], size - k)
113-
assert_equal(self.nodes[0].getrawmempool(True)[tx]['descendantsize'], sum(tx_size[k:size]))
114-
assert_equal(self.nodes[0].getrawmempool(True)[tx]['ancestorcount'], k + 1)
115-
assert_equal(self.nodes[0].getrawmempool(True)[tx]['ancestorsize'], sum(tx_size[0:(k + 1)]))
112+
entry = self.nodes[0].getmempoolentry(tx)
113+
assert_equal(entry['descendantcount'], size - k)
114+
assert_equal(entry['descendantsize'], sum(tx_size[k:size]))
115+
assert_equal(entry['ancestorcount'], k + 1)
116+
assert_equal(entry['ancestorsize'], sum(tx_size[0:(k + 1)]))
116117

117118
def run_test(self):
118119
# Use batch size limited by DEFAULT_ANCESTOR_LIMIT = 25 to not fire "too many unconfirmed parents" error.

test/functional/rpc_fundrawtransaction.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ def test_fee_p2pkh(self):
380380

381381
# Create same transaction over sendtoaddress.
382382
txId = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1.1)
383-
signedFee = self.nodes[0].getrawmempool(True)[txId]['fee']
383+
signedFee = self.nodes[0].getmempoolentry(txId)['fee']
384384

385385
# Compare fee.
386386
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
@@ -403,7 +403,7 @@ def test_fee_p2pkh_multi_out(self):
403403

404404
# Create same transaction over sendtoaddress.
405405
txId = self.nodes[0].sendmany("", outputs)
406-
signedFee = self.nodes[0].getrawmempool(True)[txId]['fee']
406+
signedFee = self.nodes[0].getmempoolentry(txId)['fee']
407407

408408
# Compare fee.
409409
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
@@ -427,7 +427,7 @@ def test_fee_p2sh(self):
427427

428428
# Create same transaction over sendtoaddress.
429429
txId = self.nodes[0].sendtoaddress(mSigObj, 1.1)
430-
signedFee = self.nodes[0].getrawmempool(True)[txId]['fee']
430+
signedFee = self.nodes[0].getmempoolentry(txId)['fee']
431431

432432
# Compare fee.
433433
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
@@ -468,7 +468,7 @@ def test_fee_4of5(self):
468468

469469
# Create same transaction over sendtoaddress.
470470
txId = self.nodes[0].sendtoaddress(mSigObj, 1.1)
471-
signedFee = self.nodes[0].getrawmempool(True)[txId]['fee']
471+
signedFee = self.nodes[0].getmempoolentry(txId)['fee']
472472

473473
# Compare fee.
474474
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
@@ -600,7 +600,7 @@ def test_many_inputs_fee(self):
600600

601601
# Create same transaction over sendtoaddress.
602602
txId = self.nodes[1].sendmany("", outputs)
603-
signedFee = self.nodes[1].getrawmempool(True)[txId]['fee']
603+
signedFee = self.nodes[1].getmempoolentry(txId)['fee']
604604

605605
# Compare fee.
606606
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)

0 commit comments

Comments
 (0)