Skip to content

Commit 251c535

Browse files
author
MacroFake
committed
Merge bitcoin/bitcoin#25810: scripted-diff: test: rename MAX_{ANCESTORS,DESCENDANTS} to DEFAULT_{ANCESTOR,DESCENDANT}_LIMIT
b4a5ab9 test: refactor: deduplicate `DEFAULT_{ANCESTOR,DESCENDANT}_LIMIT` constants (Sebastian Falbesoner) 0fda1c7 scripted-diff: test: rename `MAX_{ANCESTORS,DESCENDANTS}` to `DEFAULT_{ANCESTOR,DESCENDANT}_LIMIT` (Sebastian Falbesoner) Pull request description: This PR renames the default in-mempool max ancestors/descendants constants `MAX_ANCESTORS`/`MAX_DESCENDANTS` in the functional tests to match the ones in the codebase: https://github.com/bitcoin/bitcoin/blob/c012875b9ded0a5183602f002738ca823d559518/src/policy/policy.h#L58-L59 https://github.com/bitcoin/bitcoin/blob/c012875b9ded0a5183602f002738ca823d559518/src/policy/policy.h#L62-L63 The custom limit constants `MAX_ANCESTORS_CUSTOM`/`MAX_DESCENDANTS_CUSTOM` are also renamed accordingly to better fit to this naming style. In the second commit, the default constants are deduplicated by moving them into the `messages.py` module. (Not sure if this module is really appropriate, as it doesn't have a connection to messages. If someone has a good suggestion, would be glad to hear it.) ACKs for top commit: w0xlt: ACK bitcoin/bitcoin@b4a5ab9 glozow: utACK b4a5ab9 fanquake: ACK b4a5ab9 Tree-SHA512: a15c8256170afce3e383fceddcb562f588a02be97ce4202c84a2ebf22d73ab843f5e5a7d7c98e9ea044d8bcb7a4aeae0081d0e84c53e8fc0edffbcca00460139
2 parents f89ce1f + b4a5ab9 commit 251c535

File tree

3 files changed

+35
-30
lines changed

3 files changed

+35
-30
lines changed

