aboutsummaryrefslogtreecommitdiff
path: root/src/validation.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2019-02-13 18:07:16 -0800
committerPieter Wuille <pieter.wuille@gmail.com>2019-02-28 14:12:26 -0800
commit8d220417cd7bc34464e28a4861a885193ec091c2 (patch)
tree36a2ab48f4543bde188b54054a792d971628f220 /src/validation.cpp
parent9ce9c37004440d6a329874dbf66b51666d497dcb (diff)
Optimization: don't add txn back to mempool after 10 invalidates
Diffstat (limited to 'src/validation.cpp')
-rw-r--r--src/validation.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/validation.cpp b/src/validation.cpp
index d0d2227664..c112fbdcc0 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -2797,6 +2797,7 @@ bool CChainState::InvalidateBlock(CValidationState& state, const CChainParams& c
{
CBlockIndex* to_mark_failed = pindex;
bool pindex_was_in_chain = false;
+ int disconnected = 0;
// Disconnect (descendants of) pindex, and mark them invalid.
while (true) {
@@ -2816,8 +2817,10 @@ bool CChainState::InvalidateBlock(CValidationState& state, const CChainParams& c
bool ret = DisconnectTip(state, chainparams, &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 succesful.
- UpdateMempoolForReorg(disconnectpool, /* fAddToMempool = */ ret);
+ // transactions back to the mempool if disconnecting was succesful,
+ // and we're not doing a very deep invalidation (in which case
+ // keeping the mempool up to date is probably futile anyway).
+ UpdateMempoolForReorg(disconnectpool, /* fAddToMempool = */ (++disconnected <= 10) && ret);
if (!ret) return false;
assert(invalid_walk_tip->pprev == chainActive.Tip());