mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-19 05:48:31 +00:00
Merge branch 'release-v7.0.0' into unstable
This commit is contained in:
@@ -5,6 +5,7 @@ use derivative::Derivative;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use ssz_types::BitVector;
|
||||
use std::collections::HashSet;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use superstruct::superstruct;
|
||||
use test_random_derive::TestRandom;
|
||||
@@ -210,6 +211,13 @@ impl<E: EthSpec> Attestation<E> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_committee_indices_map(&self) -> HashSet<u64> {
|
||||
match self {
|
||||
Attestation::Base(att) => HashSet::from([att.data.index]),
|
||||
Attestation::Electra(att) => att.get_committee_indices().into_iter().collect(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_aggregation_bits_zero(&self) -> bool {
|
||||
match self {
|
||||
Attestation::Base(att) => att.aggregation_bits.is_zero(),
|
||||
@@ -293,7 +301,11 @@ impl<E: EthSpec> AttestationRef<'_, E> {
|
||||
|
||||
impl<E: EthSpec> AttestationElectra<E> {
|
||||
pub fn committee_index(&self) -> Option<u64> {
|
||||
self.get_committee_indices().first().cloned()
|
||||
self.committee_bits
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|&(_, bit)| bit)
|
||||
.map(|(index, _)| index as u64)
|
||||
}
|
||||
|
||||
pub fn get_aggregation_bits(&self) -> Vec<u64> {
|
||||
|
||||
@@ -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,
|
||||
@@ -716,6 +715,35 @@ impl ChainSpec {
|
||||
(0..self.data_column_sidecar_subnet_count).map(DataColumnSubnetId::new)
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
@@ -883,7 +911,7 @@ impl ChainSpec {
|
||||
* Electra hard fork params
|
||||
*/
|
||||
electra_fork_version: [0x05, 00, 00, 00],
|
||||
electra_fork_epoch: None,
|
||||
electra_fork_epoch: Some(Epoch::new(364032)),
|
||||
unset_deposit_requests_start_index: u64::MAX,
|
||||
full_exit_request_amount: 0,
|
||||
min_activation_balance: option_wrapper(|| {
|
||||
@@ -930,9 +958,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(),
|
||||
@@ -1213,7 +1240,7 @@ impl ChainSpec {
|
||||
* Electra hard fork params
|
||||
*/
|
||||
electra_fork_version: [0x05, 0x00, 0x00, 0x64],
|
||||
electra_fork_epoch: None,
|
||||
electra_fork_epoch: Some(Epoch::new(1337856)),
|
||||
unset_deposit_requests_start_index: u64::MAX,
|
||||
full_exit_request_amount: 0,
|
||||
min_activation_balance: option_wrapper(|| {
|
||||
@@ -1235,7 +1262,7 @@ impl ChainSpec {
|
||||
})
|
||||
.expect("calculation does not overflow"),
|
||||
max_per_epoch_activation_exit_churn_limit: option_wrapper(|| {
|
||||
u64::checked_pow(2, 8)?.checked_mul(u64::checked_pow(10, 9)?)
|
||||
u64::checked_pow(2, 6)?.checked_mul(u64::checked_pow(10, 9)?)
|
||||
})
|
||||
.expect("calculation does not overflow"),
|
||||
|
||||
@@ -1260,9 +1287,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(),
|
||||
@@ -1278,7 +1304,7 @@ impl ChainSpec {
|
||||
max_request_data_column_sidecars: default_max_request_data_column_sidecars(),
|
||||
min_epochs_for_blob_sidecars_requests: 16384,
|
||||
blob_sidecar_subnet_count: default_blob_sidecar_subnet_count(),
|
||||
max_blobs_per_block: default_max_blobs_per_block(),
|
||||
max_blobs_per_block: 2,
|
||||
|
||||
/*
|
||||
* Derived Deneb Specific
|
||||
@@ -1291,9 +1317,9 @@ impl ChainSpec {
|
||||
/*
|
||||
* Networking Electra specific
|
||||
*/
|
||||
max_blobs_per_block_electra: default_max_blobs_per_block_electra(),
|
||||
blob_sidecar_subnet_count_electra: default_blob_sidecar_subnet_count_electra(),
|
||||
max_request_blob_sidecars_electra: default_max_request_blob_sidecars_electra(),
|
||||
max_blobs_per_block_electra: 2,
|
||||
blob_sidecar_subnet_count_electra: 2,
|
||||
max_request_blob_sidecars_electra: 256,
|
||||
|
||||
/*
|
||||
* Application specific
|
||||
@@ -1434,18 +1460,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,
|
||||
@@ -1580,7 +1603,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
|
||||
}
|
||||
|
||||
@@ -1588,10 +1611,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
|
||||
}
|
||||
@@ -1857,10 +1876,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,
|
||||
@@ -1938,9 +1956,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,
|
||||
@@ -2009,9 +2026,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,
|
||||
@@ -2311,9 +2327,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);
|
||||
@@ -2339,4 +2354,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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,28 +227,36 @@ pub struct ElectraPreset {
|
||||
pub min_activation_balance: u64,
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
pub max_effective_balance_electra: u64,
|
||||
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
pub min_slashing_penalty_quotient_electra: u64,
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
pub whistleblower_reward_quotient_electra: u64,
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
pub max_pending_partials_per_withdrawals_sweep: u64,
|
||||
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
pub pending_deposits_limit: u64,
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
pub pending_partial_withdrawals_limit: u64,
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
pub pending_consolidations_limit: u64,
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
pub max_consolidation_requests_per_payload: u64,
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
pub max_deposit_requests_per_payload: u64,
|
||||
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
pub max_attester_slashings_electra: u64,
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
pub max_attestations_electra: u64,
|
||||
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
pub max_deposit_requests_per_payload: u64,
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
pub max_withdrawal_requests_per_payload: u64,
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
pub max_consolidation_requests_per_payload: u64,
|
||||
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
pub max_pending_partials_per_withdrawals_sweep: u64,
|
||||
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
pub max_pending_deposits_per_epoch: u64,
|
||||
}
|
||||
|
||||
impl ElectraPreset {
|
||||
@@ -256,19 +264,26 @@ impl ElectraPreset {
|
||||
Self {
|
||||
min_activation_balance: spec.min_activation_balance,
|
||||
max_effective_balance_electra: spec.max_effective_balance_electra,
|
||||
|
||||
min_slashing_penalty_quotient_electra: spec.min_slashing_penalty_quotient_electra,
|
||||
whistleblower_reward_quotient_electra: spec.whistleblower_reward_quotient_electra,
|
||||
max_pending_partials_per_withdrawals_sweep: spec
|
||||
.max_pending_partials_per_withdrawals_sweep,
|
||||
|
||||
pending_deposits_limit: E::pending_deposits_limit() as u64,
|
||||
pending_partial_withdrawals_limit: E::pending_partial_withdrawals_limit() as u64,
|
||||
pending_consolidations_limit: E::pending_consolidations_limit() as u64,
|
||||
max_consolidation_requests_per_payload: E::max_consolidation_requests_per_payload()
|
||||
as u64,
|
||||
max_deposit_requests_per_payload: E::max_deposit_requests_per_payload() as u64,
|
||||
|
||||
max_attester_slashings_electra: E::max_attester_slashings_electra() as u64,
|
||||
max_attestations_electra: E::max_attestations_electra() as u64,
|
||||
|
||||
max_deposit_requests_per_payload: E::max_deposit_requests_per_payload() as u64,
|
||||
max_withdrawal_requests_per_payload: E::max_withdrawal_requests_per_payload() as u64,
|
||||
max_consolidation_requests_per_payload: E::max_consolidation_requests_per_payload()
|
||||
as u64,
|
||||
|
||||
max_pending_partials_per_withdrawals_sweep: spec
|
||||
.max_pending_partials_per_withdrawals_sweep,
|
||||
|
||||
max_pending_deposits_per_epoch: E::max_pending_deposits_per_epoch() as u64,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,7 +249,6 @@ impl Validator {
|
||||
}
|
||||
}
|
||||
|
||||
/// TODO(electra): refactor these functions and make it simpler.. this is a mess
|
||||
/// Returns `true` if the validator is partially withdrawable.
|
||||
fn is_partially_withdrawable_validator_capella(&self, balance: u64, spec: &ChainSpec) -> bool {
|
||||
self.has_eth1_withdrawal_credential(spec)
|
||||
|
||||
Reference in New Issue
Block a user