Skip to content

Commit

Permalink
increase the default max message size for p2p messages (#4120)
Browse files Browse the repository at this point in the history
* remove the limit for the incoming message size. The size is limited on the RLPx layer (16.7MB)

Signed-off-by: Stefan <[email protected]>
  • Loading branch information
pinges authored Jul 20, 2022
1 parent b7877be commit 86197c4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ public class EthProtocolManager implements ProtocolManager, MinedBlockObserver {
private final Blockchain blockchain;
private final BlockBroadcaster blockBroadcaster;
private final List<PeerValidator> peerValidators;
// The max size of messages (in bytes)
private final int maxMessageSize;
private final Optional<MergePeerFilter> mergePeerFilter;

public EthProtocolManager(
Expand All @@ -93,7 +91,6 @@ public EthProtocolManager(
this.peerValidators = peerValidators;
this.scheduler = scheduler;
this.blockchain = blockchain;
this.maxMessageSize = ethereumWireProtocolConfiguration.getMaxMessageSize();
this.mergePeerFilter = mergePeerFilter;
this.shutdown = new CountDownLatch(1);
this.genesisHash = blockchain.getBlockHashByNumber(0L).orElse(Hash.ZERO);
Expand Down Expand Up @@ -250,17 +247,6 @@ public void processMessage(final Capability cap, final Message message) {
return;
}

if (messageData.getSize() > maxMessageSize) {
LOG.warn(
"Received message (code: {}) exceeding size limit of {} bytes: {} bytes. Disconnecting from {}",
Integer.toString(code, 16),
maxMessageSize,
messageData.getSize(),
ethPeer);
ethPeer.disconnect(DisconnectReason.SUBPROTOCOL_TRIGGERED);
return;
}

// Handle STATUS processing
if (code == EthPV62.STATUS) {
handleStatusMessage(ethPeer, messageData);
Expand Down Expand Up @@ -391,7 +377,7 @@ private void handleStatusMessage(final EthPeer peer, final MessageData data) {
status.genesisHash());
peer.disconnect(DisconnectReason.SUBPROTOCOL_TRIGGERED);
} else if (mergePeerFilter.isPresent()) {
boolean disconnected = mergePeerFilter.get().disconnectIfPoW(status, peer);
final boolean disconnected = mergePeerFilter.get().disconnectIfPoW(status, peer);
if (disconnected) {
handleDisconnect(peer.getConnection(), DisconnectReason.SUBPROTOCOL_TRIGGERED, false);
}
Expand Down Expand Up @@ -422,7 +408,7 @@ public void blockMined(final Block block) {
}

public List<Bytes> getForkIdAsBytesList() {
ForkId chainHeadForkId = forkIdManager.getForkIdForChainHead();
final ForkId chainHeadForkId = forkIdManager.getForkIdForChainHead();
return chainHeadForkId == null
? Collections.emptyList()
: chainHeadForkId.getForkIdAsBytesList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,28 +202,9 @@ public void disconnectOnWrongChainId() {
}
}

@Test
public void disconnectOnVeryLargeMessage() {
try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create(
blockchain,
() -> false,
protocolContext.getWorldStateArchive(),
transactionPool,
EthProtocolConfiguration.defaultConfig())) {
final MessageData messageData = mock(MessageData.class);
when(messageData.getSize()).thenReturn(EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE + 1);
when(messageData.getCode()).thenReturn(EthPV62.TRANSACTIONS);
final MockPeerConnection peer = setupPeer(ethManager, (cap, msg, conn) -> {});

ethManager.processMessage(EthProtocol.ETH63, new DefaultMessage(peer, messageData));
assertThat(peer.isDisconnected()).isTrue();
}
}

@Test
public void disconnectNewPoWPeers() {
MergePeerFilter mergePeerFilter = new MergePeerFilter();
final MergePeerFilter mergePeerFilter = new MergePeerFilter();
try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create(
blockchain,
Expand Down Expand Up @@ -1119,7 +1100,7 @@ public void transactionMessagesGoToTheCorrectExecutor() {

@Test
public void forkIdForChainHeadMayBeNull() {
EthScheduler ethScheduler = mock(EthScheduler.class);
final EthScheduler ethScheduler = mock(EthScheduler.class);
try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create(
blockchain,
Expand Down

0 comments on commit 86197c4

Please sign in to comment.