Skip to content

Commit

Permalink
test: check custom descendant limit in mempool_packages.py
Browse files Browse the repository at this point in the history
Summary:
> 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

Note: Core accepts one more descendant than we do, as of [[bitcoin/bitcoin#15681 | PR15681]] (change related to Lightning Network and bumping fees)

This is backport of Core [[bitcoin/bitcoin#17461 | PR17461]]

Test Plan: `ninja && test/functional/test_runner.py mempool_packages`

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D8770
  • Loading branch information
theStack authored and PiRK committed Jan 8, 2021
1 parent 9f3f4dd commit 0ea7b89
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions test/functional/mempool_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
assert_equal,
assert_raises_rpc_error,
satoshi_round,
wait_until,
)

# default limits
Expand All @@ -20,15 +21,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
common_params = ["-maxorphantx=1000"]
self.extra_args = [
common_params, common_params +
["-limitancestorcount={}".format(MAX_ANCESTORS_CUSTOM)]]
[
"-maxorphantx=1000",
# immediate tx relay
"-whitelist=noban@127.0.0.1",
],
[
"-maxorphantx=1000",
"-limitancestorcount={}".format(MAX_ANCESTORS_CUSTOM),
"-limitdescendantcount={}".format(MAX_DESCENDANTS_CUSTOM),
],
]

def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
Expand Down Expand Up @@ -246,10 +257,14 @@ def run_test(self):

# Sign and send up to MAX_DESCENDANT transactions chained off the
# parent tx
# Save sent txs for the purpose of checking node1's mempool later
# (see below)
chain = []
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):
Expand All @@ -270,7 +285,21 @@ def run_test(self):
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 + 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 - 1]:
assert tx in mempool1
for tx in chain[MAX_DESCENDANTS_CUSTOM - 1:]:
assert tx not in mempool1
# TODO: more detailed check of node1's mempool (fees etc.)

# TODO: test descendant size limits

Expand Down

0 comments on commit 0ea7b89

Please sign in to comment.