Skip to content

Commit

Permalink
Tidy, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhauner committed Jan 8, 2024
1 parent 5033bfa commit 0153572
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
12 changes: 7 additions & 5 deletions beacon_node/client/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,17 @@ where
.map_err(|e| format!("Unable to read system time: {e:}"))?
.as_secs();
let genesis_time = genesis_state.genesis_time();
let blob_availability_window = MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS.as_u64()
* TEthSpec::slots_per_epoch()
* spec.seconds_per_slot;
// Shrink the blob availability window so users don't start
// a sync right before blobs start to disappear from the P2P
// network.
let reduced_blob_availability_window = blob_availability_window.saturating_sub(TEthSpec::slots_per_epoch() * spec.seconds_per_slot * BLOB_AVAILABILITY_REDUCTION_EPOCHS)
let reduced_p2p_availability_epochs = MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS
.as_u64()
.saturating_sub(BLOB_AVAILABILITY_REDUCTION_EPOCHS);
let blob_availability_window = reduced_p2p_availability_epochs
* TEthSpec::slots_per_epoch()
* spec.seconds_per_slot;

if now > genesis_time + reduced_blob_availability_window {
if now > genesis_time + blob_availability_window {
return Err(
"Syncing from genesis is insecure and incompatible with data availability checks. \
You should instead perform a checkpoint sync from a trusted node using the --checkpoint-sync-url option. \
Expand Down
15 changes: 13 additions & 2 deletions lighthouse/tests/beacon_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,19 @@ fn staking_flag() {

#[test]
#[should_panic]
fn run_without_allow_genesis_sync() {
CommandLineTest::without_allow_genesis_sync().run_with_zero_port();
fn allow_insecure_genesis_sync() {
CommandLineTest::new()
.run_with_zero_port()
.with_config(|config| {
assert_eq!(config.allow_insecure_genesis_sync, false);
});

CommandLineTest::new()
.flag("allow-insecure-genesis-sync", None)
.run_with_zero_port()
.with_config(|config| {
assert_eq!(config.allow_insecure_genesis_sync, true);
});
}

#[test]
Expand Down

0 comments on commit 0153572

Please sign in to comment.