diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -525,7 +525,6 @@ node/transaction.cpp noui.cpp policy/fees.cpp - policy/mempool.cpp policy/settings.cpp pow.cpp rest.cpp diff --git a/src/Makefile.am b/src/Makefile.am --- a/src/Makefile.am +++ b/src/Makefile.am @@ -323,7 +323,6 @@ node/transaction.cpp \ noui.cpp \ policy/fees.cpp \ - policy/mempool.cpp \ policy/settings.cpp \ pow.cpp \ rest.cpp \ diff --git a/src/Makefile.test.include b/src/Makefile.test.include --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -137,7 +137,6 @@ test/lcg_tests.cpp \ test/lcg.h \ test/limitedmap_tests.cpp \ - test/mempool_policy_tests.cpp \ test/mempool_tests.cpp \ test/merkle_tests.cpp \ test/merkleblock_tests.cpp \ diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -865,10 +865,8 @@ OptionsCategory::DEBUG_TEST); gArgs.AddArg("-limitancestorcount=<n>", strprintf("Do not accept transactions if number of in-mempool " - "ancestors is <n> or more (pre-phonon-upgrade " - "default: %u, post-phonon-upgrade default: %u)", - DEFAULT_ANCESTOR_LIMIT, - DEFAULT_ANCESTOR_LIMIT_LONGER), + "ancestors is <n> or more (default: %u)", + DEFAULT_ANCESTOR_LIMIT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); gArgs.AddArg( @@ -881,9 +879,8 @@ gArgs.AddArg( "-limitdescendantcount=<n>", strprintf("Do not accept transactions if any ancestor would have <n> " - "or more in-mempool descendants (default pre-phonon-upgrade: " - "%u, default post-phonon-upgrade: %u)", - DEFAULT_DESCENDANT_LIMIT, DEFAULT_DESCENDANT_LIMIT_LONGER), + "or more in-mempool descendants (default: %u)", + DEFAULT_DESCENDANT_LIMIT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); gArgs.AddArg( diff --git a/src/policy/mempool.h b/src/policy/mempool.h --- a/src/policy/mempool.h +++ b/src/policy/mempool.h @@ -12,26 +12,18 @@ } /** Default for -limitancestorcount, max number of in-mempool ancestors */ -static const unsigned int DEFAULT_ANCESTOR_LIMIT = 25; -static const unsigned int DEFAULT_ANCESTOR_LIMIT_LONGER = 50; +static constexpr unsigned int DEFAULT_ANCESTOR_LIMIT = 50; /** * Default for -limitancestorsize, maximum kilobytes of tx + all in-mempool * ancestors. */ -static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT = 101; +static constexpr unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT = 101; /** Default for -limitdescendantcount, max number of in-mempool descendants */ -static const unsigned int DEFAULT_DESCENDANT_LIMIT = 25; -static const unsigned int DEFAULT_DESCENDANT_LIMIT_LONGER = 50; +static constexpr unsigned int DEFAULT_DESCENDANT_LIMIT = 50; /** * Default for -limitdescendantsize, maximum kilobytes of in-mempool * descendants. */ static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT = 101; -uint32_t GetDefaultAncestorLimit(const Consensus::Params ¶ms, - const CBlockIndex *pindexPrev); - -uint32_t GetDefaultDescendantLimit(const Consensus::Params ¶ms, - const CBlockIndex *pindexPrev); - #endif // BITCOIN_POLICY_MEMPOOL_H diff --git a/src/policy/mempool.cpp b/src/policy/mempool.cpp deleted file mode 100644 --- a/src/policy/mempool.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) 2020 The Bitcoin developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include <policy/mempool.h> - -#include <consensus/activation.h> - -uint32_t GetDefaultAncestorLimit(const Consensus::Params ¶ms, - const CBlockIndex *pindexPrev) { - return IsPhononEnabled(params, pindexPrev) ? DEFAULT_ANCESTOR_LIMIT_LONGER - : DEFAULT_ANCESTOR_LIMIT; -} - -uint32_t GetDefaultDescendantLimit(const Consensus::Params ¶ms, - const CBlockIndex *pindexPrev) { - return IsPhononEnabled(params, pindexPrev) ? DEFAULT_DESCENDANT_LIMIT_LONGER - : DEFAULT_DESCENDANT_LIMIT; -} diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -140,7 +140,6 @@ key_tests.cpp lcg_tests.cpp limitedmap_tests.cpp - mempool_policy_tests.cpp mempool_tests.cpp merkle_tests.cpp merkleblock_tests.cpp diff --git a/src/test/mempool_policy_tests.cpp b/src/test/mempool_policy_tests.cpp deleted file mode 100644 --- a/src/test/mempool_policy_tests.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) 2019-2020 The Bitcoin developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include <chain.h> -#include <chainparams.h> -#include <consensus/activation.h> -#include <policy/mempool.h> -#include <util/system.h> - -#include <test/util/setup_common.h> - -#include <boost/test/unit_test.hpp> - -BOOST_FIXTURE_TEST_SUITE(mempool_policy_tests, BasicTestingSetup) - -static void SetMTP(std::array<CBlockIndex, 12> &blocks, int64_t mtp) { - size_t len = blocks.size(); - - for (size_t i = 0; i < len; ++i) { - blocks[i].nTime = mtp + (i - (len / 2)); - } - - BOOST_CHECK_EQUAL(blocks.back().GetMedianTimePast(), mtp); -} - -BOOST_AUTO_TEST_CASE(mempool_policy_activation_tests) { - CBlockIndex prev; - - const Consensus::Params ¶ms = Params().GetConsensus(); - const auto activation = - gArgs.GetArg("-phononactivationtime", params.phononActivationTime); - SetMockTime(activation - 1000000); - - std::array<CBlockIndex, 12> blocks; - for (size_t i = 1; i < blocks.size(); ++i) { - blocks[i].pprev = &blocks[i - 1]; - } - SetMTP(blocks, activation - 1); - BOOST_CHECK(!IsPhononEnabled(params, &blocks.back())); - BOOST_CHECK_EQUAL(DEFAULT_ANCESTOR_LIMIT, - GetDefaultAncestorLimit(params, &blocks.back())); - BOOST_CHECK_EQUAL(DEFAULT_DESCENDANT_LIMIT, - GetDefaultDescendantLimit(params, &blocks.back())); - - SetMTP(blocks, activation); - BOOST_CHECK(IsPhononEnabled(params, &blocks.back())); - BOOST_CHECK_EQUAL(DEFAULT_ANCESTOR_LIMIT_LONGER, - GetDefaultAncestorLimit(params, &blocks.back())); - BOOST_CHECK_EQUAL(DEFAULT_DESCENDANT_LIMIT_LONGER, - GetDefaultDescendantLimit(params, &blocks.back())); -} - -BOOST_AUTO_TEST_SUITE_END() diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -559,15 +559,13 @@ // Calculate in-mempool ancestors, up to a limit. CTxMemPool::setEntries setAncestors; - size_t nLimitAncestors = gArgs.GetArg( - "-limitancestorcount", - GetDefaultAncestorLimit(consensusParams, ::ChainActive().Tip())); + size_t nLimitAncestors = + gArgs.GetArg("-limitancestorcount", DEFAULT_ANCESTOR_LIMIT); size_t nLimitAncestorSize = gArgs.GetArg("-limitancestorsize", DEFAULT_ANCESTOR_SIZE_LIMIT) * 1000; - size_t nLimitDescendants = gArgs.GetArg( - "-limitdescendantcount", - GetDefaultDescendantLimit(consensusParams, ::ChainActive().Tip())); + size_t nLimitDescendants = + gArgs.GetArg("-limitdescendantcount", DEFAULT_DESCENDANT_LIMIT); size_t nLimitDescendantSize = gArgs.GetArg("-limitdescendantsize", DEFAULT_DESCENDANT_SIZE_LIMIT) * diff --git a/test/functional/abc-phonon-mempoolpolicy.py b/test/functional/abc-phonon-mempoolpolicy.py deleted file mode 100755 --- a/test/functional/abc-phonon-mempoolpolicy.py +++ /dev/null @@ -1,283 +0,0 @@ -#!/usr/bin/env python3 -# Copyright (c) 2020 The Bitcoin developers -# Distributed under the MIT software license, see the accompanying -# file COPYING or http://www.opensource.org/licenses/mit-license.php. - -"""Test ancestor and descendants policies around phonon-activation.""" - -from test_framework.blocktools import ( - create_block, - create_coinbase, - create_tx_with_script, - make_conform_to_ctor, -) -from test_framework.txtools import pad_tx -from test_framework.messages import ( - CBlock, - COutPoint, - CTransaction, - CTxIn, - CTxOut, - FromHex, - ToHex, -) -from test_framework.mininode import ( - P2PDataStore, -) -from test_framework.script import ( - CScript, - OP_TRUE -) -from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, assert_raises_rpc_error - -# Phonon dummy activation time -PHONON_START_TIME = 2000000000 - -# Replay protection time needs to be moved beyond phonon activation -REPLAY_PROTECTION_TIME = PHONON_START_TIME * 2 - -PREFORK_MAX_ANCESTORS = 25 -PREFORK_MAX_DESCENDANTS = 25 -POSTFORK_MAX_ANCESTORS = 50 -POSTFORK_MAX_DESCENDANTS = 50 - -LONG_MEMPOOL_ERROR = "too-long-mempool-chain" - - -class PhononPolicyChangeTest(BitcoinTestFramework): - def set_test_params(self): - self.num_nodes = 1 - - self.block_heights = {} - self.extra_args = [[ - "-phononactivationtime={}".format(PHONON_START_TIME), - "-replayprotectionactivationtime={}".format( - REPLAY_PROTECTION_TIME), - "-acceptnonstdtxn=1"]] - - def bootstrap_p2p(self): - self.nodes[0].add_p2p_connection(P2PDataStore()) - self.nodes[0].p2p.wait_for_verack() - - def get_best_block(self, node): - """Get the best block. Register its height so we can use build_block.""" - block_height = node.getblockcount() - blockhash = node.getblockhash(block_height) - block = FromHex(CBlock(), node.getblock(blockhash, 0)) - block.calc_sha256() - self.block_heights[block.sha256] = block_height - return block - - def check_for_no_ban_on_rejected_tx(self, tx, reject_reason): - """Check we are not disconnected when sending a txn that the node rejects.""" - self.nodes[0].p2p.send_txs_and_test( - [tx], self.nodes[0], success=False, reject_reason=reject_reason) - - def build_block(self, parent, transactions=(), n_time=None): - """Make a new block with an OP_1 coinbase output. - - Requires parent to have its height registered.""" - parent.calc_sha256() - block_height = self.block_heights[parent.sha256] + 1 - block_time = (parent.nTime + 1) if n_time is None else n_time - - block = create_block( - parent.sha256, create_coinbase(block_height), block_time) - block.vtx.extend(transactions) - make_conform_to_ctor(block) - block.hashMerkleRoot = block.calc_merkle_root() - block.solve() - self.block_heights[block.sha256] = block_height - return block - - def build_ancestor_chain(self, spend_from, num_ancestors): - fee = 1000 - chain = [spend_from] - for _ in range(num_ancestors): - parent_tx = chain[-1] - tx = create_tx_with_script( - parent_tx, - n=0, - amount=parent_tx.vout[0].nValue - - fee, - script_pub_key=CScript( - [OP_TRUE])) - chain.append(tx) - - return chain[1:] - - def build_descendants_chain(self, spend_from, num_descendants): - # -1 as parent counts toward descendants - num_descendants -= 1 - fee = 1000 - descendants = [] - - parent_tx = CTransaction() - parent_tx.vin.append( - CTxIn( - COutPoint( - spend_from.sha256, - 0), - b'', - 0xffffffff)) - amount = (spend_from.vout[0].nValue - fee) // num_descendants - - for _ in range(num_descendants): - parent_tx.vout.append(CTxOut(amount, CScript([OP_TRUE]))) - pad_tx(parent_tx) - parent_tx.rehash() - - for n in range(num_descendants): - child_tx = create_tx_with_script( - parent_tx, n=n, amount=parent_tx.vout[0].nValue - fee) - descendants.append(child_tx) - - assert(len(descendants) == num_descendants) - - return [parent_tx] + descendants - - def run_test(self): - node, = self.nodes - - self.bootstrap_p2p() - - tip = self.get_best_block(node) - - self.log.info("Create some blocks with OP_1 coinbase for spending.") - blocks = [] - for _ in range(10): - tip = self.build_block(tip) - blocks.append(tip) - node.p2p.send_blocks_and_test(blocks, node, success=True) - spendable_outputs = [block.vtx[0] for block in blocks] - - self.log.info("Mature the blocks and get out of IBD.") - node.generatetoaddress(100, node.get_deterministic_priv_key().address) - - tip = self.get_best_block(node) - self.log.info("Start pre-upgrade tests") - - # Test pre-upgrade max ancestor limit. - # We create the full post-fork length chain for use later (+1 to test - # too long chain) - ancestors = self.build_ancestor_chain( - spendable_outputs.pop(0), POSTFORK_MAX_ANCESTORS + 1) - [node.sendrawtransaction(ToHex(tx)) - for tx in ancestors[:PREFORK_MAX_ANCESTORS]] - - self.log.info( - "Sending rejected transaction (too many ancestors) via RPC") - assert_raises_rpc_error(-26, - LONG_MEMPOOL_ERROR, - node.sendrawtransaction, - ToHex(ancestors[PREFORK_MAX_ANCESTORS])) - - self.log.info( - "Sending rejected transaction (too many ancestors) via net") - self.check_for_no_ban_on_rejected_tx( - ancestors[PREFORK_MAX_ANCESTORS], LONG_MEMPOOL_ERROR) - - # Test pre-upgrade max descendants limit - # We create the full post-fork length chain for use later (+1 to test - # too long chain) - descendants = self.build_descendants_chain( - spendable_outputs.pop(0), POSTFORK_MAX_DESCENDANTS + 1) - [node.sendrawtransaction(ToHex(tx)) - for tx in descendants[:PREFORK_MAX_DESCENDANTS]] - - self.log.info( - "Sending rejected transaction (too many descendants) via RPC") - assert_raises_rpc_error(-26, - LONG_MEMPOOL_ERROR, - node.sendrawtransaction, - ToHex(descendants[PREFORK_MAX_DESCENDANTS])) - - self.log.info( - "Sending rejected transaction (too many descendants) via net") - self.check_for_no_ban_on_rejected_tx( - descendants[PREFORK_MAX_DESCENDANTS], LONG_MEMPOOL_ERROR) - - self.log.info("Start activation tests") - - self.log.info("Approach to just before upgrade activation") - # Move our clock to the upgrade time so we will accept such - # future-timestamped blocks. - node.setmocktime(PHONON_START_TIME) - - # Mine six blocks with timestamp starting at PHONON_START_TIME-1 - blocks = [] - for i in range(-1, 5): - tip = self.build_block(tip, n_time=PHONON_START_TIME + i) - blocks.append(tip) - node.p2p.send_blocks_and_test(blocks, node) - - # Ensure our MTP is PHONON_START_TIME-1, just before activation - assert_equal(node.getblockchaininfo()['mediantime'], - PHONON_START_TIME - 1) - - self.log.info( - "The next block will activate, but at the activation block itself must follow old rules") - - self.check_for_no_ban_on_rejected_tx( - ancestors[PREFORK_MAX_ANCESTORS], LONG_MEMPOOL_ERROR) - self.check_for_no_ban_on_rejected_tx( - descendants[PREFORK_MAX_DESCENDANTS], LONG_MEMPOOL_ERROR) - - # Save pre-upgrade block, we will reorg based on this block later - pre_upgrade_block = tip - - self.log.info("Mine the activation block itself") - tip = self.build_block(tip, []) - node.p2p.send_blocks_and_test([tip], node) - - self.log.info("We have activated!") - # Ensure our MTP is PHONON_START_TIME, exactly at activation - assert_equal(node.getblockchaininfo()['mediantime'], PHONON_START_TIME) - - # Test post-upgrade max ancestor limit - [node.sendrawtransaction( - ToHex(tx)) for tx in ancestors[PREFORK_MAX_ANCESTORS:POSTFORK_MAX_ANCESTORS]] - - self.log.info( - "Sending rejected transaction (too many ancestors) via RPC") - assert_raises_rpc_error(-26, - LONG_MEMPOOL_ERROR, - node.sendrawtransaction, - ToHex(ancestors[-1])) - - self.log.info( - "Sending rejected transaction (too many ancestors) via net") - self.check_for_no_ban_on_rejected_tx(ancestors[-1], LONG_MEMPOOL_ERROR) - - # Test post-upgrade max descendants limit - [node.sendrawtransaction(ToHex( - tx)) for tx in descendants[PREFORK_MAX_DESCENDANTS:POSTFORK_MAX_DESCENDANTS]] - - self.log.info( - "Sending rejected transaction (too many descendants) via RPC") - assert_raises_rpc_error(-26, - LONG_MEMPOOL_ERROR, - node.sendrawtransaction, - ToHex(descendants[-1])) - - self.log.info( - "Sending rejected transaction (too many descendants) via net") - self.check_for_no_ban_on_rejected_tx( - descendants[-1], LONG_MEMPOOL_ERROR) - - self.log.info("Start deactivation tests") - - self.log.info( - "Invalidating the pre-upgrade blocks trims the mempool back to old policies") - node.invalidateblock(pre_upgrade_block.hash) - - assert_equal(PREFORK_MAX_ANCESTORS + - PREFORK_MAX_DESCENDANTS, len(node.getrawmempool())) - expected = set([tx.hash for tx in ancestors[:PREFORK_MAX_ANCESTORS] + - descendants[:PREFORK_MAX_ANCESTORS]]) - assert_equal(set(node.getrawmempool()), expected) - - -if __name__ == '__main__': - PhononPolicyChangeTest().main() diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -658,7 +658,7 @@ def check_script_prefixes(all_scripts): """Check that no more than `EXPECTED_VIOLATION_COUNT` of the test scripts don't start with one of the allowed name prefixes.""" - EXPECTED_VIOLATION_COUNT = 20 + EXPECTED_VIOLATION_COUNT = 19 # LEEWAY is provided as a transition measure, so that pull-requests # that introduce new tests that don't conform with the naming