diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3076,6 +3076,7 @@ CBlockIndex *to_mark_failed = pindex; bool pindex_was_in_chain = false; + int disconnected = 0; // Disconnect (descendants of) pindex, and mark them invalid. while (true) { @@ -3097,8 +3098,12 @@ bool ret = DisconnectTip(config, state, &disconnectpool); // DisconnectTip will add transactions to disconnectpool. // Adjust the mempool to be consistent with the new tip, adding - // transactions back to the mempool if disconnecting was successful. - disconnectpool.updateMempoolForReorg(config, /* fAddToMempool = */ ret); + // transactions back to the mempool if disconnecting was successful, + // and we're not doing a very deep invalidation (in which case + // keeping the mempool up to date is probably futile anyway). + disconnectpool.updateMempoolForReorg( + config, /* fAddToMempool = */ (++disconnected <= 10) && ret); + if (!ret) return false; assert(invalid_walk_tip->pprev == chainActive.Tip());