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);
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();
}
@ -95,6 +98,7 @@ public abstract class AbstractGetHeadersFromPeerTask
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
@ -103,8 +107,7 @@ public abstract class AbstractGetHeadersFromPeerTask
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();
}
@ -113,7 +116,7 @@ public abstract class AbstractGetHeadersFromPeerTask
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);
}

@ -74,13 +74,18 @@ public class GetBlockFromPeerTask extends AbstractPeerTask<Block> {
.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(
@ -111,6 +116,7 @@ public class GetBlockFromPeerTask extends AbstractPeerTask<Block> {
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());
}

@ -106,9 +106,11 @@ public class GetBodiesFromPeerTask extends AbstractPeerRequestTask<List<Block>>
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();
}
@ -117,6 +119,7 @@ public class GetBodiesFromPeerTask extends AbstractPeerRequestTask<List<Block>>
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)));

Loading…
Cancel
Save