From 1822e31142e20ac3735841aa3335ee72185a3da6 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Tue, 21 Nov 2023 01:53:05 -0500 Subject: [PATCH] Grow the yamux buffers to exceed the maximum message size --- coordinator/src/p2p.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/coordinator/src/p2p.rs b/coordinator/src/p2p.rs index e0b25e4e..aa392c52 100644 --- a/coordinator/src/p2p.rs +++ b/coordinator/src/p2p.rs @@ -211,6 +211,9 @@ impl fmt::Debug for LibP2p { impl LibP2p { #[allow(clippy::new_without_default)] pub fn new() -> Self { + // Block size limit + 1 KB of space for signatures/metadata + const MAX_LIBP2P_MESSAGE_SIZE: usize = tributary::BLOCK_SIZE_LIMIT + 1024; + log::info!("creating a libp2p instance"); let throwaway_key_pair = Keypair::generate_ed25519(); @@ -218,9 +221,6 @@ impl LibP2p { let behavior = Behavior { gossipsub: { - // Block size limit + 1 KB of space for signatures/metadata - const MAX_LIBP2P_MESSAGE_SIZE: usize = tributary::BLOCK_SIZE_LIMIT + 1024; - let heartbeat_interval = tributary::tendermint::LATENCY_TIME / 2; let heartbeats_per_block = usize::try_from(tributary::tendermint::TARGET_BLOCK_TIME / heartbeat_interval).unwrap(); @@ -276,7 +276,15 @@ impl LibP2p { // TODO: Relay client? let mut swarm = SwarmBuilder::with_existing_identity(throwaway_key_pair) .with_tokio() - .with_tcp(TcpConfig::default().nodelay(true), noise::Config::new, yamux::Config::default) + .with_tcp(TcpConfig::default().nodelay(true), noise::Config::new, || { + let mut config = yamux::Config::default(); + // 1 MiB default + max message size + config.set_max_buffer_size((1024 * 1024) + MAX_LIBP2P_MESSAGE_SIZE); + // 256 KiB default + max message size + config + .set_receive_window_size(((256 * 1024) + MAX_LIBP2P_MESSAGE_SIZE).try_into().unwrap()); + config + }) .unwrap() .with_behaviour(|_| behavior) .unwrap()