Skip to content

Commit

Permalink
add more logging for get blocks form peers task (#3047)
Browse files Browse the repository at this point in the history
* add more logging for get blocks form peers task

Signed-off-by: Stefan Pingel <stefan.pingel@consensys.net>
  • Loading branch information
pinges authored Nov 26, 2021
1 parent 2ed6c61 commit 0b4c03c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,19 @@ protected Optional<List<BlockHeader>> processResponse(
final List<BlockHeader> headers = headersMessage.getHeaders(protocolSchedule);
if (headers.isEmpty()) {
// Message contains no data - nothing to do
LOG.debug("headers.isEmpty. Peer: {}", peer);
return Optional.empty();
}
if (headers.size() > count) {
// Too many headers - this isn't our response
LOG.debug("headers.size()>count. Peer: {}", peer);
return Optional.empty();
}

final BlockHeader firstHeader = headers.get(0);
if (!matchesFirstHeader(firstHeader)) {
// This isn't our message - nothing to do
LOG.debug("!matchesFirstHeader. Peer: {}", peer);
return Optional.empty();
}

Expand All @@ -95,6 +98,7 @@ protected Optional<List<BlockHeader>> processResponse(
final BlockHeader 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);
return Optional.empty();
}
// if headers are supposed to be sequential check if a chain is formed
Expand All @@ -103,8 +107,7 @@ protected Optional<List<BlockHeader>> processResponse(
final BlockHeader child = reverse ? prevBlockHeader : header;
if (!parent.getHash().equals(child.getParentHash())) {
LOG.debug(
"Sequential headers must form a chain through hashes, disconnecting peer: {}",
peer.toString());
"Sequential headers must form a chain through hashes, disconnecting peer: {}", peer);
peer.disconnect(DisconnectMessage.DisconnectReason.BREACH_OF_PROTOCOL);
return Optional.empty();
}
Expand All @@ -113,7 +116,7 @@ protected Optional<List<BlockHeader>> processResponse(
headersList.add(header);
}

LOG.debug("Received {} of {} headers requested from peer.", headersList.size(), count);
LOG.debug("Received {} of {} headers requested from peer {}", headersList.size(), count, peer);
return Optional.of(headersList);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,18 @@ protected void executeTask() {
.whenComplete(
(r, t) -> {
if (t != null) {
LOG.info(
"Failed to download block {} from peer {}.",
LOG.debug(
"Failed to download block {} from peer {} with message '{}' and cause '{}'",
blockIdentifier,
assignedPeer.map(EthPeer::toString).orElse("<any>"));
assignedPeer.map(EthPeer::toString).orElse("<any>"),
t.getMessage(),
t.getCause());
result.completeExceptionally(t);
} else if (r.getResult().isEmpty()) {
LOG.info("Failed to download block {} from peer {}.", blockIdentifier, r.getPeer());
LOG.debug(
"Failed to download block {} from peer {} with empty result.",
blockIdentifier,
r.getPeer());
result.completeExceptionally(new IncompleteResultsException());
} else {
LOG.debug(
Expand Down Expand Up @@ -111,6 +116,7 @@ private CompletableFuture<PeerTaskResult<List<BlockHeader>>> downloadHeader() {
private CompletableFuture<PeerTaskResult<List<Block>>> completeBlock(
final PeerTaskResult<List<BlockHeader>> headerResult) {
if (headerResult.getResult().isEmpty()) {
LOG.debug("header result is empty.");
return CompletableFuture.failedFuture(new IncompleteResultsException());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ protected Optional<List<Block>> processResponse(
final List<BlockBody> bodies = bodiesMessage.bodies(protocolSchedule);
if (bodies.size() == 0) {
// Message contains no data - nothing to do
LOG.debug("Message contains no data. Peer: {}", peer);
return Optional.empty();
} else if (bodies.size() > headers.size()) {
// Message doesn't match our request - nothing to do
LOG.debug("Message doesn't match our request. Peer: {}", peer);
return Optional.empty();
}

Expand All @@ -117,6 +119,7 @@ protected Optional<List<Block>> processResponse(
final List<BlockHeader> headers = bodyToHeaders.get(new BodyIdentifier(body));
if (headers == null) {
// This message contains unrelated bodies - exit
LOG.debug("This message contains unrelated bodies. Peer: {}", peer);
return Optional.empty();
}
headers.forEach(h -> blocks.add(new Block(h, body)));
Expand Down

0 comments on commit 0b4c03c

Please sign in to comment.