Skip to content

Commit 8d03d34

Browse files
authored
Add cli flag to enable sampling and disable by default. (#6209)
1 parent e1f8909 commit 8d03d34

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

beacon_node/beacon_chain/src/beacon_chain.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6991,8 +6991,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
69916991
/// Returns true if we should issue a sampling request for this block
69926992
/// TODO(das): check if the block is still within the da_window
69936993
pub fn should_sample_slot(&self, slot: Slot) -> bool {
6994-
self.spec
6995-
.is_peer_das_enabled_for_epoch(slot.epoch(T::EthSpec::slots_per_epoch()))
6994+
self.config.enable_sampling
6995+
&& self
6996+
.spec
6997+
.is_peer_das_enabled_for_epoch(slot.epoch(T::EthSpec::slots_per_epoch()))
69966998
}
69976999

69987000
pub fn logger(&self) -> &Logger {

beacon_node/beacon_chain/src/chain_config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ pub struct ChainConfig {
8888
pub enable_light_client_server: bool,
8989
/// Enable malicious PeerDAS mode where node withholds data columns when publishing a block
9090
pub malicious_withhold_count: usize,
91+
/// Enable peer sampling on blocks.
92+
pub enable_sampling: bool,
9193
}
9294

9395
impl Default for ChainConfig {
@@ -121,6 +123,7 @@ impl Default for ChainConfig {
121123
epochs_per_migration: crate::migrate::DEFAULT_EPOCHS_PER_MIGRATION,
122124
enable_light_client_server: false,
123125
malicious_withhold_count: 0,
126+
enable_sampling: false,
124127
}
125128
}
126129
}

beacon_node/src/cli.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ pub fn cli_app() -> Command {
7474
.hide(true)
7575
.display_order(0)
7676
)
77+
.arg(
78+
Arg::new("enable-sampling")
79+
.long("enable-sampling")
80+
.action(ArgAction::SetTrue)
81+
.help_heading(FLAG_HEADER)
82+
.help("Enable peer sampling on data columns. Disabled by default.")
83+
.hide(true)
84+
.display_order(0)
85+
)
7786
.arg(
7887
Arg::new("subscribe-all-subnets")
7988
.long("subscribe-all-subnets")

beacon_node/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ pub fn get_config<E: EthSpec>(
181181
client_config.chain.shuffling_cache_size = cache_size;
182182
}
183183

184+
if cli_args.get_flag("enable-sampling") {
185+
client_config.chain.enable_sampling = true;
186+
}
187+
184188
/*
185189
* Prometheus metrics HTTP server
186190
*/

lighthouse/tests/beacon_node.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,19 @@ fn network_subscribe_all_data_column_subnets_flag() {
830830
.with_config(|config| assert!(config.network.subscribe_all_data_column_subnets));
831831
}
832832
#[test]
833+
fn network_enable_sampling_flag() {
834+
CommandLineTest::new()
835+
.flag("enable-sampling", None)
836+
.run_with_zero_port()
837+
.with_config(|config| assert!(config.chain.enable_sampling));
838+
}
839+
#[test]
840+
fn network_enable_sampling_flag_default() {
841+
CommandLineTest::new()
842+
.run_with_zero_port()
843+
.with_config(|config| assert!(!config.chain.enable_sampling));
844+
}
845+
#[test]
833846
fn network_subscribe_all_subnets_flag() {
834847
CommandLineTest::new()
835848
.flag("subscribe-all-subnets", None)

0 commit comments

Comments
 (0)