Skip to content

Fix8725: Do not ask for chain head header when using eth69 #8756

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

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

pinges
Copy link
Contributor

@pinges pinges commented Jun 6, 2025

PR description

This PR is a slight optimisation in case we are using eth69 with a peer, where we don't have to ask for their chain head header after receiving their status message.

Fixed Issue(s)

#8725

Copy link

@Copilot 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

This PR optimizes Eth69 peer handling by skipping redundant chain head requests and refactors peer checking logic for clarity and performance.

  • Simplified SnapServerChecker by making its constructor private and streamlining its check method.
  • Added debug logging in ChainHeadTracker#getBestHeaderFromPeerCompletableFuture.
  • Refactored EthPeers.ethPeerStatusExchanged to extract and reuse checkHeadBlock and checkSnapServer, with conditional skipping for Eth69 peers.

Reviewed Changes

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

File Description
ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/SnapServerChecker.java Made constructor private; simplified check to use thenApply.
ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTracker.java Added debug log before fetching headers from peer.
ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java Refactored ethPeerStatusExchanged, extracted helper methods, and skipped chain head fetch for Eth69 peers.

@@ -46,34 +46,30 @@ public static void createAndSetSnapServerChecker(
ethContext.getEthPeers().setSnapServerChecker(checker);
}

public CompletableFuture<Boolean> check(final EthPeer peer, final BlockHeader peersHeadHeader) {
public CompletableFuture<Boolean> check(final EthPeer peer, final BlockHeader headBlockHeader) {
LOG.atTrace()
.setMessage("Checking whether peer {} is a snap server ...")
.addArgument(peer::getLoggableId)
.log();
Copy link
Preview

Copilot AI Jun 6, 2025

Choose a reason for hiding this comment

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

Passing a null headBlockHeader for Eth69-compatible peers will be forwarded to getAccountRangeFromPeer and may cause an NPE or unexpected behavior. Consider handling the null case explicitly (e.g., using the status message header) before calling this method.

Suggested change
.log();
.log();
if (headBlockHeader == null) {
LOG.atWarn()
.setMessage("headBlockHeader is null. Cannot check if peer {} is a snap server.")
.addArgument(peer::getLoggableId)
.log();
return CompletableFuture.completedFuture(false);
}

Copilot uses AI. Check for mistakes.

@pinges pinges changed the title Rework eth peers changes Fix8725: Do not ask for chain head header when using eth69 Jun 6, 2025
pinges and others added 2 commits June 8, 2025 03:29
…anager/EthPeers.java

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Stefan Pingel <[email protected]>
…anager/EthPeers.java

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Stefan Pingel <[email protected]>
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.

1 participant