Skip to content

Commit cc91d44

Browse files
TheBlueMattfurszy
authored andcommitted
Block ActivateBestChain to empty validationinterface queue
1 parent 0c68e2f commit cc91d44

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/validation.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
#include "zpiv/zerocoin.h"
5454
#include "zpiv/zpivmodule.h"
5555

56+
#include <future>
57+
5658
#include <boost/algorithm/string/replace.hpp>
5759
#include <boost/thread.hpp>
5860
#include <atomic>
@@ -2258,6 +2260,17 @@ bool ActivateBestChain(CValidationState& state, std::shared_ptr<const CBlock> pb
22582260
do {
22592261
boost::this_thread::interruption_point();
22602262

2263+
if (GetMainSignals().CallbacksPending() > 10) {
2264+
// Block until the validation queue drains. This should largely
2265+
// never happen in normal operation, however may happen during
2266+
// reindex, causing memory blowup if we run too far ahead.
2267+
std::promise<void> promise;
2268+
CallFunctionInValidationInterfaceQueue([&promise] {
2269+
promise.set_value();
2270+
});
2271+
promise.get_future().wait();
2272+
}
2273+
22612274
const CBlockIndex *pindexFork;
22622275
bool fInitialDownload;
22632276
while (true) {

0 commit comments

Comments
 (0)