diff options
author | MarcoFalke <falke.marco@gmail.com> | 2020-02-28 03:02:14 +0700 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2020-02-28 03:02:24 +0700 |
commit | 1615043935ef9c185eb1dc5d2365d0460424bc7b (patch) | |
tree | e62b655e307f96bd783c66d12e03e861cfe0d6a0 /test/functional/mempool_packages.py | |
parent | 324a6dfeafcbee8d92231d23f15064edf12715b4 (diff) | |
parent | b902bd66b0f35c5016dc5d7aaf501940935edd62 (diff) |
Merge #17461: test: check custom descendant limit in mempool_packages.py
b902bd66b0f35c5016dc5d7aaf501940935edd62 test: check custom descendant limit in mempool_packages.py (Sebastian Falbesoner)
Pull request description:
This is a follow-up PR to #17435, testing the custom descendant limit, passed by the argument `-limitdescendantcount`. ~~It was more tricky than expected, mainly because we don't know for sure at which point node1 has got all the transactions broadcasted from node0 (for the ancestor test this wasn't a problem since the txs were immediately available through `invalidateblock`) -- a simple `sync_mempools()` doesn't work here since the mempool contents are not equal due to different ancestor/descendant limits. Hence I came up with a "hacky manual sync":~~
1. ~~wait until the mempool has the _expected_ tx count (see conditions below)~~
2. ~~after that, wait some time and get sure that the mempool contents haven't changed in-between~~
~~Like for~~ Similar to the ancestor test, we overall check for ~~three~~ four conditions:
- the # of txs in the node1 mempool is equal to the descendant limit (plus 1 for the parent tx, plus the # txs from the previous ancestor test which are still in) ~~(done by the hacky sync above)~~
- 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
ACKs for top commit:
JeremyRubin:
Excellent. utACK b902bd6
Tree-SHA512: 7de96dd248f16ab740e178ac5b64b57ead18cdcf74adfe989709d215e4a67b6b6d20de22c48e885d5f2edc55caaddd44a4261e996c5c87687ceb6a47f1d1fdaf
Diffstat (limited to 'test/functional/mempool_packages.py')
-rwxr-xr-x | test/functional/mempool_packages.py | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/test/functional/mempool_packages.py b/test/functional/mempool_packages.py index 7014105d88..a07dad18d6 100755 --- a/test/functional/mempool_packages.py +++ b/test/functional/mempool_packages.py @@ -12,6 +12,7 @@ from test_framework.util import ( assert_equal, assert_raises_rpc_error, satoshi_round, + wait_until, ) # default limits @@ -19,13 +20,22 @@ MAX_ANCESTORS = 25 MAX_DESCENDANTS = 25 # custom limits for node1 MAX_ANCESTORS_CUSTOM = 5 +MAX_DESCENDANTS_CUSTOM = 10 +assert MAX_DESCENDANTS_CUSTOM >= MAX_ANCESTORS_CUSTOM class MempoolPackagesTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 2 self.extra_args = [ - ["-maxorphantx=1000"], - ["-maxorphantx=1000", "-limitancestorcount={}".format(MAX_ANCESTORS_CUSTOM)], + [ + "-maxorphantx=1000", + "-whitelist=noban@127.0.0.1", # immediate tx relay + ], + [ + "-maxorphantx=1000", + "-limitancestorcount={}".format(MAX_ANCESTORS_CUSTOM), + "-limitdescendantcount={}".format(MAX_DESCENDANTS_CUSTOM), + ], ] def skip_test_if_missing_module(self): @@ -219,9 +229,11 @@ class MempoolPackagesTest(BitcoinTestFramework): transaction_package.append({'txid': txid, 'vout': i, 'amount': sent_value}) # Sign and send up to MAX_DESCENDANT transactions chained off the parent tx + chain = [] # save sent txs for the purpose of checking node1's mempool later (see below) for i in range(MAX_DESCENDANTS - 1): utxo = transaction_package.pop(0) (txid, sent_value) = self.chain_transaction(self.nodes[0], utxo['txid'], utxo['vout'], utxo['amount'], fee, 10) + chain.append(txid) if utxo['txid'] is parent_transaction: tx_children.append(txid) for j in range(10): @@ -238,7 +250,21 @@ class MempoolPackagesTest(BitcoinTestFramework): utxo = transaction_package.pop(0) assert_raises_rpc_error(-26, "too-long-mempool-chain", self.chain_transaction, self.nodes[0], utxo['txid'], utxo['vout'], utxo['amount'], fee, 10) - # TODO: check that node1's mempool is as expected + # Check that node1's mempool is as expected, containing: + # - txs from previous ancestor test (-> custom ancestor limit) + # - parent tx for descendant test + # - txs chained off parent tx (-> custom descendant limit) + wait_until(lambda: len(self.nodes[1].getrawmempool(False)) == + MAX_ANCESTORS_CUSTOM + 1 + MAX_DESCENDANTS_CUSTOM, timeout=10) + mempool0 = self.nodes[0].getrawmempool(False) + mempool1 = self.nodes[1].getrawmempool(False) + assert set(mempool1).issubset(set(mempool0)) + assert parent_transaction in mempool1 + for tx in chain[:MAX_DESCENDANTS_CUSTOM]: + assert tx in mempool1 + for tx in chain[MAX_DESCENDANTS_CUSTOM:]: + assert tx not in mempool1 + # TODO: more detailed check of node1's mempool (fees etc.) # TODO: test descendant size limits |