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

BIP9: versionbits #6816

Closed
wants to merge 10 commits into from
Closed

BIP9: versionbits #6816

wants to merge 10 commits into from

Conversation

CodeShark
Copy link
Contributor

This is the reference implementation for BIP9.

@CodeShark CodeShark force-pushed the versionbits branch 2 times, most recently from 3b58dd7 to 220bd24 Compare October 13, 2015 16:52
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
/*
_ _ _ _
__ _____ _ __ ___(_) ___ _ __ | |__ (_) |_ ___ ___ _ __ _ __
Copy link
Contributor

Choose a reason for hiding this comment

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

Beauty, but nack this thing.

Copy link
Member

Choose a reason for hiding this comment

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

Agree with @jtimon. Also it may be better to split the copyright (c) line into two. One for the initial author and initial year and a second one for the bitcoin core devs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Doxygen supports documentation on a file level, which seems more useful than ascii arts.

One for the initial author and initial year and a second one for the bitcoin core devs.

Is this really necessary? There is already the much more precise git history, and to my understanding, all contributors qualify as "Bitcoin Core developers".

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry to be a spoilsport, but the ASCII art has to go.

@jtimon
Copy link
Contributor

jtimon commented Oct 14, 2015

The deployment times of concrete softforks depend on the chain (ie they are expected to be different in main and testnet3). Here's one solution:

  1. The Softfork class moves to consensus/params.h (and becomes a method-less struct, since that file is expected to be exposed to a complete libconsensus).

  2. Consensus::Params gets a new field softforks, which is an array of these new Softfork structs, and whose static size is determined by MAX_SOFTFORKS, the last element of an enumeration of all currently supported softforks.

  3. Every time a new softfork is supported, it must be included in that enum and the static size of the array will increase.

This way we maintain the ability to independently deploy different softforks in different testchains while respecting Consensus::Params as the only interface to communicate differences between chains to the consensus code (a problem we had already solved, in a way that is compatible with a C API).

@sipa
Copy link
Member

sipa commented Oct 14, 2015

Agree with @jtimon's comments.

@jtimon jtimon mentioned this pull request Oct 15, 2015
int bit = psoftFork->GetBit();
bool isBitSet = (pblockIndex->pprev->nVersion >> bit) & 0x1;

cout << "STATE CHANGED - height: " << pblockIndex->nHeight << " median time: " << pblockIndex->GetMedianTimePast()
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the extra information, but you may look into BOOST_TEST_MESSAGE().

@CodeShark CodeShark force-pushed the versionbits branch 5 times, most recently from dd93db7 to 329ffc7 Compare October 16, 2015 07:11
@CodeShark
Copy link
Contributor Author

@jtimon @sipa After thinking a little bit more about how to make the soft fork deployments chain-specific, I think CChainParams is the place to initialize that, not Consensus::Params. So I added a SoftForkDeployments member to CChainParams and created a dummy BIP9999 on regtest to demonstrate the deployment mechanism in action.

@jtimon
Copy link
Contributor

jtimon commented Oct 16, 2015

Consensus::Params it's the place to put consensus critical chain params, not CChainParams. If libconsensus was complete you would have just broke its build or moved consensus functionality out of libconsensus by putting it in the NON CONSENSUS COMPATIBLE CChainParams. Can you please follow the C API compatible suggestion?
How do you plan to expose CChainParams in libconsensus' API if not by passing Consensus::Params to the exposed functions that need it?

@CodeShark CodeShark force-pushed the versionbits branch 3 times, most recently from b96ad40 to f0cb9d3 Compare October 16, 2015 10:40
@sipa
Copy link
Member

sipa commented Oct 16, 2015

@CodeShark The idea is that there are three layers of chain-specific parameters...:

  • basechainparams, which contain things shared by both nodes and RPC clients
  • consensus/params, which contains all consensus-critical parametersl
  • chainparams, which contains node operation parameters, including an encapsulated consensus/params

The reason is to avoid having the consensus code depend on knowing where DNS seeds are, or to avoid having the RPC code depend on CBlock because of the genesis definition.

@CodeShark
Copy link
Contributor Author

@sipa OK, I guess what I meant to say is that CChainParams (or its subclasses, rather) is where the Consensus::Params structure gets initialized. So I went ahead and moved the SoftForkDeployments instance to Consensus::Params and am initializing immediately after the other Consensus::Params fields are initialized.

@sipa
Copy link
Member

sipa commented Oct 16, 2015 via email

@CodeShark CodeShark force-pushed the versionbits branch 2 times, most recently from 1e1dc7e to 77c3fad Compare October 17, 2015 10:01
@@ -19,6 +20,8 @@ struct Params {
int nMajorityEnforceBlockUpgrade;
int nMajorityRejectBlockOutdated;
int nMajorityWindow;
/** Used for versionbits */
VersionBits::SoftForkDeployments softForkDeployments;
Copy link
Contributor

Choose a reason for hiding this comment

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

This field ( by being a C++ class with methods) impedes this file from being exposed in the libconsensus C API. What's wrong with moving the rules enum to this file and having a static size array as suggested?
Maybe you have an alternative to passing a Consensus::Params struct as a parameter of the exposed C libconsensus runctions that need it the communicate chain-dependent data?
Can you draft a C API for contextualcheckblockheader after this (don't worry about CBlockIndex which is that part to be solved, worry about the part that was solved but you are breaking here). Maybe taking a look at #5995 (where a C API compatible VerifyHeader is compiled within libconsensus) helps you understand what exactly you are breaking with this.


// -regtest only: allow overriding block.nVersion with
// -blockversion=N to test forking scenarios
if (Params().MineBlocksOnDemand())
Copy link
Contributor

Choose a reason for hiding this comment

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

Please s/Params()/chainparams/


private:
RuleStateMap m_ruleStateMap;
int m_activationInterval;
Copy link
Contributor

Choose a reason for hiding this comment

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

This field is unnecessarily redundant. If you don't want to create a new field in Consensus::Params, can you at least use consensusParams.DifficultyAdjustmentInterval() directly?

@jtimon
Copy link
Contributor

jtimon commented Oct 26, 2015

Here's a version rebased on top of master:

bitcoin:master...jtimon:CodeShark_versionbits_rebased

Here are a couple of nits (don't BIP42 and BIP62, and don't BlockRuleIndex::m_activationInterval) implemented in code: jtimon/bitcoin@CodeShark_versionbits_rebased...jtimon:versionbits-nits

@CodeShark CodeShark force-pushed the versionbits branch 2 times, most recently from c671a6e to 06992eb Compare October 26, 2015 18:42
{
using namespace Consensus::VersionBits;

if (!pindexPrev)
Copy link
Contributor

Choose a reason for hiding this comment

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

In which cases does pindexPrev need be passed as something different from NULL?
Same question for Consensus::SoftForks::UseRule().

@dcousens
Copy link
Contributor

concept ACK, needs rebase

@jtimon
Copy link
Contributor

jtimon commented Mar 16, 2016

close in favor of #7575 ?

@btcdrak
Copy link
Contributor

btcdrak commented Mar 16, 2016

@jtimon Yes.

@laanwj laanwj closed this Mar 17, 2016
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
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.