-
Notifications
You must be signed in to change notification settings - Fork 38.6k
RPC: add versionHex in getblock and getblockheader JSON results #7774
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
Conversation
|
I'd like to see this, but I'm not sure it's worth breaking the RPC interface for (something we generally try hard to avoid). |
|
Is the PRC designed for human (readable) consumption anyway? Converting these numbers to hex is often a 1-liner. |
|
@mruddy did you change In any case, I'm for it (without the |
|
@dcousens no, but that was from a node running -regtest. Yes, for that reason I'll probably put up a different commit that just has another field for the hex encoding. I think I'll stick with the |
|
Maybe |
|
That sounds pretty good although I'm hesitant to use the terminology that overlaps with BIP9. For example, there are two more possible future mechanisms where a hex encoding might also be helpful (and I think some BIP101 blocks used something very close or similar to BIP9 IIRC). So, how about versionHex: 'ffff0000'. That is obvious enough to drop the |
|
|
|
RPC isn't meant for human consumption. Do this in the client. |
|
I agree with @luke-jr. It's certainly not worth breaking the interface for. Also realize that a client may need this value to process further, not to show to the user: e.g. bitwise-AND operations should be done on a number, not a string, so this change may mean doing an extra conversion from hex to int on the client side. No strong opposition to adding it as extra field, though I'd still say adding a field to avoid an extra hex conversion on the client side is too much hand-holding. This shouldn't set a precedent to add hex, octal, binary for every field. |
src/rpc/blockchain.cpp
Outdated
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.
do we have these 1 and 4 available as constants somewhere?
Edit: or maybe just always add it
|
@laanwj Updated to use the VERSIONBITS_LAST_OLD_BLOCK_VERSION constant and added help text. I opted to not always add the new hex formatted field to avoid redundancy when the version is visually obvious. |
|
BTW we should probably add the bit number to |
|
Or add some command to list the defined bip9 softforks with their starttime, timeout and bit. |
|
Well that can all be on getblockchaininfo IMO.
More on topic: another wild idea here would be to try to actually decode
the versionbits and return a list of deployment names. That is at least
non-trivial handholding as they are context dependent.
|
|
@laanwj You could only decode the BIP9 deployments your version understands, so earlier versions are just going to return "unknown" and it's also conceivable that Bitcoin Core would not necessarily have the definitions for all softforks (because it doesnt support them). For a full "decode", we should better rely on a file BIPs which lists all known deployments, and it would also serve to help the community co-ordinate on free bits. |
|
I went ahead and added the extra data to The first thing to decide was if/when to show the bit information. "Miners should continue setting the bit in LOCKED_IN phase so uptake is visible, though this has no effect on consensus rules." "There could be two non-overlapping deployments on the same bit, where the first one transitions to LOCKED_IN while the other one simultaneously transitions to STARTED, which would mean both would demand setting the bit." "Once the consensus change succeeds or times out, there is a "fallow" pause after which the bit can be reused for later changes." Although the plan is to have a fallow period, due to consensus allowing a locked in bit to be immediately reused, it might not really be safe for a miner to continue setting the bit. So, I took the conservative approach and decided to only show the bit info during an active voting period, that is when the soft fork is in state STARTED. I left the condition as a separate block in-case we decide to change it to |
@btcdrak I agree. It can't be complete, but it can show the known ones. Tons of options for the unknown ones, one would be to show them as 'unknownXX' where XX is the bit. E.g. in UpdateTip logging we issue a warning per block, see #7795. IMO where to coordinate the bits is completely offtopic here :) It shouldn't happen in our repository at all, but indeed in BIPs. @mruddy Sounds good to me. |
|
@laanwj Yes. I like the patch as it is now. |
src/rpc/blockchain.cpp
Outdated
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.
"when version is greater than %d" looks kind of arbitrary, out of context.
Maybe we should mention BIP9 explicitly in the help.
The reason for this threshold is that BIP9 version bits start to be relevant, 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.
Kind of. It's a little more generic than that though. That threshold is the highest version number that I know for sure will be treated as a simple integer. I wanted to avoid redundancy for the easy to ascertain version numbers that are definitely treated as integers.
I was trying to avoid being too specific to BIP9 because it allows for two future mechanisms (top bits 010 and 011). I thought of using >= VERSIONBITS_TOP_BITS, but that ignores [5, 0x1fffffff] which I think could be re-purposed too. I don't see any rule limiting that range's use to only being simple integers.
I should probably just keep it simple and always display versionHex. My redundancy limiting kinda feels like unnecessary optimization.
…nd data in getblockchaininfo bip9_softforks field.
|
ok, i pushed up a commit that simplifies and always shows the |
…results 92107d5 RPC: add versionHex in getblock and getblockheader JSON results; expand data in getblockchaininfo bip9_softforks field. (mruddy)
|
post humus ACK |
|
Tested ACK 92107d5 |
| " {\n" | ||
| " \"id\": \"xxxx\", (string) name of the softfork\n" | ||
| " \"status\": \"xxxx\", (string) one of \"defined\", \"started\", \"lockedin\", \"active\", \"failed\"\n" | ||
| " \"bit\": xx, (numeric) the bit, 0-28, in the block version field used to signal this soft fork\n" |
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.
Nit: Prob good to mention this only shows up when status=="started"
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.
that had crossed my mind before. either way works for me.
…results 92107d5 RPC: add versionHex in getblock and getblockheader JSON results; expand data in getblockchaininfo bip9_softforks field. (mruddy)
…r JSON results 92107d5 RPC: add versionHex in getblock and getblockheader JSON results; expand data in getblockchaininfo bip9_softforks field. (mruddy)


Update
getblockandgetblockheaderRPCs and rest to return hex encoded block versions, e.g.:"version": "0x01""version": "0x20000000"Reason is similar to #7763: "The decimal printing of block nVersion is not very readable in a versionbits world."
My only apprehension is that this could be disruptive to people that have script relying on this output. But, I'm not aware of any guarantee that this will not change.
I purposefully chose 02 instead of 08 in order to get a smaller encoding when possible.