-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Add test and docs for getblockfrompeer with pruning #23813
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
Add test and docs for getblockfrompeer with pruning #23813
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsNo conflicts as of last run. |
Concept ACK |
Can you rebase this on #23706? Otherwise it might get confusing... |
fa03845
to
5ed8de7
Compare
Done |
5ed8de7
to
809b2af
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.
tACK 809b2af
func logs
➜ bitcoin git:(fjahr) ✗ ./test/functional/rpc_getblockfrompeer.py 2021-12-22T10:51:49.578000Z TestFramework (INFO): Initializing test directory /var/folders/7j/m0yjzmhj4ys9jgl353v2mqph0000gn/T/bitcoin_func_test__5i5gur3 2021-12-22T10:51:50.430000Z TestFramework (INFO): Mine 4 blocks on Node 0 2021-12-22T10:51:50.434000Z TestFramework (INFO): Mine competing 3 blocks on Node 1 2021-12-22T10:51:50.438000Z TestFramework (INFO): Connect nodes to sync headers 2021-12-22T10:51:50.499000Z TestFramework (INFO): Node 0 should only have the header for node 1's block 3 2021-12-22T10:51:50.500000Z TestFramework (INFO): Fetch block from node 1 2021-12-22T10:51:50.501000Z TestFramework (INFO): Arguments must be sensible 2021-12-22T10:51:50.501000Z TestFramework (INFO): We must already have the header 2021-12-22T10:51:50.502000Z TestFramework (INFO): Non-existent peer generates error 2021-12-22T10:51:50.503000Z TestFramework (INFO): Successful fetch 2021-12-22T10:51:50.504000Z TestFramework (INFO): Don't fetch blocks we already have 2021-12-22T10:51:50.505000Z TestFramework (INFO): Connect pruned node 2021-12-22T10:51:50.967000Z TestFramework (INFO): Fetch pruned block 2021-12-22T10:51:51.024000Z TestFramework (INFO): Stopping nodes 2021-12-22T10:51:51.515000Z TestFramework (INFO): Cleaning up /var/folders/7j/m0yjzmhj4ys9jgl353v2mqph0000gn/T/bitcoin_func_test__5i5gur3 on exit 2021-12-22T10:51:51.515000Z TestFramework (INFO): Tests successful
809b2af
to
6946327
Compare
Rebased since #23706 was merged |
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.
6946327 looks good.
Do you want to expand the test to show how the fetched block disappears again at the next prune event?
src/rpc/blockchain.cpp
Outdated
@@ -793,7 +793,8 @@ static RPCHelpMan getblockfrompeer() | |||
"\nAttempt to fetch block from a given peer.\n" | |||
"\nWe must have the header for this block, e.g. using submitheader.\n" | |||
"Subsequent calls for the same block and a new peer will cause the response from the previous peer to be ignored.\n" | |||
"\nReturns an empty JSON object if the request was successfully scheduled.", | |||
"\nReturns an empty JSON object if the request was successfully scheduled." | |||
"\nNote: On a pruned node this block might be pruned again as soon as the pruneheight surpasses the blockheight at the time of fetching the block.\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.
What block does "the block" refer to? The most recent block that's being fetched as part of the regular activity?
Maybe this can be a bit shorter: "Previously pruned blocks are only preserved until the next pruning event." (afaik this is true as long as the user doesn't change -prune
)
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.
"block" both times refers to the block being fetched with getblockfrompeer
. I see how it was not super clear so I revised the wording a bit.
I think your shorter version is not necessarily correct. The block might be pruned with the next pruning event or not, it depends on the prune height requested if it is in a file that is otherwise ready to be pruned. So the block with the highest height in the same file is the deciding factor as far as I understand. Since the fetched blocked is usually appended in the file with the current tip, the next pruning event will often not allow that file to be pruned. The expanded test that you requested actually shows this well already and so I structured it in a way that this behavior is made explicit.
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.
Ah I see. Then I think there should be a warning that this can temporarily cause pruning to be deferred? I.e. disk space may exceed -prune
? Is there an upper limit of required extra free disk space that we can suggest?
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.
Yes, if the node has not synced up to the fetched block yet, that can happen. That is the issue I am addressing with #23927 . I could amend the comment here now and then change it again if that PR is merged. But I think I would rather keep it separate since I also don't know what might be merged first. If the fix in #23927 is not getting in, I would change that PR to at least document the issue better for the user instead.
Expanded the test. See my comment for some more related info. |
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 6946327
Couple nits, happy to re-ACK if take.
6946327
to
476f63a
Compare
Rebased and took @jonatack 's suggestions. |
Somewhat ominous CI failure. |
06d1947
to
da1bd8e
Compare
Seems to have been the CI choking but I also saw that there was a silent merge conflict after I re-ran, so rebased and fixed that. |
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.
utACK da1bd8e
da1bd8e
to
23ea3e0
Compare
rebased |
23ea3e0
to
c9d2f75
Compare
c9d2f75
to
3679ae5
Compare
3679ae5
to
fe329dc
Compare
Failed to address @Sjors ' comments on the previous rebase, done 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.
ACK fe329dc.
Went through the test and observed how:
- 200 + 4 + 400 = 1..604 blocks present in
blk0.dat
,blk1.dat
,blk2.dat
pruneblockchain(300)
removesblk0.dat
and now 249..604 blocks inblk1.dat
,blk2.dat
- then a previously pruned block is stored in
blk2.dat
(usinggetblockfrompeer
RPC) - 604 + 250 = 249..854 blocks in
blk1.dat
,blk2.dat
,blk3.dat
(+ prev pruned block inblk2.dat
) - pruneblockchain(700) removes
blk1.dat
. we still haveblk2.dat
,blk3.dat
and so prev pruned block also. - 854 + 250 = 500..1104 blocks in
blk2.dat
,blk3.dat
,blk4.dat
(+ prev pruned block inblk2.dat
) pruneblockchain(1000)
removesblk2.dat
and prev pruned block is no longer there
re-utACK fe329dc |
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 fe329dc
review ACK fe329dc 🍉 Show signatureSignature:
|
fe329dc test: Add test for getblockfrompeer on pruned nodes (Fabian Jahr) cd761e6 rpc: Add note on guarantees to getblockfrompeer (Fabian Jahr) Pull request description: These are additions to `getblockfrompeer` that I already [suggested on the original PR](bitcoin#20295 (review)). The two commits do the following: 1. Add a test for `getblockfrompeer` usage on pruned nodes. This is important because many use-cases for `getblockfrompeer` are in a context of a pruned node. 2. Add some information on how long the users of pruned nodes can expect the block to be available after they have used the RPC. I think the behavior is not very intuitive for users and I would not be surprised if users expect the block to be available indefinitely. ACKs for top commit: Sjors: re-utACK fe329dc MarcoFalke: review ACK fe329dc 🍉 stratospher: ACK fe329dc. brunoerg: re-ACK fe329dc Tree-SHA512: a686bd8955d9c3baf365db384e497d6ee1aa9ce2fdb0733fe6150f7e3d94bae19d55bc1b347f1c9f619e749e18b41a52b9f8c0aa2042dd311a968a4b5d251fac
These are additions to
getblockfrompeer
that I already suggested on the original PR.The two commits do the following:
getblockfrompeer
usage on pruned nodes. This is important because many use-cases forgetblockfrompeer
are in a context of a pruned node.