BIP9: versionbits In a Nutshell
Hi, I was one of the authors/bikeshedders of BIP9, which Pieter Wuille recently refined (and implemented) into its final form. The bitcoin core plan is to use BIP9 for activations from now on, so let's look at how it works!
Some background:
- Blocks have a 32-bit "version" field. If the top three bits are "001", the other 29 bits represent possible soft forks.
- BIP9 uses the same 2016-block periods (roughly 2 weeks) as the difficulty adjustment does.
So, let's look at BIP68 & 112 (Sequence locks and OP_CHECKSEQUENCEVERIFY) which are being activated together:
- Every soft fork chooses an unused bit: these are using bit 1 (not bit 0), so expect to see blocks with version 536870914.
- Every soft fork chooses an start date: these use May 1st, 2016, and time out a year later if it fails.
- Every period, we look back to see if 95% have a bit set (75% for testnet).
- If so, and that bit is for a known soft fork, and we're within its start time that soft fork is locked-in: it will activate after another 2016 blocks, giving the stragglers time to upgrade.
There are also two alerts in the bitcoin core implementation:
- If at any stage 50 of the last 100 blocks have unexpected bits set, you get Warning: Unknown block versions being mined! It's possible unknown rules are in effect.
- If we see an unknown softfork bit activate: you get Warning: unknown new rules activated (versionbit X).
Now, when could the OP_CSV soft forks activate? bitcoin-core will only start setting the bit in the first period after the start date, so somewhere between 1st and 15th of May[1], then will take another period to lock-in (even if 95% of miners are already upgraded), then another period to activate. So early June would be the earliest possible date, but we'll get two weeks notice for sure.
The Old Algorithm
For historical purposes, I'll describe how the old soft-fork code worked. It used version as a simple counter, eg. 3 or above meant BIP66, 4 or above meant BIP65 support. Every block, it examined the last 1000 blocks to see if more than 75% had the new version. If so, then the new softfork rules were enforced on new version blocks: old version blocks would still be accepted, and use the old rules. If more than 95% had the new version, old version blocks would be rejected outright.
I remember Gregory Maxwell and other core devs stayed up late several nights because BIP66 was almost activated, but not quite. And as a miner there was no guarantee on how long before you had to upgrade: one smaller miner kept producing invalid blocks for weeks after the BIP66 soft fork. Now you get two weeks' notice (probably more if you're watching the network).
Finally, this change allows for miners to reject a particular soft fork without rejecting them all. If we're going to see more contentious or competing proposals in the future, this kind of plumbing allows it.
Hope that answers all your questions!
[1] It would be legal for an implementation to start setting it on the very first block past the start date, though it's easier to only think about version bits once every two weeks as bitcoin-core does.