6
2
While reading bitcoin source I found this short comment:
// Height first in coinbase required for block.version=2
(From https://github.com/bitcoin/bitcoin/blob/master/src/miner.cpp#L338).
Why this is required? Does it prevent some misuse or attack?
I found that this change was introduced in BIP-0034. In relevant pull request it is justified by following points:
Putting the height in the coinbase is desired for at least two reasons:
- It guarantees that every subsequent block and transaction hash is unique.
- It can be used to better reason about plausible difficulty for not-yet-connected blocks.
But for me this explains nothing: I don't see how adding height guarantees unique block hashes and I don't understand what is "plausible difficulty for not-yet-connected blocks".
Can you please explain how previous block hash guarantees block hash uniqueness? – max taldykin – 2014-10-02T05:38:55.983
Why do you think that it is not very important that there were duplicate coinbase transactions? It looks like that the sole reason of adding height is to prevent duplicate coinbase transactions. – max taldykin – 2014-10-02T05:42:49.287
BIP-30 prevents duplicate coinbase transactions. Adding block height allows the programs be less complicated while parsing arriving blocks – amaclin – 2014-10-02T07:00:27.420
@amaclin Thanks for pointing to BIP-30. I think this is the real answer to the "Why?" part of the question (please consider adding this to your answer).
– max taldykin – 2014-10-02T07:22:27.5401It is important for coinbase transactions to be unique because duplicates can't be referred to because they have the same transaction I'd as the first. Therefore they be spent and the 25 bitcoins (currently) are lost. – Jannes – 2014-10-02T23:32:48.660
@Jannes Sure. But that doesn't really matter. It's happened, what, once or twice in the history of Bitcoin? – Nick ODell – 2014-10-20T02:41:23.527
It does matter. Read the accepted answer. And the reason it hasn't happens more often is because it's now impossible. Which means that it was apparently 'important' enough to fix. – Jannes – 2014-10-20T06:33:29.860
1@Jannes That's a good point. You've convinced me, and I've removed the part of my post that was wrong. – Nick ODell – 2014-10-20T17:01:09.073