make obvious when a breach of protocol is logged, add peer in some places (#4268)

Signed-off-by: Stefan <stefan.pingel@consensys.net>
Co-authored-by: Sally MacFarlane <sally.macfarlane@consensys.net>
pull/4277/head
Stefan Pingel 2 years ago committed by GitHub
parent 63331cd55d
commit 113bd54c6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java
  2. 10
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/RequestManager.java
  3. 3
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/AbstractGetHeadersFromPeerTask.java
  4. 4
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/BlockPropagationManager.java
  5. 2
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/PipelineChainDownloader.java
  6. 4
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DownloadHeaderSequenceTask.java
  7. 4
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/NewPooledTransactionHashesMessageProcessor.java
  8. 5
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionsMessageProcessor.java
  9. 4
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/connections/netty/DeFramer.java

@ -257,7 +257,7 @@ public class EthProtocolManager implements ProtocolManager, MinedBlockObserver {
} else if (!ethPeer.statusHasBeenReceived()) {
// Peers are required to send status messages before any other message type
LOG.debug(
"{} requires a Status ({}) message to be sent first. Instead, received message {}. Disconnecting from {}.",
"{} requires a Status ({}) message to be sent first. Instead, received message {} (BREACH_OF_PROTOCOL). Disconnecting from {}.",
this.getClass().getSimpleName(),
EthPV62.STATUS,
code,
@ -277,7 +277,9 @@ public class EthProtocolManager implements ProtocolManager, MinedBlockObserver {
final EthMessage ethMessage = new EthMessage(ethPeer, messageData);
if (!ethPeer.validateReceivedMessage(ethMessage, getSupportedProtocol())) {
LOG.debug("Unsolicited message received, disconnecting from EthPeer: {}", ethPeer);
LOG.debug(
"Unsolicited message received (BREACH_OF_PROTOCOL), disconnecting from EthPeer: {}",
ethPeer);
ethPeer.disconnect(DisconnectReason.BREACH_OF_PROTOCOL);
return;
}
@ -308,7 +310,10 @@ public class EthProtocolManager implements ProtocolManager, MinedBlockObserver {
}
} catch (final RLPException e) {
LOG.debug(
"Received malformed message {} , disconnecting: {}", messageData.getData(), ethPeer, e);
"Received malformed message {} (BREACH_OF_PROTOCOL), disconnecting: {}",
messageData.getData(),
ethPeer,
e);
ethPeer.disconnect(DisconnectMessage.DisconnectReason.BREACH_OF_PROTOCOL);
}

@ -29,7 +29,12 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RequestManager {
private static final Logger LOG = LoggerFactory.getLogger(RequestManager.class);
private final AtomicLong requestIdCounter = new AtomicLong(0);
private final Map<BigInteger, ResponseStream> responseStreams = new ConcurrentHashMap<>();
private final EthPeer peer;
@ -73,7 +78,10 @@ public class RequestManager {
.ifPresentOrElse(
responseStream -> responseStream.processMessage(requestIdAndEthMessage.getValue()),
// disconnect on incorrect requestIds
() -> peer.disconnect(DisconnectMessage.DisconnectReason.BREACH_OF_PROTOCOL));
() -> {
LOG.debug("Request ID incorrect (BREACH_OF_PROTOCOL), disconnecting peer {}", peer);
peer.disconnect(DisconnectMessage.DisconnectReason.BREACH_OF_PROTOCOL);
});
} else {
// otherwise iterate through all of them
streams.forEach(stream -> stream.processMessage(ethMessage.getData()));

@ -109,7 +109,8 @@ 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);
"Sequential headers must form a chain through hashes (BREACH_OF_PROTOCOL), disconnecting peer: {}",
peer);
peer.disconnect(DisconnectMessage.DisconnectReason.BREACH_OF_PROTOCOL);
return Optional.empty();
}

