Skip to content

Conversation

@Sjors
Copy link
Member

@Sjors Sjors commented Dec 8, 2021

Followups from #20295.

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach ACK

@Sjors Sjors force-pushed the 2021/12/getblockfrompeer_followups branch 2 times, most recently from c0d3124 to 49c18da Compare December 9, 2021 02:48
@Sjors
Copy link
Member Author

Sjors commented Dec 9, 2021

Rebased and addresses @MarcoFalke's and @jonatack's comments.

Co-authored-by: MarcoFalke <falke.marco@gmail.com>
@Sjors Sjors force-pushed the 2021/12/getblockfrompeer_followups branch from 49c18da to 00e23db Compare December 9, 2021 08:53
Copy link
Member

@jonatack jonatack left a 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/

@maflcko
Copy link
Member

maflcko commented Dec 10, 2021

AssertionError: RPC client conversion table (/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-i686-pc-linux-gnu/src/rpc/client.cpp) and RPC server named arguments mismatch! {('getblockfrompeer', 1, 'peer_id'), ('getblockfrompeer', 1, 'nodeid')}

@Sjors Sjors force-pushed the 2021/12/getblockfrompeer_followups branch from 0510ada to 009ccf8 Compare December 11, 2021 02:30
@jonatack
Copy link
Member

jonatack commented Dec 11, 2021

ACK 009ccf8d3b173b44b05a7784bb4d053f770b8619

$ ./src/bitcoin-cli -signet getblockfrompeer 00000152031b708d8b29013d55aedd24e8db90af7fcf7f1e51881ad97cf0e9a4 0
{
  "warnings": "Block already downloaded"
}
$ ./src/bitcoin-cli -signet help getblockfrompeer 
getblockfrompeer "blockhash" 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 a block-request was successfully scheduled.

Arguments:
1. blockhash    (string, required) The block hash
2. peer_id      (numeric, required) The peer ID (see getpeerinfo for peer IDs)

Result:
{                        (json object)
  "warnings" : "str"     (string, optional) any warnings
}

If you have to retouch, maybe s/a block-request/the request/ in the help and snakecase naming for the blockhash param, e.g. block_hash like peer_id (sorry for the incremental review, iteration works for me :D)

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 11, 2021

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #23927 (rpc: Pruning nodes can not fetch blocks before syncing past their height by fjahr)
  • #23813 (Add test and docs for getblockfrompeer by fjahr)
  • #22932 (Add CBlockIndex lock annotations, guard nStatus/nFile/nDataPos/nUndoPos by cs_main by jonatack)

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.

Comment on lines -808 to -811
Copy link
Member

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?

Copy link
Member Author

@Sjors Sjors Dec 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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)

Copy link
Member Author

@Sjors Sjors Dec 13, 2021

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.

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved.

@Sjors Sjors force-pushed the 2021/12/getblockfrompeer_followups branch from 009ccf8 to 45ed85e Compare December 13, 2021 02:53
Copy link
Member Author

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

@Sjors Sjors force-pushed the 2021/12/getblockfrompeer_followups branch from 45ed85e to d631b1d Compare December 13, 2021 06:35
@Sjors
Copy link
Member Author

Sjors commented Dec 13, 2021

@MarcoFalke I added a commit to allow the RPC result to be an empty JSON object (rather than null or no result).

src/rpc/util.cpp Outdated
Copy link
Member

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?

Copy link
Member Author

@Sjors Sjors Dec 13, 2021

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.

Copy link
Member Author

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

Copy link
Member Author

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)

@Sjors Sjors force-pushed the 2021/12/getblockfrompeer_followups branch from d631b1d to 86c9863 Compare December 13, 2021 12:02
luke-jr added a commit to bitcoinknots/bitcoin that referenced this pull request Dec 14, 2021
Github-Pull: bitcoin#23706
Partially-Rebased-From: 9d70f38f757fd540edf10eb392028867927856bf
luke-jr added a commit to bitcoinknots/bitcoin that referenced this pull request Dec 14, 2021
…e changing to peer_id

Github-Pull: bitcoin#23706
Partially-Rebased-From: 009ccf8d3b173b44b05a7784bb4d053f770b8619
Copy link
Member

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

Copy link
Member

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

Suggested change
RPCResult{RPCResult::Type::EMPTY, "", /* optional */ false, "", {}},
RPCResult{RPCResult::Type::EMPTY, "", /*optional=*/ false, "", {}},

Copy link
Member Author

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

@Sjors Sjors force-pushed the 2021/12/getblockfrompeer_followups branch from 86c9863 to a7bd4aa Compare December 16, 2021 11:33
Copy link
Member

@jonatack jonatack left a 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
Copy link
Member

@jonatack jonatack Dec 16, 2021

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)

Suggested change
EMPTY, //!< Special type to allow empty OBJ
EMPTY_OBJ, //!< Special type to allow empty JSON object

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, @MarcoFalke?

Copy link
Member

@maflcko maflcko Dec 24, 2021

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OBJ_EMPTY it is!

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 923312f 📦

Copy link
Contributor

@fjahr fjahr left a 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.

@maflcko maflcko merged commit 39d9bbe into bitcoin:master Jan 25, 2022
@maflcko
Copy link
Member

maflcko commented Jan 25, 2022

This broke the rpc docs: #24155 (comment)

@Sjors Sjors deleted the 2021/12/getblockfrompeer_followups branch January 25, 2022 20:08
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 28, 2022
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Dec 3, 2022
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
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Dec 3, 2022
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
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Dec 3, 2022
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
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Dec 3, 2022
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
@bitcoin bitcoin locked and limited conversation to collaborators Jan 25, 2023
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.

6 participants