mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-11 18:04:18 +00:00
Global Sync access (#994)
* Connect sync logic to network globals * Add further sync info to sync status * Build new syncing HTTP API methods * Fix bug in updating sync state * Highest slot is current slot * Update book for syncing API
This commit is contained in:
@@ -1,9 +1,50 @@
|
||||
use crate::response_builder::ResponseBuilder;
|
||||
use crate::ApiResult;
|
||||
use eth2_libp2p::{types::SyncState, NetworkGlobals};
|
||||
use hyper::{Body, Request};
|
||||
use rest_types::{SyncingResponse, SyncingStatus};
|
||||
use std::sync::Arc;
|
||||
use types::{EthSpec, Slot};
|
||||
use version;
|
||||
|
||||
/// Read the version string from the current Lighthouse build.
|
||||
pub fn get_version(req: Request<Body>) -> ApiResult {
|
||||
ResponseBuilder::new(&req)?.body_no_ssz(&version::version())
|
||||
}
|
||||
|
||||
pub fn syncing<T: EthSpec>(
|
||||
req: Request<Body>,
|
||||
network: Arc<NetworkGlobals<T>>,
|
||||
current_slot: Slot,
|
||||
) -> ApiResult {
|
||||
let (starting_slot, highest_slot) = match network.sync_state() {
|
||||
SyncState::SyncingFinalized {
|
||||
start_slot,
|
||||
head_slot,
|
||||
..
|
||||
}
|
||||
| SyncState::SyncingHead {
|
||||
start_slot,
|
||||
head_slot,
|
||||
} => (start_slot, head_slot),
|
||||
SyncState::Synced | SyncState::Stalled => (Slot::from(0u64), current_slot),
|
||||
};
|
||||
|
||||
let sync_status = SyncingStatus {
|
||||
starting_slot,
|
||||
current_slot,
|
||||
highest_slot,
|
||||
};
|
||||
|
||||
ResponseBuilder::new(&req)?.body(&SyncingResponse {
|
||||
is_syncing: network.is_syncing(),
|
||||
sync_status,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn lighthouse_syncing<T: EthSpec>(
|
||||
req: Request<Body>,
|
||||
network: Arc<NetworkGlobals<T>>,
|
||||
) -> ApiResult {
|
||||
ResponseBuilder::new(&req)?.body_no_ssz(&network.sync_state())
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ use slog::debug;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
use types::Slot;
|
||||
|
||||
fn into_boxfut<F: IntoFuture + 'static>(item: F) -> BoxFut
|
||||
where
|
||||
@@ -44,7 +45,20 @@ pub fn route<T: BeaconChainTypes>(
|
||||
// Methods for Client
|
||||
(&Method::GET, "/node/version") => into_boxfut(node::get_version(req)),
|
||||
(&Method::GET, "/node/syncing") => {
|
||||
into_boxfut(helpers::implementation_pending_response(req))
|
||||
// inform the current slot, or set to 0
|
||||
let current_slot = beacon_chain
|
||||
.head_info()
|
||||
.map(|info| info.slot)
|
||||
.unwrap_or_else(|_| Slot::from(0u64));
|
||||
|
||||
into_boxfut(node::syncing::<T::EthSpec>(
|
||||
req,
|
||||
network_globals,
|
||||
current_slot,
|
||||
))
|
||||
}
|
||||
(&Method::GET, "/node/lighthouse_syncing") => {
|
||||
into_boxfut(node::lighthouse_syncing::<T::EthSpec>(req, network_globals))
|
||||
}
|
||||
|
||||
// Methods for Network
|
||||
|
||||
Reference in New Issue
Block a user