|
|
|
@ -811,6 +811,24 @@ bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock)
@@ -811,6 +811,24 @@ bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock)
|
|
|
|
|
// CBlock and CBlockIndex
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
static CBlockIndex* pblockindexFBBHLast; |
|
|
|
|
CBlockIndex* FindBlockByHeight(int nHeight) |
|
|
|
|
{ |
|
|
|
|
CBlockIndex *pblockindex; |
|
|
|
|
if (nHeight < nBestHeight / 2) |
|
|
|
|
pblockindex = pindexGenesisBlock; |
|
|
|
|
else |
|
|
|
|
pblockindex = pindexBest; |
|
|
|
|
if (pblockindexFBBHLast && abs(nHeight - pblockindex->nHeight) > abs(nHeight - pblockindexFBBHLast->nHeight)) |
|
|
|
|
pblockindex = pblockindexFBBHLast; |
|
|
|
|
while (pblockindex->nHeight > nHeight) |
|
|
|
|
pblockindex = pblockindex->pprev; |
|
|
|
|
while (pblockindex->nHeight < nHeight) |
|
|
|
|
pblockindex = pblockindex->pnext; |
|
|
|
|
pblockindexFBBHLast = pblockindex; |
|
|
|
|
return pblockindex; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool CBlock::ReadFromDisk(const CBlockIndex* pindex, bool fReadTransactions) |
|
|
|
|
{ |
|
|
|
|
if (!fReadTransactions) |
|
|
|
@ -1634,6 +1652,7 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew)
@@ -1634,6 +1652,7 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew)
|
|
|
|
|
// New best block
|
|
|
|
|
hashBestChain = hash; |
|
|
|
|
pindexBest = pindexNew; |
|
|
|
|
pblockindexFBBHLast = NULL; |
|
|
|
|
nBestHeight = pindexBest->nHeight; |
|
|
|
|
bnBestChainWork = pindexNew->bnChainWork; |
|
|
|
|
nTimeBestReceived = GetTime(); |
|
|
|
|