mirror of
https://github.com/sigp/lighthouse.git
synced 2026-07-05 05:44:30 +00:00
Remove LC server config from HTTP API (#7017)
Partly addresses - https://github.com/sigp/lighthouse/issues/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.
This commit is contained in:
@@ -155,7 +155,6 @@ pub struct Config {
|
|||||||
pub enable_beacon_processor: bool,
|
pub enable_beacon_processor: bool,
|
||||||
#[serde(with = "eth2::types::serde_status_code")]
|
#[serde(with = "eth2::types::serde_status_code")]
|
||||||
pub duplicate_block_status_code: StatusCode,
|
pub duplicate_block_status_code: StatusCode,
|
||||||
pub enable_light_client_server: bool,
|
|
||||||
pub target_peers: usize,
|
pub target_peers: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +170,6 @@ impl Default for Config {
|
|||||||
sse_capacity_multiplier: 1,
|
sse_capacity_multiplier: 1,
|
||||||
enable_beacon_processor: true,
|
enable_beacon_processor: true,
|
||||||
duplicate_block_status_code: StatusCode::ACCEPTED,
|
duplicate_block_status_code: StatusCode::ACCEPTED,
|
||||||
enable_light_client_server: true,
|
|
||||||
target_peers: 100,
|
target_peers: 100,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -296,18 +294,6 @@ pub fn prometheus_metrics() -> warp::filters::log::Log<impl Fn(warp::filters::lo
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enable(is_enabled: bool) -> impl Filter<Extract = (), Error = warp::Rejection> + Clone {
|
|
||||||
warp::any()
|
|
||||||
.and_then(move || async move {
|
|
||||||
if is_enabled {
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(warp::reject::not_found())
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.untuple_one()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a server that will serve requests using information from `ctx`.
|
/// Creates a server that will serve requests using information from `ctx`.
|
||||||
///
|
///
|
||||||
/// The server will shut down gracefully when the `shutdown` future resolves.
|
/// The server will shut down gracefully when the `shutdown` future resolves.
|
||||||
@@ -493,6 +479,18 @@ pub fn serve<T: BeaconChainTypes>(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Create a `warp` filter that returns 404s if the light client server is disabled.
|
||||||
|
let light_client_server_filter =
|
||||||
|
warp::any()
|
||||||
|
.and(chain_filter.clone())
|
||||||
|
.then(|chain: Arc<BeaconChain<T>>| async move {
|
||||||
|
if chain.config.enable_light_client_server {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(warp::reject::not_found())
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Create a `warp` filter that provides access to the logger.
|
// Create a `warp` filter that provides access to the logger.
|
||||||
let inner_ctx = ctx.clone();
|
let inner_ctx = ctx.clone();
|
||||||
let log_filter = warp::any().map(move || inner_ctx.log.clone());
|
let log_filter = warp::any().map(move || inner_ctx.log.clone());
|
||||||
@@ -2452,6 +2450,7 @@ pub fn serve<T: BeaconChainTypes>(
|
|||||||
let beacon_light_client_path = eth_v1
|
let beacon_light_client_path = eth_v1
|
||||||
.and(warp::path("beacon"))
|
.and(warp::path("beacon"))
|
||||||
.and(warp::path("light_client"))
|
.and(warp::path("light_client"))
|
||||||
|
.and(light_client_server_filter)
|
||||||
.and(chain_filter.clone());
|
.and(chain_filter.clone());
|
||||||
|
|
||||||
// GET beacon/light_client/bootstrap/{block_root}
|
// GET beacon/light_client/bootstrap/{block_root}
|
||||||
@@ -2467,11 +2466,13 @@ pub fn serve<T: BeaconChainTypes>(
|
|||||||
.and(warp::path::end())
|
.and(warp::path::end())
|
||||||
.and(warp::header::optional::<api_types::Accept>("accept"))
|
.and(warp::header::optional::<api_types::Accept>("accept"))
|
||||||
.then(
|
.then(
|
||||||
|chain: Arc<BeaconChain<T>>,
|
|light_client_server_enabled: Result<(), Rejection>,
|
||||||
|
chain: Arc<BeaconChain<T>>,
|
||||||
task_spawner: TaskSpawner<T::EthSpec>,
|
task_spawner: TaskSpawner<T::EthSpec>,
|
||||||
block_root: Hash256,
|
block_root: Hash256,
|
||||||
accept_header: Option<api_types::Accept>| {
|
accept_header: Option<api_types::Accept>| {
|
||||||
task_spawner.blocking_response_task(Priority::P1, move || {
|
task_spawner.blocking_response_task(Priority::P1, move || {
|
||||||
|
light_client_server_enabled?;
|
||||||
get_light_client_bootstrap::<T>(chain, &block_root, accept_header)
|
get_light_client_bootstrap::<T>(chain, &block_root, accept_header)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -2485,10 +2486,12 @@ pub fn serve<T: BeaconChainTypes>(
|
|||||||
.and(warp::path::end())
|
.and(warp::path::end())
|
||||||
.and(warp::header::optional::<api_types::Accept>("accept"))
|
.and(warp::header::optional::<api_types::Accept>("accept"))
|
||||||
.then(
|
.then(
|
||||||
|chain: Arc<BeaconChain<T>>,
|
|light_client_server_enabled: Result<(), Rejection>,
|
||||||
|
chain: Arc<BeaconChain<T>>,
|
||||||
task_spawner: TaskSpawner<T::EthSpec>,
|
task_spawner: TaskSpawner<T::EthSpec>,
|
||||||
accept_header: Option<api_types::Accept>| {
|
accept_header: Option<api_types::Accept>| {
|
||||||
task_spawner.blocking_response_task(Priority::P1, move || {
|
task_spawner.blocking_response_task(Priority::P1, move || {
|
||||||
|
light_client_server_enabled?;
|
||||||
let update = chain
|
let update = chain
|
||||||
.light_client_server_cache
|
.light_client_server_cache
|
||||||
.get_latest_optimistic_update()
|
.get_latest_optimistic_update()
|
||||||
@@ -2532,10 +2535,12 @@ pub fn serve<T: BeaconChainTypes>(
|
|||||||
.and(warp::path::end())
|
.and(warp::path::end())
|
||||||
.and(warp::header::optional::<api_types::Accept>("accept"))
|
.and(warp::header::optional::<api_types::Accept>("accept"))
|
||||||
.then(
|
.then(
|
||||||
|chain: Arc<BeaconChain<T>>,
|
|light_client_server_enabled: Result<(), Rejection>,
|
||||||
|
chain: Arc<BeaconChain<T>>,
|
||||||
task_spawner: TaskSpawner<T::EthSpec>,
|
task_spawner: TaskSpawner<T::EthSpec>,
|
||||||
accept_header: Option<api_types::Accept>| {
|
accept_header: Option<api_types::Accept>| {
|
||||||
task_spawner.blocking_response_task(Priority::P1, move || {
|
task_spawner.blocking_response_task(Priority::P1, move || {
|
||||||
|
light_client_server_enabled?;
|
||||||
let update = chain
|
let update = chain
|
||||||
.light_client_server_cache
|
.light_client_server_cache
|
||||||
.get_latest_finality_update()
|
.get_latest_finality_update()
|
||||||
@@ -2580,11 +2585,13 @@ pub fn serve<T: BeaconChainTypes>(
|
|||||||
.and(warp::query::<api_types::LightClientUpdatesQuery>())
|
.and(warp::query::<api_types::LightClientUpdatesQuery>())
|
||||||
.and(warp::header::optional::<api_types::Accept>("accept"))
|
.and(warp::header::optional::<api_types::Accept>("accept"))
|
||||||
.then(
|
.then(
|
||||||
|chain: Arc<BeaconChain<T>>,
|
|light_client_server_enabled: Result<(), Rejection>,
|
||||||
|
chain: Arc<BeaconChain<T>>,
|
||||||
task_spawner: TaskSpawner<T::EthSpec>,
|
task_spawner: TaskSpawner<T::EthSpec>,
|
||||||
query: LightClientUpdatesQuery,
|
query: LightClientUpdatesQuery,
|
||||||
accept_header: Option<api_types::Accept>| {
|
accept_header: Option<api_types::Accept>| {
|
||||||
task_spawner.blocking_response_task(Priority::P1, move || {
|
task_spawner.blocking_response_task(Priority::P1, move || {
|
||||||
|
light_client_server_enabled?;
|
||||||
get_light_client_updates::<T>(chain, query, accept_header)
|
get_light_client_updates::<T>(chain, query, accept_header)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -4723,22 +4730,10 @@ pub fn serve<T: BeaconChainTypes>(
|
|||||||
.uor(get_lighthouse_database_info)
|
.uor(get_lighthouse_database_info)
|
||||||
.uor(get_lighthouse_block_rewards)
|
.uor(get_lighthouse_block_rewards)
|
||||||
.uor(get_lighthouse_attestation_performance)
|
.uor(get_lighthouse_attestation_performance)
|
||||||
.uor(
|
.uor(get_beacon_light_client_optimistic_update)
|
||||||
enable(ctx.config.enable_light_client_server)
|
.uor(get_beacon_light_client_finality_update)
|
||||||
.and(get_beacon_light_client_optimistic_update),
|
.uor(get_beacon_light_client_bootstrap)
|
||||||
)
|
.uor(get_beacon_light_client_updates)
|
||||||
.uor(
|
|
||||||
enable(ctx.config.enable_light_client_server)
|
|
||||||
.and(get_beacon_light_client_finality_update),
|
|
||||||
)
|
|
||||||
.uor(
|
|
||||||
enable(ctx.config.enable_light_client_server)
|
|
||||||
.and(get_beacon_light_client_bootstrap),
|
|
||||||
)
|
|
||||||
.uor(
|
|
||||||
enable(ctx.config.enable_light_client_server)
|
|
||||||
.and(get_beacon_light_client_updates),
|
|
||||||
)
|
|
||||||
.uor(get_lighthouse_block_packing_efficiency)
|
.uor(get_lighthouse_block_packing_efficiency)
|
||||||
.uor(get_lighthouse_merge_readiness)
|
.uor(get_lighthouse_merge_readiness)
|
||||||
.uor(get_events)
|
.uor(get_events)
|
||||||
|
|||||||
@@ -249,7 +249,6 @@ pub async fn create_api_server_with_config<T: BeaconChainTypes>(
|
|||||||
enabled: true,
|
enabled: true,
|
||||||
listen_port: port,
|
listen_port: port,
|
||||||
data_dir: std::path::PathBuf::from(DEFAULT_ROOT_DIR),
|
data_dir: std::path::PathBuf::from(DEFAULT_ROOT_DIR),
|
||||||
enable_light_client_server: true,
|
|
||||||
..http_config
|
..http_config
|
||||||
},
|
},
|
||||||
chain: Some(chain),
|
chain: Some(chain),
|
||||||
|
|||||||
@@ -174,9 +174,6 @@ pub fn get_config<E: EthSpec>(
|
|||||||
|
|
||||||
client_config.http_api.duplicate_block_status_code =
|
client_config.http_api.duplicate_block_status_code =
|
||||||
parse_required(cli_args, "http-duplicate-block-status")?;
|
parse_required(cli_args, "http-duplicate-block-status")?;
|
||||||
|
|
||||||
client_config.http_api.enable_light_client_server =
|
|
||||||
!cli_args.get_flag("disable-light-client-server");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if cli_args.get_flag("light-client-server") {
|
if cli_args.get_flag("light-client-server") {
|
||||||
|
|||||||
@@ -2506,7 +2506,6 @@ fn light_client_server_default() {
|
|||||||
.with_config(|config| {
|
.with_config(|config| {
|
||||||
assert!(config.network.enable_light_client_server);
|
assert!(config.network.enable_light_client_server);
|
||||||
assert!(config.chain.enable_light_client_server);
|
assert!(config.chain.enable_light_client_server);
|
||||||
assert!(config.http_api.enable_light_client_server);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2539,7 +2538,6 @@ fn light_client_http_server_disabled() {
|
|||||||
.flag("disable-light-client-server", None)
|
.flag("disable-light-client-server", None)
|
||||||
.run_with_zero_port()
|
.run_with_zero_port()
|
||||||
.with_config(|config| {
|
.with_config(|config| {
|
||||||
assert!(!config.http_api.enable_light_client_server);
|
|
||||||
assert!(!config.network.enable_light_client_server);
|
assert!(!config.network.enable_light_client_server);
|
||||||
assert!(!config.chain.enable_light_client_server);
|
assert!(!config.chain.enable_light_client_server);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ fn default_client_config(network_params: LocalNetworkParams, genesis_time: u64)
|
|||||||
beacon_config.network.enable_light_client_server = true;
|
beacon_config.network.enable_light_client_server = true;
|
||||||
beacon_config.network.discv5_config.enable_packet_filter = false;
|
beacon_config.network.discv5_config.enable_packet_filter = false;
|
||||||
beacon_config.chain.enable_light_client_server = true;
|
beacon_config.chain.enable_light_client_server = true;
|
||||||
beacon_config.http_api.enable_light_client_server = true;
|
|
||||||
beacon_config.chain.optimistic_finalized_sync = false;
|
beacon_config.chain.optimistic_finalized_sync = false;
|
||||||
beacon_config.trusted_setup = serde_json::from_reader(get_trusted_setup().as_slice())
|
beacon_config.trusted_setup = serde_json::from_reader(get_trusted_setup().as_slice())
|
||||||
.expect("Trusted setup bytes should be valid");
|
.expect("Trusted setup bytes should be valid");
|
||||||
|
|||||||
Reference in New Issue
Block a user