Skip to content

Commit

Permalink
Metrics for sync aggregate fullness (#2439)
Browse files Browse the repository at this point in the history
## Issue Addressed

NA

## Proposed Changes

Adds a metric to see how many set bits are in the sync aggregate for each beacon block being imported.

## Additional Info

NA
  • Loading branch information
paulhauner committed Jul 13, 2021
1 parent 27aec19 commit 9656ffe
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
20 changes: 16 additions & 4 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1976,10 +1976,22 @@ impl<T: BeaconChainTypes> BeaconChain<T> {

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);

Expand Down
4 changes: 4 additions & 0 deletions beacon_node/beacon_chain/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IntGauge> = try_create_int_gauge(
"block_sync_aggregate_set_bits",
"The number of true bits in the last sync aggregate in a block"
);

/*
* Block Production
Expand Down
10 changes: 10 additions & 0 deletions consensus/types/src/beacon_block_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ pub struct BeaconBlockBody<T: EthSpec> {
pub sync_aggregate: SyncAggregate<T>,
}

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<T>> {
match self {
BeaconBlockBodyRef::Base(_) => None,
BeaconBlockBodyRef::Altair(inner) => Some(&inner.sync_aggregate),
}
}
}

#[cfg(test)]
mod tests {
mod base {
Expand Down
5 changes: 5 additions & 0 deletions consensus/types/src/sync_aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ impl<T: EthSpec> SyncAggregate<T> {
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()
}
}

0 comments on commit 9656ffe

Please sign in to comment.