diff --git a/beacon_node/beacon_chain/src/chain_config.rs b/beacon_node/beacon_chain/src/chain_config.rs index b262fe6ada..99199d813b 100644 --- a/beacon_node/beacon_chain/src/chain_config.rs +++ b/beacon_node/beacon_chain/src/chain_config.rs @@ -95,6 +95,7 @@ pub struct ChainConfig { /// This doesn't apply if the node is the block proposer. pub blob_publication_batch_interval: Duration, pub disable_attesting: bool, + pub sync_tolerance_epochs: u64, } impl Default for ChainConfig { @@ -131,6 +132,7 @@ impl Default for ChainConfig { blob_publication_batches: 4, blob_publication_batch_interval: Duration::from_millis(300), disable_attesting: false, + sync_tolerance_epochs: 16, } } } diff --git a/beacon_node/http_api/src/lib.rs b/beacon_node/http_api/src/lib.rs index 47a1557e90..38758fe5c3 100644 --- a/beacon_node/http_api/src/lib.rs +++ b/beacon_node/http_api/src/lib.rs @@ -107,13 +107,6 @@ use warp_utils::{query::multi_key_query, reject::convert_rejection, uor::Unifyin const API_PREFIX: &str = "eth"; -/// If the node is within this many epochs from the head, we declare it to be synced regardless of -/// the network sync state. -/// -/// This helps prevent attacks where nodes can convince us that we're syncing some non-existent -/// finalized head. -const SYNC_TOLERANCE_EPOCHS: u64 = 8; - /// A custom type which allows for both unsecured and TLS-enabled HTTP servers. type HttpServer = (SocketAddr, Pin + Send>>); @@ -157,6 +150,7 @@ pub struct Config { pub duplicate_block_status_code: StatusCode, pub enable_light_client_server: bool, pub target_peers: usize, + pub sync_tolerance_epochs: usize, } impl Default for Config { @@ -173,6 +167,7 @@ impl Default for Config { duplicate_block_status_code: StatusCode::ACCEPTED, enable_light_client_server: true, target_peers: 100, + sync_tolerance_epochs: 16, } } } @@ -473,7 +468,8 @@ pub fn serve( ) })?; - let tolerance = SYNC_TOLERANCE_EPOCHS * T::EthSpec::slots_per_epoch(); + let tolerance = + chain.config.sync_tolerance_epochs * T::EthSpec::slots_per_epoch(); if head_slot + tolerance >= current_slot { Ok(()) diff --git a/beacon_node/src/cli.rs b/beacon_node/src/cli.rs index e86cc3b42c..470907094a 100644 --- a/beacon_node/src/cli.rs +++ b/beacon_node/src/cli.rs @@ -561,6 +561,14 @@ pub fn cli_app() -> Command { .action(ArgAction::SetTrue) .display_order(0) ) + .arg( + Arg::new("sync-tolerance-epochs") + .long("sync-tolerance-epochs") + .help("If the beacon node is within this many epochs from the head, we declare it to \ + be synced regardless of the network sync state") + .action(ArgAction::Set) + .display_order(0) + ) .arg( Arg::new("http-sse-capacity-multiplier") .long("http-sse-capacity-multiplier")