diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -743,8 +743,10 @@ true, OptionsCategory::DEBUG_TEST); gArgs.AddArg("-limitancestorcount=", strprintf("Do not accept transactions if number of in-mempool " - "ancestors is or more (default: %u)", - DEFAULT_ANCESTOR_LIMIT), + "ancestors is or more (pre-fork default: %u, " + "post-fork default: %u)", + DEFAULT_ANCESTOR_LIMIT, + DEFAULT_ANCESTOR_LIMIT_LONGER), true, OptionsCategory::DEBUG_TEST); gArgs.AddArg( "-limitancestorsize=", @@ -755,8 +757,9 @@ gArgs.AddArg( "-limitdescendantcount=", strprintf("Do not accept transactions if any ancestor would have " - "or more in-mempool descendants (default: %u)", - DEFAULT_DESCENDANT_LIMIT), + "or more in-mempool descendants (default pre-fork: %u, " + "default post-fork: %u)", + DEFAULT_DESCENDANT_LIMIT, DEFAULT_DESCENDANT_LIMIT_LONGER), true, OptionsCategory::DEBUG_TEST); gArgs.AddArg( "-limitdescendantsize=", diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -742,13 +742,15 @@ // Calculate in-mempool ancestors, up to a limit. CTxMemPool::setEntries setAncestors; - size_t nLimitAncestors = - gArgs.GetArg("-limitancestorcount", DEFAULT_ANCESTOR_LIMIT); + size_t nLimitAncestors = gArgs.GetArg( + "-limitancestorcount", + GetDefaultAncestorLimit(consensusParams, chainActive.Tip())); size_t nLimitAncestorSize = gArgs.GetArg("-limitancestorsize", DEFAULT_ANCESTOR_SIZE_LIMIT) * 1000; - size_t nLimitDescendants = - gArgs.GetArg("-limitdescendantcount", DEFAULT_DESCENDANT_LIMIT); + size_t nLimitDescendants = gArgs.GetArg( + "-limitdescendantcount", + GetDefaultDescendantLimit(consensusParams, chainActive.Tip())); size_t nLimitDescendantSize = gArgs.GetArg("-limitdescendantsize", DEFAULT_DESCENDANT_SIZE_LIMIT) * diff --git a/test/functional/mempool_packages.py b/test/functional/mempool_packages.py --- a/test/functional/mempool_packages.py +++ b/test/functional/mempool_packages.py @@ -16,15 +16,25 @@ sync_mempools, ) -MAX_ANCESTORS = 25 -MAX_DESCENDANTS = 25 +# TODO: The activation code can be reverted after the new policy becomes +# active. We don't need to test the old policy anymore then. + +# Phonon dummy activation time +ACTIVATION_TIME = 2000000000 + +# Replay protection time needs to be moved beyond phonon activation +REPLAY_PROTECTION_TIME = ACTIVATION_TIME * 2 class MempoolPackagesTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 2 - self.extra_args = [["-maxorphantx=1000"], - ["-maxorphantx=1000", "-limitancestorcount=5"]] + + common_params = ["-phononactivationtime={}".format(ACTIVATION_TIME), + "-replayprotectionactivationtime={}".format(REPLAY_PROTECTION_TIME)] + + self.extra_args = [common_params + ["-maxorphantx=1000"], + common_params + ["-maxorphantx=1000", "-limitancestorcount=5"]] def skip_test_if_missing_module(self): self.skip_if_no_wallet() @@ -47,32 +57,43 @@ return (txid, send_value) def run_test(self): + # Pre-phonon test + [n.setmocktime(ACTIVATION_TIME - 10000) for n in self.nodes] + self.run_mempool_test(max_ancestors=25, max_descendants=25) + + # Post-phonon test + [n.setmocktime(ACTIVATION_TIME) for n in self.nodes] + self.run_mempool_test(max_ancestors=50, max_descendants=50) + + def run_mempool_test(self, *, max_ancestors, max_descendants): # Mine some blocks and have them mature. self.nodes[0].generate(101) - utxo = self.nodes[0].listunspent(10) + utxo = self.nodes[0].listunspent( + minconf=10, query_options={ + 'minimumAmount': 50}) txid = utxo[0]['txid'] vout = utxo[0]['vout'] value = utxo[0]['amount'] fee = Decimal("0.0001") - # MAX_ANCESTORS transactions off a confirmed tx should be fine + # max_ancestors transactions off a confirmed tx should be fine chain = [] - for i in range(MAX_ANCESTORS): + for i in range(max_ancestors): (txid, sent_value) = self.chain_transaction( self.nodes[0], txid, 0, value, fee, 1) value = sent_value chain.append(txid) - # Check mempool has MAX_ANCESTORS transactions in it, and descendant and ancestor + # Check mempool has max_ancestors transactions in it, and descendant and ancestor # count and fees should look correct mempool = self.nodes[0].getrawmempool(True) - assert_equal(len(mempool), MAX_ANCESTORS) + assert_equal(len(mempool), max_ancestors) descendant_count = 1 descendant_fees = 0 descendant_size = 0 ancestor_size = sum([mempool[tx]['size'] for tx in mempool]) - ancestor_count = MAX_ANCESTORS + ancestor_count = max_ancestors ancestor_fees = sum([mempool[tx]['fee'] for tx in mempool]) descendants = [] @@ -235,7 +256,7 @@ # Sign and send up to MAX_DESCENDANT transactions chained off the # parent tx - for i in range(MAX_DESCENDANTS - 1): + 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) @@ -247,7 +268,7 @@ mempool = self.nodes[0].getrawmempool(True) assert_equal(mempool[parent_transaction] - ['descendantcount'], MAX_DESCENDANTS) + ['descendantcount'], max_descendants) assert_equal(sorted(mempool[parent_transaction] ['spentby']), sorted(tx_children)) @@ -284,7 +305,7 @@ # last block. # Create tx0 with 2 outputs - utxo = self.nodes[0].listunspent() + utxo = self.nodes[0].listunspent(query_options={'minimumAmount': 50}) txid = utxo[0]['txid'] value = utxo[0]['amount'] vout = utxo[0]['vout']