diff --git a/src/chain.cpp b/src/chain.cpp index e13c047861..222d98981f 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 6292ffe801..3b65ed6047 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 6ed9169e44..241857d9bc 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();