Skip to content

Instantly share code, notes, and snippets.

@fjahr
Last active May 17, 2023 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fjahr/4b90adf2c24b39b84d5e6f4822f6a14f to your computer and use it in GitHub Desktop.
Save fjahr/4b90adf2c24b39b84d5e6f4822f6a14f to your computer and use it in GitHub Desktop.
Blocks for #24008

For discussion of https://github.com/bitcoin/bitcoin/pull/24008/commits/c14ae132c5a5204a9a755c84c6de05fb30459221

Conditions in GetChainstateForNewBlock

  • IF1: if(!m_snapshot_chainstate) => use ibd
  • IF2: if(m_blockman.LookupBlockIndex(blockhash) == nullptr) => use snapshot
    • This means we use the snapshot chainstate if we have not seen this block’s header yet, implied from it not being in m_block_index
  • IF3: if (!m_snapshot_chainstate->m_chain.Contains(pblock))) => use snapshot
    • This means we use the snapshot chainstate if the block header is not part of the current best chain (included in m_chain) which can mean we have not validated the full block yet or the block is not part of the best chain after validation
  • FB: fallback => use ibd

Cases

New Block location A) Before Snapshot B) After Snapshot C) At Tip
1. Normal operation Block location doesn't matter, the guard clause is hit because there is no snapshot so the block goes to ibd. (IF1) <-- <--
2. Snapshot loading We have seen the the header but not the block, going to snapshot (inactive). If we have received the block already, it's going to ibd. (IF3) We have seen the the header but not the block, going to snapshot (inactive). If we have received the block already, it's going to ibd. (IF3) We have not seen the header yet so snapshot is used even though it's considered "inactive" at this moment. (IF2)
3. Snapshot loaded We have seen the the header but not the block, going to snapshot. If we have received the block already, it's going to ibd. (IF3) We have seen the the header but not the block, going to snapshot. If we have received the block already, it's going to ibd. (IF3) We have not seen the header yet so snapshot is used. (IF2)
4. Snapshot has hit tip We have seen the the header but not the block, going to snapshot. If we have received the block already, it's going to ibd. (IF3) We have seen the the header and the block, going to ibd. (FB) We have not seen the header yet so snapshot is used. (IF2)
5. Validation complete, pending restart ibd would be used but it is now m_disabled so there is no effect. (FB) ibd would be used but it is now m_disabled so there is no effect. (FB) We have not seen the header yet so snapshot is used. snapshot now has the complete chain and is pending to become ibd after restart. (IF2)
6. Validation complete, after restart Like in normal operation, only ibd (used to be snapshot) is available in any case. (IF1) <-- <--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment