-
Notifications
You must be signed in to change notification settings - Fork 36.3k
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
Introduce deploymentstatus #19438
Introduce deploymentstatus #19438
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
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.
Concept ACK and some lite code review feedback.
src/consensus/params.h
Outdated
@@ -11,6 +11,15 @@ | |||
|
|||
namespace Consensus { | |||
|
|||
enum BuriedDeployment |
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.
prefer enum class to prevent leaking names.
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.
Also helps with avoiding overlap with SignalledDeployment.
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.
Leaking the names is the point -- otherwise you'd need to change every use from Consensus::DeploymentPos::SEGWIT
to Consensus::BuriedDeployment::SEGWIT
. With C++20, you will be able to specify enum class DeploymentPos { .. }; using enum DeploymentPos;
but that's a while away.
src/consensus/params.h
Outdated
DEPLOYMENT_CLTV = -255, | ||
DEPLOYMENT_DERSIG, | ||
DEPLOYMENT_CSV, | ||
DEPLOYMENT_SEGWIT, |
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.
prefer explicitly numbering these.
-255 is an extremely odd number, can you clarify why you picked it? It doesn't fit in a signed byte.
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.
Explicitly numbering them risks accidentally repeating a number. No particular objection to a different starting point. Could perhaps make it enum DeploymentPos : uint8_t
and enum BuriedDeployment : int16_t { DEPLOYMENT_CLTV = 256, // larger than largest possible DeploymentPos value
.
(I guess 2**n
is an "extremely even" number, so calling +/- 2**n-1
"extremely odd" makes a lot of sense...)
src/consensus/params.h
Outdated
@@ -80,7 +89,19 @@ struct Params { | |||
int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; } | |||
uint256 nMinimumChainWork; | |||
uint256 defaultAssumeValid; | |||
|
|||
inline int DeploymentHeight(BuriedDeployment dep) const |
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.
Maybe tighter to make this a templated function as we're never calling DeploymentHeight with a variable, only literal.
Then we get not just a warning, but a compiler error.
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 tried that, but thought that it might be useful to be able to do for (dep = 0; dep < MAX_VERSIONBITS_DEPLOYMENTS; ++dep) { ... DeploymentActiveAt(pindex, consParams, dep) .. }
. I think in all the cases where that currently comes up you want to know more fine grained details though. (Changing BuriedForkDescPushBack
to take a BuriedDeployment instead of a height would make use of that, eg)
I don't think the type checking is any better with the template though, as unfortunately you can invoke DeploymentHeight<(BuriedDeployment)9000>()
just as easily as DeploymentHeight((BuriedDeployment)9000)
with both g++ and clang++.
extern VersionBitsCache versionbitscache GUARDED_BY(cs_main); | ||
|
||
/** Determine if a deployment is active for the next block */ | ||
inline bool DeploymentActiveAfter(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::BuriedDeployment dep) |
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.
This dispatch scares me a bit unless we use enum class -- enums could coerce poorly right?
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.
Nope; int (and the like) won't automatically coerce to enum, so with int x = Consensus::DEPLOYMENT_SEGWIT; return DeploymentActiveAt(pindex, params, x)
you get errors:
validation.cpp:1921:12: error: no matching function for call to 'DeploymentActiveAt'
return DeploymentActiveAt(pindex, consensusparams, x);
^~~~~~~~~~~~~~~~~~
./deploymentstatus.h:32:13: note: candidate function not viable: no known conversion from 'int' to 'Consensus::BuriedDeployment' for 3rd argument
inline bool DeploymentActiveAt(const CBlockIndex* pindex, const Consensus::Params& params, Consensus::BuriedDeployment dep)
^
./deploymentstatus.h:37:13: note: candidate function not viable: no known conversion from 'int' to 'Consensus::DeploymentPos' for 3rd argument
inline bool DeploymentActiveAt(const CBlockIndex* pindex, const Consensus::Params& params, Consensus::DeploymentPos dep) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
^
(even if it did, which enum it coerced to is ambiguous between the two types, resulting in a failure like error: call to 'DeploymentActiveAt' is ambiguous
)
5834cc8
to
6b08b76
Compare
6b08b76
to
787040b
Compare
787040b
to
1f1d51d
Compare
1f1d51d
to
91572f3
Compare
e14966e
to
df308ab
Compare
Rebased past #21789 |
Adds support for versionbits deployments to DeploymentEnabled, DeploymentActiveAfter and DeploymentActiveAt. Also moves versionbitscache from validation to deploymentstatus.
-BEGIN VERIFY SCRIPT- sed -i -e 's/versionbitscache/g_versionbitscache/g' $(git grep -l versionbitscache) -END VERIFY SCRIPT-
Rename BIP9SoftForkPushBack and BuriedSoftForkPushBack to SoftForkPushBack and have the compiler figure out which one to use based on the deployment type. Avoids the need to update the file when burying a deployment.
Moves the VersionBits* functions to be methods of the cache class, and makes the cache and its lock private to the class.
This also changes ComputeBlockVersion to take the versionbits cache mutex once, rather than once for each versionbits deployment.
df308ab
to
e48826a
Compare
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.
re-ACK e48826a 🥈
Checked with:
git range-diff bitcoin-core/master e14966e e48826a --word-diff-regex=. -U0
Show signature and timestamp
Signature:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
re-ACK e48826ad87b4f92261f7433e84f48dac9bd9e5c3 🥈
Checked with:
git range-diff bitcoin-core/master e14966ee31f02e359896dbb72e2627b3ae12a314 e48826ad87b4f92261f7433e84f48dac9bd9e5c3 --word-diff-regex=. -U0
-----BEGIN PGP SIGNATURE-----
iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUh+dAv+NVpZKf22BScmqPb4YLJH2snw87TwSnr6Ez2ocyL441p57JrElilouzMN
gklFgwx0RYY2WlGKtGVub1aa3gVLqmDbdWKi6sGxTJB+5tbQnaK4S5tEDKAWfPDu
q7xawsZ7mOKeyIJXlRrwMiipeziVGtuDW7pQ5OkfCfQevvCMmexdA/vwigKR9UbW
adVkvMNwkA1g8LLbfn3xMUGk3QnidnYyaJtP+55LK91kLMx/5fDgmEoj5kBFYu1s
8n5SE4UW06RfkUfAuPJT5TgM3IjxoHmO9bwQbdh27a/1yY+zTggjy9Ak8cWs3xAi
jr3NjAohqfp1EKKMP8/oGTUn7AHMUu/tUPzqWH0iTJ2NdGt8HHrT54qBSB7ryS/W
+rfMOv0G3quOWCd0jc5zQLHsaMndlItfPgRMWBgMQ255zo0hWBOs6HV9Xe1kuZgF
4jCLR/KvxoK9/e0ore9XqEDpyeABo0oRwzVSg0XrHIMWHSpB2qOZx1ycQwqnoaR4
Y722yBJ3
=PNtg
-----END PGP SIGNATURE-----
Timestamp of file with hash 51b700b2e20a4085313cce0dc833915df20496b87f40dbee5ed2e7651008877d -
ACK e48826a |
ACK e48826a |
Introduces helper functions to make it easy to bury future deployments, along the lines of the suggestion from 11398 "I would prefer it if a buried deployment wouldn't require all code paths that check the BIP9 status to require changing".
This provides three functions:
DeploymentEnabled()
which tests if a deployment can ever be active,DeploymentActiveAt()
which checks if a deployment should be enforced in the given block, andDeploymentActiveAfter()
which checks if a deployment should be enforced in the block following the given block, and overloads all three to work both with buried deployments and versionbits deployments.This adds a dedicated lock for the versionbits cache, which is acquired internally by the versionbits functions, rather than relying on
cs_main
. It also moves moves versionbitscache into deploymentstatus to avoid a circular dependency with validation.