Skip to content

Commit

Permalink
resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
eserilev committed Feb 26, 2025
2 parents 842932f + 80cd8bd commit 9455fd0
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 10 deletions.
17 changes: 13 additions & 4 deletions beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ 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 DEFAULT_SYNC_TOLERANCE_EPOCHS: u64 = 8;

/// A custom type which allows for both unsecured and TLS-enabled HTTP servers.
type HttpServer = (SocketAddr, Pin<Box<dyn Future<Output = ()> + Send>>);

Expand Down Expand Up @@ -150,7 +157,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,
pub sync_tolerance_epochs: Option<u64>,
}

impl Default for Config {
Expand All @@ -167,7 +174,7 @@ impl Default for Config {
duplicate_block_status_code: StatusCode::ACCEPTED,
enable_light_client_server: true,
target_peers: 100,
sync_tolerance_epochs: 16,
sync_tolerance_epochs: None,
}
}
}
Expand Down Expand Up @@ -468,8 +475,10 @@ pub fn serve<T: BeaconChainTypes>(
)
})?;

let tolerance =
chain.config.sync_tolerance_epochs * T::EthSpec::slots_per_epoch();
let sync_tolerance_epochs = config
.sync_tolerance_epochs
.unwrap_or(DEFAULT_SYNC_TOLERANCE_EPOCHS);
let tolerance = sync_tolerance_epochs * T::EthSpec::slots_per_epoch();

if head_slot + tolerance >= current_slot {
Ok(())
Expand Down
13 changes: 13 additions & 0 deletions beacon_node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,19 @@ pub fn cli_app() -> Command {
.help_heading(FLAG_HEADER)
.display_order(0)
)
.arg(
Arg::new("sync-tolerance-epochs")
.long("sync-tolerance-epochs")
.help("Overrides the default SYNC_TOLERANCE_EPOCHS. This flag is not intended \
for production and MUST only be used in TESTING only. This is primarily used \
for testing range sync, to prevent the node from producing a block before the \
node is synced with the network which may result in the node getting \
disconnected from peers immediately.")
.hide(true)
.requires("enable_http")
.action(ArgAction::Set)
.display_order(0)
)
.arg(
Arg::new("gui")
.long("gui")
Expand Down
5 changes: 4 additions & 1 deletion beacon_node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use beacon_chain::graffiti_calculator::GraffitiOrigin;
use beacon_chain::TrustedSetup;
use clap::{parser::ValueSource, ArgMatches, Id};
use clap_utils::flags::DISABLE_MALLOC_TUNING_FLAG;
use clap_utils::{parse_flag, parse_required};
use clap_utils::{parse_flag, parse_optional, parse_required};
use client::{ClientConfig, ClientGenesis};
use directory::{DEFAULT_BEACON_NODE_DIR, DEFAULT_NETWORK_DIR, DEFAULT_ROOT_DIR};
use environment::RuntimeContext;
Expand Down Expand Up @@ -178,6 +178,9 @@ pub fn get_config<E: EthSpec>(

client_config.http_api.enable_light_client_server =
!cli_args.get_flag("disable-light-client-server");

client_config.http_api.sync_tolerance_epochs =
parse_optional(cli_args, "sync-tolerance-epochs")?;
}

if cli_args.get_flag("light-client-server") {
Expand Down
4 changes: 3 additions & 1 deletion book/src/help_vc.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ Flags:
block headers during proposals and will sign over headers. Useful for
outsourcing execution payload construction during proposals.
--disable-attesting
Disable everything except block proposals
Disable the performance of attestation duties (and sync committee
duties). This flag should only be used in emergencies to prioritise
block proposal duties.
--disable-auto-discover
If present, do not attempt to discover new validators in the
validators-dir. Validators will need to be manually added to the
Expand Down
7 changes: 4 additions & 3 deletions lighthouse/tests/beacon_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2580,12 +2580,13 @@ fn light_client_http_server_disabled() {
}

#[test]
fn disable_attesting() {
fn sync_tolerance_epochs() {
CommandLineTest::new()
.flag("disable-attesting", None)
.flag("http", None)
.flag("sync-tolerance-epochs", Some("0"))
.run_with_zero_port()
.with_config(|config| {
assert!(config.chain.disable_attesting);
assert_eq!(config.http_api.sync_tolerance_epochs, Some(0));
});
}

Expand Down
4 changes: 4 additions & 0 deletions scripts/local_testnet/network_params_das.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ participants:
cl_extra_params:
- --subscribe-all-data-column-subnets
- --subscribe-all-subnets
# Note: useful for testing range sync (only produce block if node is in sync to prevent forking)
- --sync-tolerance-epochs=0
- --target-peers=3
count: 2
- cl_type: lighthouse
cl_image: lighthouse:local
cl_extra_params:
# Note: useful for testing range sync (only produce block if node is in sync to prevent forking)
- --sync-tolerance-epochs=0
- --target-peers=3
count: 2
network_params:
Expand Down
3 changes: 2 additions & 1 deletion validator_client/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ pub struct ValidatorClient {

#[clap(
long,
help = "Disable everything except block proposals",
help = "Disable the performance of attestation duties (and sync committee duties). This \
flag should only be used in emergencies to prioritise block proposal duties.",
display_order = 0,
help_heading = FLAG_HEADER
)]
Expand Down

0 comments on commit 9455fd0

Please sign in to comment.