mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-09 03:17:55 +00:00
Implement weak subjectivity safety checks (#7347)
Closes #7273 https://github.com/ethereum/consensus-specs/pull/4179 Co-Authored-By: Eitan Seri-Levi <eserilev@ucsc.edu> Co-Authored-By: Eitan Seri- Levi <eserilev@gmail.com> Co-Authored-By: Michael Sproul <michaelsproul@users.noreply.github.com> Co-Authored-By: dapplion <35266934+dapplion@users.noreply.github.com>
This commit is contained in:
@@ -15,7 +15,8 @@ use state_processing::EpochProcessingError;
|
||||
use state_processing::{per_slot_processing, per_slot_processing::Error as SlotProcessingError};
|
||||
use std::sync::LazyLock;
|
||||
use types::{
|
||||
BeaconState, BeaconStateError, BlockImportSource, Checkpoint, EthSpec, Hash256, MinimalEthSpec,
|
||||
BeaconState, BeaconStateError, BlockImportSource, ChainSpec, Checkpoint,
|
||||
DEFAULT_PRE_ELECTRA_WS_PERIOD, EthSpec, ForkName, Hash256, MainnetEthSpec, MinimalEthSpec,
|
||||
RelativeEpoch, Slot,
|
||||
};
|
||||
|
||||
@@ -38,6 +39,27 @@ fn get_harness(validator_count: usize) -> BeaconChainHarness<EphemeralHarnessTyp
|
||||
)
|
||||
}
|
||||
|
||||
fn get_harness_with_spec(
|
||||
validator_count: usize,
|
||||
spec: &ChainSpec,
|
||||
) -> BeaconChainHarness<EphemeralHarnessType<MainnetEthSpec>> {
|
||||
let chain_config = ChainConfig {
|
||||
reconstruct_historic_states: true,
|
||||
..Default::default()
|
||||
};
|
||||
let harness = BeaconChainHarness::builder(MainnetEthSpec)
|
||||
.spec(spec.clone().into())
|
||||
.chain_config(chain_config)
|
||||
.keypairs(KEYPAIRS[0..validator_count].to_vec())
|
||||
.fresh_ephemeral_store()
|
||||
.mock_execution_layer()
|
||||
.build();
|
||||
|
||||
harness.advance_slot();
|
||||
|
||||
harness
|
||||
}
|
||||
|
||||
fn get_harness_with_config(
|
||||
validator_count: usize,
|
||||
chain_config: ChainConfig,
|
||||
@@ -1083,3 +1105,28 @@ async fn pseudo_finalize_with_lagging_split_update() {
|
||||
let expect_true_migration = false;
|
||||
pseudo_finalize_test_generic(epochs_per_migration, expect_true_migration).await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_compute_weak_subjectivity_period() {
|
||||
type E = MainnetEthSpec;
|
||||
let expected_ws_period_pre_electra = DEFAULT_PRE_ELECTRA_WS_PERIOD;
|
||||
let expected_ws_period_post_electra = 256;
|
||||
|
||||
// test Base variant
|
||||
let spec = ForkName::Altair.make_genesis_spec(E::default_spec());
|
||||
let harness = get_harness_with_spec(VALIDATOR_COUNT, &spec);
|
||||
let head_state = harness.get_current_state();
|
||||
|
||||
let calculated_ws_period = head_state.compute_weak_subjectivity_period(&spec).unwrap();
|
||||
|
||||
assert_eq!(calculated_ws_period, expected_ws_period_pre_electra);
|
||||
|
||||
// test Electra variant
|
||||
let spec = ForkName::Electra.make_genesis_spec(E::default_spec());
|
||||
let harness = get_harness_with_spec(VALIDATOR_COUNT, &spec);
|
||||
let head_state = harness.get_current_state();
|
||||
|
||||
let calculated_ws_period = head_state.compute_weak_subjectivity_period(&spec).unwrap();
|
||||
|
||||
assert_eq!(calculated_ws_period, expected_ws_period_post_electra);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user