Skip to content

Commit 8d22041

Browse files
committed
Optimization: don't add txn back to mempool after 10 invalidates
1 parent 9ce9c37 commit 8d22041

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/validation.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2797,6 +2797,7 @@ bool CChainState::InvalidateBlock(CValidationState& state, const CChainParams& c
27972797
{
27982798
CBlockIndex* to_mark_failed = pindex;
27992799
bool pindex_was_in_chain = false;
2800+
int disconnected = 0;
28002801

28012802
// Disconnect (descendants of) pindex, and mark them invalid.
28022803
while (true) {
@@ -2816,8 +2817,10 @@ bool CChainState::InvalidateBlock(CValidationState& state, const CChainParams& c
28162817
bool ret = DisconnectTip(state, chainparams, &disconnectpool);
28172818
// DisconnectTip will add transactions to disconnectpool.
28182819
// Adjust the mempool to be consistent with the new tip, adding
2819-
// transactions back to the mempool if disconnecting was succesful.
2820-
UpdateMempoolForReorg(disconnectpool, /* fAddToMempool = */ ret);
2820+
// transactions back to the mempool if disconnecting was succesful,
2821+
// and we're not doing a very deep invalidation (in which case
2822+
// keeping the mempool up to date is probably futile anyway).
2823+
UpdateMempoolForReorg(disconnectpool, /* fAddToMempool = */ (++disconnected <= 10) && ret);
28212824
if (!ret) return false;
28222825
assert(invalid_walk_tip->pprev == chainActive.Tip());
28232826

0 commit comments

Comments
 (0)