Skip to content

Conversation

@mruddy
Copy link
Contributor

@mruddy mruddy commented Mar 30, 2016

Update getblock and getblockheader RPCs 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.

@sipa
Copy link
Member

sipa commented Mar 30, 2016

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).

@dcousens
Copy link
Contributor

Is the PRC designed for human (readable) consumption anyway? Converting these numbers to hex is often a 1-liner.
This would also break a lot of code.

@mruddy
Copy link
Contributor Author

mruddy commented Mar 31, 2016

Yes, these two RPCs have a verbose version (the default) that returns JSON. It's pretty useful to look something up quick via the debug window CLI in bitcoin-qt. The version makes more sense to me quickly when it's in hex, that's all.
For example:
image

And yes, the type changes from number to string because in JSON, "the octal and hexadecimal formats are not used" [http://www.json.org/].

Actually, I suppose that just adding this as "version_hex" would be just as well. I might do that later.

@dcousens
Copy link
Contributor

@mruddy did you change bits in the example above?

In any case, I'm for it (without the 0x though), but it would break code.

@mruddy
Copy link
Contributor Author

mruddy commented Mar 31, 2016

@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 0x because then it's visually obvious that it's not base 10. I'm thinking about only including this new field for versions other than 1-4, but I haven't decided yet.

@dcousens
Copy link
Contributor

Maybe versionBits: 'ffff0000' instead of replacing version

@mruddy
Copy link
Contributor Author

mruddy commented Mar 31, 2016

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 0x and still generic enough that I don't have to apply BIP specific logic to it or create another field in the far future. The only decision is whether to show this field for versions 1-4. I'm leaning towards not showing it for versions 1-4.

@dcousens
Copy link
Contributor

versionHex: 'ffff0000' 👍

@mruddy
Copy link
Contributor Author

mruddy commented Mar 31, 2016

Cool, yeah that works for me. Thanks for the help!

image

@mruddy mruddy changed the title RPC: BIP9 version bits related, format version as hex in getblock and getblockheader RPC: add versionHex in getblock and getblockheader JSON results Mar 31, 2016
@luke-jr
Copy link
Member

luke-jr commented Mar 31, 2016

RPC isn't meant for human consumption. Do this in the client.

@laanwj
Copy link
Member

laanwj commented Mar 31, 2016

I agree with @luke-jr.
This is a number, keep passing it as a number. Client software can format it to the user however they want.
(we do this consistently in other places too; e.g. we even report timestamps as numbers, and don't bother formatting them as date-times)

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.

Copy link
Member

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

@mruddy
Copy link
Contributor Author

mruddy commented Mar 31, 2016

@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.

@laanwj
Copy link
Member

laanwj commented Apr 2, 2016

BTW we should probably add the bit number to bip9_softforks in getblockchaininfo. It would provide some context to these bits.
(doesn't necessarily have to be in this pull, but it's another idea to make BIP9 more visible and transparent, and allowing clients to interpret this)

@paveljanik
Copy link
Contributor

Or add some command to list the defined bip9 softforks with their starttime, timeout and bit.

@laanwj
Copy link
Member

laanwj commented Apr 2, 2016 via email

@btcdrak
Copy link
Contributor

btcdrak commented Apr 2, 2016

@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.

@mruddy
Copy link
Contributor Author

mruddy commented Apr 2, 2016

I went ahead and added the extra data to bip9_softforks in getblockchaininfo.

The first thing to decide was if/when to show the bit information.
Since the relevant bit information for a given block version changes over time, it would be confusing to always show the bit info for every soft fork that was ever defined with this mechanism.
It's actually not quite as straightforward as I guessed it would be.
For example, BIP9 gives the guidance:

"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.
EDIT: this is also feedback to @sipa about ComputeBlockVersion continuing to set the version bit during LOCKED_IN, assuming my understanding of BIP9 is correct.
Thus, it might not make sense to show the info for a locked in soft fork even though during normal operations, the fallow period is observed and it would make sense to give a user the info.

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.
This gives an indication to users that if the hex block version is other than 20000000 and no info is shown in bip9_softforks, then either everything is locked in, or there is fork voting going on for something the node software being used does not know about.

I left the condition as a separate block in-case we decide to change it to THRESHOLD_STARTED == thresholdState || THRESHOLD_LOCKED_IN == thresholdState. I figured I'd throw this out there and see what other people thought.

@laanwj
Copy link
Member

laanwj commented Apr 3, 2016

it's also conceivable that Bitcoin Core would not necessarily have the definitions for all softforks (because it doesnt support them)

@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.

@btcdrak
Copy link
Contributor

btcdrak commented Apr 3, 2016

@laanwj Yes. I like the patch as it is now.

Copy link
Member

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?

Copy link
Contributor Author

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.
@mruddy
Copy link
Contributor Author

mruddy commented Apr 4, 2016

ok, i pushed up a commit that simplifies and always shows the versionHex for getblock and getblockheader instead of only showing it when version > 4.

@laanwj laanwj merged commit 92107d5 into bitcoin:master Apr 5, 2016
laanwj added a commit that referenced this pull request Apr 5, 2016
…results

92107d5 RPC: add versionHex in getblock and getblockheader JSON results; expand data in getblockchaininfo bip9_softforks field. (mruddy)
@btcdrak
Copy link
Contributor

btcdrak commented Apr 5, 2016

post humus ACK

@laanwj
Copy link
Member

laanwj commented Apr 5, 2016

Tested ACK 92107d5

@mruddy mruddy deleted the hexver branch April 5, 2016 19:15
" {\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"
Copy link
Member

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"

Copy link
Contributor Author

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.

@dcousens dcousens mentioned this pull request Jun 2, 2016
sickpig referenced this pull request in sickpig/BitcoinUnlimited Mar 31, 2017
…results

92107d5 RPC: add versionHex in getblock and getblockheader JSON results; expand data in getblockchaininfo bip9_softforks field. (mruddy)
codablock pushed a commit to codablock/dash that referenced this pull request Dec 19, 2017
…r JSON results

92107d5 RPC: add versionHex in getblock and getblockheader JSON results; expand data in getblockchaininfo bip9_softforks field. (mruddy)
@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.

8 participants