Skip to content

Commit dcbca71

Browse files
committed
Add test flag to override SYNC_TOLERANCE_EPOCHS for testing range sync.
1 parent 3fab6a2 commit dcbca71

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

beacon_node/http_api/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const API_PREFIX: &str = "eth";
112112
///
113113
/// This helps prevent attacks where nodes can convince us that we're syncing some non-existent
114114
/// finalized head.
115-
const SYNC_TOLERANCE_EPOCHS: u64 = 8;
115+
const DEFAULT_SYNC_TOLERANCE_EPOCHS: u64 = 8;
116116

117117
/// A custom type which allows for both unsecured and TLS-enabled HTTP servers.
118118
type HttpServer = (SocketAddr, Pin<Box<dyn Future<Output = ()> + Send>>);
@@ -157,6 +157,7 @@ pub struct Config {
157157
pub duplicate_block_status_code: StatusCode,
158158
pub enable_light_client_server: bool,
159159
pub target_peers: usize,
160+
pub sync_tolerance_epochs: Option<u64>,
160161
}
161162

162163
impl Default for Config {
@@ -173,6 +174,7 @@ impl Default for Config {
173174
duplicate_block_status_code: StatusCode::ACCEPTED,
174175
enable_light_client_server: true,
175176
target_peers: 100,
177+
sync_tolerance_epochs: None,
176178
}
177179
}
178180
}
@@ -473,7 +475,10 @@ pub fn serve<T: BeaconChainTypes>(
473475
)
474476
})?;
475477

476-
let tolerance = SYNC_TOLERANCE_EPOCHS * T::EthSpec::slots_per_epoch();
478+
let sync_tolerance_epochs = config
479+
.sync_tolerance_epochs
480+
.unwrap_or(DEFAULT_SYNC_TOLERANCE_EPOCHS);
481+
let tolerance = sync_tolerance_epochs * T::EthSpec::slots_per_epoch();
477482

478483
if head_slot + tolerance >= current_slot {
479484
Ok(())

beacon_node/src/cli.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,18 @@ pub fn cli_app() -> Command {
15091509
.help_heading(FLAG_HEADER)
15101510
.display_order(0)
15111511
)
1512+
.arg(
1513+
Arg::new("sync-tolerance-epochs")
1514+
.long("sync-tolerance-epochs")
1515+
.help("Overrides the default SYNC_TOLERANCE_EPOCHS. This flag is not intended \
1516+
for production and MUST only be used in TESTING only. This is primarily used \
1517+
for testing range sync, to prevent the node from producing a block before the \
1518+
node is synced with the network which may result in the node getting \
1519+
disconnected from peers immediately.")
1520+
.hide(true)
1521+
.action(ArgAction::Set)
1522+
.display_order(0)
1523+
)
15121524
.arg(
15131525
Arg::new("gui")
15141526
.long("gui")

beacon_node/src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ pub fn get_config<E: EthSpec>(
177177

178178
client_config.http_api.enable_light_client_server =
179179
!cli_args.get_flag("disable-light-client-server");
180+
181+
client_config.http_api.sync_tolerance_epochs =
182+
cli_args.get_one("sync-tolerance-epochs").copied();
180183
}
181184

182185
if cli_args.get_flag("light-client-server") {

lighthouse/tests/beacon_node.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,6 +2545,16 @@ fn light_client_http_server_disabled() {
25452545
});
25462546
}
25472547

2548+
#[test]
2549+
fn sync_tolerance_epochs() {
2550+
CommandLineTest::new()
2551+
.flag("sync-tolerance-epochs", Some("0"))
2552+
.run_with_zero_port()
2553+
.with_config(|config| {
2554+
assert_eq!(config.http_api.sync_tolerance_epochs, Some(0));
2555+
});
2556+
}
2557+
25482558
#[test]
25492559
fn gui_flag() {
25502560
CommandLineTest::new()

scripts/local_testnet/network_params_das.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ participants:
44
cl_extra_params:
55
- --subscribe-all-data-column-subnets
66
- --subscribe-all-subnets
7+
# Note: useful for testing range sync (only produce block if node is in sync to prevent forking)
8+
- --sync-tolerance-epochs=0
79
- --target-peers=3
810
count: 2
911
- cl_type: lighthouse
1012
cl_image: lighthouse:local
1113
cl_extra_params:
14+
# Note: useful for testing range sync (only produce block if node is in sync to prevent forking)
15+
- --sync-tolerance-epochs=0
1216
- --target-peers=3
1317
count: 2
1418
network_params:

0 commit comments

Comments
 (0)