Skip to content

Commit

Permalink
Fix db query and add some additional metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
eserilev committed Oct 24, 2024
1 parent 40d3423 commit 074ba18
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
13 changes: 8 additions & 5 deletions beacon_node/beacon_chain/src/light_client_server_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ impl<T: BeaconChainTypes> LightClientServerCache<T> {
log: &Logger,
chain_spec: &ChainSpec,
) -> Result<(), BeaconChainError> {
metrics::inc_counter(&metrics::LIGHT_CLIENT_SERVER_CACHE_PROCESSING_REQUESTS);
let _timer =
metrics::start_timer(&metrics::LIGHT_CLIENT_SERVER_CACHE_RECOMPUTE_UPDATES_TIMES);

Expand Down Expand Up @@ -214,6 +215,7 @@ impl<T: BeaconChainTypes> LightClientServerCache<T> {
*self.latest_light_client_update.write() = Some(new_light_client_update);
}

metrics::inc_counter(&metrics::LIGHT_CLIENT_SERVER_CACHE_PROCESSING_SUCCESSES);
Ok(())
}

Expand Down Expand Up @@ -289,6 +291,11 @@ impl<T: BeaconChainTypes> LightClientServerCache<T> {
let (sync_committee_bytes, light_client_update_bytes) = res?;
let sync_committee_period = u64::from_ssz_bytes(&sync_committee_bytes)
.map_err(store::errors::Error::SszDecodeError)?;

if sync_committee_period >= start_period + count {
break;
}

let epoch = sync_committee_period
.safe_mul(chain_spec.epochs_per_sync_committee_period.into())?;

Expand All @@ -297,12 +304,8 @@ impl<T: BeaconChainTypes> LightClientServerCache<T> {
let light_client_update =
LightClientUpdate::from_ssz_bytes(&light_client_update_bytes, &fork_name)
.map_err(store::errors::Error::SszDecodeError)?;

light_client_updates.push(light_client_update);

if sync_committee_period >= start_period + count {
break;
}
}
Ok(light_client_updates)
}
Expand Down
16 changes: 16 additions & 0 deletions beacon_node/beacon_chain/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1937,6 +1937,22 @@ pub static LIGHT_CLIENT_SERVER_CACHE_PREV_BLOCK_CACHE_MISS: LazyLock<Result<IntC
)
});

pub static LIGHT_CLIENT_SERVER_CACHE_PROCESSING_REQUESTS: LazyLock<Result<IntCounter>> =
LazyLock::new(|| {
try_create_int_counter(
"light_client_server_cache_processing_requests",
"Count of all requests to recompute and cache updates",
)
});

pub static LIGHT_CLIENT_SERVER_CACHE_PROCESSING_SUCCESSES: LazyLock<Result<IntCounter>> =
LazyLock::new(|| {
try_create_int_counter(
"light_client_server_cache_processing_successes",
"Count of all successful requests to recompute and cache updates",
)
});

/// Scrape the `beacon_chain` for metrics that are not constantly updated (e.g., the present slot,
/// head state info, etc) and update the Prometheus `DEFAULT_REGISTRY`.
pub fn scrape_for_metrics<T: BeaconChainTypes>(beacon_chain: &BeaconChain<T>) {
Expand Down

0 comments on commit 074ba18

Please sign in to comment.