Skip to content

Commit

Permalink
Fix mempool reorg issue
Browse files Browse the repository at this point in the history
Signed-off-by: Anthony Fieroni <[email protected]>
  • Loading branch information
bvbfan committed Jan 17, 2022
1 parent 06f2ed8 commit d1f2118
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -591,6 +592,7 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
}

if (pcustomcsview) {
accountsViewDirty |= forceRebuildForReorg;
rebuildAccountsView(nBlockHeight, &::ChainstateActive().CoinsTip());
}

Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/txmempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ class CTxMemPool
std::vector<indexed_transaction_set::const_iterator> GetSortedDepthAndScore() const EXCLUSIVE_LOCKS_REQUIRED(cs);

bool accountsViewDirty;
bool forceRebuildForReorg;
std::unique_ptr<CCustomCSView> acview;
public:
indirectmap<COutPoint, const CTransaction*> mapNextTx GUARDED_BY(cs);
Expand Down
3 changes: 1 addition & 2 deletions test/functional/rpc_mn_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d1f2118

Please sign in to comment.