From e54e47eb579dfa14b18097031b9dadb7849b4832 Mon Sep 17 00:00:00 2001 From: Stefan Pingel <16143240+pinges@users.noreply.github.com> Date: Fri, 30 Jun 2023 12:11:23 +1000 Subject: [PATCH] Only update peer with the first and last block (#5659) * only update peer with the first and last block Signed-off-by: Stefan --- .../eth/manager/task/AbstractGetHeadersFromPeerTask.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/AbstractGetHeadersFromPeerTask.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/AbstractGetHeadersFromPeerTask.java index 1b10c15c0df..e7180715b03 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/AbstractGetHeadersFromPeerTask.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/AbstractGetHeadersFromPeerTask.java @@ -95,8 +95,9 @@ protected Optional> processResponse( BlockHeader prevBlockHeader = firstHeader; updatePeerChainState(peer, firstHeader); final int expectedDelta = reverse ? -(skip + 1) : (skip + 1); + BlockHeader header = null; for (int i = 1; i < headers.size(); i++) { - final BlockHeader header = headers.get(i); + header = headers.get(i); if (header.getNumber() != prevBlockHeader.getNumber() + expectedDelta) { // Skip doesn't match, this isn't our data LOG.debug("header not matching the expected number. Peer: {}", peer); @@ -116,6 +117,11 @@ protected Optional> processResponse( } prevBlockHeader = header; headersList.add(header); + } + // if we have received more than one header we have to update the chain state with the last + // header as well, as the header with the highest block number can be the first or the last + // header. + if (headers.size() > 1) { updatePeerChainState(peer, header); }