This builds on #1525 (the framework for smoothly rolling out new chain/transaction rules), defining "nVersion=2" blocks that include the block height as the first bytes of their coinbase.
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.
The format of the height is "serialized CScript" -- first byte is number of bytes in the number (will be 0x03 on main net for the next 300 or so years), following bytes are little-endian representation of the number.
Only blocks with nVersion=2 are expected to have the height as the first bytes, and the "must have the height in the coinbase" rule is only enforced if nVersion=2 blocks are a super-majority (75% of last 1,000 blocks on main network) of the block's immediate ancestors.
This pull also contains a rule to REJECT nVersion=1 blocks once 95% of hashing power is producing nVersion=2 blocks. That means the last 5% of hashing power who refuse to upgrade will get orphaned.
All of this won't affect users/merchants at all, they will happily accept nVersion=1 or nVersion=2 blocks.
I tested this with a testnet-in-a-box setup, creating a 100-block-long nVersion=2 chain and then making sure that:
- nVersion=1 blocks were accepted
- nVersion=2 blocks that included the wrong block height were rejected (I hacked a bitcoind to test that).