user89133: 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.

user85437: 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.

89133: <p>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?</p>

<p>Any explanation would also be greatly appreciated.</p>
 85437: <p>Block tree is stored on-disk. During startup, is read into memory. When read, <code>BlockManager::m_block_index</code> field is filled with data - CBlockIndexes. Every CBlockIndex contains memory-only field <code>arith_uint256 nChainWork</code>, which is a total amount of work in the chain up to (and including) current block.</p>

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