Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

increase the default max message size for p2p messages #4120

Merged
merged 6 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still have a test for the 16Mb limit? is that at the Rlpx layer?

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