fix: update peer difficulty on header/block receipt#3898
Open
iho wants to merge 1 commit into
Open
Conversation
PeerLiveInfo height/total_difficulty was only refreshed on ping/pong, so a peer that just sent a new tip header could look stale for up to ~10s. Refresh live info (if work increased) when we accept a header, compact block, or full block — including already-known duplicates that still advertise that peer has the tip. Closes mimblewimble#3167
wiesche89
self-requested a review
July 12, 2026 09:35
wiesche89
reviewed
Jul 19, 2026
wiesche89
left a comment
Contributor
There was a problem hiding this comment.
please fix merge conflicts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PeerLiveInfoheight andtotal_difficultywere only updated from Ping/Pong, so after a peer sent a new tip header/block we could still treat them as stale for up to ~10 seconds (until the next ping cycle). That delays peer selection, sync decisions, and TUI/API peer stats.This updates peer live info as soon as we accept a header, compact block, or full block from that peer — and also when they re-send an already-known tip (they are still advertising that work).
Closes #3167
Changes
PeerInfo::update_if_better— only increases advertised work (higher difficulty, or same difficulty with higher height)NetToChainAdapteron:Ping/Pong still uses absolute
update()as before.Test plan
cargo test -p grin_p2p --lib update_if_bettercargo check -p grin_serversget_connected_peersimmediately after a peer announces a new tip (should update without waiting for ping)