diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 8f1908e80..227813380 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -1976,10 +1976,22 @@ impl BeaconChain { drop(validator_monitor); - metrics::observe( - &metrics::OPERATIONS_PER_BLOCK_ATTESTATION, - block.body().attestations().len() as f64, - ); + // Only present some metrics for blocks from the previous epoch or later. + // + // This helps avoid noise in the metrics during sync. + if block.slot().epoch(T::EthSpec::slots_per_epoch()) + 1 >= self.epoch()? { + metrics::observe( + &metrics::OPERATIONS_PER_BLOCK_ATTESTATION, + block.body().attestations().len() as f64, + ); + + if let Some(sync_aggregate) = block.body().sync_aggregate() { + metrics::set_gauge( + &metrics::BLOCK_SYNC_AGGREGATE_SET_BITS, + sync_aggregate.num_set_bits() as i64, + ); + } + } let db_write_timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_DB_WRITE); diff --git a/beacon_node/beacon_chain/src/metrics.rs b/beacon_node/beacon_chain/src/metrics.rs index fd79c0e66..314d1c482 100644 --- a/beacon_node/beacon_chain/src/metrics.rs +++ b/beacon_node/beacon_chain/src/metrics.rs @@ -54,6 +54,10 @@ lazy_static! { "beacon_block_processing_attestation_observation_seconds", "Time spent hashing and remembering all the attestations in the block" ); + pub static ref BLOCK_SYNC_AGGREGATE_SET_BITS: Result = try_create_int_gauge( + "block_sync_aggregate_set_bits", + "The number of true bits in the last sync aggregate in a block" + ); /* * Block Production diff --git a/consensus/types/src/beacon_block_body.rs b/consensus/types/src/beacon_block_body.rs index 1924ca14f..ceb90fef9 100644 --- a/consensus/types/src/beacon_block_body.rs +++ b/consensus/types/src/beacon_block_body.rs @@ -45,6 +45,16 @@ pub struct BeaconBlockBody { pub sync_aggregate: SyncAggregate, } +impl<'a, T: EthSpec> BeaconBlockBodyRef<'a, T> { + /// Access the sync aggregate from the block's body, if one exists. + pub fn sync_aggregate(self) -> Option<&'a SyncAggregate> { + match self { + BeaconBlockBodyRef::Base(_) => None, + BeaconBlockBodyRef::Altair(inner) => Some(&inner.sync_aggregate), + } + } +} + #[cfg(test)] mod tests { mod base { diff --git a/consensus/types/src/sync_aggregate.rs b/consensus/types/src/sync_aggregate.rs index 85547e1b0..ea2298d23 100644 --- a/consensus/types/src/sync_aggregate.rs +++ b/consensus/types/src/sync_aggregate.rs @@ -33,4 +33,9 @@ impl SyncAggregate { sync_committee_signature: AggregateSignature::empty(), } } + + /// Returns how many bits are `true` in `self.sync_committee_bits`. + pub fn num_set_bits(&self) -> usize { + self.sync_committee_bits.num_set_bits() + } }