mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 11:41:51 +00:00
Merged with unstable
This commit is contained in:
@@ -59,3 +59,6 @@ task_executor = { path = "../common/task_executor" }
|
||||
reqwest = { version = "0.11.0", features = ["json","stream"] }
|
||||
url = "2.2.2"
|
||||
malloc_utils = { path = "../common/malloc_utils" }
|
||||
sysinfo = "0.26.5"
|
||||
system_health = { path = "../common/system_health" }
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ use eth2::lighthouse_vc::{
|
||||
types::{self as api_types, GenericResponse, PublicKey, PublicKeyBytes},
|
||||
};
|
||||
use lighthouse_version::version_with_platform;
|
||||
use parking_lot::RwLock;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use slog::{crit, info, warn, Logger};
|
||||
use slot_clock::SlotClock;
|
||||
@@ -24,6 +25,8 @@ use std::marker::PhantomData;
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use sysinfo::{System, SystemExt};
|
||||
use system_health::observe_system_health_vc;
|
||||
use task_executor::TaskExecutor;
|
||||
use types::{ChainSpec, ConfigAndPreset, EthSpec};
|
||||
use validator_dir::Builder as ValidatorDirBuilder;
|
||||
@@ -183,6 +186,35 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
let api_token_path_inner = api_token_path.clone();
|
||||
let api_token_path_filter = warp::any().map(move || api_token_path_inner.clone());
|
||||
|
||||
// Create a `warp` filter that provides access to local system information.
|
||||
let system_info = Arc::new(RwLock::new(sysinfo::System::new()));
|
||||
{
|
||||
// grab write access for initialisation
|
||||
let mut system_info = system_info.write();
|
||||
system_info.refresh_disks_list();
|
||||
system_info.refresh_networks_list();
|
||||
} // end lock
|
||||
|
||||
let system_info_filter =
|
||||
warp::any()
|
||||
.map(move || system_info.clone())
|
||||
.map(|sysinfo: Arc<RwLock<System>>| {
|
||||
{
|
||||
// refresh stats
|
||||
let mut sysinfo_lock = sysinfo.write();
|
||||
sysinfo_lock.refresh_memory();
|
||||
sysinfo_lock.refresh_cpu_specifics(sysinfo::CpuRefreshKind::everything());
|
||||
sysinfo_lock.refresh_cpu();
|
||||
sysinfo_lock.refresh_system();
|
||||
sysinfo_lock.refresh_networks();
|
||||
sysinfo_lock.refresh_disks();
|
||||
} // end lock
|
||||
sysinfo
|
||||
});
|
||||
|
||||
let app_start = std::time::Instant::now();
|
||||
let app_start_filter = warp::any().map(move || app_start);
|
||||
|
||||
// GET lighthouse/version
|
||||
let get_node_version = warp::path("lighthouse")
|
||||
.and(warp::path("version"))
|
||||
@@ -279,6 +311,24 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
},
|
||||
);
|
||||
|
||||
// GET lighthouse/ui/health
|
||||
let get_lighthouse_ui_health = warp::path("lighthouse")
|
||||
.and(warp::path("ui"))
|
||||
.and(warp::path("health"))
|
||||
.and(warp::path::end())
|
||||
.and(system_info_filter)
|
||||
.and(app_start_filter)
|
||||
.and(validator_dir_filter.clone())
|
||||
.and(signer.clone())
|
||||
.and_then(|sysinfo, app_start: std::time::Instant, val_dir, signer| {
|
||||
blocking_signed_json_task(signer, move || {
|
||||
let app_uptime = app_start.elapsed().as_secs() as u64;
|
||||
Ok(api_types::GenericResponse::from(observe_system_health_vc(
|
||||
sysinfo, val_dir, app_uptime,
|
||||
)))
|
||||
})
|
||||
});
|
||||
|
||||
// POST lighthouse/validators/
|
||||
let post_validators = warp::path("lighthouse")
|
||||
.and(warp::path("validators"))
|
||||
@@ -894,6 +944,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
.or(get_lighthouse_spec)
|
||||
.or(get_lighthouse_validators)
|
||||
.or(get_lighthouse_validators_pubkey)
|
||||
.or(get_lighthouse_ui_health)
|
||||
.or(get_fee_recipient)
|
||||
.or(get_gas_limit)
|
||||
.or(get_std_keystores)
|
||||
|
||||
@@ -174,39 +174,40 @@ impl<T: SlotClock + 'static, E: EthSpec> SyncCommitteeService<T, E> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Fetch `block_root` and `execution_optimistic` for `SyncCommitteeContribution`.
|
||||
// Fetch `block_root` with non optimistic execution for `SyncCommitteeContribution`.
|
||||
let response = self
|
||||
.beacon_nodes
|
||||
.first_success(RequireSynced::Yes, OfflineOnFailure::Yes,|beacon_node| async move {
|
||||
beacon_node.get_beacon_blocks_root(BlockId::Head).await
|
||||
})
|
||||
.await
|
||||
.map_err(|e| e.to_string())?
|
||||
.ok_or_else(|| format!("No block root found for slot {}", slot))?;
|
||||
.first_success(
|
||||
RequireSynced::Yes,
|
||||
OfflineOnFailure::Yes,
|
||||
|beacon_node| async move {
|
||||
match beacon_node.get_beacon_blocks_root(BlockId::Head).await {
|
||||
Ok(Some(block)) if block.execution_optimistic == Some(false) => {
|
||||
Ok(block)
|
||||
}
|
||||
Ok(Some(_)) => {
|
||||
Err(format!("To sign sync committee messages for slot {slot} a non-optimistic head block is required"))
|
||||
}
|
||||
Ok(None) => Err(format!("No block root found for slot {}", slot)),
|
||||
Err(e) => Err(e.to_string()),
|
||||
}
|
||||
},
|
||||
)
|
||||
.await;
|
||||
|
||||
let block_root = response.data.root;
|
||||
if let Some(execution_optimistic) = response.execution_optimistic {
|
||||
if execution_optimistic {
|
||||
let block_root = match response {
|
||||
Ok(block) => block.data.root,
|
||||
Err(errs) => {
|
||||
warn!(
|
||||
log,
|
||||
"Refusing to sign sync committee messages for optimistic head block";
|
||||
"Refusing to sign sync committee messages for an optimistic head block or \
|
||||
a block head with unknown optimistic status";
|
||||
"errors" => errs.to_string(),
|
||||
"slot" => slot,
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
} else if let Some(bellatrix_fork_epoch) = self.duties_service.spec.bellatrix_fork_epoch {
|
||||
// If the slot is post Bellatrix, do not sign messages when we cannot verify the
|
||||
// optimistic status of the head block.
|
||||
if slot.epoch(E::slots_per_epoch()) > bellatrix_fork_epoch {
|
||||
warn!(
|
||||
log,
|
||||
"Refusing to sign sync committee messages for a head block with an unknown \
|
||||
optimistic status";
|
||||
"slot" => slot,
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Spawn one task to publish all of the sync committee signatures.
|
||||
let validator_duties = slot_duties.duties;
|
||||
|
||||
Reference in New Issue
Block a user