Skip to content

Commit

Permalink
Add cli flag to enable sampling and disable by default. (#6209)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmygchen committed Aug 1, 2024
1 parent b148c4b commit 37dd0ea
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
6 changes: 4 additions & 2 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6960,8 +6960,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
/// Returns true if we should issue a sampling request for this block
/// TODO(das): check if the block is still within the da_window
pub fn should_sample_slot(&self, slot: Slot) -> bool {
self.spec
.is_peer_das_enabled_for_epoch(slot.epoch(T::EthSpec::slots_per_epoch()))
self.config.enable_sampling
&& self
.spec
.is_peer_das_enabled_for_epoch(slot.epoch(T::EthSpec::slots_per_epoch()))
}

pub fn logger(&self) -> &Logger {
Expand Down
3 changes: 3 additions & 0 deletions beacon_node/beacon_chain/src/chain_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ pub struct ChainConfig {
pub enable_light_client_server: bool,
/// Enable malicious PeerDAS mode where node withholds data columns when publishing a block
pub malicious_withhold_count: usize,
/// Enable peer sampling on blocks.
pub enable_sampling: bool,
}

impl Default for ChainConfig {
Expand Down Expand Up @@ -118,6 +120,7 @@ impl Default for ChainConfig {
epochs_per_migration: crate::migrate::DEFAULT_EPOCHS_PER_MIGRATION,
enable_light_client_server: false,
malicious_withhold_count: 0,
enable_sampling: false,
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions beacon_node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ pub fn cli_app() -> Command {
.hide(true)
.display_order(0)
)
.arg(
Arg::new("enable-sampling")
.long("enable-sampling")
.action(ArgAction::SetTrue)
.help_heading(FLAG_HEADER)
.help("Enable peer sampling on data columns. Disabled by default.")
.hide(true)
.display_order(0)
)
.arg(
Arg::new("subscribe-all-subnets")
.long("subscribe-all-subnets")
Expand Down
4 changes: 4 additions & 0 deletions beacon_node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ pub fn get_config<E: EthSpec>(
client_config.chain.shuffling_cache_size = cache_size;
}

if cli_args.get_flag("enable-sampling") {
client_config.chain.enable_sampling = true;
}

/*
* Prometheus metrics HTTP server
*/
Expand Down
13 changes: 13 additions & 0 deletions lighthouse/tests/beacon_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,19 @@ fn network_subscribe_all_data_column_subnets_flag() {
.with_config(|config| assert!(config.network.subscribe_all_data_column_subnets));
}
#[test]
fn network_enable_sampling_flag() {
CommandLineTest::new()
.flag("enable-sampling", None)
.run_with_zero_port()
.with_config(|config| assert!(config.chain.enable_sampling));
}
#[test]
fn network_enable_sampling_flag_default() {
CommandLineTest::new()
.run_with_zero_port()
.with_config(|config| assert!(!config.chain.enable_sampling));
}
#[test]
fn network_subscribe_all_subnets_flag() {
CommandLineTest::new()
.flag("subscribe-all-subnets", None)
Expand Down

0 comments on commit 37dd0ea

Please sign in to comment.