3

If there are "fork" chains coming off a block, how do we keep track of the UTXOs of different public keys?

Would I just store UTXOs derived from the longest chain and recalculate if another "branch" becomes longer than this chain?

1 Answer 1

2

Each node considers the valid chaintip with the most-work that it knows about the canonical state of the network. Only this "best chain" matters to establish the state of the UTXO set. If another chaintip overtakes the prior best chain, the node reverts blocks until it arrives at the highest common previous block and then applies the new chain.

The nodes only need to assess the header of the block. Each block mentions its predecessor in the header, so the node can see where a block attaches to the blockchain. If a new block header is not leading to a better chaintip, nodes will not even retrieve the block. Pieter recently wrote a detailed description of how block synchronization works today, if you want to understand the process in more depth.

Of course a miner could extend whatever chaintip they want, however not only are stale chaintips easy to identify, the miners will also lose money on doing so:
The best chain is a single-file connection between Genesis block and the best chaintip. Every block has exactly one predecessor and you can only spend coinbase transaction outputs (i.e. the mining reward) when they have 100 confirmations. Stale chaintips are not part of that best chain, and therefore the block rewards are paid to outputs that don’t exist in the best chain. Mining on top of invalid blocks costs you the same effort, but nets you zero revenue.

4
  • Ah right, thanks, that makes sense. But wouldn't that mean blocks can't be published with previous blocks on invalid chaintips? Does that restrict miners to only publishing blocks on the chain that the node considers the longest?
    – Shay
    Commented Jan 22 at 20:03
  • 1
    Any miner can extend whatever chaintip they want, it’s just that if their block isn’t part of the best chain in the long run, they’ll find it hard to sell their mining reward, because the output doesn’t exist in the best chain. The best chain is single-file, every block has exactly one predecessor and you can only spend coinbase transaction outputs when they have 100 confirmations. Mining on top of invalid blocks costs you the same effort, but nets you zero.
    – Murch
    Commented Jan 22 at 20:25
  • So if miners extend a shorter length chain, would I have to search UTXOs on that "branch" to see if their block is valid instead of using the UTXO set? Since surely the UTXO set the node has stored would just be valid for the longest chain.
    – Shay
    Commented Jan 22 at 22:45
  • 2
    @Shay Your node will only download the headers of this new branch unless it actually is a (candidate) best block. Once the branch is extended long enough to potentially overtake (or at least tie with) the current best block in terms of work, it is downloaded and partially validated. The actual full validation that involves the UTXO set is only performed if it would actually be the best chain. See my answer here for more depth: bitcoin.stackexchange.com/a/121293/208 Commented Jan 23 at 0:38

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.