test: rpc: add last block announcement time to getpeerinfo result#27052
test: rpc: add last block announcement time to getpeerinfo result#27052LarryRuane wants to merge 5 commits into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/27052. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please copy-paste 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. LLM Linter (✨ experimental)Possible typos and grammar issues:
2026-06-07 15:53:08 |
20368e3 to
becf380
Compare
|
Force pushed to fix CI failure |
|
Concept ACK. I spent quite a bit of time trying to test #26172 (my findings are documented here) and can confirm the difficulty of testing it with the current state of the test framework. I also support the suggestion to add |
becf380 to
efc2e70
Compare
efc2e70 to
16d2903
Compare
16d2903 to
2e80e3b
Compare
2e80e3b to
6c564aa
Compare
|
Force pushed from becf38061b2625bcc629293fec0dce7c27292e14 to
I'll take this out of draft now since I think it's ready for review. |
Will get around to it soon. |
|
I think the commit messages for the last two commits should be more detailed |
danielabrozzoni
left a comment
There was a problem hiding this comment.
Code Review d46a3a5
I still haven't tested, I only looked at the code for now. The code looks ok, but there are some style improvements that I think should be picked up:
- I would like to see #27052 (comment), I think it would make the code more consistent and easier to understand
- In the first commit (e3ea536), it would be nice to have some more context in the commit message on why you're converting
m_last_block_announcementtoNodeSeconds. Something as easy as "preparatory for next commit" is fine, it's just to have some history in git as well - The PR description is good and gives a lot of insight as of why the PR is useful, but this context should be in the commit messages as well. I would add it to the commit message of the third commit (34b9122)
- The first three commits should have the prefixes
rpc:ornet:in the commit message.
naiyoma
left a comment
There was a problem hiding this comment.
TestedACK d46a3a5
Tested without the fix from PR #26172 by flipping the null check condition.
The test fails as expected, catching last_block_announcement not being updated
when a peer announces a new block.
assert peerinfo['last_block_announcement'] == cur_time
AssertionError
I have not been able to observe any eviction logs, but I could see the last_block_announcement being set for my peers
Every 5.0s: bitcoin-cli getpeerinfo | grep last_block_announcement ubuntu: Fri Mar 20 12:46:28 2026
"last_block_announcement": 1773995600,
"last_block_announcement": 0,
"last_block_announcement": 0,
"last_block_announcement": 1773999976,
"last_block_announcement": 1773999593,
"last_block_announcement": 0,
"last_block_announcement": 1773997866,
"last_block_announcement": 0,
micro nits: you can address this if you have to make another push
Consider adding a test case for when a peer sends a header that is new to us but has less chain work than our tip last_block_announcement.
|
I think I've addressed (and accepted) all suggestions, thanks! |
will re-review I haven't been able to reproduce the test failing
I think this is where the timeout is happening -> https://github.com/bitcoin/bitcoin/blob/master/test/functional/test_framework/p2p.py#L917 |
|
@LarryRuane can you fix the CI failures here? |
I added this to the test, but could not get it to work (CI fails intermittently). I don't think it's very important, so I reverted it (force-pushed 136eed4). In this very rare situation, if the timestamp gets updated (I don't think it will, but if it does), it's not much of a problem; it isn't critical that this timestamp is correct. If you know how to add this to the test, please explain; otherwise, I think this is okay to merge. |
Yeah, this is not important. I just thought it would be a good addition to the test, but it shouldn’t block this PR from moving forward. |
If it isn't important, then why expose it to RPC at all? |
I think I've been able to reproduce the CI failure. When the test runs quickly, the first and second blocks are identical because When there is a slight delay between the two create_block calls, A second issue is that the test was not correclty checking the edge case i suggested. My suggestion is to create a genuinely different block with an explicit timestamp: This ensures I did generate mutants for this condition Testing this edge case does kill these two surviving mutants (> -> >= and && -> ||). In my opinion, this is worth testing, so maybe it can be included here or in a follow-up. |
|
@LarryRuane do you plan to update your approach here with @naiyoma's suggestions? |
|
@naiyoma - thanks for the review and mutation testing! |
This non-functional change makes it clear that this variable is a time_point (point-in-time) rather than a duration. (An int64_t can be either). This variable's use is modified in the following commits, so we may as well moderize its type. This type is also mockable, which a later test commit takes advantage of.
Copy its value from CNodeState. Unused until the next commit.
This is the most recent time that this peer was the first to notify our node of a new block (one that we didn't already know about), or zero if this peer has never been the first to notify us of a new block. This can be used to evaluate the quality (performance) of this peer, similar to the existing `last_block` field. This timestamp already exists internally and is used for stale-tip eviction logic; this PR exposes it at the RPC layer. This will also be used (in a later commit) to increase stale-tip test coverage.
Co-authored-by: naiyoma <lankas.aurelia@gmail.com>
The `getpeerinfo` RPC now returns `last_block_announcement`.
Thanks for catching that, force-pushed to fix that (just the commit message, no other changes). |
| @@ -200,7 +199,7 @@ BOOST_FIXTURE_TEST_CASE(stale_tip_peer_management, OutboundTest) | |||
|
|
|||
| // Update the last announced block time for the last | |||
| // peer, and check that the next newest node gets evicted. | |||
| peerLogic->UpdateLastBlockAnnounceTime(vNodes.back()->GetId(), GetTime()); | |||
| peerLogic->UpdateLastBlockAnnounceTime(vNodes.back()->GetId(), Now<NodeSeconds>()); | |||
There was a problem hiding this comment.
nit in the first commit: This is not worse, but I don't think NodeSeconds is the right type here.
It seems more consistent to use the native clock type (and resolution), that is NodeClock::time_point.
I've pushed a commit that does this to fa67c65 (https://github.com/bitcoin/bitcoin/pull/35315/commits)
This PR adds
last_block_announcementto the per-peergetpeerinfoRPC result. This is the most recent time that this peer was the first to notify our node of a new block (one that we didn't already know about), or zero if this peer has never been the first to notify us of a new block. This timestamp already exists internally and is used for stale-tip eviction logic; this PR exposes it at the RPC layer.This PR started out as a suggestion for additional test coverage, see #26172 (comment). It turned out that the easiest way to test (already-merged) #26172 is to add this field to
getpeerinfoand have a functional test verify its value. But it may also be useful to have this result in its own right, similar to that RPC's existinglast_blockfield -- it indicates something about the quality of our peers. It allows one to predict which peer will be evicted when the stale tip logic activates. (I'm not sure if that would be useful, but it may be.)The functional test added here fails without #26172, which is the main goal.
This PR does not test the actual stale-tip eviction logic; that's difficult to do with a functional test. But it does test the correctness of the timestamp that the eviction logic depends on. #23352 is an attempt to test the eviction logic using a unit test, it's not ready to be merged yet. I think having both kinds of tests would be beneficial.