0

I'm trying to understand how Bitcoin Core works in-depth. Can someone tell me where is the code executed during a blockchain reorganization in Bitcoin Core?

Any explanation would also be greatly appreciated.

  • Possible duplicate of Where in Bitcoin Core does it do X? – Ugam Kamat May 29 '19 at 14:09
  • When you say reorganization, do you mean a spontaneous fork in the blockchain? or are you referring to the suggestion of Binance recently after their hack, to “reorganize” and rollback the blockchain, and you are wondereing if there is code in place to do the reorg of the blockchain? (spoiler alert: there isn’t any). – bitcoinero Jun 1 '19 at 12:46
  • @bitcoinero I mean spontaneous fork. How the best chain is selected. – SystemGlitch Jun 2 '19 at 12:54
1

Block tree is stored on-disk. During startup, is read into memory. When read, BlockManager::m_block_index field is filled with data - CBlockIndexes. Every CBlockIndex contains memory-only field arith_uint256 nChainWork, which is a total amount of work in the chain up to (and including) current block.

Best chain is selected as maximum among all nChainWork of all tips and saved to CChainState::m_chain - currently active chain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.