From 8c6f756362bc32d06a0b7644d92dd448e229af96 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sat, 4 Feb 2017 04:42:04 +0400 Subject: [PATCH] put some reasonable limits on SPORK_12_RECONSIDER_BLOCKS (#1312) * put some reasonable limits on SPORK_12_RECONSIDER_BLOCKS * 6h -> 24h --- src/spork.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/spork.cpp b/src/spork.cpp index 512957e11d..b161527020 100644 --- a/src/spork.cpp +++ b/src/spork.cpp @@ -75,9 +75,28 @@ void CSporkManager::ExecuteSpork(int nSporkID, int nValue) { //correct fork via spork technology if(nSporkID == SPORK_12_RECONSIDER_BLOCKS && nValue > 0) { + // allow to reprocess 24h of blocks max, which should be enough to resolve any issues + int64_t nMaxBlocks = 576; + // this potentially can be a heavy operation, so only allow this to be executed once per 10 minutes + int64_t nTimeout = 10 * 60; + + static int64_t nTimeExecuted = 0; // i.e. it was never executed before + + if(GetTime() - nTimeExecuted < nTimeout) { + LogPrint("spork", "CSporkManager::ExecuteSpork -- ERROR: Trying to reconsider blocks, too soon - %d/%d\n", GetTime() - nTimeExecuted, nTimeout); + return; + } + + if(nValue > nMaxBlocks) { + LogPrintf("CSporkManager::ExecuteSpork -- ERROR: Trying to reconsider too many blocks %d/%d\n", nValue, nMaxBlocks); + return; + } + + LogPrintf("CSporkManager::ExecuteSpork -- Reconsider Last %d Blocks\n", nValue); ReprocessBlocks(nValue); + nTimeExecuted = GetTime(); } }