Skip to content

Commit 1822e31

Browse files
committed
Grow the yamux buffers to exceed the maximum message size
1 parent 6efc313 commit 1822e31

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

coordinator/src/p2p.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,16 @@ impl fmt::Debug for LibP2p {
211211
impl LibP2p {
212212
#[allow(clippy::new_without_default)]
213213
pub fn new() -> Self {
214+
// Block size limit + 1 KB of space for signatures/metadata
215+
const MAX_LIBP2P_MESSAGE_SIZE: usize = tributary::BLOCK_SIZE_LIMIT + 1024;
216+
214217
log::info!("creating a libp2p instance");
215218

216219
let throwaway_key_pair = Keypair::generate_ed25519();
217220
let throwaway_peer_id = PeerId::from(throwaway_key_pair.public());
218221

219222
let behavior = Behavior {
220223
gossipsub: {
221-
// Block size limit + 1 KB of space for signatures/metadata
222-
const MAX_LIBP2P_MESSAGE_SIZE: usize = tributary::BLOCK_SIZE_LIMIT + 1024;
223-
224224
let heartbeat_interval = tributary::tendermint::LATENCY_TIME / 2;
225225
let heartbeats_per_block =
226226
usize::try_from(tributary::tendermint::TARGET_BLOCK_TIME / heartbeat_interval).unwrap();
@@ -276,7 +276,15 @@ impl LibP2p {
276276
// TODO: Relay client?
277277
let mut swarm = SwarmBuilder::with_existing_identity(throwaway_key_pair)
278278
.with_tokio()
279-
.with_tcp(TcpConfig::default().nodelay(true), noise::Config::new, yamux::Config::default)
279+
.with_tcp(TcpConfig::default().nodelay(true), noise::Config::new, || {
280+
let mut config = yamux::Config::default();
281+
// 1 MiB default + max message size
282+
config.set_max_buffer_size((1024 * 1024) + MAX_LIBP2P_MESSAGE_SIZE);
283+
// 256 KiB default + max message size
284+
config
285+
.set_receive_window_size(((256 * 1024) + MAX_LIBP2P_MESSAGE_SIZE).try_into().unwrap());
286+
config
287+
})
280288
.unwrap()
281289
.with_behaviour(|_| behavior)
282290
.unwrap()

0 commit comments

Comments
 (0)