Skip to content

Commit 919db03

Browse files
author
MarcoFalke
committed
Merge #9274: [qa] Use cached utxo set to fix performance regression
fab1af3 [qa] maxuploadtarget: Use cached utxo set (MarcoFalke) fa2ecc4 [qa] pruning: Use cached utxo set to run faster (MarcoFalke)
2 parents ed8d693 + fab1af3 commit 919db03

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

qa/rpc-tests/maxuploadtarget.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ def __init__(self):
8686
self.setup_clean_chain = True
8787
self.num_nodes = 1
8888

89+
# Cache for utxos, as the listunspent may take a long time later in the test
90+
self.utxo_cache = []
91+
8992
def setup_network(self):
9093
# Start a node with maxuploadtarget of 200 MB (/24h)
9194
self.nodes = []
@@ -118,7 +121,7 @@ def run_test(self):
118121
# Test logic begins here
119122

120123
# Now mine a big block
121-
mine_large_block(self.nodes[0])
124+
mine_large_block(self.nodes[0], self.utxo_cache)
122125

123126
# Store the hash; we'll request this later
124127
big_old_block = self.nodes[0].getbestblockhash()
@@ -129,7 +132,7 @@ def run_test(self):
129132
self.nodes[0].setmocktime(int(time.time()) - 2*60*60*24)
130133

131134
# Mine one more block, so that the prior block looks old
132-
mine_large_block(self.nodes[0])
135+
mine_large_block(self.nodes[0], self.utxo_cache)
133136

134137
# We'll be requesting this new block too
135138
big_new_block = self.nodes[0].getbestblockhash()

qa/rpc-tests/mempool_limit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __init__(self):
2626

2727
def run_test(self):
2828
txids = []
29-
utxos = create_confirmed_utxos(self.relayfee, self.nodes[0], 90)
29+
utxos = create_confirmed_utxos(self.relayfee, self.nodes[0], 91)
3030

3131
#create a mempool tx that will be evicted
3232
us0 = utxos.pop()
@@ -41,9 +41,9 @@ def run_test(self):
4141

4242
relayfee = self.nodes[0].getnetworkinfo()['relayfee']
4343
base_fee = relayfee*100
44-
for i in range (4):
44+
for i in range (3):
4545
txids.append([])
46-
txids[i] = create_lots_of_big_transactions(self.nodes[0], self.txouts, utxos[30*i:30*i+30], (i+1)*base_fee)
46+
txids[i] = create_lots_of_big_transactions(self.nodes[0], self.txouts, utxos[30*i:30*i+30], 30, (i+1)*base_fee)
4747

4848
# by now, the tx should be evicted, check confirmation state
4949
assert(txid not in self.nodes[0].getrawmempool())

qa/rpc-tests/prioritise_transaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def run_test(self):
3939
txids.append([])
4040
start_range = i * range_size
4141
end_range = start_range + range_size
42-
txids[i] = create_lots_of_big_transactions(self.nodes[0], self.txouts, utxos[start_range:end_range], (i+1)*base_fee)
42+
txids[i] = create_lots_of_big_transactions(self.nodes[0], self.txouts, utxos[start_range:end_range], end_range - start_range, (i+1)*base_fee)
4343

4444
# Make sure that the size of each group of transactions exceeds
4545
# MAX_BLOCK_BASE_SIZE -- otherwise the test needs to be revised to create

qa/rpc-tests/pruning.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
from test_framework.test_framework import BitcoinTestFramework
1515
from test_framework.util import *
16+
import time
17+
import os
18+
1619

1720
def calc_usage(blockdir):
1821
return sum(os.path.getsize(blockdir+f) for f in os.listdir(blockdir) if os.path.isfile(blockdir+f)) / (1024. * 1024.)
@@ -24,6 +27,10 @@ def __init__(self):
2427
self.setup_clean_chain = True
2528
self.num_nodes = 3
2629

30+
# Cache for utxos, as the listunspent may take a long time later in the test
31+
self.utxo_cache_0 = []
32+
self.utxo_cache_1 = []
33+
2734
def setup_network(self):
2835
self.nodes = []
2936
self.is_network_split = False
@@ -48,7 +55,7 @@ def create_big_chain(self):
4855
self.nodes[0].generate(150)
4956
# Then mine enough full blocks to create more than 550MiB of data
5057
for i in range(645):
51-
mine_large_block(self.nodes[0])
58+
mine_large_block(self.nodes[0], self.utxo_cache_0)
5259

5360
sync_blocks(self.nodes[0:3])
5461

@@ -60,7 +67,7 @@ def test_height_min(self):
6067
print("Mining 25 more blocks should cause the first block file to be pruned")
6168
# Pruning doesn't run until we're allocating another chunk, 20 full blocks past the height cutoff will ensure this
6269
for i in range(25):
63-
mine_large_block(self.nodes[0])
70+
mine_large_block(self.nodes[0], self.utxo_cache_0)
6471

6572
waitstart = time.time()
6673
while os.path.isfile(self.prunedir+"blk00000.dat"):
@@ -87,13 +94,13 @@ def create_chain_with_staleblocks(self):
8794
# Mine 24 blocks in node 1
8895
for i in range(24):
8996
if j == 0:
90-
mine_large_block(self.nodes[1])
97+
mine_large_block(self.nodes[1], self.utxo_cache_1)
9198
else:
9299
self.nodes[1].generate(1) #tx's already in mempool from previous disconnects
93100

94101
# Reorg back with 25 block chain from node 0
95102
for i in range(25):
96-
mine_large_block(self.nodes[0])
103+
mine_large_block(self.nodes[0], self.utxo_cache_0)
97104

98105
# Create connections in the order so both nodes can see the reorg at the same time
99106
connect_nodes(self.nodes[1], 0)

qa/rpc-tests/test_framework/util.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -654,10 +654,10 @@ def create_tx(node, coinbase, to_address, amount):
654654

655655
# Create a spend of each passed-in utxo, splicing in "txouts" to each raw
656656
# transaction to make it large. See gen_return_txouts() above.
657-
def create_lots_of_big_transactions(node, txouts, utxos, fee):
657+
def create_lots_of_big_transactions(node, txouts, utxos, num, fee):
658658
addr = node.getnewaddress()
659659
txids = []
660-
for _ in range(len(utxos)):
660+
for _ in range(num):
661661
t = utxos.pop()
662662
inputs=[{ "txid" : t["txid"], "vout" : t["vout"]}]
663663
outputs = {}
@@ -672,13 +672,17 @@ def create_lots_of_big_transactions(node, txouts, utxos, fee):
672672
txids.append(txid)
673673
return txids
674674

675-
def mine_large_block(node):
675+
def mine_large_block(node, utxos=None):
676676
# generate a 66k transaction,
677677
# and 14 of them is close to the 1MB block limit
678+
num = 14
678679
txouts = gen_return_txouts()
679-
utxos = node.listunspent()[:14]
680+
utxos = utxos if utxos is not None else []
681+
if len(utxos) < num:
682+
utxos.clear()
683+
utxos.extend(node.listunspent())
680684
fee = 100 * node.getnetworkinfo()["relayfee"]
681-
create_lots_of_big_transactions(node, txouts, utxos, fee=fee)
685+
create_lots_of_big_transactions(node, txouts, utxos, num, fee=fee)
682686
node.generate(1)
683687

684688
def get_bip9_status(node, key):

0 commit comments

Comments
 (0)