-
Notifications
You must be signed in to change notification settings - Fork 38.7k
rpc: getblockfrompeer followups #23706
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
rpc: getblockfrompeer followups #23706
Conversation
jonatack
left a comment
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.
Approach ACK
c0d3124 to
49c18da
Compare
|
Rebased and addresses @MarcoFalke's and @jonatack's comments. |
Co-authored-by: MarcoFalke <falke.marco@gmail.com>
49c18da to
00e23db
Compare
jonatack
left a comment
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.
Lightly tested ACK 00e23db610d3ed206b8d34cf296540b594264732
$ ./src/bitcoin-cli -signet getblockfrompeer 00000152031b708d8b29013d55aedd24e8db90af7fcf7f1e51881ad97cf0e9a4 0
{
"warnings": "Block already downloaded"
}
$ ./src/bitcoin-cli -signet help getblockfrompeer
getblockfrompeer "blockhash" nodeid
Attempt to fetch block from a given peer.
We must have the header for this block, e.g. using submitheader.
Subsequent calls for the same block and a new peer will cause the response from the previous peer to be ignored.
Returns an empty JSON object if a block-request was successfully scheduled.
Arguments:
1. blockhash (string, required) The block hash
2. nodeid (numeric, required) The node ID (see getpeerinfo for node IDs)
Result:
{ (json object)
"warnings" : "str" (string, optional) any warnings
}
Examples:
> bitcoin-cli getblockfrompeer "00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09" 0
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getblockfrompeer", "params": ["00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09" 0]}' -H 'content-type: text/plain;' http://127.0.0.1:8332/
|
|
0510ada to
009ccf8
Compare
|
ACK 009ccf8d3b173b44b05a7784bb4d053f770b8619 If you have to retouch, maybe |
|
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. |
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.
Why are you removing this? Where is the peer id checked now?
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.
It's checked in FetchBlock:
https://github.com/Sjors/bitcoin/blob/009ccf8d3b173b44b05a7784bb4d053f770b8619/src/net_processing.cpp#L1437-L1439
As suggested here:
#20295 (comment)
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.
But this check was for the case where FetchBlock is not called (block already downloaded)
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 see. But we only return one error, and it seems to me that the "block already downloaded" error is more relevant anyway.
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's currently just a warning. Maybe it should be an 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.
Good point, let's just make it an error, so it's easier to reason about.
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.
my previous test:
$ ./src/bitcoin-cli -signet getblockfrompeer 00000152031b708d8b29013d55aedd24e8db90af7fcf7f1e51881ad97cf0e9a4 0
{
"warnings": "Block already downloaded"
}
now
$ ./src/bitcoin-cli -signet getblockfrompeer 00000152031b708d8b29013d55aedd24e8db90af7fcf7f1e51881ad97cf0e9a4 0
error code: -1
error message:
Block already downloaded
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.
Nit: This change appears to be part of the wrong commit
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.
Moved.
009ccf8 to
45ed85e
Compare
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.
@jonatack I also fixed the ParseHashV call while renaming
45ed85e to
d631b1d
Compare
|
@MarcoFalke I added a commit to allow the RPC result to be an empty JSON object (rather than |
src/rpc/util.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.
why does this need a new case? Why can't the above case be re-used?
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.
Because of CHECK_NONFATAL(!m_inner.empty());
The rest of the Type::OBJ code block doesn't seem to do anything useful for an empty object either, so it seemed more readable to just add a new case. But I could use an if statement instead.
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 found a more compact solution...
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.
Reverting back to using a separate case. The string manipulation code Type:OBJ does not behave nicely if the object is empty, see #23706 (review)
d631b1d to
86c9863
Compare
Github-Pull: bitcoin#23706 Partially-Rebased-From: 9d70f38f757fd540edf10eb392028867927856bf
…e changing to peer_id Github-Pull: bitcoin#23706 Partially-Rebased-From: 009ccf8d3b173b44b05a7784bb4d053f770b8619
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.
Is the help now missing a brace?
previous reviews
Result:
{ (json object)
"warnings" : "str" (string, optional) any warnings
}
now
Result:
(json object)
}
maybe this would be nice
Result:
{
(empty json object)
}
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.
2158b9f (nit, seems new since my last review) format for clang-tidy verification of this named arg in the RPCResult constructor
| RPCResult{RPCResult::Type::EMPTY, "", /* optional */ false, "", {}}, | |
| RPCResult{RPCResult::Type::EMPTY, "", /*optional=*/ 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.
I'll bring back the braces and fix the nit
86c9863 to
a7bd4aa
Compare
jonatack
left a comment
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.
Lightly tested diff-review ACK a7bd4aaf17fdbfc2cbc5080467b3d17977b8b6b5 per git diff 86c9863 a7bd4aa
$ ./src/bitcoin-cli -signet help getblockfrompeer
getblockfrompeer "block_hash" peer_id
Attempt to fetch block from a given peer.
We must have the header for this block, e.g. using submitheader.
Subsequent calls for the same block and a new peer will cause the response from the previous peer to be ignored.
Returns an empty JSON object if the request was successfully scheduled.
Arguments:
1. block_hash (string, required) The block hash to try to fetch
2. peer_id (numeric, required) The peer to fetch it from (see getpeerinfo for peer IDs)
Result:
{} (empty JSON object)
$ ./src/bitcoin-cli -signet getblockfrompeer 00000152031b708d8b29013d55aedd24e8db90af7fcf7f1e51881ad97cf0e9a4 0
error code: -1
error message:
Block already downloaded
src/rpc/util.h
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.
pico-nit, wonder if EMPTY_OBJ would be clearer, as there are OBJ and OBJ_DYN enums (feel free to ignore)
| EMPTY, //!< Special type to allow empty OBJ | |
| EMPTY_OBJ, //!< Special type to allow empty JSON object |
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, @MarcoFalke?
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.
OBJ_EMPTY 🗳️
Also, if you retouch, pls put it next to OBJ_DYN in the list
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.
OBJ_EMPTY it is!
a7bd4aa to
923312f
Compare
jonatack
left a comment
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 923312f 📦
fjahr
left a comment
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.
tested ACK 923312f
Reviewed code, built and tested the rpc locally.
|
This broke the rpc docs: #24155 (comment) |
Summary: This adds an RPC method to fetch a block directly from a peer. This can used to fetch stale blocks with lower proof of work that are normally ignored by the node (`headers-only` in `getchaintips`). Limitations: - you have to specify which peer to fetch the block from - the node must already have the header Co-authored-by: John Newbery <john@johnnewbery.com> This is a backport of [[bitcoin/bitcoin#20295 | core#20295]], [[bitcoin/bitcoin#23702 | core#23702]] and [[bitcoin/bitcoin#23706 | core#23706]] (partial) bitcoin/bitcoin@dce8c4c bitcoin/bitcoin@aaaa34e bitcoin/bitcoin@bfbf91d bitcoin/bitcoin@809d66b bitcoin/bitcoin@0e3d7c5 The main commit is the first one. The other commits are minor style & comments improvements, and one commit removing an unnecessary argument in the newly added `FetchBlock` function. Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D12716
Summary: > rpc: allow empty JSON object result bitcoin/bitcoin@8d1a3e6 > rpc: turn already downloaded into error in getblockfrompeer bitcoin/bitcoin@60243ca This is a partial backport of [[bitcoin/bitcoin#23706 | core#23706]] Depends on D12717 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D12719
Summary: This is a partial backport of [[bitcoin/bitcoin#23706 | core#23706]] bitcoin/bitcoin@34d5399 Depends on D12719 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D12720
Summary: This concludes backport of [[bitcoin/bitcoin#23706 | core#23706]] and [[bitcoin/bitcoin#24806 | core#24806]] bitcoin/bitcoin@923312f Depends on D12720 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D12721
Followups from #20295.