Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cli flag to enable sampling and disable by default #6209

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -6991,8 +6991,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 @@ -88,6 +88,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 @@ -121,6 +123,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 @@ -830,6 +830,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
Loading