Skip to content

Commit

Permalink
Grow the yamux buffers to exceed the maximum message size
Browse files Browse the repository at this point in the history
  • Loading branch information
kayabaNerve committed Nov 21, 2023
1 parent 6efc313 commit 1822e31
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions coordinator/src/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,16 @@ 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();
let throwaway_peer_id = PeerId::from(throwaway_key_pair.public());

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();
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 1822e31

Please sign in to comment.