-
Notifications
You must be signed in to change notification settings - Fork 36.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minimal BIP9 implementation #7575
Conversation
Could you add deployment status to the |
Concept ACK, I prefer this BIP9 implementation. |
There are some |
Fixed tests. |
} | ||
} | ||
|
||
if (nVersion == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not simply start using the versionbit prefix without voting for any concrete bit instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not simply start using the versionbit prefix without voting for any
concrete bit instead?
That would mean that versionbits on itself is a change, and lack of
adoption of versionbits by miners would then cause the warning logic to
trigger on new nodes.
Using this logc here, versionbits gets rolled out simultaneously with the
first fork that uses it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, if we are going to wait to deploy the first SF to merge it, I think it makes even more sense that we never return Consensus::VERSIONBITS_LAST_OLD_BLOCK_VERSION here.
That would mean that versionbits on itself is a change, and lack of
adoption of versionbits by miners would then cause the warning logic to
trigger on new nodes.
Just like changing the version to 8 without doing anything else would be. But it doesn't affect functionality.
The new nodes would only get warnings if the miners, apart from adopting this change were adopting or implementing other change to vote on concrete bits (if they only set nVersion to Consensus::VERSIONBITS_TOP_BITS), no warnings should be raised (unless an unknown SF has been deployed using versionbits, in which case is good that they get the warnings).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I get it, it's the old nodes seeing the "empty versionbits" version which would get (unnecessarily?) be told to upgrade and it doesn't matter whether we introduce a SF with BIP9 or not because the start date will be after the miners start using the new code to produce their new versions.
But I think I still disagree, though.
If in march 15th 95% of the miners are ready to deploy a softfork scheduled for april 1st, I believe old nodes should actually receive the upgrade warning already, even if the message is not accurate.
EDIT: anyway, this disagreement is minor in the sense that it cannot greatly affect the implementation, the difference will be about 3-lines. So don't hurry to answer this.
EDIT: nah, 95% of miner will use BIP9 later, never mind, question answered.
Updated to correspond to latest BIP9 (see bitcoin/bips#344, bitcoin/bips#345, bitcoin/bips#346), and fixed the tests. I also have an alternate version that factors out the cache, see sipa@218d2fd). |
Should be ready for review. |
utACK 7662816 |
strMiscWarning = _("Warning: unknown softfork has activated"); | ||
CAlert::Notify(strMiscWarning, true); | ||
} else { | ||
LogPrintf("Warning: An unknown softfork is about to activate"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing a trailing \n
Fixed a few bugs:
|
@@ -22,6 +43,14 @@ struct Params { | |||
/** Block height and hash at which BIP34 becomes active */ | |||
int BIP34Height; | |||
uint256 BIP34Hash; | |||
/** | |||
* Minimum blocks including miner confirmation of the total of 2016 blocks in a retargetting period, | |||
* (nPowTargetTimespan / nPowTargetSpacing) wich is also used for BIP9 deployments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wich -> which
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
} | ||
} | ||
} | ||
int32_t nExpectedVersion = ComputeBlockVersion(pindex->pprev, chainParams.GetConsensus()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Sorry if this is a repost, I think github ate my first attempt to comment)
I think we should move this line into the for loop below; otherwise we'd generate a warning after a known soft-fork activates.
Inspired by former implementations by Eric Lombrozo and Rusty Russell, and based on code by Jorge Timon.
All comments addressed, I think. |
Tested ACK 532cbb2 |
ACK If anyone is interested I also tested the warning logic with an RPC test (sdaftuar@4c2e8ba) |
Included @sdaftuar's warning logic RPC test. |
@@ -604,6 +604,20 @@ static UniValue SoftForkDesc(const std::string &name, int version, CBlockIndex* | |||
return rv; | |||
} | |||
|
|||
static UniValue BIP9SoftForkDesc(const std::string& name, const Consensus::Params& consensusParams, Consensus::DeploymentPos id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this loop throught all the deployments defined in Consensus::Params and be called from somewhere?
Style: why is not indented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's called once for every deployment below, similar to how SoftForkMajorityDesc is. There just are no deployments just yet.
Making this function iterate through all deployments would require putting knowledge of the names of all deployments in the consensus params, and would make it inevitable that the test deployment is listed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: what do you mean by not indented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhmm, I can only find one instance of the string "BIP9SoftForkDesc" in the changes.
re itarate with knowledge of the names, what's wrong with
for (int i = 0; i < MAX_VERSION_BITS_DEPLOYMENTS; ++i)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't know what string name to give to the Object entry inside "bip9_softforks".
Yes you can't find any calls to it yet, because there are no BIP9 softforks defined. Future deployments using BIP9 are supposed to be added below, just like ISM softforks were supposed to be added below to "softforks".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style, oh, never mind: https://github.com/bitcoin/bitcoin/blob/master/src/.clang-format#L27
I see, I didn't thought about the name.
re-utACK 8c74ced |
Code review ACK |
Tested ACK 8c74ced |
@sipa I realize you might still be changing this, but in the event that you're not, I backported it to 0.11 along with the soft fork for BIP 68,112,113 here: The RPC tests are annoying to backport, so I left 2 of them out, but tested using the recent RPC test bip68-112-113.py against the 0.11 binary. |
@morcos I'm fine with the current state. |
utACK |
8c74ced RPC test for BIP9 warning logic (Suhas Daftuar) 7870deb Test versionbits deployments (Suhas Daftuar) 532cbb2 Add testing of ComputeBlockVersion (Suhas Daftuar) d23f6c6 Softfork status report in RPC (Pieter Wuille) 732e774 Versionbits tests (Pieter Wuille) 6851107 BIP9 Implementation (Pieter Wuille)
|
||
namespace Consensus { | ||
|
||
enum DeploymentPos |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this called "DeploymentPos"? It's not a bit position; the actual bit positions have another layer of indirection in the BIP9Deployment structure: https://github.com/sipa/bitcoin/blob/8c74cedef53ab791ed333f25794f8b9d2e9f51aa/src/consensus/params.h#L26
We should change this to DeploymentId
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'position' is a very ambigious, yes. It's almost never a good choice.
Made a similar comment here on another pull: #7541 (comment)
Agree 'Id' seems be a better fit here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I'll do a pull-req to fix that - but next week after the long weekend!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the position in Consensus::Params::vDeployments. Id could have been another option, but O disagree there's anything to fix here. Seems too late for bike-shedding this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a comment for doxygen would also help if the purpose is not immediately clear from the code alone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same confusion as @petertodd when initially reading the code, so for new developers it must be worse. I do think at least a comment should be added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK on adding documentation.
Network upgrade activation mechanism Implements ZIP 200. Integration with `CChainParams` inspired by bitcoin/bitcoin#7575. Includes block index rewinding logic cherry-picked from bitcoin/bitcoin#8149. Closes #2286. Part of #2905.
This is an alternative to #6816 and #7566, implementing BIP9 with minimal code changes, including mining logic, softfork warning logic, and some unit tests.
It adds support for a begin time before version bits are counted, which is not in BIP9 currently, though it is compatible.
The last commit demonstrates how to add a simple softfork.