@@ -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)
0 commit comments