@ -296,7 +296,7 @@ public class BlockPropagationManager implements ForkchoiceMessageListener {
importOrSavePendingBlock(block, message.getPeer().nodeId());
} catch (final RLPException e) {
LOG.debug(
"Malformed NEW_BLOCK message received from peer, disconnecting: {}",
"Malformed NEW_BLOCK message received from peer (BREACH_OF_PROTOCOL), disconnecting: {}",
message.getPeer(),
e);
message.getPeer().disconnect(DisconnectReason.BREACH_OF_PROTOCOL);
@ -359,7 +359,7 @@ public class BlockPropagationManager implements ForkchoiceMessageListener {
}
} catch (final RLPException e) {
LOG.debug(
"Malformed NEW_BLOCK_HASHES message received from peer, disconnecting: {}",
"Malformed NEW_BLOCK_HASHES message received from peer (BREACH_OF_PROTOCOL), disconnecting: {}",
message.getPeer(),
e);
message.getPeer().disconnect(DisconnectReason.BREACH_OF_PROTOCOL);

@ -119,7 +119,7 @@ public class PipelineChainDownloader implements ChainDownloader {
pipelineErrorCounter.inc();
if (ExceptionUtils.rootCause(error) instanceof InvalidBlockException) {
LOG.warn(
"Invalid block detected. Disconnecting from sync target. {}",
"Invalid block detected (BREACH_OF_PROTOCOL). Disconnecting from sync target. {}",
ExceptionUtils.rootCause(error).getMessage());
syncState.disconnectSyncTarget(DisconnectReason.BREACH_OF_PROTOCOL);
}

@ -219,10 +219,10 @@ public class DownloadHeaderSequenceTask extends AbstractRetryingPeerTask<List<Bl
if (error == null && blockPeerTaskResult.getResult() != null) {
badBlockManager.addBadBlock(blockPeerTaskResult.getResult());
}
headersResult.getPeer().disconnect(DisconnectReason.BREACH_OF_PROTOCOL);
LOG.debug(
"Received invalid headers from peer, disconnecting from: {}",
"Received invalid headers from peer (BREACH_OF_PROTOCOL), disconnecting from: {}",
headersResult.getPeer());
headersResult.getPeer().disconnect(DisconnectReason.BREACH_OF_PROTOCOL);
future.completeExceptionally(
new InvalidBlockException(
"Header failed validation.",

@ -133,7 +133,9 @@ public class NewPooledTransactionHashesMessageProcessor {
} catch (final RLPException ex) {
if (peer != null) {
LOG.debug(
"Malformed pooled transaction hashes message received, disconnecting: {}", peer, ex);
"Malformed pooled transaction hashes message received (BREACH_OF_PROTOCOL), disconnecting: {}",
peer,
ex);
peer.disconnect(DisconnectReason.BREACH_OF_PROTOCOL);
}
}

@ -112,7 +112,10 @@ class TransactionsMessageProcessor {
} catch (final RLPException ex) {
if (peer != null) {
LOG.debug("Malformed transaction message received, disconnecting: {}", peer, ex);
LOG.debug(
"Malformed transaction message received (BREACH_OF_PROTOCOL), disconnecting: {}",
peer,
ex);
peer.disconnect(DisconnectReason.BREACH_OF_PROTOCOL);
}
}

@ -184,7 +184,7 @@ final class DeFramer extends ByteToMessageDecoder {
} else {
// Unexpected message - disconnect
LOG.debug(
"Message received before HELLO's exchanged, disconnecting. Peer: {}, Code: {}, Data: {}",
"Message received before HELLO's exchanged (BREACH_OF_PROTOCOL), disconnecting. Peer: {}, Code: {}, Data: {}",
expectedPeer.map(Peer::getEnodeURLString).orElse("unknown"),
message.getCode(),
message.getData().toString());
@ -227,7 +227,7 @@ final class DeFramer extends ByteToMessageDecoder {
if (cause instanceof FramingException
|| cause instanceof RLPException
|| cause instanceof IllegalArgumentException) {
LOG.debug("Invalid incoming message", throwable);
LOG.debug("Invalid incoming message (BREACH_OF_PROTOCOL)", throwable);
if (connectFuture.isDone() && !connectFuture.isCompletedExceptionally()) {
connectFuture.get().disconnect(DisconnectMessage.DisconnectReason.BREACH_OF_PROTOCOL);
return;

Loading…
Cancel
Save