mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 19:51:05 +00:00
Add explicit limits to notifications sizes and adjust yamux buffer size (#7925)
* Add explicit limits to notifications sizes and adjust yamux buffer size * Docfix * Tests * Document these 10 bytes
This commit is contained in:
@@ -83,7 +83,9 @@ use sp_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnbound
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
collections::{HashMap, HashSet},
|
||||
convert::TryFrom as _,
|
||||
fs,
|
||||
iter,
|
||||
marker::PhantomData,
|
||||
num:: NonZeroUsize,
|
||||
pin::Pin,
|
||||
@@ -283,6 +285,48 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
|
||||
config
|
||||
};
|
||||
|
||||
let (transport, bandwidth) = {
|
||||
let (config_mem, config_wasm) = match params.network_config.transport {
|
||||
TransportConfig::MemoryOnly => (true, None),
|
||||
TransportConfig::Normal { wasm_external_transport, .. } =>
|
||||
(false, wasm_external_transport)
|
||||
};
|
||||
|
||||
// The yamux buffer size limit is configured to be equal to the maximum frame size
|
||||
// of all protocols. 10 bytes are added to each limit for the length prefix that
|
||||
// is not included in the upper layer protocols limit but is still present in the
|
||||
// yamux buffer. These 10 bytes correspond to the maximum size required to encode
|
||||
// a variable-length-encoding 64bits number. In other words, we make the
|
||||
// assumption that no notification larger than 2^64 will ever be sent.
|
||||
let yamux_maximum_buffer_size = {
|
||||
let requests_max = params.network_config
|
||||
.request_response_protocols.iter()
|
||||
.map(|cfg| usize::try_from(cfg.max_request_size).unwrap_or(usize::max_value()));
|
||||
let responses_max = params.network_config
|
||||
.request_response_protocols.iter()
|
||||
.map(|cfg| usize::try_from(cfg.max_response_size).unwrap_or(usize::max_value()));
|
||||
let notifs_max = params.network_config
|
||||
.extra_sets.iter()
|
||||
.map(|cfg| usize::try_from(cfg.max_notification_size).unwrap_or(usize::max_value()));
|
||||
|
||||
// A "default" max is added to cover all the other protocols: ping, identify,
|
||||
// kademlia.
|
||||
let default_max = 1024 * 1024;
|
||||
iter::once(default_max)
|
||||
.chain(requests_max).chain(responses_max).chain(notifs_max)
|
||||
.max().expect("iterator known to always yield at least one element; qed")
|
||||
.saturating_add(10)
|
||||
};
|
||||
|
||||
transport::build_transport(
|
||||
local_identity,
|
||||
config_mem,
|
||||
config_wasm,
|
||||
params.network_config.yamux_window_size,
|
||||
yamux_maximum_buffer_size
|
||||
)
|
||||
};
|
||||
|
||||
let behaviour = {
|
||||
let result = Behaviour::new(
|
||||
protocol,
|
||||
@@ -305,20 +349,6 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
|
||||
}
|
||||
};
|
||||
|
||||
let (transport, bandwidth) = {
|
||||
let (config_mem, config_wasm) = match params.network_config.transport {
|
||||
TransportConfig::MemoryOnly => (true, None),
|
||||
TransportConfig::Normal { wasm_external_transport, .. } =>
|
||||
(false, wasm_external_transport)
|
||||
};
|
||||
|
||||
transport::build_transport(
|
||||
local_identity,
|
||||
config_mem,
|
||||
config_wasm,
|
||||
params.network_config.yamux_window_size
|
||||
)
|
||||
};
|
||||
let mut builder = SwarmBuilder::new(transport, behaviour, local_peer_id.clone())
|
||||
.connection_limits(ConnectionLimits::default()
|
||||
.with_max_established_per_peer(Some(crate::MAX_CONNECTIONS_PER_PEER as u32))
|
||||
|
||||
Reference in New Issue
Block a user