Skip to content

Conversation

luke-jr
Copy link
Member

@luke-jr luke-jr commented Apr 25, 2016

Versionbits was released in 0.12.1, but only included updates for the consensus layer. Due to the low-level design of GBT, it is currently not possible to use in practice, since the client has no way to identify the meaning of the block version anymore. Miners and pools can as a hack override/ignore the block version entirely, but this is not really a solution.

This change adds the necessary versionbits information to GBT so that miners can implement it safely.

It also detects when the client is outdated, but can still safely use the template as-is, and uses the GBT version/force and/or rules/force mutability flags to indicate that. This enables older miners that only support at least BIP 34 (block v2) to work with the newer bitcoind. Obviously this is a very short-term benefit in practice, since segwit necessarily will break such miners, but will become useful again as soon as the next simple softfork is deployed (in which case clients need only support segwit).

@luke-jr
Copy link
Member Author

luke-jr commented Apr 27, 2016

@sipa Added a commit to try to address the locking stuff cleaner.

UniValue aRules(UniValue::VARR);
UniValue vbavailable(UniValue::VOBJ);
const std::vector<ThresholdState> vbstates = versionbitscache.GetAllThresholdStates(pindexPrev, cparams);
for (int i = 0; i < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++i) {
Copy link
Member

@theuni theuni May 3, 2016

Choose a reason for hiding this comment

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

Tangential nit (just so I don't forget): DeploymentPos should become a strongly typed enum
edit: ThresholdState too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Should I be iterating over them some other way?

Copy link
Member

Choose a reason for hiding this comment

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

See below. I think returning a map would make this more clear.

@theuni
Copy link
Member

theuni commented May 5, 2016

ut ACK, other than the nits.

@theuni
Copy link
Member

theuni commented May 5, 2016

Needs some tests, though.

{
private:
CCriticalSection cs;
Copy link
Member

@sipa sipa May 9, 2016

Choose a reason for hiding this comment

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

NACK on this; this class will be needed inside abstracted consensus logic, which shouldn't do its own locking.

VersionBitsCache is intended to be a black box data type locked by the user (main, in this case) but only accessed through functions in versionbits.cpp.

@sipa
Copy link
Member

sipa commented May 9, 2016

@luke-jr Can you revert the last commit? The design for having the data structure not do its own locking is very intentional.

@luke-jr
Copy link
Member Author

luke-jr commented May 9, 2016

Reverted... but it's what I thought you wanted.

@luke-jr
Copy link
Member Author

luke-jr commented May 13, 2016

Updated for '!' prefix

@@ -458,9 +490,10 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
pindexPrev = pindexPrevNew;
}
CBlock* pblock = &pblocktemplate->block; // pointer for convenience
const Consensus::Params& cparams = Params().GetConsensus();
Copy link
Contributor

@jtimon jtimon May 20, 2016

Choose a reason for hiding this comment

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

Bike-shedding: Can you call this var consensusParams for consistency with other parts of the code?

@jtimon
Copy link
Contributor

jtimon commented May 21, 2016

Fast-review ACK

@luke-jr
Copy link
Member Author

luke-jr commented May 29, 2016

Tested with libblkmaker 0.5.3 (ie, using version/force) and bitcoin/libblkmaker#5 on testnet-in-a-box.

@sipa
Copy link
Member

sipa commented May 31, 2016

utACK 46e8e06a5b62892024bf0da0e6104cc30a2a50cb. Squash some?

@luke-jr
Copy link
Member Author

luke-jr commented Jun 1, 2016

Squashing is a bad practice, so I prefer not to, if that's okay...

@maflcko
Copy link
Member

maflcko commented Jun 1, 2016

There is 12 commits, so squashing would help to not bury the previous code under several layers of history. Not to mention that squashing would make it probably easier to read the commits of this pull.

@sipa
Copy link
Member

sipa commented Jun 1, 2016 via email

@gmaxwell
Copy link
Contributor

gmaxwell commented Jun 1, 2016

The merged tree is forever. We should favor post-merge reviewability.

@luke-jr
Copy link
Member Author

luke-jr commented Jun 1, 2016

Squashed into 4 logical commits, and added a few comment lines explaining the logic around omitting a rule check for version/force.

// Add to vbavailable (and it's presumably in version already)
vbavailable.push_back(Pair(gbt_vb_name(pos), consensusParams.vDeployments[pos].bit));
{
const struct BIP9DeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos]; vbavailable.push_back(Pair(gbt_vb_name(pos), consensusParams.vDeployments[pos].bit));
Copy link
Member

Choose a reason for hiding this comment

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

more than a small formatting nit here :)

Copy link
Member Author

Choose a reason for hiding this comment

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

LOL, how did that happen? >_<

@@ -16,6 +16,7 @@ enum DeploymentPos
{
DEPLOYMENT_TESTDUMMY,
DEPLOYMENT_CSV, // Deployment of BIP68, BIP112, and BIP113.
// NOTE: Also add new deployments to VersionBitsDeploymentNames in versionbits.cpp
Copy link
Member

Choose a reason for hiding this comment

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

VersionBitsDeploymentInfo

@theuni
Copy link
Member

theuni commented Jun 6, 2016

ut ACK, other than the nits above. I'll do thorough testing of segwit's implementation here.

luke-jr added 4 commits June 6, 2016 17:10
- BIP9DeploymentInfo struct for static deployment info
- VersionBitsDeploymentInfo: Avoid C++11ism by commenting parameter names
- getblocktemplate: Make sure to set deployments in the version if it is LOCKED_IN
- In this commit, all rules are considered required for clients to support
@luke-jr
Copy link
Member Author

luke-jr commented Jun 6, 2016

Nits fixed.

@sipa
Copy link
Member

sipa commented Jun 6, 2016

utACK 12c708a

@sipa
Copy link
Member

sipa commented Jun 8, 2016

Also needs backport to 0.12.

@sipa sipa merged commit 12c708a into bitcoin:master Jun 8, 2016
sipa added a commit that referenced this pull request Jun 8, 2016
12c708a getblocktemplate: Use version/force mutation to support pre-BIP9 clients (Luke Dashjr)
9879060 getblocktemplate: Explicitly handle the distinction between GBT-affecting softforks vs not (Luke Dashjr)
72cd6b2 qa/rpc-tests: bip9-softforks: Add tests for getblocktemplate versionbits updates (Luke Dashjr)
d3df40e Implement BIP 9 GBT changes (Luke Dashjr)
@sipa sipa mentioned this pull request Jun 13, 2016
7 tasks
luke-jr added a commit to bitcoinknots/bitcoin that referenced this pull request Jun 27, 2016
@laanwj laanwj added this to the 0.12.2 milestone Sep 26, 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.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants