Skip to content

Commit b902bd6

Browse files
committed
test: check custom descendant limit in mempool_packages.py
To test the custom descendant limit on node1 (passed by the argument -limitdescendantcount), we check for four conditions: -> the # of txs in the node1 mempool is equal to the limit (plus 1 for the parent tx, plus the # txs from the previous ancestor test which are still in) -> all txs in node1 mempool are a subset of txs in node0 mempool -> part of the constructed descendant-chain (the first ones up to the limit) are contained in node1 mempool -> the remaining part of the constructed descendant-chain (all after the first ones up to the limit) is *not* contained in node1 mempool
1 parent e5d47ed commit b902bd6

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

test/functional/mempool_packages.py

+29-3
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,30 @@
1212
assert_equal,
1313
assert_raises_rpc_error,
1414
satoshi_round,
15+
wait_until,
1516
)
1617

1718
# default limits
1819
MAX_ANCESTORS = 25
1920
MAX_DESCENDANTS = 25
2021
# custom limits for node1
2122
MAX_ANCESTORS_CUSTOM = 5
23+
MAX_DESCENDANTS_CUSTOM = 10
24+
assert MAX_DESCENDANTS_CUSTOM >= MAX_ANCESTORS_CUSTOM
2225

2326
class MempoolPackagesTest(BitcoinTestFramework):
2427
def set_test_params(self):
2528
self.num_nodes = 2
2629
self.extra_args = [
27-
["-maxorphantx=1000"],
28-
["-maxorphantx=1000", "-limitancestorcount={}".format(MAX_ANCESTORS_CUSTOM)],
30+
[
31+
"-maxorphantx=1000",
32+
"[email protected]", # immediate tx relay
33+
],
34+
[
35+
"-maxorphantx=1000",
36+
"-limitancestorcount={}".format(MAX_ANCESTORS_CUSTOM),
37+
"-limitdescendantcount={}".format(MAX_DESCENDANTS_CUSTOM),
38+
],
2939
]
3040

3141
def skip_test_if_missing_module(self):
@@ -219,9 +229,11 @@ def run_test(self):
219229
transaction_package.append({'txid': txid, 'vout': i, 'amount': sent_value})
220230

221231
# Sign and send up to MAX_DESCENDANT transactions chained off the parent tx
232+
chain = [] # save sent txs for the purpose of checking node1's mempool later (see below)
222233
for i in range(MAX_DESCENDANTS - 1):
223234
utxo = transaction_package.pop(0)
224235
(txid, sent_value) = self.chain_transaction(self.nodes[0], utxo['txid'], utxo['vout'], utxo['amount'], fee, 10)
236+
chain.append(txid)
225237
if utxo['txid'] is parent_transaction:
226238
tx_children.append(txid)
227239
for j in range(10):
@@ -238,7 +250,21 @@ def run_test(self):
238250
utxo = transaction_package.pop(0)
239251
assert_raises_rpc_error(-26, "too-long-mempool-chain", self.chain_transaction, self.nodes[0], utxo['txid'], utxo['vout'], utxo['amount'], fee, 10)
240252

241-
# TODO: check that node1's mempool is as expected
253+
# Check that node1's mempool is as expected, containing:
254+
# - txs from previous ancestor test (-> custom ancestor limit)
255+
# - parent tx for descendant test
256+
# - txs chained off parent tx (-> custom descendant limit)
257+
wait_until(lambda: len(self.nodes[1].getrawmempool(False)) ==
258+
MAX_ANCESTORS_CUSTOM + 1 + MAX_DESCENDANTS_CUSTOM, timeout=10)
259+
mempool0 = self.nodes[0].getrawmempool(False)
260+
mempool1 = self.nodes[1].getrawmempool(False)
261+
assert set(mempool1).issubset(set(mempool0))
262+
assert parent_transaction in mempool1
263+
for tx in chain[:MAX_DESCENDANTS_CUSTOM]:
264+
assert tx in mempool1
265+
for tx in chain[MAX_DESCENDANTS_CUSTOM:]:
266+
assert tx not in mempool1
267+
# TODO: more detailed check of node1's mempool (fees etc.)
242268

243269
# TODO: test descendant size limits
244270

0 commit comments

Comments
 (0)