From 229bc37b5f18cffbc85efbad3b6e9047c6951e95 Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Wed, 16 Sep 2020 17:00:04 -0400 Subject: [PATCH] validation: Pass in chainstate to ::AcceptToMemoryPool --- src/validation.cpp | 10 ++++++++-- src/validation.h | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/validation.cpp b/src/validation.cpp index 8a0820515f3f7..e40a273257ed7 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -387,7 +387,7 @@ static void UpdateMempoolForReorg(CTxMemPool& mempool, DisconnectedBlockTransact while (it != disconnectpool.queuedTx.get().rend()) { // ignore validation errors in resurrected transactions if (!fAddToMempool || (*it)->IsCoinBase() || - AcceptToMemoryPool(mempool, *it, true /* bypass_limits */).m_result_type != MempoolAcceptResult::ResultType::VALID) { + AcceptToMemoryPool(::ChainstateActive(), mempool, *it, true /* bypass_limits */).m_result_type != MempoolAcceptResult::ResultType::VALID) { // If the transaction doesn't make it in to the mempool, remove any // transactions that depend on it (which would now be orphans). mempool.removeRecursive(**it, MemPoolRemovalReason::REORG); @@ -1103,7 +1103,13 @@ static MempoolAcceptResult AcceptToMemoryPoolWithTime(const CChainParams& chainp MempoolAcceptResult AcceptToMemoryPool(CTxMemPool& pool, const CTransactionRef &tx, bool bypass_limits, bool test_accept) { - return AcceptToMemoryPoolWithTime(Params(), pool, ::ChainstateActive(), tx, GetTime(), bypass_limits, test_accept); + return AcceptToMemoryPool(::ChainstateActive(), pool, tx, bypass_limits, test_accept); +} + +MempoolAcceptResult AcceptToMemoryPool(CChainState& active_chainstate, CTxMemPool& pool, const CTransactionRef& tx, bool bypass_limits, bool test_accept) +{ + assert(std::addressof(::ChainstateActive()) == std::addressof(active_chainstate)); + return AcceptToMemoryPoolWithTime(Params(), pool, active_chainstate, tx, GetTime(), bypass_limits, test_accept); } CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const uint256& hash, const Consensus::Params& consensusParams, uint256& hashBlock) diff --git a/src/validation.h b/src/validation.h index cc59b8f706a81..80ef0eaa7deb1 100644 --- a/src/validation.h +++ b/src/validation.h @@ -225,6 +225,8 @@ struct MempoolAcceptResult { */ MempoolAcceptResult AcceptToMemoryPool(CTxMemPool& pool, const CTransactionRef& tx, bool bypass_limits, bool test_accept=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main); +MempoolAcceptResult AcceptToMemoryPool(CChainState& active_chainstate, CTxMemPool& pool, const CTransactionRef& tx, + bool bypass_limits, bool test_accept=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main); /** Get the BIP9 state for a given deployment at the current tip. */ ThresholdState VersionBitsTipState(const Consensus::Params& params, Consensus::DeploymentPos pos);