@@ -2642,6 +2642,14 @@ static void NotifyHeaderTip() LOCKS_EXCLUDED(cs_main) {
2642
2642
}
2643
2643
}
2644
2644
2645
+ static void LimitValidationInterfaceQueue () {
2646
+ AssertLockNotHeld (cs_main);
2647
+
2648
+ if (GetMainSignals ().CallbacksPending () > 10 ) {
2649
+ SyncWithValidationInterfaceQueue ();
2650
+ }
2651
+ }
2652
+
2645
2653
/* *
2646
2654
* Make the best chain active, in multiple steps. The result is either failure
2647
2655
* or an activated best chain. pblock is either nullptr or a pointer to a block
@@ -2670,15 +2678,13 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams&
2670
2678
do {
2671
2679
boost::this_thread::interruption_point ();
2672
2680
2673
- if (GetMainSignals ().CallbacksPending () > 10 ) {
2674
- // Block until the validation queue drains. This should largely
2675
- // never happen in normal operation, however may happen during
2676
- // reindex, causing memory blowup if we run too far ahead.
2677
- // Note that if a validationinterface callback ends up calling
2678
- // ActivateBestChain this may lead to a deadlock! We should
2679
- // probably have a DEBUG_LOCKORDER test for this in the future.
2680
- SyncWithValidationInterfaceQueue ();
2681
- }
2681
+ // Block until the validation queue drains. This should largely
2682
+ // never happen in normal operation, however may happen during
2683
+ // reindex, causing memory blowup if we run too far ahead.
2684
+ // Note that if a validationinterface callback ends up calling
2685
+ // ActivateBestChain this may lead to a deadlock! We should
2686
+ // probably have a DEBUG_LOCKORDER test for this in the future.
2687
+ LimitValidationInterfaceQueue ();
2682
2688
2683
2689
{
2684
2690
LOCK (cs_main);
@@ -2796,6 +2802,9 @@ bool CChainState::InvalidateBlock(CValidationState& state, const CChainParams& c
2796
2802
while (true ) {
2797
2803
if (ShutdownRequested ()) break ;
2798
2804
2805
+ // Make sure the queue of validation callbacks doesn't grow unboundedly.
2806
+ LimitValidationInterfaceQueue ();
2807
+
2799
2808
LOCK (cs_main);
2800
2809
if (!chainActive.Contains (pindex)) break ;
2801
2810
pindex_was_in_chain = true ;
@@ -4285,6 +4294,9 @@ bool CChainState::RewindBlockIndex(const CChainParams& params)
4285
4294
4286
4295
tip = tip->pprev ;
4287
4296
}
4297
+ // Make sure the queue of validation callbacks doesn't grow unboundedly.
4298
+ LimitValidationInterfaceQueue ();
4299
+
4288
4300
// Occasionally flush state to disk.
4289
4301
if (!FlushStateToDisk (params, state, FlushStateMode::PERIODIC)) {
4290
4302
LogPrintf (" RewindBlockIndex: unable to flush state to disk (%s)\n " , FormatStateMessage (state));
0 commit comments