MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / AddToBlockIndex

Function AddToBlockIndex

src/main.cpp:3119–3151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3117}
3118
3119CBlockIndex* AddToBlockIndex(const CBlockHeader& block)
3120{
3121 // Check for duplicate
3122 uint256 hash = block.GetHash();
3123 BlockMap::iterator it = mapBlockIndex.find(hash);
3124 if (it != mapBlockIndex.end())
3125 return it->second;
3126
3127 // Construct new block index object
3128 CBlockIndex* pindexNew = new CBlockIndex(block);
3129 assert(pindexNew);
3130 // We assign the sequence id to blocks only when the full data is available,
3131 // to avoid miners withholding blocks but broadcasting headers, to get a
3132 // competitive advantage.
3133 pindexNew->nSequenceId = 0;
3134 BlockMap::iterator mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first;
3135 pindexNew->phashBlock = &((*mi).first);
3136 BlockMap::iterator miPrev = mapBlockIndex.find(block.hashPrevBlock);
3137 if (miPrev != mapBlockIndex.end())
3138 {
3139 pindexNew->pprev = (*miPrev).second;
3140 pindexNew->nHeight = pindexNew->pprev->nHeight + 1;
3141 pindexNew->BuildSkip();
3142 }
3143 pindexNew->nChainWork = (pindexNew->pprev ? pindexNew->pprev->nChainWork : 0) + GetBlockProof(*pindexNew);
3144 pindexNew->RaiseValidity(BLOCK_VALID_TREE);
3145 if (pindexBestHeader == NULL || pindexBestHeader->nChainWork < pindexNew->nChainWork)
3146 pindexBestHeader = pindexNew;
3147
3148 setDirtyBlockIndex.insert(pindexNew);
3149
3150 return pindexNew;
3151}
3152
3153/** Mark a block as having its data received and checked (up to BLOCK_VALID_TRANSACTIONS). */
3154bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBlockIndex *pindexNew, const CDiskBlockPos& pos)

Callers 2

AcceptBlockHeaderFunction · 0.85
InitBlockIndexFunction · 0.85

Calls 7

GetBlockProofFunction · 0.85
findMethod · 0.80
BuildSkipMethod · 0.80
RaiseValidityMethod · 0.80
GetHashMethod · 0.45
endMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected