MCPcopy Create free account
hub / github.com/ElementsProject/elements / BlockConnected

Method BlockConnected

src/index/base.cpp:243–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

241}
242
243void BaseIndex::BlockConnected(const std::shared_ptr<const CBlock>& block, const CBlockIndex* pindex)
244{
245 if (!m_synced) {
246 return;
247 }
248
249 const CBlockIndex* best_block_index = m_best_block_index.load();
250 if (!best_block_index) {
251 if (pindex->nHeight != 0) {
252 FatalError("%s: First block connected is not the genesis block (height=%d)",
253 __func__, pindex->nHeight);
254 return;
255 }
256 } else {
257 // Ensure block connects to an ancestor of the current best block. This should be the case
258 // most of the time, but may not be immediately after the sync thread catches up and sets
259 // m_synced. Consider the case where there is a reorg and the blocks on the stale branch are
260 // in the ValidationInterface queue backlog even after the sync thread has caught up to the
261 // new chain tip. In this unlikely event, log a warning and let the queue clear.
262 if (best_block_index->GetAncestor(pindex->nHeight - 1) != pindex->pprev) {
263 LogPrintf("%s: WARNING: Block %s does not connect to an ancestor of " /* Continued */
264 "known best chain (tip=%s); not updating index\n",
265 __func__, pindex->GetBlockHash().ToString(),
266 best_block_index->GetBlockHash().ToString());
267 return;
268 }
269 if (best_block_index != pindex->pprev && !Rewind(best_block_index, pindex->pprev)) {
270 FatalError("%s: Failed to rewind index %s to a previous chain tip",
271 __func__, GetName());
272 return;
273 }
274 }
275
276 if (WriteBlock(*block, pindex)) {
277 m_best_block_index = pindex;
278 } else {
279 FatalError("%s: Failed to write block %s to index",
280 __func__, pindex->GetBlockHash().ToString());
281 return;
282 }
283}
284
285void BaseIndex::ChainStateFlushed(const CBlockLocator& locator)
286{

Callers

nothing calls this directly

Calls 5

FatalErrorFunction · 0.85
GetAncestorMethod · 0.80
loadMethod · 0.45
ToStringMethod · 0.45
GetBlockHashMethod · 0.45

Tested by

no test coverage detected