Skip to content

Commit

Permalink
Only update peer with the first and last block (hyperledger#5659)
Browse files Browse the repository at this point in the history
* only update peer with the first and last block

Signed-off-by: Stefan <stefan.pingel@consensys.net>
  • Loading branch information
pinges authored and eum602 committed Nov 3, 2023
1 parent 097d8a2 commit d5cc6b5
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ protected Optional<List<BlockHeader>> 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);
Expand All @@ -116,6 +117,11 @@ protected Optional<List<BlockHeader>> 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);
}

Expand Down

0 comments on commit d5cc6b5

Please sign in to comment.