Restore per-algo block index tracking
This commit is contained in:
parent
b913f39508
commit
2210ac3451
3 changed files with 40 additions and 5 deletions
|
|
@ -33,6 +33,18 @@ CBlockIndex::CBlockIndex(const CBlockHeader& block)
|
|||
|
||||
}
|
||||
|
||||
int CBlockIndex::GetAlgo() const
|
||||
{
|
||||
switch (nVersion & BLOCK_VERSION_ALGO) {
|
||||
case BLOCK_VERSION_SHA256D:
|
||||
return ALGO_SHA256D;
|
||||
case BLOCK_VERSION_RANDOMX:
|
||||
return ALGO_RANDOMX;
|
||||
default:
|
||||
return ALGO_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
void CChain::SetTip(CBlockIndex *pindex) {
|
||||
if (pindex == nullptr) {
|
||||
vChain.clear();
|
||||
|
|
|
|||
|
|
@ -201,6 +201,9 @@ public:
|
|||
//! (memory only) Maximum nTime in the chain up to and including this block.
|
||||
unsigned int nTimeMax{0};
|
||||
|
||||
//! (memory only) Most recent block index for each mining algorithm.
|
||||
CBlockIndex* lastAlgoBlocks[NUM_ALGOS_IMPL]{};
|
||||
|
||||
/**
|
||||
* Default constructor (no header):
|
||||
*/
|
||||
|
|
@ -264,6 +267,8 @@ public:
|
|||
|
||||
bool HaveTxsDownloaded() const { return nChainTx != 0; }
|
||||
|
||||
int GetAlgo() const;
|
||||
|
||||
int64_t GetBlockTime() const
|
||||
{
|
||||
return (int64_t)nTime;
|
||||
|
|
|
|||
|
|
@ -3036,9 +3036,18 @@ CBlockIndex* BlockManager::AddToBlockIndex(const CBlockHeader& block)
|
|||
pindexNew->nHeight = pindexNew->pprev->nHeight + 1;
|
||||
pindexNew->BuildSkip();
|
||||
}
|
||||
|
||||
// Use memcpy to copy the entire array at once.
|
||||
// Keep track of the most recent block for each mining algorithm.
|
||||
if (pindexNew->pprev) {
|
||||
memcpy(
|
||||
pindexNew->lastAlgoBlocks,
|
||||
pindexNew->pprev->lastAlgoBlocks,
|
||||
sizeof(pindexNew->lastAlgoBlocks)
|
||||
);
|
||||
}
|
||||
|
||||
const int algo = pindexNew->GetAlgo();
|
||||
if (algo >= 0 && algo < NUM_ALGOS_IMPL) {
|
||||
pindexNew->lastAlgoBlocks[algo] = pindexNew;
|
||||
}
|
||||
|
||||
pindexNew->nTimeMax = (pindexNew->pprev ? std::max(pindexNew->pprev->nTimeMax, pindexNew->nTime) : pindexNew->nTime);
|
||||
|
|
@ -3822,9 +3831,18 @@ bool BlockManager::LoadBlockIndex(
|
|||
}
|
||||
if (ShutdownRequested()) return false;
|
||||
CBlockIndex* pindex = item.second;
|
||||
|
||||
// Use memcpy to copy the entire array at once.
|
||||
// Rebuild the most recent block pointer for each mining algorithm.
|
||||
if (pindex->pprev) {
|
||||
memcpy(
|
||||
pindex->lastAlgoBlocks,
|
||||
pindex->pprev->lastAlgoBlocks,
|
||||
sizeof(pindex->lastAlgoBlocks)
|
||||
);
|
||||
}
|
||||
|
||||
const int algo = pindex->GetAlgo();
|
||||
if (algo >= 0 && algo < NUM_ALGOS_IMPL) {
|
||||
pindex->lastAlgoBlocks[algo] = pindex;
|
||||
}
|
||||
|
||||
nHeight = pindex-> nHeight;
|
||||
|
|
|
|||
Loading…
Reference in a new issue