mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 04:01:51 +00:00
#7815 - removes all existing spans, so some span fields that appear in logs like `service_name` may be lost. - instruments a few key code paths in the beacon node, starting from **root spans** named below: * Gossip block and blobs * `process_gossip_data_column_sidecar` * `process_gossip_blob` * `process_gossip_block` * Rpc block and blobs * `process_rpc_block` * `process_rpc_blobs` * `process_rpc_custody_columns` * Rpc blocks (range and backfill) * `process_chain_segment` * `PendingComponents` lifecycle * `pending_components` To test locally: * Run Grafana and Tempo with https://github.com/sigp/lighthouse-metrics/pull/57 * Run Lighthouse BN with `--telemetry-collector-url http://localhost:4317` Some captured traces can be found here: https://hackmd.io/@jimmygchen/r1sLOxPPeg Removing the old spans seem to have reduced the memory usage quite a lot - i think we were using them on long running tasks and too excessively: <img width="910" height="495" alt="image" src="https://github.com/user-attachments/assets/5208bbe4-53b2-4ead-bc71-0b782c788669" />
79 lines
2.4 KiB
Rust
79 lines
2.4 KiB
Rust
#![deny(clippy::wildcard_imports)]
|
|
|
|
use crate::metrics;
|
|
pub use epoch_processing_summary::{EpochProcessingSummary, ParticipationEpochSummary};
|
|
use errors::EpochProcessingError as Error;
|
|
pub use justification_and_finalization_state::JustificationAndFinalizationState;
|
|
use safe_arith::SafeArith;
|
|
use tracing::instrument;
|
|
use types::{BeaconState, ChainSpec, EthSpec};
|
|
|
|
pub use registry_updates::{process_registry_updates, process_registry_updates_slow};
|
|
pub use slashings::{process_slashings, process_slashings_slow};
|
|
pub use weigh_justification_and_finalization::weigh_justification_and_finalization;
|
|
|
|
pub mod altair;
|
|
pub mod base;
|
|
pub mod capella;
|
|
pub mod effective_balance_updates;
|
|
pub mod epoch_processing_summary;
|
|
pub mod errors;
|
|
pub mod historical_roots_update;
|
|
pub mod justification_and_finalization_state;
|
|
pub mod registry_updates;
|
|
pub mod resets;
|
|
pub mod single_pass;
|
|
pub mod slashings;
|
|
pub mod tests;
|
|
pub mod weigh_justification_and_finalization;
|
|
|
|
/// Performs per-epoch processing on some BeaconState.
|
|
///
|
|
/// Mutates the given `BeaconState`, returning early if an error is encountered. If an error is
|
|
/// returned, a state might be "half-processed" and therefore in an invalid state.
|
|
#[instrument(skip_all)]
|
|
pub fn process_epoch<E: EthSpec>(
|
|
state: &mut BeaconState<E>,
|
|
spec: &ChainSpec,
|
|
) -> Result<EpochProcessingSummary<E>, Error> {
|
|
let _timer = metrics::start_timer(&metrics::PROCESS_EPOCH_TIME);
|
|
|
|
// Verify that the `BeaconState` instantiation matches the fork at `state.slot()`.
|
|
state
|
|
.fork_name(spec)
|
|
.map_err(Error::InconsistentStateFork)?;
|
|
|
|
if state.fork_name_unchecked().altair_enabled() {
|
|
altair::process_epoch(state, spec)
|
|
} else {
|
|
base::process_epoch(state, spec)
|
|
}
|
|
}
|
|
|
|
/// Used to track the changes to a validator's balance.
|
|
#[derive(Default, Clone)]
|
|
pub struct Delta {
|
|
pub rewards: u64,
|
|
pub penalties: u64,
|
|
}
|
|
|
|
impl Delta {
|
|
/// Reward the validator with the `reward`.
|
|
pub fn reward(&mut self, reward: u64) -> Result<(), Error> {
|
|
self.rewards = self.rewards.safe_add(reward)?;
|
|
Ok(())
|
|
}
|
|
|
|
/// Penalize the validator with the `penalty`.
|
|
pub fn penalize(&mut self, penalty: u64) -> Result<(), Error> {
|
|
self.penalties = self.penalties.safe_add(penalty)?;
|
|
Ok(())
|
|
}
|
|
|
|
/// Combine two deltas.
|
|
fn combine(&mut self, other: Delta) -> Result<(), Error> {
|
|
self.reward(other.rewards)?;
|
|
self.penalize(other.penalties)
|
|
}
|
|
}
|