add more logging for get blocks form peers task (#3047)

* add more logging for get blocks form peers task

Signed-off-by: Stefan Pingel <stefan.pingel@consensys.net>
pull/3116/head
Stefan Pingel 3 years ago committed by GitHub
parent 2ed6c61f6b
commit 0b4c03c8ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/AbstractGetHeadersFromPeerTask.java
  2. 14
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetBlockFromPeerTask.java
  3. 3
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetBodiesFromPeerTask.java

@ -74,16 +74,19 @@ public abstract class AbstractGetHeadersFromPeerTask
final List<BlockHeader> headers = headersMessage.getHeaders(protocolSchedule); final List<BlockHeader> headers = headersMessage.getHeaders(protocolSchedule);
if (headers.isEmpty()) { if (headers.isEmpty()) {
// Message contains no data - nothing to do // Message contains no data - nothing to do
LOG.debug("headers.isEmpty. Peer: {}", peer);
return Optional.empty(); return Optional.empty();
} }
if (headers.size() > count) { if (headers.size() > count) {
// Too many headers - this isn't our response // Too many headers - this isn't our response
LOG.debug("headers.size()>count. Peer: {}", peer);
return Optional.empty(); return Optional.empty();
} }
final BlockHeader firstHeader = headers.get(0); final BlockHeader firstHeader = headers.get(0);
if (!matchesFirstHeader(firstHeader)) { if (!matchesFirstHeader(firstHeader)) {
// This isn't our message - nothing to do // This isn't our message - nothing to do
LOG.debug("!matchesFirstHeader. Peer: {}", peer);
return Optional.empty(); return Optional.empty();
} }
@ -95,6 +98,7 @@ public abstract class AbstractGetHeadersFromPeerTask
final BlockHeader header = headers.get(i); final BlockHeader header = headers.get(i);
if (header.getNumber() != prevBlockHeader.getNumber() + expectedDelta) { if (header.getNumber() != prevBlockHeader.getNumber() + expectedDelta) {
// Skip doesn't match, this isn't our data // Skip doesn't match, this isn't our data
LOG.debug("header not matching the expected number. Peer: {}", peer);
return Optional.empty(); return Optional.empty();
} }
// if headers are supposed to be sequential check if a chain is formed // if headers are supposed to be sequential check if a chain is formed
@ -103,8 +107,7 @@ public abstract class AbstractGetHeadersFromPeerTask
final BlockHeader child = reverse ? prevBlockHeader : header; final BlockHeader child = reverse ? prevBlockHeader : header;
if (!parent.getHash().equals(child.getParentHash())) { if (!parent.getHash().equals(child.getParentHash())) {
LOG.debug( LOG.debug(
"Sequential headers must form a chain through hashes, disconnecting peer: {}", "Sequential headers must form a chain through hashes, disconnecting peer: {}", peer);
peer.toString());
peer.disconnect(DisconnectMessage.DisconnectReason.BREACH_OF_PROTOCOL); peer.disconnect(DisconnectMessage.DisconnectReason.BREACH_OF_PROTOCOL);
return Optional.empty(); return Optional.empty();
} }
@ -113,7 +116,7 @@ public abstract class AbstractGetHeadersFromPeerTask
headersList.add(header); 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); return Optional.of(headersList);
} }

@ -74,13 +74,18 @@ public class GetBlockFromPeerTask extends AbstractPeerTask<Block> {
.whenComplete( .whenComplete(
(r, t) -> { (r, t) -> {
if (t != null) { if (t != null) {
LOG.info( LOG.debug(
"Failed to download block {} from peer {}.", "Failed to download block {} from peer {} with message '{}' and cause '{}'",
blockIdentifier, blockIdentifier,
assignedPeer.map(EthPeer::toString).orElse("<any>")); assignedPeer.map(EthPeer::toString).orElse("<any>"),
t.getMessage(),
t.getCause());
result.completeExceptionally(t); result.completeExceptionally(t);
} else if (r.getResult().isEmpty()) { } 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()); result.completeExceptionally(new IncompleteResultsException());
} else { } else {
LOG.debug( LOG.debug(
@ -111,6 +116,7 @@ public class GetBlockFromPeerTask extends AbstractPeerTask<Block> {
private CompletableFuture<PeerTaskResult<List<Block>>> completeBlock( private CompletableFuture<PeerTaskResult<List<Block>>> completeBlock(
final PeerTaskResult<List<BlockHeader>> headerResult) { final PeerTaskResult<List<BlockHeader>> headerResult) {
if (headerResult.getResult().isEmpty()) { if (headerResult.getResult().isEmpty()) {
LOG.debug("header result is empty.");
return CompletableFuture.failedFuture(new IncompleteResultsException()); return CompletableFuture.failedFuture(new IncompleteResultsException());
} }

@ -106,9 +106,11 @@ public class GetBodiesFromPeerTask extends AbstractPeerRequestTask<List<Block>>
final List<BlockBody> bodies = bodiesMessage.bodies(protocolSchedule); final List<BlockBody> bodies = bodiesMessage.bodies(protocolSchedule);
if (bodies.size() == 0) { if (bodies.size() == 0) {
// Message contains no data - nothing to do // Message contains no data - nothing to do
LOG.debug("Message contains no data. Peer: {}", peer);
return Optional.empty(); return Optional.empty();
} else if (bodies.size() > headers.size()) { } else if (bodies.size() > headers.size()) {
// Message doesn't match our request - nothing to do // Message doesn't match our request - nothing to do
LOG.debug("Message doesn't match our request. Peer: {}", peer);
return Optional.empty(); return Optional.empty();
} }
@ -117,6 +119,7 @@ public class GetBodiesFromPeerTask extends AbstractPeerRequestTask<List<Block>>
final List<BlockHeader> headers = bodyToHeaders.get(new BodyIdentifier(body)); final List<BlockHeader> headers = bodyToHeaders.get(new BodyIdentifier(body));
if (headers == null) { if (headers == null) {
// This message contains unrelated bodies - exit // This message contains unrelated bodies - exit
LOG.debug("This message contains unrelated bodies. Peer: {}", peer);
return Optional.empty(); return Optional.empty();
} }
headers.forEach(h -> blocks.add(new Block(h, body))); headers.forEach(h -> blocks.add(new Block(h, body)));

Loading…
Cancel
Save