-
Notifications
You must be signed in to change notification settings - Fork 37.7k
rpc: Add level 3 verbosity to getblock RPC call. #21245
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
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. |
8f41540
to
6eede79
Compare
Concept ACK. Thanks for picking this up! Will have a closer look and test this soon. |
6eede79
to
dc68479
Compare
13974de
to
53ea5bd
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.
ACK 53ea5bd
Code reviewed and tested both the RPC and REST interface on testnet with a few blocks.
7569d7c
to
d39eb54
Compare
Ideally, this should probably be 3 commits: one changing the bool to the class enum (with 2 values), one adding the new feature, and another adding tests. |
d39eb54
to
5710e3f
Compare
Done |
37f2c4e
to
d512661
Compare
c8ecb1d
to
4aaebc1
Compare
3f70a60
to
72dbe98
Compare
@kiminuo i think your comments should be addressed now. Can you mark this as reviewed once this looks good? |
Currently Console output
It would be great to:
Edit: I'll try to carve out some more time tomorrow to test it more. |
The following examples may be worth adding to your original post: Examples of the
|
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.
@@ -1017,7 +1025,16 @@ static RPCHelpMan getblock() | |||
return strHex; | |||
} | |||
|
|||
return blockToJSON(block, tip, pblockindex, verbosity >= 2); | |||
TxVerbosity block_to_json_verbosity; |
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: The name block_to_json_verbosity
seems long and it does not add any more meaning than just tx_verbosity
, imho.
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.
Thank u
@@ -20,6 +20,12 @@ class uint256; | |||
class UniValue; | |||
class CTxUndo; | |||
|
|||
enum class TxVerbosity { |
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.
Some enum class
es have these nice doxygen comments:
bitcoin/src/consensus/validation.h
Line 63 in d67330d
enum class BlockValidationResult { |
@@ -312,6 +312,16 @@ def run_test(self): | |||
if 'coinbase' not in tx['vin'][0]} | |||
assert_equal(non_coinbase_txs, set(txs)) | |||
|
|||
# Verify that the non-coinbase tx has "prevout" field set |
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:
# Verify that the non-coinbase tx has "prevout" field set | |
# Verify that the non-coinbase tx has "prevout" key set |
A Python dictionary is a set of key-value pairs.
prevout = vin["prevout"] | ||
assert_equal(prevout["generated"], False) |
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.
Given that prevout
variable is used just once, it may be shorter and actually easier to read:
prevout = vin["prevout"] | |
assert_equal(prevout["generated"], False) | |
assert_equal(vin["prevout"]["generated"], False) |
def assert_vin_contains_prevout(verbosity): | ||
block = node.getblock(blockhash, verbosity) | ||
tx = block["tx"][1] | ||
total_vin = 0 |
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 believe this should be more like:
total_vin = 0 | |
total_vin = Decimal("0.00000000") |
|
||
for (size_t i = 0; i < block.vtx.size(); ++i) { | ||
const CTransactionRef& tx = block.vtx.at(i); | ||
// coinbase transaction (i == 0) doesn't have undo data |
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:
// coinbase transaction (i == 0) doesn't have undo data | |
// coinbase transaction (i.e. i == 0) doesn't have undo data |
|
||
case TxVerbosity::SHOW_DETAILS_AND_PREVOUT: | ||
UniValue o_script_pub_key(UniValue::VOBJ); | ||
ScriptPubKeyToUniv(prev_txout.scriptPubKey, o_script_pub_key, /* includeHex */ true, /* include_addresses */ true); |
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.
Question: There is include_addresses
parameter which is not used here. true
is passed instead. Is that correct or should it look like:
ScriptPubKeyToUniv(prev_txout.scriptPubKey, o_script_pub_key, /* includeHex */ true, /* include_addresses */ true); | |
ScriptPubKeyToUniv(prev_txout.scriptPubKey, o_script_pub_key, /* includeHex */ true, include_addresses); |
It looks to me that include_addresses = true
is deprecated actually.
Edit: This PR will be most likely affected by #22650.
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.
Since this is adding new output, I think it should probably just be a constant false
here, actually.
@fyquah I have attempted to address my comments above and add RPC help here: https://github.com/kiminuo/bitcoin/tree/feature/2021-08-08-verbosity-level-3-getblock-iteration-3: ./bitcoin-cli -testnet getblock reports for me: Console output
If you find any of the modifications useful, please include it in your PR. |
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 72dbe98
Verified via git range-diff cecbfed9...72dbe981
that since my last ACK all requested changes since then (e.g. rename calculate_fee to have_undo (#21245 (comment)), more detailled "prevout" checking w.r.t. to coinbase/non-coinbase txs (#21245 (comment)), RPC help improvement (#21245 (comment))) were tackled. Also compiled locally and successfully ran the involved functional tests.
Did some more review, tested it and the PR is shaping up very nicely.
Agree! :)
@kiminuo made some very good points for further improvements, especially considering the missing result desription for the newly introduced level in the RPC help. Since none of them are really blockers IMHO and the PR author does seem to be quite busy, maybe they can be done in a follow-up PR, to move things forward?
This has only been ACK'd by a single reviewer. |
I would re-ACK except for #21245 (comment) |
@fyquah I think #21245 (comment) is important so I would ACK once this is fixed. Also, the work is actually done here #21245 (comment) I believe (the last commit is extra and is for a follow-up PR). |
@fyquah Could you find a moment to address #21245 (comment)? (PS: I'm willing to take over your PR to work on it if you are too busy. Anyway, it seems to me one little change is needed here, nothing time consuming.) |
Closing this for now that #22918 is open. |
…PC call (#21245 modified) 5c34507 core_write: Rename calculate_fee to have_undo for clarity (fyquah) 8edf620 release-notes: Add release note about getblock verbosity level 3. (fyquah) 459104b rest: Add test for prevout fields in getblock (fyquah) 4330af6 rpc: Add test for level 3 verbosity getblock rpc call. (fyquah) 51dbc16 rpc: Add level 3 verbosity to getblock RPC call. (fyquah) 3cc9534 rpc: Replace boolean argument for tx details with enum class. (fyquah) Pull request description: Author of #21245 expressed [time issues](bitcoin/bitcoin#21245 (comment)) in the original PR. Given that #21245 has received a lot of review*, I have decided to open this new pull request with [modifications required to get ACK from luke-jr ](bitcoin/bitcoin#21245 (comment)) and a few nits of mine. ### Original PR description > Display the prevout in transaction inputs when calling getblock level 3 verbosity. This PR affects the existing `/rest/block` API by adding a `prevout` fields to tx inputs. This is mentioned in the change to the release notes. > > I added some functional tests that > > * checks that the RPC call still works when TxUndo can't be found > > * Doesn't display the "value" or "scriptPubKey" of the previous output when at a lower verbosity level > > > This "completes" the issue #18771 ### Possible improvements * kiminuo/bitcoin@b0bf4f2 - I can include even this commit to this PR if deemed useful or I can leave it for a follow-up PR. See bitcoin/bitcoin#21245 (comment) for more context. ### Examples Examples of the `getblock` output with various verbose levels. Note that `000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5` contains only 2 transactions. #### Verbose level 0 ```bash ./bitcoin-cli -testnet getblock 000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5 0 ``` ##### Verbose level 1 ```bash ./bitcoin-cli -testnet getblock 000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5 1 ``` ##### Verbose level 2 ```bash ./bitcoin-cli -testnet getblock 000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5 2 ``` ##### Verbose level 3 ```bash ./bitcoin-cli -testnet getblock 000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5 3 ``` #### REST ```bash curl -H "content-type:text/plain;" http://127.0.0.1:18332/rest/block/000000000000001f682b188971cc1a121546be4e9d5baf22934fdc7f538288d5.json ``` <sub>* ... and my everyday obsessive checking of my email inbox whether the PR moves forward.</sub> Edit laanwj: Removed at symbol from message, and large example output to prevent it from all ending up in the commit message. ACKs for top commit: 0xB10C: ACK 5c34507 meshcollider: utACK 5c34507 theStack: ACK 5c34507 👘 promag: Concept ACK 5c34507 Tree-SHA512: bbff120d8fd76e617b723b102b0c606e0d8eb27f21c631d5f4cdab0892137c4bc7c65b1df144993405f942c91be47a26e80480102af55bff22621c19f518aea3
Display the prevout in transaction inputs when calling getblock level 3 verbosity. This PR affects the existing
/rest/block
API by adding aprevout
fields to tx inputs. This is mentioned in the change to the release notes.I added some functional tests that
This "completes" the issue #18771