diff --git a/ci/dash/lint-tidy.sh b/ci/dash/lint-tidy.sh index d7d63656d842..757009610a9c 100755 --- a/ci/dash/lint-tidy.sh +++ b/ci/dash/lint-tidy.sh @@ -90,6 +90,7 @@ iwyu_tool.py \ "src/init" \ "src/kernel" \ "src/node/chainstate.cpp" \ + "src/node/mempool_args.cpp" \ "src/node/minisketchwrapper.cpp" \ "src/policy/feerate.cpp" \ "src/policy/packages.cpp" \ diff --git a/src/Makefile.am b/src/Makefile.am index 501a695cf852..1c2d3d57f68a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -320,7 +320,6 @@ BITCOIN_CORE_H = \ masternode/payments.h \ masternode/sync.h \ masternode/utils.h \ - mempool_args.h \ memusage.h \ merkleblock.h \ messagesigner.h \ @@ -342,6 +341,7 @@ BITCOIN_CORE_H = \ node/context.h \ node/eviction.h \ node/interface_ui.h \ + node/mempool_args.h \ node/mempool_persist_args.h \ node/miner.h \ node/minisketchwrapper.h \ @@ -596,7 +596,6 @@ libbitcoin_node_a_SOURCES = \ masternode/payments.cpp \ masternode/sync.cpp \ masternode/utils.cpp \ - mempool_args.cpp \ net.cpp \ net_processing.cpp \ netfulfilledman.cpp \ @@ -610,6 +609,7 @@ libbitcoin_node_a_SOURCES = \ node/eviction.cpp \ node/interface_ui.cpp \ node/interfaces.cpp \ + node/mempool_args.cpp \ node/mempool_persist_args.cpp \ node/miner.cpp \ node/minisketchwrapper.cpp \ diff --git a/src/Makefile.test_fuzz.include b/src/Makefile.test_fuzz.include index 9ad315beb0aa..e909ab9359c1 100644 --- a/src/Makefile.test_fuzz.include +++ b/src/Makefile.test_fuzz.include @@ -12,7 +12,7 @@ TEST_FUZZ_H = \ test/fuzz/FuzzedDataProvider.h \ test/fuzz/util.h \ test/util/mining.h \ - test/fuzz/mempool_utils.h \ + test/fuzz/util/mempool.h \ test/fuzz/util/net.h libtest_fuzz_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BOOST_CPPFLAGS) @@ -21,5 +21,6 @@ libtest_fuzz_a_SOURCES = \ test/fuzz/fuzz.cpp \ test/util/mining.cpp \ test/fuzz/util.cpp \ + test/fuzz/util/mempool.cpp \ test/fuzz/util/net.cpp \ $(TEST_FUZZ_H) diff --git a/src/index/addressindex.cpp b/src/index/addressindex.cpp index fbd862769580..fedbcefd7e7b 100644 --- a/src/index/addressindex.cpp +++ b/src/index/addressindex.cpp @@ -161,7 +161,7 @@ bool AddressIndex::DB::RewindBatch(const std::vector& addres } AddressIndex::AddressIndex(std::unique_ptr chain, size_t n_cache_size, bool f_memory, bool f_wipe) : - BaseIndex(std::move(chain)), + BaseIndex(std::move(chain), "addressindex"), m_db(std::make_unique(n_cache_size, f_memory, f_wipe)) { } diff --git a/src/index/addressindex.h b/src/index/addressindex.h index cce6c70517c4..443ac6cea58f 100644 --- a/src/index/addressindex.h +++ b/src/index/addressindex.h @@ -69,8 +69,6 @@ class AddressIndex final : public BaseIndex BaseIndex::DB& GetDB() const override; - const char* GetName() const override { return "addressindex"; } - public: /// Constructs the index, which becomes available to be queried explicit AddressIndex(std::unique_ptr chain, size_t n_cache_size, bool f_memory = false, bool f_wipe = false); diff --git a/src/index/base.cpp b/src/index/base.cpp index 139deb129f2d..b52ff2d11055 100644 --- a/src/index/base.cpp +++ b/src/index/base.cpp @@ -17,6 +17,9 @@ #include #include +#include +#include + using node::PruneLockInfo; using node::ReadBlockFromDisk; using node::fPruneMode; @@ -58,8 +61,8 @@ void BaseIndex::DB::WriteBestBlock(CDBBatch& batch, const CBlockLocator& locator batch.Write(DB_BEST_BLOCK, locator); } -BaseIndex::BaseIndex(std::unique_ptr chain) - : m_chain{std::move(chain)} {} +BaseIndex::BaseIndex(std::unique_ptr chain, std::string name) + : m_chain{std::move(chain)}, m_name{std::move(name)} {} BaseIndex::~BaseIndex() { diff --git a/src/index/base.h b/src/index/base.h index a2e0d941d776..daf411c8053b 100644 --- a/src/index/base.h +++ b/src/index/base.h @@ -12,6 +12,7 @@ #include #include +#include class CBlock; class CBlockIndex; @@ -98,6 +99,7 @@ class BaseIndex : public CValidationInterface protected: std::unique_ptr m_chain; Chainstate* m_chainstate{nullptr}; + const std::string m_name; void BlockConnected(const std::shared_ptr& block, const CBlockIndex* pindex) override; @@ -122,7 +124,7 @@ class BaseIndex : public CValidationInterface virtual DB& GetDB() const = 0; /// Get the name of the index for display in logs. - virtual const char* GetName() const = 0; + const std::string& GetName() const LIFETIMEBOUND { return m_name; } /// Trigger a fatal index error and initiate shutdown. static void FatalErrorImpl(const std::string& message); @@ -137,7 +139,7 @@ class BaseIndex : public CValidationInterface void SetBestBlockIndex(const CBlockIndex* block); public: - BaseIndex(std::unique_ptr chain); + BaseIndex(std::unique_ptr chain, std::string name); /// Destructor interrupts sync thread if running and blocks until it exits. virtual ~BaseIndex(); diff --git a/src/index/blockfilterindex.cpp b/src/index/blockfilterindex.cpp index 4b855000b489..3b66b634071c 100644 --- a/src/index/blockfilterindex.cpp +++ b/src/index/blockfilterindex.cpp @@ -105,7 +105,8 @@ static std::map g_filter_indexes; BlockFilterIndex::BlockFilterIndex(std::unique_ptr chain, BlockFilterType filter_type, size_t n_cache_size, bool f_memory, bool f_wipe) - : BaseIndex(std::move(chain)), m_filter_type(filter_type) + : BaseIndex(std::move(chain), BlockFilterTypeName(filter_type) + " block filter index") + , m_filter_type(filter_type) { const std::string& filter_name = BlockFilterTypeName(filter_type); if (filter_name.empty()) throw std::invalid_argument("unknown filter_type"); @@ -113,7 +114,6 @@ BlockFilterIndex::BlockFilterIndex(std::unique_ptr chain, Blo fs::path path = gArgs.GetDataDirNet() / "indexes" / "blockfilter" / fs::u8path(filter_name); fs::create_directories(path); - m_name = filter_name + " block filter index"; m_db = std::make_unique(path / "db", n_cache_size, f_memory, f_wipe); // Check version diff --git a/src/index/blockfilterindex.h b/src/index/blockfilterindex.h index 30a583b34267..5694ad22f2b5 100644 --- a/src/index/blockfilterindex.h +++ b/src/index/blockfilterindex.h @@ -31,7 +31,6 @@ class BlockFilterIndex final : public BaseIndex static constexpr int CURRENT_VERSION = 2; BlockFilterType m_filter_type; - std::string m_name; std::unique_ptr m_db; FlatFilePos m_next_filter_pos; @@ -57,8 +56,6 @@ class BlockFilterIndex final : public BaseIndex BaseIndex::DB& GetDB() const LIFETIMEBOUND override { return *m_db; } - const char* GetName() const LIFETIMEBOUND override { return m_name.c_str(); } - public: /** Constructs the index, which becomes available to be queried. */ explicit BlockFilterIndex(std::unique_ptr chain, BlockFilterType filter_type, diff --git a/src/index/coinstatsindex.cpp b/src/index/coinstatsindex.cpp index 54481366f250..59c9cf99a863 100644 --- a/src/index/coinstatsindex.cpp +++ b/src/index/coinstatsindex.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -105,7 +106,7 @@ struct DBHashKey { std::unique_ptr g_coin_stats_index; CoinStatsIndex::CoinStatsIndex(std::unique_ptr chain, size_t n_cache_size, bool f_memory, bool f_wipe) - : BaseIndex(std::move(chain)) + : BaseIndex(std::move(chain), "coinstatsindex") { fs::path path{gArgs.GetDataDirNet() / "indexes" / "coinstats"}; fs::create_directories(path); @@ -315,13 +316,13 @@ static bool LookUpOne(const CDBWrapper& db, const interfaces::BlockKey& block, D return db.Read(DBHashKey(block.hash), result); } -std::optional CoinStatsIndex::LookUpStats(const CBlockIndex* block_index) const +std::optional CoinStatsIndex::LookUpStats(const CBlockIndex& block_index) const { - CCoinsStats stats{Assert(block_index)->nHeight, block_index->GetBlockHash()}; + CCoinsStats stats{block_index.nHeight, block_index.GetBlockHash()}; stats.index_used = true; DBVal entry; - if (!LookUpOne(*m_db, {block_index->GetBlockHash(), block_index->nHeight}, entry)) { + if (!LookUpOne(*m_db, {block_index.GetBlockHash(), block_index.nHeight}, entry)) { return std::nullopt; } diff --git a/src/index/coinstatsindex.h b/src/index/coinstatsindex.h index bf30bf12fc66..90f7c0edcab9 100644 --- a/src/index/coinstatsindex.h +++ b/src/index/coinstatsindex.h @@ -5,11 +5,14 @@ #ifndef BITCOIN_INDEX_COINSTATSINDEX_H #define BITCOIN_INDEX_COINSTATSINDEX_H -#include #include -#include #include -#include + +class CBlockIndex; +class CDBBatch; +namespace kernel { +struct CCoinsStats; +} static constexpr bool DEFAULT_COINSTATSINDEX{false}; @@ -19,7 +22,6 @@ static constexpr bool DEFAULT_COINSTATSINDEX{false}; class CoinStatsIndex final : public BaseIndex { private: - std::string m_name; std::unique_ptr m_db; MuHash3072 m_muhash; @@ -51,14 +53,12 @@ class CoinStatsIndex final : public BaseIndex BaseIndex::DB& GetDB() const override { return *m_db; } - const char* GetName() const override { return "coinstatsindex"; } - public: // Constructs the index, which becomes available to be queried. explicit CoinStatsIndex(std::unique_ptr chain, size_t n_cache_size, bool f_memory = false, bool f_wipe = false); // Look up stats for a specific block using CBlockIndex - std::optional LookUpStats(const CBlockIndex* block_index) const; + std::optional LookUpStats(const CBlockIndex& block_index) const; }; /// The global UTXO set hash object. diff --git a/src/index/spentindex.cpp b/src/index/spentindex.cpp index a12c37a1b553..531fdb3f9361 100644 --- a/src/index/spentindex.cpp +++ b/src/index/spentindex.cpp @@ -55,7 +55,7 @@ bool SpentIndex::DB::EraseSpentIndex(const std::vector& keys) } SpentIndex::SpentIndex(std::unique_ptr chain, size_t n_cache_size, bool f_memory, bool f_wipe) : - BaseIndex(std::move(chain)), + BaseIndex(std::move(chain), "spentindex"), m_db(std::make_unique(n_cache_size, f_memory, f_wipe)) { } diff --git a/src/index/spentindex.h b/src/index/spentindex.h index 00f10d355fa1..bd5212cda1be 100644 --- a/src/index/spentindex.h +++ b/src/index/spentindex.h @@ -50,7 +50,6 @@ class SpentIndex final : public BaseIndex bool CustomRewind(const interfaces::BlockKey& current_tip, const interfaces::BlockKey& new_tip) override; BaseIndex::DB& GetDB() const override; - const char* GetName() const override { return "spentindex"; } /// SpentIndex cannot work with pruned nodes as it requires UTXO data bool AllowPrune() const override { return false; } diff --git a/src/index/timestampindex.cpp b/src/index/timestampindex.cpp index b0e7f54942c1..933677ebdda5 100644 --- a/src/index/timestampindex.cpp +++ b/src/index/timestampindex.cpp @@ -51,7 +51,7 @@ bool TimestampIndex::DB::EraseTimestampIndex(const CTimestampIndexKey& key) } TimestampIndex::TimestampIndex(std::unique_ptr chain, size_t n_cache_size, bool f_memory, bool f_wipe) : - BaseIndex(std::move(chain)), + BaseIndex(std::move(chain), "timestampindex"), m_db(std::make_unique(n_cache_size, f_memory, f_wipe)) { } diff --git a/src/index/timestampindex.h b/src/index/timestampindex.h index 544b1116c609..b2f613e2c52f 100644 --- a/src/index/timestampindex.h +++ b/src/index/timestampindex.h @@ -46,7 +46,6 @@ class TimestampIndex final : public BaseIndex bool CustomRewind(const interfaces::BlockKey& current_tip, const interfaces::BlockKey& new_tip) override; BaseIndex::DB& GetDB() const override; - const char* GetName() const override { return "timestampindex"; } /// TimestampIndex works with pruned nodes since it only stores block metadata bool AllowPrune() const override { return true; } diff --git a/src/index/txindex.cpp b/src/index/txindex.cpp index de9114cea59b..69a43f442346 100644 --- a/src/index/txindex.cpp +++ b/src/index/txindex.cpp @@ -49,7 +49,7 @@ bool TxIndex::DB::WriteTxs(const std::vector>& v_ } TxIndex::TxIndex(std::unique_ptr chain, size_t n_cache_size, bool f_memory, bool f_wipe) - : BaseIndex(std::move(chain)), m_db(std::make_unique(n_cache_size, f_memory, f_wipe)) + : BaseIndex(std::move(chain), "txindex"), m_db(std::make_unique(n_cache_size, f_memory, f_wipe)) {} TxIndex::~TxIndex() = default; diff --git a/src/index/txindex.h b/src/index/txindex.h index 3ef4f3975dec..f9f73496bc78 100644 --- a/src/index/txindex.h +++ b/src/index/txindex.h @@ -29,8 +29,6 @@ class TxIndex final : public BaseIndex BaseIndex::DB& GetDB() const override; - const char* GetName() const override { return "txindex"; } - public: /// Constructs the index, which becomes available to be queried. explicit TxIndex(std::unique_ptr chain, size_t n_cache_size, bool f_memory = false, bool f_wipe = false); diff --git a/src/init.cpp b/src/init.cpp index 04f026e2463c..84b5f79a221f 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -40,7 +40,6 @@ #include #include #include -#include #include #include #include @@ -51,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -1294,10 +1294,6 @@ bool AppInitParameterInteraction(const ArgsManager& args) fCheckpointsEnabled = args.GetBoolArg("-checkpoints", DEFAULT_CHECKPOINTS_ENABLED); hashAssumeValid = uint256S(args.GetArg("-assumevalid", chainparams.GetConsensus().defaultAssumeValid.GetHex())); - if (!hashAssumeValid.IsNull()) - LogPrintf("Assuming ancestors of block %s have valid signatures.\n", hashAssumeValid.GetHex()); - else - LogPrintf("Validating signatures for all blocks.\n"); if (args.IsArgSet("-minimumchainwork")) { const std::string minChainWorkStr = args.GetArg("-minimumchainwork", ""); @@ -1308,19 +1304,6 @@ bool AppInitParameterInteraction(const ArgsManager& args) } else { nMinimumChainWork = UintToArith256(chainparams.GetConsensus().nMinimumChainWork); } - LogPrintf("Setting nMinimumChainWork=%s\n", nMinimumChainWork.GetHex()); - if (nMinimumChainWork < UintToArith256(chainparams.GetConsensus().nMinimumChainWork)) { - LogPrintf("Warning: nMinimumChainWork set below default value of %s\n", chainparams.GetConsensus().nMinimumChainWork.GetHex()); - } - - // incremental relay fee sets the amount the mempool min fee increases above the feerate of txs evicted due to mempool limiting. - if (args.IsArgSet("-incrementalrelayfee")) { - if (std::optional inc_relay_fee = ParseMoney(args.GetArg("-incrementalrelayfee", ""))) { - ::incrementalRelayFee = CFeeRate{inc_relay_fee.value()}; - } else { - return InitError(AmountErrMsg("incrementalrelayfee", args.GetArg("-incrementalrelayfee", ""))); - } - } // block pruning; get the amount of disk space (in MiB) to allot for block & undo files int64_t nPruneArg = args.GetIntArg("-prune", 0); @@ -1329,7 +1312,6 @@ bool AppInitParameterInteraction(const ArgsManager& args) } nPruneTarget = (uint64_t) nPruneArg * 1024 * 1024; if (nPruneArg == 1) { // manual pruning: -prune=1 - LogPrintf("Block pruning enabled. Use RPC call pruneblockchain(height) to manually prune block and undo files.\n"); nPruneTarget = std::numeric_limits::max(); fPruneMode = true; } else if (nPruneTarget) { @@ -1343,7 +1325,6 @@ bool AppInitParameterInteraction(const ArgsManager& args) return InitError(strprintf(_("Prune configured below the minimum of %d MiB. Please use a higher number."), MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024)); } } - LogPrintf("Prune configured to target %u MiB on disk for block and undo files.\n", nPruneTarget / 1024 / 1024); fPruneMode = true; } @@ -1357,19 +1338,6 @@ bool AppInitParameterInteraction(const ArgsManager& args) return InitError(Untranslated("peertimeout must be a positive integer.")); } - if (args.IsArgSet("-minrelaytxfee")) { - if (std::optional min_relay_fee = ParseMoney(args.GetArg("-minrelaytxfee", ""))) { - // High fee check is done afterward in CWallet::Create() - ::minRelayTxFee = CFeeRate{min_relay_fee.value()}; - } else { - return InitError(AmountErrMsg("minrelaytxfee", args.GetArg("-minrelaytxfee", ""))); - } - } else if (incrementalRelayFee > ::minRelayTxFee) { - // Allow only setting incrementalRelayFee to control both - ::minRelayTxFee = incrementalRelayFee; - LogPrintf("Increasing minrelaytxfee to %s to match incrementalrelayfee\n",::minRelayTxFee.ToString()); - } - // Sanity check argument for min fee for including tx in block // TODO: Harmonize which arguments need sanity checking and where that happens if (args.IsArgSet("-blockmintxfee")) { @@ -1378,28 +1346,10 @@ bool AppInitParameterInteraction(const ArgsManager& args) } } - // Feerate used to define dust. Shouldn't be changed lightly as old - // implementations may inadvertently create non-standard transactions - if (args.IsArgSet("-dustrelayfee")) { - if (std::optional parsed = ParseMoney(args.GetArg("-dustrelayfee", ""))) { - dustRelayFee = CFeeRate{parsed.value()}; - } else { - return InitError(AmountErrMsg("dustrelayfee", args.GetArg("-dustrelayfee", ""))); - } - } - - fRequireStandard = !args.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard()); - if (!chainparams.IsTestChain() && !fRequireStandard) { - return InitError(strprintf(Untranslated("acceptnonstdtxn is not currently supported for %s chain"), chainparams.NetworkIDString())); - } nBytesPerSigOp = args.GetIntArg("-bytespersigop", nBytesPerSigOp); if (!g_wallet_init_interface.ParameterInteraction()) return false; - fIsBareMultisigStd = args.GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG); - fAcceptDatacarrier = args.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER); - nMaxDatacarrierBytes = args.GetIntArg("-datacarriersize", nMaxDatacarrierBytes); - // Option to startup with mocktime set (used for regression testing): SetMockTime(args.GetIntArg("-mocktime", 0)); // SetMockTime(0) is a no-op @@ -1987,7 +1937,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) .estimator = node.fee_estimator.get(), .check_ratio = chainparams.DefaultConsistencyChecks() ? 1 : 0, }; - ApplyArgsManOptions(args, mempool_opts); + if (const auto err{ApplyArgsManOptions(args, chainparams, mempool_opts)}) { + return InitError(*err); + } mempool_opts.check_ratio = std::clamp(mempool_opts.check_ratio, 0, 1'000'000); int64_t descendant_limit_bytes = mempool_opts.limits.descendant_size_vbytes * 40; diff --git a/src/kernel/mempool_limits.h b/src/kernel/mempool_limits.h index e192e7e6cdee..8d4495c3cb1c 100644 --- a/src/kernel/mempool_limits.h +++ b/src/kernel/mempool_limits.h @@ -24,6 +24,15 @@ struct MemPoolLimits { int64_t descendant_count{DEFAULT_DESCENDANT_LIMIT}; //! The maximum allowed size in virtual bytes of an entry and its descendants within a package. int64_t descendant_size_vbytes{DEFAULT_DESCENDANT_SIZE_LIMIT_KVB * 1'000}; + + /** + * @return MemPoolLimits with all the limits set to the maximum + */ + static constexpr MemPoolLimits NoLimits() + { + int64_t no_limit{std::numeric_limits::max()}; + return {no_limit, no_limit, no_limit, no_limit}; + } }; } // namespace kernel diff --git a/src/kernel/mempool_options.h b/src/kernel/mempool_options.h index a14abb662890..861ff4f2465c 100644 --- a/src/kernel/mempool_options.h +++ b/src/kernel/mempool_options.h @@ -6,8 +6,13 @@ #include +#include +#include +#include