Skip to content

Commit 454c7d0

Browse files
Remove LC server config from HTTP API (#7017)
Partly addresses - #6959 Use the `enable_light_client_server` field from the beacon chain config in the HTTP API. I think we can make this the single source of truth, as I think the network crate also has access to the beacon chain config.
1 parent 6e11bdd commit 454c7d0

File tree

5 files changed

+29
-41
lines changed

5 files changed

+29
-41
lines changed

beacon_node/http_api/src/lib.rs

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ pub struct Config {
155155
pub enable_beacon_processor: bool,
156156
#[serde(with = "eth2::types::serde_status_code")]
157157
pub duplicate_block_status_code: StatusCode,
158-
pub enable_light_client_server: bool,
159158
pub target_peers: usize,
160159
}
161160

@@ -171,7 +170,6 @@ impl Default for Config {
171170
sse_capacity_multiplier: 1,
172171
enable_beacon_processor: true,
173172
duplicate_block_status_code: StatusCode::ACCEPTED,
174-
enable_light_client_server: true,
175173
target_peers: 100,
176174
}
177175
}
@@ -296,18 +294,6 @@ pub fn prometheus_metrics() -> warp::filters::log::Log<impl Fn(warp::filters::lo
296294
})
297295
}
298296

299-
fn enable(is_enabled: bool) -> impl Filter<Extract = (), Error = warp::Rejection> + Clone {
300-
warp::any()
301-
.and_then(move || async move {
302-
if is_enabled {
303-
Ok(())
304-
} else {
305-
Err(warp::reject::not_found())
306-
}
307-
})
308-
.untuple_one()
309-
}
310-
311297
/// Creates a server that will serve requests using information from `ctx`.
312298
///
313299
/// The server will shut down gracefully when the `shutdown` future resolves.
@@ -493,6 +479,18 @@ pub fn serve<T: BeaconChainTypes>(
493479
},
494480
);
495481

