Skip to content

Conversation

@shohamc1
Copy link
Member

@shohamc1 shohamc1 commented Sep 20, 2025

After eth/69, we were calling getOrCreatePeer before the handshake, however in the case of a failed handshake these peers were not being cleaned up - leading to incorrect peer counts in the GoodPeers log.

Since there is a constraint of setting up defers in the correct order, we create the peerInfo after the handshake and store the handshake data in temporary variables.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Fixes incorrect GoodPeers count by delaying peer creation until after a successful handshake and applying block range updates atomically.

  • Move getOrCreatePeer to after handshake completes to avoid leaking peers on failed handshakes.
  • Introduce PeerInfo.SetBlockRange to update minBlock and height under a single lock.
  • Downgrade block range announcement send failures from error to debug logs.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
p2p/sentry/sentry_multi_client/sentry_multi_client.go Adjust log level when announcing block range fails.
p2p/sentry/sentry_grpc_server.go Add SetBlockRange, capture handshake data pre-peer creation, apply block range post-handshake, and use SetBlockRange in RPC.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@yperbasis yperbasis requested a review from anacrolix September 22, 2025 07:33
@yperbasis yperbasis added this to the 3.2.0 milestone Sep 22, 2025
})
if err != nil {
cs.logger.Error("blockRangeUpdate", "err", err)
cs.logger.Debug("blockRangeUpdate", "err", err)
Copy link
Member

Choose a reason for hiding this comment

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

we run with debug logging fairly frequently (in testnets too - it's visible for me locally and in fusaka devnets) so lowering the err to debug is not a complete solution

instead of doing this we should try to check if the sentry has eth69 or higher as a protocol and then attempt to send this msg - then we can also keep the log.Error as it was

to do this you can call s.HandShake - it gives you the relevant info

@shohamc1 shohamc1 enabled auto-merge (squash) September 22, 2025 10:31
@shohamc1 shohamc1 merged commit afb06f8 into main Sep 22, 2025
18 checks passed
@shohamc1 shohamc1 deleted the shohamc1/peers-log branch September 22, 2025 11:28
NazariiDenha pushed a commit that referenced this pull request Oct 24, 2025
After eth/69, we were calling `getOrCreatePeer` before the handshake,
however in the case of a failed handshake these peers were not being
cleaned up - leading to incorrect peer counts in the `GoodPeers` log.

Since there is a constraint of setting up `defer`s in the correct order,
we create the `peerInfo` after the handshake and store the handshake
data in temporary variables.
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.

4 participants