diff --git a/src/validation.cpp b/src/validation.cpp index d99efd4cf8b08..4c8883073e513 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -53,6 +53,8 @@ #include "zpiv/zerocoin.h" #include "zpiv/zpivmodule.h" +#include + #include #include #include @@ -2258,6 +2260,17 @@ bool ActivateBestChain(CValidationState& state, std::shared_ptr pb do { boost::this_thread::interruption_point(); + if (GetMainSignals().CallbacksPending() > 10) { + // Block until the validation queue drains. This should largely + // never happen in normal operation, however may happen during + // reindex, causing memory blowup if we run too far ahead. + std::promise promise; + CallFunctionInValidationInterfaceQueue([&promise] { + promise.set_value(); + }); + promise.get_future().wait(); + } + const CBlockIndex *pindexFork; bool fInitialDownload; while (true) {