| 241 | } |
| 242 | |
| 243 | void 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 | |
| 285 | void BaseIndex::ChainStateFlushed(const CBlockLocator& locator) |
| 286 | { |
nothing calls this directly
no test coverage detected