Merge unstable

This commit is contained in:
Eitan Seri-Levi
2025-02-02 00:18:00 +03:00
340 changed files with 10457 additions and 4957 deletions

View File

@@ -17,6 +17,7 @@ pub mod types;
use self::mixin::{RequestAccept, ResponseOptional};
use self::types::{Error as ResponseError, *};
use derivative::Derivative;
use either::Either;
use futures::Stream;
use futures_util::StreamExt;
use lighthouse_network::PeerId;
@@ -1330,7 +1331,7 @@ impl BeaconNodeHttpClient {
/// `POST v2/beacon/pool/attestations`
pub async fn post_beacon_pool_attestations_v2<E: EthSpec>(
&self,
attestations: &[Attestation<E>],
attestations: Either<Vec<Attestation<E>>, Vec<SingleAttestation>>,
fork_name: ForkName,
) -> Result<(), Error> {
let mut path = self.eth_path(V2)?;
@@ -1341,13 +1342,26 @@ impl BeaconNodeHttpClient {
.push("pool")
.push("attestations");
self.post_with_timeout_and_consensus_header(
path,
&attestations,
self.timeouts.attestation,
fork_name,
)
.await?;
match attestations {
Either::Right(attestations) => {
self.post_with_timeout_and_consensus_header(
path,
&attestations,
self.timeouts.attestation,
fork_name,
)
.await?;
}
Either::Left(attestations) => {
self.post_with_timeout_and_consensus_header(
path,
&attestations,
self.timeouts.attestation,
fork_name,
)
.await?;
}
};
Ok(())
}

View File

@@ -88,12 +88,6 @@ pub struct ValidatorInclusionData {
pub is_previous_epoch_head_attester: bool,
}
#[cfg(target_os = "linux")]
use {
psutil::cpu::os::linux::CpuTimesExt, psutil::memory::os::linux::VirtualMemoryExt,
psutil::process::Process,
};
/// Reports on the health of the Lighthouse instance.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Health {
@@ -164,69 +158,6 @@ pub struct SystemHealth {
pub misc_os: String,
}
impl SystemHealth {
#[cfg(not(target_os = "linux"))]
pub fn observe() -> Result<Self, String> {
Err("Health is only available on Linux".into())
}
#[cfg(target_os = "linux")]
pub fn observe() -> Result<Self, String> {
let vm = psutil::memory::virtual_memory()
.map_err(|e| format!("Unable to get virtual memory: {:?}", e))?;
let loadavg =
psutil::host::loadavg().map_err(|e| format!("Unable to get loadavg: {:?}", e))?;
let cpu =
psutil::cpu::cpu_times().map_err(|e| format!("Unable to get cpu times: {:?}", e))?;
let disk_usage = psutil::disk::disk_usage("/")
.map_err(|e| format!("Unable to disk usage info: {:?}", e))?;
let disk = psutil::disk::DiskIoCountersCollector::default()
.disk_io_counters()
.map_err(|e| format!("Unable to get disk counters: {:?}", e))?;
let net = psutil::network::NetIoCountersCollector::default()
.net_io_counters()
.map_err(|e| format!("Unable to get network io counters: {:?}", e))?;
let boot_time = psutil::host::boot_time()
.map_err(|e| format!("Unable to get system boot time: {:?}", e))?
.duration_since(std::time::UNIX_EPOCH)
.map_err(|e| format!("Boot time is lower than unix epoch: {}", e))?
.as_secs();
Ok(Self {
sys_virt_mem_total: vm.total(),
sys_virt_mem_available: vm.available(),
sys_virt_mem_used: vm.used(),
sys_virt_mem_free: vm.free(),
sys_virt_mem_cached: vm.cached(),
sys_virt_mem_buffers: vm.buffers(),
sys_virt_mem_percent: vm.percent(),
sys_loadavg_1: loadavg.one,
sys_loadavg_5: loadavg.five,
sys_loadavg_15: loadavg.fifteen,
cpu_cores: psutil::cpu::cpu_count_physical(),
cpu_threads: psutil::cpu::cpu_count(),
system_seconds_total: cpu.system().as_secs(),
cpu_time_total: cpu.total().as_secs(),
user_seconds_total: cpu.user().as_secs(),
iowait_seconds_total: cpu.iowait().as_secs(),
idle_seconds_total: cpu.idle().as_secs(),
disk_node_bytes_total: disk_usage.total(),
disk_node_bytes_free: disk_usage.free(),
disk_node_reads_total: disk.read_count(),
disk_node_writes_total: disk.write_count(),
network_node_bytes_total_received: net.bytes_recv(),
network_node_bytes_total_transmit: net.bytes_sent(),
misc_node_boot_ts_seconds: boot_time,
misc_os: std::env::consts::OS.to_string(),
})
}
}
/// Process specific health
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ProcessHealth {
@@ -244,59 +175,6 @@ pub struct ProcessHealth {
pub pid_process_seconds_total: u64,
}
impl ProcessHealth {
#[cfg(not(target_os = "linux"))]
pub fn observe() -> Result<Self, String> {
Err("Health is only available on Linux".into())
}
#[cfg(target_os = "linux")]
pub fn observe() -> Result<Self, String> {
let process =
Process::current().map_err(|e| format!("Unable to get current process: {:?}", e))?;
let process_mem = process
.memory_info()
.map_err(|e| format!("Unable to get process memory info: {:?}", e))?;
let me = procfs::process::Process::myself()
.map_err(|e| format!("Unable to get process: {:?}", e))?;
let stat = me
.stat()
.map_err(|e| format!("Unable to get stat: {:?}", e))?;
let process_times = process
.cpu_times()
.map_err(|e| format!("Unable to get process cpu times : {:?}", e))?;
Ok(Self {
pid: process.pid(),
pid_num_threads: stat.num_threads,
pid_mem_resident_set_size: process_mem.rss(),
pid_mem_virtual_memory_size: process_mem.vms(),
pid_mem_shared_memory_size: process_mem.shared(),
pid_process_seconds_total: process_times.busy().as_secs()
+ process_times.children_system().as_secs()
+ process_times.children_system().as_secs(),
})
}
}
impl Health {
#[cfg(not(target_os = "linux"))]
pub fn observe() -> Result<Self, String> {
Err("Health is only available on Linux".into())
}
#[cfg(target_os = "linux")]
pub fn observe() -> Result<Self, String> {
Ok(Self {
process: ProcessHealth::observe()?,
system: SystemHealth::observe()?,
})
}
}
/// Indicates how up-to-date the Eth1 caches are.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Eth1SyncStatusData {

View File

@@ -584,12 +584,20 @@ pub struct IdentityData {
pub metadata: MetaData,
}
#[superstruct(
variants(V2, V3),
variant_attributes(derive(Clone, Debug, PartialEq, Serialize, Deserialize))
)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub struct MetaData {
#[serde(with = "serde_utils::quoted_u64")]
pub seq_number: u64,
pub attnets: String,
pub syncnets: String,
#[superstruct(only(V3))]
#[serde(with = "serde_utils::quoted_u64")]
pub custody_group_count: u64,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
@@ -1091,6 +1099,9 @@ impl ForkVersionDeserialize for SsePayloadAttributes {
ForkName::Electra => serde_json::from_value(value)
.map(Self::V3)
.map_err(serde::de::Error::custom),
ForkName::Fulu => serde_json::from_value(value)
.map(Self::V3)
.map_err(serde::de::Error::custom),
ForkName::Base | ForkName::Altair => Err(serde::de::Error::custom(format!(
"SsePayloadAttributes deserialization for {fork_name} not implemented"
))),
@@ -1123,6 +1134,7 @@ impl ForkVersionDeserialize for SseExtendedPayloadAttributes {
#[serde(bound = "E: EthSpec", untagged)]
pub enum EventKind<E: EthSpec> {
Attestation(Box<Attestation<E>>),
SingleAttestation(Box<SingleAttestation>),
Block(SseBlock),
BlobSidecar(SseBlobSidecar),
FinalizedCheckpoint(SseFinalizedCheckpoint),
@@ -1149,6 +1161,7 @@ impl<E: EthSpec> EventKind<E> {
EventKind::Block(_) => "block",
EventKind::BlobSidecar(_) => "blob_sidecar",
EventKind::Attestation(_) => "attestation",
EventKind::SingleAttestation(_) => "single_attestation",
EventKind::VoluntaryExit(_) => "voluntary_exit",
EventKind::FinalizedCheckpoint(_) => "finalized_checkpoint",
EventKind::ChainReorg(_) => "chain_reorg",
@@ -1171,6 +1184,11 @@ impl<E: EthSpec> EventKind<E> {
"attestation" => Ok(EventKind::Attestation(serde_json::from_str(data).map_err(
|e| ServerError::InvalidServerSentEvent(format!("Attestation: {:?}", e)),
)?)),
"single_attestation" => Ok(EventKind::SingleAttestation(
serde_json::from_str(data).map_err(|e| {
ServerError::InvalidServerSentEvent(format!("SingleAttestation: {:?}", e))
})?,
)),
"block" => Ok(EventKind::Block(serde_json::from_str(data).map_err(
|e| ServerError::InvalidServerSentEvent(format!("Block: {:?}", e)),
)?)),
@@ -1265,6 +1283,7 @@ pub enum EventTopic {
Block,
BlobSidecar,
Attestation,
SingleAttestation,
VoluntaryExit,
FinalizedCheckpoint,
ChainReorg,
@@ -1290,6 +1309,7 @@ impl FromStr for EventTopic {
"block" => Ok(EventTopic::Block),
"blob_sidecar" => Ok(EventTopic::BlobSidecar),
"attestation" => Ok(EventTopic::Attestation),
"single_attestation" => Ok(EventTopic::SingleAttestation),
"voluntary_exit" => Ok(EventTopic::VoluntaryExit),
"finalized_checkpoint" => Ok(EventTopic::FinalizedCheckpoint),
"chain_reorg" => Ok(EventTopic::ChainReorg),
@@ -1316,6 +1336,7 @@ impl fmt::Display for EventTopic {
EventTopic::Block => write!(f, "block"),
EventTopic::BlobSidecar => write!(f, "blob_sidecar"),
EventTopic::Attestation => write!(f, "attestation"),
EventTopic::SingleAttestation => write!(f, "single_attestation"),
EventTopic::VoluntaryExit => write!(f, "voluntary_exit"),
EventTopic::FinalizedCheckpoint => write!(f, "finalized_checkpoint"),
EventTopic::ChainReorg => write!(f, "chain_reorg"),
@@ -1874,14 +1895,10 @@ impl<E: EthSpec> PublishBlockRequest<E> {
impl<E: EthSpec> TryFrom<Arc<SignedBeaconBlock<E>>> for PublishBlockRequest<E> {
type Error = &'static str;
fn try_from(block: Arc<SignedBeaconBlock<E>>) -> Result<Self, Self::Error> {
match *block {
SignedBeaconBlock::Base(_)
| SignedBeaconBlock::Altair(_)
| SignedBeaconBlock::Bellatrix(_)
| SignedBeaconBlock::Capella(_) => Ok(PublishBlockRequest::Block(block)),
SignedBeaconBlock::Deneb(_) | SignedBeaconBlock::Electra(_) => Err(
"post-Deneb block contents cannot be fully constructed from just the signed block",
),
if block.message().fork_name_unchecked().deneb_enabled() {
Err("post-Deneb block contents cannot be fully constructed from just the signed block")
} else {
Ok(PublishBlockRequest::Block(block))
}
}
}
@@ -1985,16 +2002,18 @@ impl<E: EthSpec> ForkVersionDeserialize for FullPayloadContents<E> {
value: Value,
fork_name: ForkName,
) -> Result<Self, D::Error> {
match fork_name {
ForkName::Bellatrix | ForkName::Capella => serde_json::from_value(value)
.map(Self::Payload)
.map_err(serde::de::Error::custom),
ForkName::Deneb | ForkName::Electra => serde_json::from_value(value)
if fork_name.deneb_enabled() {
serde_json::from_value(value)
.map(Self::PayloadAndBlobs)
.map_err(serde::de::Error::custom),
ForkName::Base | ForkName::Altair => Err(serde::de::Error::custom(format!(
.map_err(serde::de::Error::custom)
} else if fork_name.bellatrix_enabled() {
serde_json::from_value(value)
.map(Self::Payload)
.map_err(serde::de::Error::custom)
} else {
Err(serde::de::Error::custom(format!(
"FullPayloadContents deserialization for {fork_name} not implemented"
))),
)))
}
}
}