Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
RPC: augment getblockchaininfo bip9_softforks data #7948
Conversation
sipa
and 1 other
commented on an outdated diff
Apr 26, 2016
| @@ -5952,6 +5952,20 @@ ThresholdState VersionBitsTipState(const Consensus::Params& params, Consensus::D | ||
| return VersionBitsState(chainActive.Tip(), params, pos, versionbitscache); | ||
| } | ||
| +const CBlockIndex* VersionBitsLockedInBlock(const Consensus::DeploymentPos pos) | ||
| +{ | ||
| + LOCK(cs_main); | ||
| + ThresholdConditionCache cache = versionbitscache.caches[pos]; |
|
|
|
Why do you prefer to print block hash instead of block height? |
|
No real strong reason. Just that the height does not uniquely identify a block like its hash does, and if you want to lookup the block info (including its height), all you have to do after you have the hash is |
|
@mruddy Sure. But in this case, the lock in happens at height, not in the particular block hash - it can be reorganized. No? |
|
@paveljanik Yes, that's usually going to be the case. It would take an extraordinarily long re-org to change the height too (testnet style shenanigans). Height may be more intuitive to use here in that sense. If I made that change, I'd probably rename the attribute "lockedInHeight" too. I might do this tomorrow pending other feedback that that's not a good idea for some reason. |
mruddy
changed the title from
RPC: add locked_in block hash to getblockchaininfo bip9_softforks data
to
RPC: augment getblockchaininfo bip9_softforks data
Apr 27, 2016
|
Changed my mind on how this should work. Now a new member named "since" is part of the BIP9 data and it gives the height of the first block to which the current deployment status applied. Seems like this might be more useful. |
|
Travis problem unrelated ( ACK 4ba7830 Thanks!
This corresponds with the activation (https://www.reddit.com/r/Bitcoin/comments/4f4210/the_bip9_versionbits_csv_softfork_of_bip68_bip112/). |
MarcoFalke
added
the
RPC/REST/ZMQ
label
Apr 27, 2016
|
The "since" height is off-by-one, as the rules wouldn't have gone into effect until block height 770112 (all the version bits state calculations take the prev block as an argument, so 770111 was the height of the last block before the rules were activated). Also, when walking the versionbitscache, we should skip over entries that are not on Concept ACK. |
|
@sdaftuar Wow, great code review, thanks! You're right. Geez, I totally missed that. Updates made. Added tests. I also used some C++11 in the latest updates because that was enabled earlier today. |
|
@sipa now that this is stable (hasn't changed in about a week) are you ok with adding this bip9 data in this way? |
sipa
commented on an outdated diff
May 5, 2016
| @@ -5952,6 +5952,30 @@ ThresholdState VersionBitsTipState(const Consensus::Params& params, Consensus::D | ||
| return VersionBitsState(chainActive.Tip(), params, pos, versionbitscache); | ||
| } | ||
| +int VersionBitsStateBeginningBlockHeight(const Consensus::DeploymentPos pos, const ThresholdState thresholdState) |
sipa
Owner
|
|
@sipa I restructured things how I believe you meant. I tried to follow existing patterns at the same time. Please check it when you get a chance. I also added more tests. Thanks! |
sipa
commented on the diff
May 9, 2016
| + // BIP 9 about state DEFINED: "The genesis block is by definition in this state for each deployment." | ||
| + if (initialState == THRESHOLD_DEFINED) { | ||
| + return 0; | ||
| + } | ||
| + | ||
| + const int nPeriod = Period(params); | ||
| + | ||
| + // A block's state is always the same as that of the first of its period, so it is computed based on a pindexPrev whose height equals a multiple of nPeriod - 1. | ||
| + // To ease understanding of the following height calculation, it helps to remember that | ||
| + // right now pindexPrev points to the block prior to the block that we are computing for, thus: | ||
| + // if we are computing for the last block of a period, then pindexPrev points to the second to last block of the period, and | ||
| + // if we are computing for the first block of a period, then pindexPrev points to the last block of the previous period. | ||
| + // The parent of the genesis block is represented by NULL. | ||
| + pindexPrev = pindexPrev->GetAncestor(pindexPrev->nHeight - ((pindexPrev->nHeight + 1) % nPeriod)); | ||
| + | ||
| + const CBlockIndex* previousPeriodParent = pindexPrev->GetAncestor(pindexPrev->nHeight - nPeriod); |
mruddy
Contributor
|
|
@laanwj I think this is ready. Do you agree? |
|
utACK 6293424 |
|
IMO it would be nice to know at which block hash/height each transition was made. I think using the hash makes more sense, but not sure it matters much with BIP 9 (perhaps it might with some future softfork scheme?). |
|
@luke-jr By definition, consensus rules within a blockchain can only depend on its history, and not on that of other branches, so height is the only relevant value as it uniquely determines the block within the current chain. Furthermore, in BIP9, the status changes are never affected by the block itself (and often not by any of those in recent history before it either). |
|
ACK 6293424 |
|
Needs rebase. |
laanwj
added
the
Feature
label
Jun 16, 2016
|
rebase complete. |
|
@laanwj want to merge this? haven't changed since mid june. thanks! |
|
yep, that one-off travis failure looks unrelated to these changes. looks like something with compiling boost. |
|
rebased to stay current and get travis green again |
|
@laanwj if i rebase this to the 0.13 branch, would you merge it? if not, then should i close this pull? it's been unchanged for about four months and just got a conflict. the changes provide a little softfork info, but they also add a fair bit of code. i'm ok with either way you choose. |
|
This missed 0.13, and adds a feature, should be rebased to master instead. |
|
rebased on master. no worries, thanks for all the good work you do. |
laanwj
merged commit fc14609
into
bitcoin:master
Oct 19, 2016
1 check passed
added a commit
that referenced
this pull request
Oct 19, 2016
mruddy
deleted the
mruddy:version_bits_locked_in_block
branch
Oct 19, 2016
added a commit
to bitcoinknots/bitcoin
that referenced
this pull request
Oct 20, 2016
|
@pinheadmz I received your question: "Are you sure this offset is necessary? In regtest mode on my machine, segwit status is "started" on block 143, but this RPC call returns "since": 144 even though that block height has not been generated yet." Answer: When you start a fresh regtest node (regtest uses a retarget interval of 144 blocks), you have 1 block @ height 0 (the genesis block) and the bip9 softfork "segwit" is "defined". |
|
@mruddy Thanks! I also just saw the offset was already discussed earlier in the thread, it makes sense. |
mruddy commentedApr 26, 2016
This adds the hash of the first block of the LOCKED_IN period for a given deployment (when the deployment is LOCKED_IN or ACTIVE) to the
bip9_softforksdata of thegetblockchaininfoRPC.I implemented this as a simple scan through the already existing map values to make this change easy to review. I looked at adding an array to the version bits cache struct and then populating it from the
THRESHOLD_LOCKED_INcase inAbstractThresholdConditionChecker::GetStateFor, but that would have meant more refactoring.The motivation for this is that I was researching some forking going on on testnet3 and one of the first questions I had was, "When were the BIP9 forks locking in and activating?" This patch provides the info necessary to begin digging around and figuring that out. This provides the lock in block. Take its height and then mentally add 2016 to get the ACTIVE block height etc... This was the simplest change to get the info I was after.