diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 94314c392c..2cf4fc7981 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -334,6 +334,7 @@ CTxMemPool::CTxMemPool(CBlockPolicyEstimator* estimator) // of transactions in the pool nCheckFrequency = 0; accountsViewDirty = false; + forceRebuildForReorg = false; } bool CTxMemPool::isSpent(const COutPoint& outpoint) const @@ -591,6 +592,7 @@ void CTxMemPool::removeForBlock(const std::vector& vtx, unsigne } if (pcustomcsview) { + accountsViewDirty |= forceRebuildForReorg; rebuildAccountsView(nBlockHeight, &::ChainstateActive().CoinsTip()); } @@ -615,9 +617,7 @@ void CTxMemPool::clear() { LOCK(cs); _clear(); - if (pcustomcsview) { - accountsView().Discard(); - } + acview.reset(); } static void CheckInputsAndUpdateCoins(const CTransaction& tx, CCoinsViewCache& mempoolDuplicate, const CCustomCSView * mnview, const int64_t spendheight, const CChainParams& chainparams) @@ -947,7 +947,8 @@ void CTxMemPool::RemoveStaged(const setEntries &stage, bool updateDescendants, M for (txiter it : stage) { removeUnchecked(it, reason); } - accountsViewDirty = accountsViewDirty || !stage.empty(); + accountsViewDirty |= !stage.empty(); + forceRebuildForReorg |= reason == MemPoolRemovalReason::REORG; } int CTxMemPool::Expire(int64_t time) { @@ -1126,6 +1127,7 @@ void CTxMemPool::rebuildAccountsView(int height, const CCoinsViewCache& coinsCac viewDuplicate.Flush(); accountsViewDirty = false; + forceRebuildForReorg = false; } uint64_t CTxMemPool::CalculateDescendantMaximum(txiter entry) const { diff --git a/src/txmempool.h b/src/txmempool.h index edfbdc8f0d..7c032619c8 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -549,6 +549,7 @@ class CTxMemPool std::vector GetSortedDepthAndScore() const EXCLUSIVE_LOCKS_REQUIRED(cs); bool accountsViewDirty; + bool forceRebuildForReorg; std::unique_ptr acview; public: indirectmap mapNextTx GUARDED_BY(cs); diff --git a/test/functional/rpc_mn_basic.py b/test/functional/rpc_mn_basic.py index 326f56ee18..94de9691b8 100644 --- a/test/functional/rpc_mn_basic.py +++ b/test/functional/rpc_mn_basic.py @@ -151,8 +151,7 @@ def run_test(self): assert_equal(len(self.nodes[0].listmasternodes()), 8) mempool = self.nodes[0].getrawmempool() - assert(idnode0 in mempool and fundingTx in mempool) - assert_equal(len(mempool), 3) # + auto auth + assert_equal(len(mempool), 1) # auto auth collateral0 = self.nodes[0].getnewaddress("", "legacy") self.nodes[0].createmasternode(collateral0)