mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-16 11:22:56 +00:00
Add API endpoint for fork choice
This commit is contained in:
18
beacon_node/rest_api/src/advanced.rs
Normal file
18
beacon_node/rest_api/src/advanced.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use crate::response_builder::ResponseBuilder;
|
||||
use crate::{ApiError, ApiResult};
|
||||
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
||||
use hyper::{Body, Request};
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Returns the `proto_array` fork choice struct, encoded as JSON.
|
||||
///
|
||||
/// Useful for debugging or advanced inspection of the chain.
|
||||
pub fn get_fork_choice<T: BeaconChainTypes>(
|
||||
req: Request<Body>,
|
||||
beacon_chain: Arc<BeaconChain<T>>,
|
||||
) -> ApiResult {
|
||||
let json = beacon_chain.fork_choice.as_json().map_err(|e| {
|
||||
ApiError::ServerError(format!("Unable to encode fork choice as JSON: {:?}", e))
|
||||
})?;
|
||||
ResponseBuilder::new(&req)?.body_no_ssz(&json)
|
||||
}
|
||||
@@ -4,6 +4,7 @@ mod macros;
|
||||
extern crate lazy_static;
|
||||
extern crate network as client_network;
|
||||
|
||||
mod advanced;
|
||||
mod beacon;
|
||||
pub mod config;
|
||||
mod consensus;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
beacon, consensus, error::ApiError, helpers, metrics, network, node, spec, validator, BoxFut,
|
||||
NetworkChannel,
|
||||
advanced, beacon, consensus, error::ApiError, helpers, metrics, network, node, spec, validator,
|
||||
BoxFut, NetworkChannel,
|
||||
};
|
||||
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
||||
use client_network::Service as NetworkService;
|
||||
@@ -147,6 +147,11 @@ pub fn route<T: BeaconChainTypes>(
|
||||
into_boxfut(spec::get_eth2_config::<T>(req, eth2_config))
|
||||
}
|
||||
|
||||
// Methods for advanced parameters
|
||||
(&Method::GET, "/advanced/fork_choice") => {
|
||||
into_boxfut(advanced::get_fork_choice::<T>(req, beacon_chain))
|
||||
}
|
||||
|
||||
(&Method::GET, "/metrics") => into_boxfut(metrics::get_prometheus::<T>(
|
||||
req,
|
||||
beacon_chain,
|
||||
|
||||
Reference in New Issue
Block a user