I'm currently implementing the rpc call invalidateblock on btcd, an alternate Bitcoin full node implementation. I'm trying to figure out how Bitcoin Core handles branch selection on reorganizations with invalidateblock.

Say there's 3 chaintips like so:

genesis -> 1  -> 2  -> 3  (active)     (chainwork=8)
       \-> 1a             (valid-fork) (chainwork=4)
       \-> 1b             (valid-fork) (chainwork=6)

Blocks at height 1 were received in the order of: 1, 1a, 1b. Block 1 was received most recently and block 1b was received last.

If I call invalidateblock on block 2, which block will become the active chaintip?

1 Answer 1


The same rules apply as during normal active-chain selection:

  1. Ignore all known-invalid blocks and their descendants
  2. Of what remains, keep only the tips with the most chainwork
  3. If there are multiple of those max-chainwork valid tips, pick the one which was received first.

So in your example it would depend on how much chainwork genesis+1 has. If it's more than 6, 1 would win. If it's less than 6, 1b would win. If it is equal to 6, it will depend on whether 1 or 1b was received first.

  • Follow up question: Suppose I called invalidateblock on block 3. genesis+1+2's chainwork is 6. If block 1b's chainwork is 7, would the active chain tip now be 1b? Dec 19, 2022 at 7:34
  • 1
    @kcalvinalvin Yes, the history is not relevant in determining what the new best block becomes, given the set of blocks, their validity, their chainwork, and their time of receiving, you can always determine what the active chaintip becomes. Dec 19, 2022 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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