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()) { } else if (!ethPeer.statusHasBeenReceived()) {
// Peers are required to send status messages before any other message type // Peers are required to send status messages before any other message type
LOG.debug( 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(), this.getClass().getSimpleName(),
EthPV62.STATUS, EthPV62.STATUS,
code, code,
@ -277,7 +277,9 @@ public class EthProtocolManager implements ProtocolManager, MinedBlockObserver {
final EthMessage ethMessage = new EthMessage(ethPeer, messageData); final EthMessage ethMessage = new EthMessage(ethPeer, messageData);
if (!ethPeer.validateReceivedMessage(ethMessage, getSupportedProtocol())) { 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); ethPeer.disconnect(DisconnectReason.BREACH_OF_PROTOCOL);
return; return;
} }
@ -308,7 +310,10 @@ public class EthProtocolManager implements ProtocolManager, MinedBlockObserver {
} }
} catch (final RLPException e) { } catch (final RLPException e) {
LOG.debug( 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); 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.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RequestManager { public class RequestManager {
private static final Logger LOG = LoggerFactory.getLogger(RequestManager.class);
private final AtomicLong requestIdCounter = new AtomicLong(0); private final AtomicLong requestIdCounter = new AtomicLong(0);
private final Map<BigInteger, ResponseStream> responseStreams = new ConcurrentHashMap<>(); private final Map<BigInteger, ResponseStream> responseStreams = new ConcurrentHashMap<>();
private final EthPeer peer; private final EthPeer peer;
@ -73,7 +78,10 @@ public class RequestManager {
.ifPresentOrElse( .ifPresentOrElse(
responseStream -> responseStream.processMessage(requestIdAndEthMessage.getValue()), responseStream -> responseStream.processMessage(requestIdAndEthMessage.getValue()),
// disconnect on incorrect requestIds // 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 { } else {
// otherwise iterate through all of them // otherwise iterate through all of them
streams.forEach(stream -> stream.processMessage(ethMessage.getData())); streams.forEach(stream -> stream.processMessage(ethMessage.getData()));

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

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

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

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

@ -133,7 +133,9 @@ public class NewPooledTransactionHashesMessageProcessor {
} catch (final RLPException ex) { } catch (final RLPException ex) {
if (peer != null) { if (peer != null) {
LOG.debug( 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); peer.disconnect(DisconnectReason.BREACH_OF_PROTOCOL);
} }
} }

@ -112,7 +112,10 @@ class TransactionsMessageProcessor {
} catch (final RLPException ex) { } catch (final RLPException ex) {
if (peer != null) { 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); peer.disconnect(DisconnectReason.BREACH_OF_PROTOCOL);
} }
} }

@ -184,7 +184,7 @@ final class DeFramer extends ByteToMessageDecoder {
} else { } else {
// Unexpected message - disconnect // Unexpected message - disconnect
LOG.debug( 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"), expectedPeer.map(Peer::getEnodeURLString).orElse("unknown"),
message.getCode(), message.getCode(),
message.getData().toString()); message.getData().toString());
@ -227,7 +227,7 @@ final class DeFramer extends ByteToMessageDecoder {
if (cause instanceof FramingException if (cause instanceof FramingException
|| cause instanceof RLPException || cause instanceof RLPException
|| cause instanceof IllegalArgumentException) { || cause instanceof IllegalArgumentException) {
LOG.debug("Invalid incoming message", throwable); LOG.debug("Invalid incoming message (BREACH_OF_PROTOCOL)", throwable);
if (connectFuture.isDone() && !connectFuture.isCompletedExceptionally()) { if (connectFuture.isDone() && !connectFuture.isCompletedExceptionally()) {
connectFuture.get().disconnect(DisconnectMessage.DisconnectReason.BREACH_OF_PROTOCOL); connectFuture.get().disconnect(DisconnectMessage.DisconnectReason.BREACH_OF_PROTOCOL);
return; return;

Loading…
Cancel
Save