Skip to content

fix: update peer difficulty on header/block receipt#3898

Open
iho wants to merge 1 commit into
mimblewimble:stagingfrom
iho:fix/peer-difficulty-on-header
Open

fix: update peer difficulty on header/block receipt#3898
iho wants to merge 1 commit into
mimblewimble:stagingfrom
iho:fix/peer-difficulty-on-header

Conversation

@iho

@iho iho commented Jul 9, 2026

Copy link
Copy Markdown

Summary

PeerLiveInfo height and total_difficulty were 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

  • Add PeerInfo::update_if_better — only increases advertised work (higher difficulty, or same difficulty with higher height)
  • Call it from NetToChainAdapter on:
    • already-known full/compact blocks and headers
    • successfully processed headers / blocks
    • orphans and other non-ban refusals when we already have the header
    • header-sync batches after successful processing
  • Unit test covering increase / ignore / ping overwrite behavior

Ping/Pong still uses absolute update() as before.

Test plan

  • cargo test -p grin_p2p --lib update_if_better
  • cargo check -p grin_servers
  • Manual: watch peer height/difficulty in TUI or get_connected_peers immediately after a peer announces a new tip (should update without waiting for ping)

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
wiesche89 self-requested a review July 12, 2026 09:35

@wiesche89 wiesche89 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please fix merge conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants