Skip to content

Commit 4fdeac9

Browse files
committed
addressed comments
1 parent 8b35077 commit 4fdeac9

File tree

11 files changed

+80
-23
lines changed

11 files changed

+80
-23
lines changed

common/eth2_network_config/built_in_network_configs/chiado/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ SUBNETS_PER_NODE: 2
124124
# 2**8 (= 64)
125125
ATTESTATION_SUBNET_COUNT: 64
126126
ATTESTATION_SUBNET_EXTRA_BITS: 0
127+
# ceillog2(ATTESTATION_SUBNET_COUNT) + ATTESTATION_SUBNET_EXTRA_BITS
127128
# computed at runtime: ceillog2(ATTESTATION_SUBNET_COUNT) + ATTESTATION_SUBNET_EXTRA_BITS
128129
ATTESTATION_SUBNET_PREFIX_BITS: 6
129130

common/eth2_network_config/built_in_network_configs/gnosis/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ MESSAGE_DOMAIN_INVALID_SNAPPY: 0x00000000
108108
MESSAGE_DOMAIN_VALID_SNAPPY: 0x01000000
109109
ATTESTATION_SUBNET_COUNT: 64
110110
ATTESTATION_SUBNET_EXTRA_BITS: 0
111+
# ceillog2(ATTESTATION_SUBNET_COUNT) + ATTESTATION_SUBNET_EXTRA_BITS
111112
# computed at runtime: ceillog2(ATTESTATION_SUBNET_COUNT) + ATTESTATION_SUBNET_EXTRA_BITS
112113
ATTESTATION_SUBNET_PREFIX_BITS: 6
113114
ATTESTATION_SUBNET_SHUFFLING_PREFIX_BITS: 3

common/eth2_network_config/built_in_network_configs/holesky/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ SUBNETS_PER_NODE: 2
126126
# 2**8 (= 64)
127127
ATTESTATION_SUBNET_COUNT: 64
128128
ATTESTATION_SUBNET_EXTRA_BITS: 0
129+
# ceillog2(ATTESTATION_SUBNET_COUNT) + ATTESTATION_SUBNET_EXTRA_BITS
129130
# computed at runtime: ceillog2(ATTESTATION_SUBNET_COUNT) + ATTESTATION_SUBNET_EXTRA_BITS
130131
ATTESTATION_SUBNET_PREFIX_BITS: 6
131132
ATTESTATION_SUBNET_SHUFFLING_PREFIX_BITS: 3

common/eth2_network_config/built_in_network_configs/hoodi/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ SUBNETS_PER_NODE: 2
132132
# 2**8 (= 64)
133133
ATTESTATION_SUBNET_COUNT: 64
134134
ATTESTATION_SUBNET_EXTRA_BITS: 0
135+
# ceillog2(ATTESTATION_SUBNET_COUNT) + ATTESTATION_SUBNET_EXTRA_BITS
135136
# computed at runtime: ceillog2(ATTESTATION_SUBNET_COUNT) + ATTESTATION_SUBNET_EXTRA_BITS
136137
ATTESTATION_SUBNET_PREFIX_BITS: 6
137138

common/eth2_network_config/built_in_network_configs/mainnet/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ SUBNETS_PER_NODE: 2
153153
ATTESTATION_SUBNET_COUNT: 64
154154
# 0 bits
155155
ATTESTATION_SUBNET_EXTRA_BITS: 0
156+
# ceillog2(ATTESTATION_SUBNET_COUNT) + ATTESTATION_SUBNET_EXTRA_BITS
156157
# computed at runtime: ceillog2(ATTESTATION_SUBNET_COUNT) + ATTESTATION_SUBNET_EXTRA_BITS
157158
ATTESTATION_SUBNET_PREFIX_BITS: 6
158159
ATTESTATION_SUBNET_SHUFFLING_PREFIX_BITS: 3

common/eth2_network_config/built_in_network_configs/sepolia/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ SUBNETS_PER_NODE: 2
132132
# 2**8 (= 64)
133133
ATTESTATION_SUBNET_COUNT: 64
134134
ATTESTATION_SUBNET_EXTRA_BITS: 0
135+
# ceillog2(ATTESTATION_SUBNET_COUNT) + ATTESTATION_SUBNET_EXTRA_BITS
135136
# computed at runtime: ceillog2(ATTESTATION_SUBNET_COUNT) + ATTESTATION_SUBNET_EXTRA_BITS
136137
ATTESTATION_SUBNET_PREFIX_BITS: 6
137138
ATTESTATION_SUBNET_SHUFFLING_PREFIX_BITS: 3

consensus/types/presets/gnosis/altair.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ EPOCHS_PER_SYNC_COMMITTEE_PERIOD: 512
2323
# 1
2424
MIN_SYNC_COMMITTEE_PARTICIPANTS: 1
2525
# SLOTS_PER_EPOCH * EPOCHS_PER_SYNC_COMMITTEE_PERIOD (= 16 * 512)
26-
UPDATE_TIMEOUT: 8192
26+
# not used by Lighthouse but required for preset testing compatibility
27+
UPDATE_TIMEOUT: 8192

consensus/types/presets/minimal/altair.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ EPOCHS_PER_SYNC_COMMITTEE_PERIOD: 8
2323
# 1
2424
MIN_SYNC_COMMITTEE_PARTICIPANTS: 1
2525
# SLOTS_PER_EPOCH * EPOCHS_PER_SYNC_COMMITTEE_PERIOD (= 8 * 8)
26-
UPDATE_TIMEOUT: 8192 # hard-coded to mainnet value for testing given this config is not used in Lighthouse
26+
# hard-coded to mainnet value for testing given this config is not used in Lighthouse
27+
UPDATE_TIMEOUT: 8192

consensus/types/src/core/chain_spec.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,7 +1861,6 @@ pub struct Config {
18611861
attestation_subnet_count: u64,
18621862
#[serde(with = "serde_utils::quoted_u64")]
18631863
attestation_subnet_extra_bits: u64,
1864-
// attestation_subnet_prefix_bits is computed dynamically in ChainSpec, not serialized from config
18651864
#[serde(default = "default_max_request_blocks_deneb")]
18661865
#[serde(with = "serde_utils::quoted_u64")]
18671866
max_request_blocks_deneb: u64,
@@ -1981,12 +1980,11 @@ fn default_subnets_per_node() -> u8 {
19811980
/// the most significant bit of n-1 (which is floor(log2(n-1))) and adding 1 to account for the 2^0 bit.
19821981
/// Therefore, we get floor(log2(n-1)) + 1 = minimum number of bits needed for n values.
19831982
/// This is the same as ceiling(log2(n)), but Rust does not have this function.
1984-
fn compute_min_bits_for_n_values(n: u32) -> u32 {
1985-
1986-
match n {
1983+
fn compute_min_bits_for_n_values(n: u32) -> Result<u32, ArithError> {
1984+
Ok(match n {
19871985
0 => 0,
1988-
n => (n - 1).ilog2() + 1, // ilog2 = floor(log2(n))
1989-
}
1986+
n => n.safe_sub(1)?.ilog2().safe_add(1)?, // ilog2 = floor(log2(n))
1987+
})
19901988
}
19911989

19921990
/// Compute attestation_subnet_prefix_bits dynamically as:
@@ -1995,7 +1993,7 @@ fn compute_attestation_subnet_prefix_bits(
19951993
attestation_subnet_count: u64,
19961994
attestation_subnet_extra_bits: u64,
19971995
) -> u8 {
1998-
let min_bits = compute_min_bits_for_n_values(attestation_subnet_count as u32);
1996+
let min_bits = compute_min_bits_for_n_values(attestation_subnet_count as u32).unwrap_or(6);
19991997
(min_bits + attestation_subnet_extra_bits as u32) as u8
20001998
}
20011999

@@ -2728,9 +2726,6 @@ mod yaml_tests {
27282726
CHURN_LIMIT_QUOTIENT: 65536
27292727
MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: 8
27302728
PROPOSER_SCORE_BOOST: 40
2731-
REORG_HEAD_WEIGHT_THRESHOLD: 20
2732-
REORG_PARENT_WEIGHT_THRESHOLD: 160
2733-
REORG_MAX_EPOCHS_SINCE_FINALIZATION: 2
27342729
EPOCHS_PER_SUBNET_SUBSCRIPTION: 256
27352730
ATTESTATION_SUBNET_COUNT: 64
27362731
ATTESTATION_SUBNET_EXTRA_BITS: 0
@@ -2880,9 +2875,6 @@ mod yaml_tests {
28802875
CHURN_LIMIT_QUOTIENT: 65536
28812876
MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: 8
28822877
PROPOSER_SCORE_BOOST: 40
2883-
REORG_HEAD_WEIGHT_THRESHOLD: 20
2884-
REORG_PARENT_WEIGHT_THRESHOLD: 160
2885-
REORG_MAX_EPOCHS_SINCE_FINALIZATION: 2
28862878
EPOCHS_PER_SUBNET_SUBSCRIPTION: 256
28872879
ATTESTATION_SUBNET_COUNT: 64
28882880
ATTESTATION_SUBNET_EXTRA_BITS: 0
@@ -2995,9 +2987,6 @@ mod yaml_tests {
29952987
MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: 8
29962988
CHURN_LIMIT_QUOTIENT: 65536
29972989
PROPOSER_SCORE_BOOST: 40
2998-
REORG_HEAD_WEIGHT_THRESHOLD: 20
2999-
REORG_PARENT_WEIGHT_THRESHOLD: 160
3000-
REORG_MAX_EPOCHS_SINCE_FINALIZATION: 2
30012990
EPOCHS_PER_SUBNET_SUBSCRIPTION: 256
30022991
ATTESTATION_SUBNET_COUNT: 64
30032992
ATTESTATION_SUBNET_EXTRA_BITS: 0

consensus/types/src/core/preset.rs

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ impl AltairPreset {
147147
sync_committee_size: E::SyncCommitteeSize::to_u64(),
148148
epochs_per_sync_committee_period: spec.epochs_per_sync_committee_period,
149149
min_sync_committee_participants: spec.min_sync_committee_participants,
150-
update_timeout: 8192, // light client constant (not used by Lighthouse)
150+
// light client constant (not used by Lighthouse)
151+
update_timeout: 8192,
151152
}
152153
}
153154
}
@@ -386,14 +387,76 @@ mod test {
386387
assert_eq!(gloas, GloasPreset::from_chain_spec::<E>(&spec));
387388
}
388389

390+
/// Special-cased test for Gnosis since it has no `UPDATE_TIMEOUT` field.
391+
fn gnosis_preset_test<E: EthSpec>() {
392+
let preset_name = E::spec_name().to_string();
393+
let spec = E::default_spec();
394+
395+
let phase0: BasePreset = preset_from_file(&preset_name, "phase0.yaml");
396+
assert_eq!(phase0, BasePreset::from_chain_spec::<E>(&spec));
397+
398+
// Gnosis altair preset has no `UPDATE_TIMEOUT`.
399+
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
400+
#[serde(rename_all = "UPPERCASE")]
401+
pub struct GnosisAltairPreset {
402+
#[serde(with = "serde_utils::quoted_u64")]
403+
pub inactivity_penalty_quotient_altair: u64,
404+
#[serde(with = "serde_utils::quoted_u64")]
405+
pub min_slashing_penalty_quotient_altair: u64,
406+
#[serde(with = "serde_utils::quoted_u64")]
407+
pub proportional_slashing_multiplier_altair: u64,
408+
#[serde(with = "serde_utils::quoted_u64")]
409+
pub sync_committee_size: u64,
410+
#[serde(with = "serde_utils::quoted_u64")]
411+
pub epochs_per_sync_committee_period: Epoch,
412+
#[serde(with = "serde_utils::quoted_u64")]
413+
pub min_sync_committee_participants: u64,
414+
}
415+
416+
impl GnosisAltairPreset {
417+
pub fn from_chain_spec<E: EthSpec>(spec: &ChainSpec) -> Self {
418+
let altair_preset = AltairPreset::from_chain_spec::<E>(spec);
419+
Self {
420+
inactivity_penalty_quotient_altair: altair_preset.inactivity_penalty_quotient_altair,
421+
min_slashing_penalty_quotient_altair: altair_preset.min_slashing_penalty_quotient_altair,
422+
proportional_slashing_multiplier_altair: altair_preset.proportional_slashing_multiplier_altair,
423+
sync_committee_size: altair_preset.sync_committee_size,
424+
epochs_per_sync_committee_period: altair_preset.epochs_per_sync_committee_period,
425+
min_sync_committee_participants: altair_preset.min_sync_committee_participants,
426+
}
427+
}
428+
}
429+
430+
let altair: GnosisAltairPreset = preset_from_file(&preset_name, "altair.yaml");
431+
assert_eq!(altair, GnosisAltairPreset::from_chain_spec::<E>(&spec));
432+
433+
let bellatrix: BellatrixPreset = preset_from_file(&preset_name, "bellatrix.yaml");
434+
assert_eq!(bellatrix, BellatrixPreset::from_chain_spec::<E>(&spec));
435+
436+
let capella: CapellaPreset = preset_from_file(&preset_name, "capella.yaml");
437+
assert_eq!(capella, CapellaPreset::from_chain_spec::<E>(&spec));
438+
439+
let deneb: DenebPreset = preset_from_file(&preset_name, "deneb.yaml");
440+
assert_eq!(deneb, DenebPreset::from_chain_spec::<E>(&spec));
441+
442+
let electra: ElectraPreset = preset_from_file(&preset_name, "electra.yaml");
443+
assert_eq!(electra, ElectraPreset::from_chain_spec::<E>(&spec));
444+
445+
let fulu: FuluPreset = preset_from_file(&preset_name, "fulu.yaml");
446+
assert_eq!(fulu, FuluPreset::from_chain_spec::<E>(&spec));
447+
448+
let gloas: GloasPreset = preset_from_file(&preset_name, "gloas.yaml");
449+
assert_eq!(gloas, GloasPreset::from_chain_spec::<E>(&spec));
450+
}
451+
389452
#[test]
390453
fn mainnet_presets_consistent() {
391454
preset_test::<MainnetEthSpec>();
392455
}
393456

394457
#[test]
395458
fn gnosis_presets_consistent() {
396-
preset_test::<GnosisEthSpec>();
459+
gnosis_preset_test::<GnosisEthSpec>();
397460
}
398461

399462
#[test]

0 commit comments

Comments
 (0)