Skip to content
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

Merged
merged 6 commits into from
Mar 18, 2016
Merged

Minimal BIP9 implementation #7575

merged 6 commits into from
Mar 18, 2016

Conversation

sipa
Copy link
Member

@sipa sipa commented Feb 21, 2016

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.

@btcdrak
Copy link
Contributor

btcdrak commented Feb 22, 2016

Could you add deployment status to the getblockchaininfo RPC?

@dcousens
Copy link
Contributor

@sipa any reason not to just extend #7566?

once-over utACK 50278bb, concept ACK

@btcdrak
Copy link
Contributor

btcdrak commented Feb 22, 2016

Concept ACK, I prefer this BIP9 implementation.

@sipa
Copy link
Member Author

sipa commented Feb 22, 2016 via email

@jonasschnelli
Copy link
Contributor

There are some versionbits_test.cpp formatting/syntax issues (https://travis-ci.org/bitcoin/bitcoin/jobs/110833452#L1736)

@sipa
Copy link
Member Author

sipa commented Feb 24, 2016

Fixed tests.

}
}

if (nVersion == 0) {
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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).

Copy link
Member Author

@sipa sipa Feb 25, 2016 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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.

@sipa
Copy link
Member Author

sipa commented Mar 3, 2016

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).

@sipa
Copy link
Member Author

sipa commented Mar 3, 2016

  1. Moved the versionbits logic out of consensus, and make it not depend on it is
  2. Added (very basic) reporting of BIP9 deployment status through RPC
  3. Switched the window size from 2016 to 144 for regtest
  4. Factored the cache out of the versionbits logic classes

Should be ready for review.

@jtimon
Copy link
Contributor

jtimon commented Mar 4, 2016

utACK 7662816
EDIT: To be clear, I didn't meant to rename consensus/versionbits.o to versionbits.o, I was just talking about the "consensus package" in the makefile (because otherwise the whole package would depend on chain.o and its dependencies). I'm sorry for the misunderstanding and I understand if you don't want to change it back again.

strMiscWarning = _("Warning: unknown softfork has activated");
CAlert::Notify(strMiscWarning, true);
} else {
LogPrintf("Warning: An unknown softfork is about to activate");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing a trailing \n

@sipa
Copy link
Member Author

sipa commented Mar 4, 2016

Fixed a few bugs:

  • typo in the warning logic which made it trigger all the time
  • newline at the end of unknown softfork warning log message
  • bip9_softforks was not being added to the getblockchaininfo output

@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wich -> which

Copy link
Member Author

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());
Copy link
Member

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.

sipa and others added 5 commits March 15, 2016 16:54
@sipa
Copy link
Member Author

sipa commented Mar 15, 2016

All comments addressed, I think.

@btcdrak
Copy link
Contributor

btcdrak commented Mar 15, 2016

Tested ACK 532cbb2

@sdaftuar
Copy link
Member

ACK

If anyone is interested I also tested the warning logic with an RPC test (sdaftuar@4c2e8ba)

@sipa
Copy link
Member Author

sipa commented Mar 16, 2016

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)
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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?

Copy link
Contributor

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)

?

Copy link
Member Author

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".

Copy link
Contributor

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.

@jtimon
Copy link
Contributor

jtimon commented Mar 16, 2016

re-utACK 8c74ced modulo last nit.

@morcos
Copy link
Contributor

morcos commented Mar 16, 2016

Code review ACK

@btcdrak
Copy link
Contributor

btcdrak commented Mar 16, 2016

Tested ACK 8c74ced

@morcos
Copy link
Contributor

morcos commented Mar 16, 2016

@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:
https://github.com/bitcoin/bitcoin/compare/0.11...morcos:backportBIP9SoftFork?expand=1

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.

@sipa
Copy link
Member Author

sipa commented Mar 16, 2016

@morcos I'm fine with the current state.

@jonasschnelli
Copy link
Contributor

utACK

@laanwj laanwj merged commit 8c74ced into bitcoin:master Mar 18, 2016
laanwj added a commit that referenced this pull request Mar 18, 2016
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
Copy link
Contributor

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

Copy link
Member

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.

Copy link
Contributor

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!

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK on adding documentation.

zkbot added a commit to zcash/zcash that referenced this pull request Feb 7, 2018
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.
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.