From b04ffb923c42f62b11fcdc1defaa45d198c8f7ae Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Sat, 4 Jul 2015 07:27:20 -0700 Subject: [PATCH] Rebuild coinbase cache when needed --- src/chain.cpp | 8 ++++++++ src/coinbase-payee.cpp | 7 +++++-- src/coinbase-payee.h | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/chain.cpp b/src/chain.cpp index e13c04786..222d98981 100644 --- a/src/chain.cpp +++ b/src/chain.cpp @@ -4,6 +4,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "chain.h" +#include "coinbase-payee.h" using namespace std; @@ -15,10 +16,17 @@ void CChain::SetTip(CBlockIndex *pindex) { vChain.clear(); return; } + int nChainSwitch = 0; vChain.resize(pindex->nHeight + 1); while (pindex && vChain[pindex->nHeight] != pindex) { vChain[pindex->nHeight] = pindex; pindex = pindex->pprev; + nChainSwitch++; + } + + //recalculate the coinbase payee cache if needed + if(nChainSwitch > 0) { + coinbasePayee.BuildIndex(true); } } diff --git a/src/coinbase-payee.cpp b/src/coinbase-payee.cpp index 6292ffe80..3b65ed604 100644 --- a/src/coinbase-payee.cpp +++ b/src/coinbase-payee.cpp @@ -169,11 +169,14 @@ void DumpCoinbasePayees() LogPrintf("Coinbase payee dump finished %dms\n", GetTimeMillis() - nStart); } -void CCoinbasePayee::BuildIndex() +void CCoinbasePayee::BuildIndex(bool bForced) { - if(mapPaidTime.size() > 0) { + if(mapPaidTime.size() > 0 && !bForced) { LogPrintf("CCoinbasePayee::BuildIndex - coinbase cache exists, skipping BuildIndex\n"); return; + } else if(bForced) { + LogPrintf("CCoinbasePayee::BuildIndex - Rebuilding coinbase cache\n"); + mapPaidTime.clear(); } //scan last 30 days worth of blocks, run processBlockCoinbaseTX for each diff --git a/src/coinbase-payee.h b/src/coinbase-payee.h index 6ed9169e4..241857d9b 100644 --- a/src/coinbase-payee.h +++ b/src/coinbase-payee.h @@ -69,7 +69,7 @@ public: mapPaidTime.clear(); } - void BuildIndex(); + void BuildIndex(bool bForced=false); void ProcessBlockCoinbaseTX(CTransaction& txCoinbase, int64_t nTime); int64_t GetLastPaid(CScript& pubkey); void CleanUp();