diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -462,6 +462,7 @@ noui.cpp outputtype.cpp policy/fees.cpp + policy/mempool.cpp policy/policy.cpp pow.cpp rest.cpp diff --git a/src/Makefile.am b/src/Makefile.am --- a/src/Makefile.am +++ b/src/Makefile.am @@ -282,6 +282,7 @@ noui.cpp \ outputtype.cpp \ policy/fees.cpp \ + policy/mempool.cpp \ policy/policy.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 @@ -109,6 +109,7 @@ 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/policy/mempool.h b/src/policy/mempool.h --- a/src/policy/mempool.h +++ b/src/policy/mempool.h @@ -4,8 +4,16 @@ #ifndef BITCOIN_POLICY_MEMPOOL_H #define BITCOIN_POLICY_MEMPOOL_H +#include + +class CBlockIndex; +namespace Consensus { +struct Params; +} + /** 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; /** * Default for -limitancestorsize, maximum kilobytes of tx + all in-mempool * ancestors. @@ -13,10 +21,17 @@ static const 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; /** * 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 new file mode 100644 --- /dev/null +++ b/src/policy/mempool.cpp @@ -0,0 +1,19 @@ +// 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 + +#include + +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 @@ -119,6 +119,7 @@ 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 new file mode 100644 --- /dev/null +++ b/src/test/mempool_policy_tests.cpp @@ -0,0 +1,54 @@ +// 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 +#include +#include +#include +#include + +#include + +#include + +BOOST_FIXTURE_TEST_SUITE(mempool_policy_tests, BasicTestingSetup) + +static void SetMTP(std::array &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 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()