test/functional/mempool_package_onemore.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
size.
88
"""
99

10+
from test_framework.messages import (
11+
DEFAULT_ANCESTOR_LIMIT,
12+
)
1013
from test_framework.test_framework import BitcoinTestFramework
1114
from test_framework.util import (
1215
assert_equal,
@@ -15,10 +18,6 @@
1518
from test_framework.wallet import MiniWallet
1619

1720

18-
MAX_ANCESTORS = 25
19-
MAX_DESCENDANTS = 25
20-
21-
2221
class MempoolPackagesTest(BitcoinTestFramework):
2322
def set_test_params(self):
2423
self.num_nodes = 1
@@ -34,19 +33,19 @@ def run_test(self):
3433
self.wallet = MiniWallet(self.nodes[0])
3534
self.wallet.rescan_utxos()
3635

37-
# MAX_ANCESTORS transactions off a confirmed tx should be fine
36+
# DEFAULT_ANCESTOR_LIMIT transactions off a confirmed tx should be fine
3837
chain = []
3938
utxo = self.wallet.get_utxo()
4039
for _ in range(4):
4140
utxo, utxo2 = self.chain_tx([utxo], num_outputs=2)
4241
chain.append(utxo2)
43-
for _ in range(MAX_ANCESTORS - 4):
42+
for _ in range(DEFAULT_ANCESTOR_LIMIT - 4):
4443
utxo, = self.chain_tx([utxo])
4544
chain.append(utxo)
4645
second_chain, = self.chain_tx([self.wallet.get_utxo()])
4746

48-
# Check mempool has MAX_ANCESTORS + 1 transactions in it
49-
assert_equal(len(self.nodes[0].getrawmempool()), MAX_ANCESTORS + 1)
47+
# Check mempool has DEFAULT_ANCESTOR_LIMIT + 1 transactions in it
48+
assert_equal(len(self.nodes[0].getrawmempool()), DEFAULT_ANCESTOR_LIMIT + 1)
5049

5150
# Adding one more transaction on to the chain should fail.
5251
assert_raises_rpc_error(-26, "too-long-mempool-chain, too many unconfirmed ancestors [limit: 25]", self.chain_tx, [utxo])
@@ -67,7 +66,7 @@ def run_test(self):
6766
self.nodes[0].sendrawtransaction(replacable_tx.serialize().hex())
6867

6968
# Finally, check that we added two transactions
70-
assert_equal(len(self.nodes[0].getrawmempool()), MAX_ANCESTORS + 3)
69+
assert_equal(len(self.nodes[0].getrawmempool()), DEFAULT_ANCESTOR_LIMIT + 3)
7170

7271

7372
if __name__ == '__main__':

test/functional/mempool_packages.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
from decimal import Decimal
88

99
from test_framework.blocktools import COINBASE_MATURITY
10-
from test_framework.messages import COIN
10+
from test_framework.messages import (
11+
COIN,
12+
DEFAULT_ANCESTOR_LIMIT,
13+
DEFAULT_DESCENDANT_LIMIT,
14+
)
1115
from test_framework.p2p import P2PTxInvStore
1216
from test_framework.test_framework import BitcoinTestFramework
1317
from test_framework.util import (
@@ -16,13 +20,12 @@
1620
chain_transaction,
1721
)
1822

19-
# default limits
20-
MAX_ANCESTORS = 25
21-
MAX_DESCENDANTS = 25
23+
2224
# custom limits for node1
23-
MAX_ANCESTORS_CUSTOM = 5
24-
MAX_DESCENDANTS_CUSTOM = 10
25-
assert MAX_DESCENDANTS_CUSTOM >= MAX_ANCESTORS_CUSTOM
25+
CUSTOM_ANCESTOR_LIMIT = 5
26+
CUSTOM_DESCENDANT_LIMIT = 10
27+
assert CUSTOM_DESCENDANT_LIMIT >= CUSTOM_ANCESTOR_LIMIT
28+
2629

2730
class MempoolPackagesTest(BitcoinTestFramework):
2831
def set_test_params(self):
@@ -34,8 +37,8 @@ def set_test_params(self):
3437
],
3538
[
3639
"-maxorphantx=1000",
37-
"-limitancestorcount={}".format(MAX_ANCESTORS_CUSTOM),
38-
"-limitdescendantcount={}".format(MAX_DESCENDANTS_CUSTOM),
40+
"-limitancestorcount={}".format(CUSTOM_ANCESTOR_LIMIT),
41+
"-limitdescendantcount={}".format(CUSTOM_DESCENDANT_LIMIT),
3942
],
4043
]
4144

@@ -55,12 +58,12 @@ def run_test(self):
5558
assert 'ancestorfees' not in utxo[0]
5659

5760
fee = Decimal("0.0001")
58-
# MAX_ANCESTORS transactions off a confirmed tx should be fine
61+
# DEFAULT_ANCESTOR_LIMIT transactions off a confirmed tx should be fine
5962
chain = []
6063
witness_chain = []
6164
ancestor_vsize = 0
6265
ancestor_fees = Decimal(0)
63-
for i in range(MAX_ANCESTORS):
66+
for i in range(DEFAULT_ANCESTOR_LIMIT):
6467
(txid, sent_value) = chain_transaction(self.nodes[0], [txid], [0], value, fee, 1)
6568
value = sent_value
6669
chain.append(txid)
@@ -81,16 +84,16 @@ def run_test(self):
8184
# Otherwise, getrawmempool may be inconsistent with getmempoolentry if unbroadcast changes in between
8285
peer_inv_store.wait_for_broadcast(witness_chain)
8386

84-
# Check mempool has MAX_ANCESTORS transactions in it, and descendant and ancestor
87+
# Check mempool has DEFAULT_ANCESTOR_LIMIT transactions in it, and descendant and ancestor
8588
# count and fees should look correct
8689
mempool = self.nodes[0].getrawmempool(True)
87-
assert_equal(len(mempool), MAX_ANCESTORS)
90+
assert_equal(len(mempool), DEFAULT_ANCESTOR_LIMIT)
8891
descendant_count = 1
8992
descendant_fees = 0
9093
descendant_vsize = 0
9194

9295
assert_equal(ancestor_vsize, sum([mempool[tx]['vsize'] for tx in mempool]))
93-
ancestor_count = MAX_ANCESTORS
96+
ancestor_count = DEFAULT_ANCESTOR_LIMIT
9497
assert_equal(ancestor_fees, sum([mempool[tx]['fees']['base'] for tx in mempool]))
9598

9699
descendants = []
@@ -213,9 +216,9 @@ def run_test(self):
213216
# Check that node1's mempool is as expected (-> custom ancestor limit)
214217
mempool0 = self.nodes[0].getrawmempool(False)
215218
mempool1 = self.nodes[1].getrawmempool(False)
216-
assert_equal(len(mempool1), MAX_ANCESTORS_CUSTOM)
219+
assert_equal(len(mempool1), CUSTOM_ANCESTOR_LIMIT)
217220
assert set(mempool1).issubset(set(mempool0))
218-
for tx in chain[:MAX_ANCESTORS_CUSTOM]:
221+
for tx in chain[:CUSTOM_ANCESTOR_LIMIT]:
219222
assert tx in mempool1
220223
# TODO: more detailed check of node1's mempool (fees etc.)
221224
# check transaction unbroadcast info (should be false if in both mempools)
@@ -240,7 +243,7 @@ def run_test(self):
240243

241244
# Sign and send up to MAX_DESCENDANT transactions chained off the parent tx
242245
chain = [] # save sent txs for the purpose of checking node1's mempool later (see below)
243-
for _ in range(MAX_DESCENDANTS - 1):
246+
for _ in range(DEFAULT_DESCENDANT_LIMIT - 1):
244247
utxo = transaction_package.pop(0)
245248
(txid, sent_value) = chain_transaction(self.nodes[0], [utxo['txid']], [utxo['vout']], utxo['amount'], fee, 10)
246249
chain.append(txid)
@@ -250,7 +253,7 @@ def run_test(self):
250253
transaction_package.append({'txid': txid, 'vout': j, 'amount': sent_value})
251254

252255
mempool = self.nodes[0].getrawmempool(True)
253-
assert_equal(mempool[parent_transaction]['descendantcount'], MAX_DESCENDANTS)
256+
assert_equal(mempool[parent_transaction]['descendantcount'], DEFAULT_DESCENDANT_LIMIT)
254257
assert_equal(sorted(mempool[parent_transaction]['spentby']), sorted(tx_children))
255258

256259
for child in tx_children:
@@ -265,14 +268,14 @@ def run_test(self):
265268
# - parent tx for descendant test
266269
# - txs chained off parent tx (-> custom descendant limit)
267270
self.wait_until(lambda: len(self.nodes[1].getrawmempool()) ==
268-
MAX_ANCESTORS_CUSTOM + 1 + MAX_DESCENDANTS_CUSTOM, timeout=10)
271+
CUSTOM_ANCESTOR_LIMIT + 1 + CUSTOM_DESCENDANT_LIMIT, timeout=10)
269272
mempool0 = self.nodes[0].getrawmempool(False)
270273
mempool1 = self.nodes[1].getrawmempool(False)
271274
assert set(mempool1).issubset(set(mempool0))
272275
assert parent_transaction in mempool1
273-
for tx in chain[:MAX_DESCENDANTS_CUSTOM]:
276+
for tx in chain[:CUSTOM_DESCENDANT_LIMIT]:
274277
assert tx in mempool1
275-
for tx in chain[MAX_DESCENDANTS_CUSTOM:]:
278+
for tx in chain[CUSTOM_DESCENDANT_LIMIT:]:
276279
assert tx not in mempool1
277280
# TODO: more detailed check of node1's mempool (fees etc.)
278281

test/functional/test_framework/messages.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565

6666
WITNESS_SCALE_FACTOR = 4
6767

68+
DEFAULT_ANCESTOR_LIMIT = 25 # default max number of in-mempool ancestors
69+
DEFAULT_DESCENDANT_LIMIT = 25 # default max number of in-mempool descendants
70+
6871

6972
def sha256(s):
7073
return hashlib.sha256(s).digest()

0 commit comments

Comments
 (0)