482+
// Create a `warp` filter that returns 404s if the light client server is disabled.
483+
let light_client_server_filter =
484+
warp::any()
485+
.and(chain_filter.clone())
486+
.then(|chain: Arc<BeaconChain<T>>| async move {
487+
if chain.config.enable_light_client_server {
488+
Ok(())
489+
} else {
490+
Err(warp::reject::not_found())
491+
}
492+
});
493+
496494
// Create a `warp` filter that provides access to the logger.
497495
let inner_ctx = ctx.clone();
498496
let log_filter = warp::any().map(move || inner_ctx.log.clone());
@@ -2452,6 +2450,7 @@ pub fn serve<T: BeaconChainTypes>(
24522450
let beacon_light_client_path = eth_v1
24532451
.and(warp::path("beacon"))
24542452
.and(warp::path("light_client"))
2453+
.and(light_client_server_filter)
24552454
.and(chain_filter.clone());
24562455

24572456
// GET beacon/light_client/bootstrap/{block_root}
@@ -2467,11 +2466,13 @@ pub fn serve<T: BeaconChainTypes>(
24672466
.and(warp::path::end())
24682467
.and(warp::header::optional::<api_types::Accept>("accept"))
24692468
.then(
2470-
|chain: Arc<BeaconChain<T>>,
2469+
|light_client_server_enabled: Result<(), Rejection>,
2470+
chain: Arc<BeaconChain<T>>,
24712471
task_spawner: TaskSpawner<T::EthSpec>,
24722472
block_root: Hash256,
24732473
accept_header: Option<api_types::Accept>| {
24742474
task_spawner.blocking_response_task(Priority::P1, move || {
2475+
light_client_server_enabled?;
24752476
get_light_client_bootstrap::<T>(chain, &block_root, accept_header)
24762477
})
24772478
},
@@ -2485,10 +2486,12 @@ pub fn serve<T: BeaconChainTypes>(
24852486
.and(warp::path::end())
24862487
.and(warp::header::optional::<api_types::Accept>("accept"))
24872488
.then(
2488-
|chain: Arc<BeaconChain<T>>,
2489+
|light_client_server_enabled: Result<(), Rejection>,
2490+
chain: Arc<BeaconChain<T>>,
24892491
task_spawner: TaskSpawner<T::EthSpec>,
24902492
accept_header: Option<api_types::Accept>| {
24912493
task_spawner.blocking_response_task(Priority::P1, move || {
2494+
light_client_server_enabled?;
24922495
let update = chain
24932496
.light_client_server_cache
24942497
.get_latest_optimistic_update()
@@ -2532,10 +2535,12 @@ pub fn serve<T: BeaconChainTypes>(
25322535
.and(warp::path::end())
25332536
.and(warp::header::optional::<api_types::Accept>("accept"))
25342537
.then(
2535-
|chain: Arc<BeaconChain<T>>,
2538+
|light_client_server_enabled: Result<(), Rejection>,
2539+
chain: Arc<BeaconChain<T>>,
25362540
task_spawner: TaskSpawner<T::EthSpec>,
25372541
accept_header: Option<api_types::Accept>| {
25382542
task_spawner.blocking_response_task(Priority::P1, move || {
2543+
light_client_server_enabled?;
25392544
let update = chain
25402545
.light_client_server_cache
25412546
.get_latest_finality_update()
@@ -2580,11 +2585,13 @@ pub fn serve<T: BeaconChainTypes>(
25802585
.and(warp::query::<api_types::LightClientUpdatesQuery>())
25812586
.and(warp::header::optional::<api_types::Accept>("accept"))
25822587
.then(
2583-
|chain: Arc<BeaconChain<T>>,
2588+
|light_client_server_enabled: Result<(), Rejection>,
2589+
chain: Arc<BeaconChain<T>>,
25842590
task_spawner: TaskSpawner<T::EthSpec>,
25852591
query: LightClientUpdatesQuery,
25862592
accept_header: Option<api_types::Accept>| {
25872593
task_spawner.blocking_response_task(Priority::P1, move || {
2594+
light_client_server_enabled?;
25882595
get_light_client_updates::<T>(chain, query, accept_header)
25892596
})
25902597
},
@@ -4723,22 +4730,10 @@ pub fn serve<T: BeaconChainTypes>(
47234730
.uor(get_lighthouse_database_info)
47244731
.uor(get_lighthouse_block_rewards)
47254732
.uor(get_lighthouse_attestation_performance)
4726-
.uor(
4727-
enable(ctx.config.enable_light_client_server)
4728-
.and(get_beacon_light_client_optimistic_update),
4729-
)
4730-
.uor(
4731-
enable(ctx.config.enable_light_client_server)
4732-
.and(get_beacon_light_client_finality_update),
4733-
)
4734-
.uor(
4735-
enable(ctx.config.enable_light_client_server)
4736-
.and(get_beacon_light_client_bootstrap),
4737-
)
4738-
.uor(
4739-
enable(ctx.config.enable_light_client_server)
4740-
.and(get_beacon_light_client_updates),
4741-
)
4733+
.uor(get_beacon_light_client_optimistic_update)
4734+
.uor(get_beacon_light_client_finality_update)
4735+
.uor(get_beacon_light_client_bootstrap)
4736+
.uor(get_beacon_light_client_updates)
47424737
.uor(get_lighthouse_block_packing_efficiency)
47434738
.uor(get_lighthouse_merge_readiness)
47444739
.uor(get_events)

beacon_node/http_api/src/test_utils.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ pub async fn create_api_server_with_config<T: BeaconChainTypes>(
249249
enabled: true,
250250
listen_port: port,
251251
data_dir: std::path::PathBuf::from(DEFAULT_ROOT_DIR),
252-
enable_light_client_server: true,
253252
..http_config
254253
},
255254
chain: Some(chain),

beacon_node/src/config.rs

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

175175
client_config.http_api.duplicate_block_status_code =
176176
parse_required(cli_args, "http-duplicate-block-status")?;
177-
178-
client_config.http_api.enable_light_client_server =
179-
!cli_args.get_flag("disable-light-client-server");
180177
}
181178

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

lighthouse/tests/beacon_node.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,7 +2506,6 @@ fn light_client_server_default() {
25062506
.with_config(|config| {
25072507
assert!(config.network.enable_light_client_server);
25082508
assert!(config.chain.enable_light_client_server);
2509-
assert!(config.http_api.enable_light_client_server);
25102509
});
25112510
}
25122511

@@ -2539,7 +2538,6 @@ fn light_client_http_server_disabled() {
25392538
.flag("disable-light-client-server", None)
25402539
.run_with_zero_port()
25412540
.with_config(|config| {
2542-
assert!(!config.http_api.enable_light_client_server);
25432541
assert!(!config.network.enable_light_client_server);
25442542
assert!(!config.chain.enable_light_client_server);
25452543
});

testing/simulator/src/local_network.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ fn default_client_config(network_params: LocalNetworkParams, genesis_time: u64)
4444
beacon_config.network.enable_light_client_server = true;
4545
beacon_config.network.discv5_config.enable_packet_filter = false;
4646
beacon_config.chain.enable_light_client_server = true;
47-
beacon_config.http_api.enable_light_client_server = true;
4847
beacon_config.chain.optimistic_finalized_sync = false;
4948
beacon_config.trusted_setup = serde_json::from_reader(get_trusted_setup().as_slice())
5049
.expect("Trusted setup bytes should be valid");

0 commit comments

Comments
 (0)