mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-18 21:38:31 +00:00
Clarify network limits (#7175)
Resolves #6811 Rename `GOSSIP_MAX_SIZE` to `MAX_PAYLOAD_SIZE` and remove `MAX_CHUNK_SIZE` in accordance with the spec. The spec also "clarifies" the message size limits at different levels. The rpc limits are equivalent to what we had before imo. The gossip limits have additional checks. I have gotten rid of the `is_bellatrix_enabled` checks that used a lower limit (1mb) pre-merge. Since all networks we run start from the merge, I don't think this will break any setups.
This commit is contained in:
@@ -210,10 +210,9 @@ pub struct ChainSpec {
|
||||
pub boot_nodes: Vec<String>,
|
||||
pub network_id: u8,
|
||||
pub target_aggregators_per_committee: u64,
|
||||
pub gossip_max_size: u64,
|
||||
pub max_payload_size: u64,
|
||||
max_request_blocks: u64,
|
||||
pub min_epochs_for_block_requests: u64,
|
||||
pub max_chunk_size: u64,
|
||||
pub ttfb_timeout: u64,
|
||||
pub resp_timeout: u64,
|
||||
pub attestation_propagation_slot_range: u64,
|
||||
@@ -712,6 +711,35 @@ impl ChainSpec {
|
||||
}
|
||||
}
|
||||
|
||||
/// Worst-case compressed length for a given payload of size n when using snappy.
|
||||
///
|
||||
/// https://github.com/google/snappy/blob/32ded457c0b1fe78ceb8397632c416568d6714a0/snappy.cc#L218C1-L218C47
|
||||
/// https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/p2p-interface.md#max_compressed_len
|
||||
fn max_compressed_len_snappy(n: usize) -> Option<usize> {
|
||||
32_usize.checked_add(n)?.checked_add(n / 6)
|
||||
}
|
||||
|
||||
/// Max compressed length of a message that we receive over gossip.
|
||||
pub fn max_compressed_len(&self) -> usize {
|
||||
Self::max_compressed_len_snappy(self.max_payload_size as usize)
|
||||
.expect("should not overflow")
|
||||
}
|
||||
|
||||
/// Max allowed size of a raw, compressed message received over the network.
|
||||
///
|
||||
/// https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/p2p-interface.md#max_compressed_len
|
||||
pub fn max_message_size(&self) -> usize {
|
||||
std::cmp::max(
|
||||
// 1024 to account for framing + encoding overhead
|
||||
Self::max_compressed_len_snappy(self.max_payload_size as usize)
|
||||
.expect("should not overflow")
|
||||
.safe_add(1024)
|
||||
.expect("should not overflow"),
|
||||
//1MB
|
||||
1024 * 1024,
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns a `ChainSpec` compatible with the Ethereum Foundation specification.
|
||||
pub fn mainnet() -> Self {
|
||||
Self {
|
||||
@@ -926,9 +954,8 @@ impl ChainSpec {
|
||||
subnets_per_node: 2,
|
||||
maximum_gossip_clock_disparity_millis: default_maximum_gossip_clock_disparity_millis(),
|
||||
target_aggregators_per_committee: 16,
|
||||
gossip_max_size: default_gossip_max_size(),
|
||||
max_payload_size: default_max_payload_size(),
|
||||
min_epochs_for_block_requests: default_min_epochs_for_block_requests(),
|
||||
max_chunk_size: default_max_chunk_size(),
|
||||
ttfb_timeout: default_ttfb_timeout(),
|
||||
resp_timeout: default_resp_timeout(),
|
||||
message_domain_invalid_snappy: default_message_domain_invalid_snappy(),
|
||||
@@ -1256,9 +1283,8 @@ impl ChainSpec {
|
||||
subnets_per_node: 4, // Make this larger than usual to avoid network damage
|
||||
maximum_gossip_clock_disparity_millis: default_maximum_gossip_clock_disparity_millis(),
|
||||
target_aggregators_per_committee: 16,
|
||||
gossip_max_size: default_gossip_max_size(),
|
||||
max_payload_size: default_max_payload_size(),
|
||||
min_epochs_for_block_requests: 33024,
|
||||
max_chunk_size: default_max_chunk_size(),
|
||||
ttfb_timeout: default_ttfb_timeout(),
|
||||
resp_timeout: default_resp_timeout(),
|
||||
message_domain_invalid_snappy: default_message_domain_invalid_snappy(),
|
||||
@@ -1430,18 +1456,15 @@ pub struct Config {
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
gas_limit_adjustment_factor: u64,
|
||||
|
||||
#[serde(default = "default_gossip_max_size")]
|
||||
#[serde(default = "default_max_payload_size")]
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
gossip_max_size: u64,
|
||||
max_payload_size: u64,
|
||||
#[serde(default = "default_max_request_blocks")]
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
max_request_blocks: u64,
|
||||
#[serde(default = "default_min_epochs_for_block_requests")]
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
min_epochs_for_block_requests: u64,
|
||||
#[serde(default = "default_max_chunk_size")]
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
max_chunk_size: u64,
|
||||
#[serde(default = "default_ttfb_timeout")]
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
ttfb_timeout: u64,
|
||||
@@ -1576,7 +1599,7 @@ const fn default_gas_limit_adjustment_factor() -> u64 {
|
||||
1024
|
||||
}
|
||||
|
||||
const fn default_gossip_max_size() -> u64 {
|
||||
const fn default_max_payload_size() -> u64 {
|
||||
10485760
|
||||
}
|
||||
|
||||
@@ -1584,10 +1607,6 @@ const fn default_min_epochs_for_block_requests() -> u64 {
|
||||
33024
|
||||
}
|
||||
|
||||
const fn default_max_chunk_size() -> u64 {
|
||||
10485760
|
||||
}
|
||||
|
||||
const fn default_ttfb_timeout() -> u64 {
|
||||
5
|
||||
}
|
||||
@@ -1853,10 +1872,9 @@ impl Config {
|
||||
|
||||
gas_limit_adjustment_factor: spec.gas_limit_adjustment_factor,
|
||||
|
||||
gossip_max_size: spec.gossip_max_size,
|
||||
max_payload_size: spec.max_payload_size,
|
||||
max_request_blocks: spec.max_request_blocks,
|
||||
min_epochs_for_block_requests: spec.min_epochs_for_block_requests,
|
||||
max_chunk_size: spec.max_chunk_size,
|
||||
ttfb_timeout: spec.ttfb_timeout,
|
||||
resp_timeout: spec.resp_timeout,
|
||||
attestation_propagation_slot_range: spec.attestation_propagation_slot_range,
|
||||
@@ -1934,9 +1952,8 @@ impl Config {
|
||||
deposit_network_id,
|
||||
deposit_contract_address,
|
||||
gas_limit_adjustment_factor,
|
||||
gossip_max_size,
|
||||
max_payload_size,
|
||||
min_epochs_for_block_requests,
|
||||
max_chunk_size,
|
||||
ttfb_timeout,
|
||||
resp_timeout,
|
||||
message_domain_invalid_snappy,
|
||||
@@ -2005,9 +2022,8 @@ impl Config {
|
||||
terminal_total_difficulty,
|
||||
terminal_block_hash,
|
||||
terminal_block_hash_activation_epoch,
|
||||
gossip_max_size,
|
||||
max_payload_size,
|
||||
min_epochs_for_block_requests,
|
||||
max_chunk_size,
|
||||
ttfb_timeout,
|
||||
resp_timeout,
|
||||
message_domain_invalid_snappy,
|
||||
@@ -2307,9 +2323,8 @@ mod yaml_tests {
|
||||
check_default!(terminal_block_hash);
|
||||
check_default!(terminal_block_hash_activation_epoch);
|
||||
check_default!(bellatrix_fork_version);
|
||||
check_default!(gossip_max_size);
|
||||
check_default!(max_payload_size);
|
||||
check_default!(min_epochs_for_block_requests);
|
||||
check_default!(max_chunk_size);
|
||||
check_default!(ttfb_timeout);
|
||||
check_default!(resp_timeout);
|
||||
check_default!(message_domain_invalid_snappy);
|
||||
@@ -2335,4 +2350,17 @@ mod yaml_tests {
|
||||
[0, 0, 0, 1]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_max_network_limits_overflow() {
|
||||
let mut spec = MainnetEthSpec::default_spec();
|
||||
// Should not overflow
|
||||
let _ = spec.max_message_size();
|
||||
let _ = spec.max_compressed_len();
|
||||
|
||||
spec.max_payload_size *= 10;
|
||||
// Should not overflow even with a 10x increase in max
|
||||
let _ = spec.max_message_size();
|
||||
let _ = spec.max_compressed_len();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user