harden beacon_pending_deposits metrics calculation against overflow (#1566)

* harden beacon_pending_deposits metrics calculation

* ...

* move beacon_pending_deposits and beacon_processed_deposits_total out of specs and into chain DAG
This commit is contained in:
tersec 2020-08-26 15:25:39 +00:00 committed by GitHub
parent b525dc9450
commit 83667dddfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 9 deletions

View File

@ -26,6 +26,9 @@ declareCounter beacon_state_data_cache_hits, "EpochRef hits"
declareCounter beacon_state_data_cache_misses, "EpochRef misses"
declareCounter beacon_state_rewinds, "State database rewinds"
declareGauge beacon_pending_deposits, "Number of pending deposits (state.eth1_data.deposit_count - state.eth1_deposit_index)" # On block
declareGauge beacon_processed_deposits_total, "Number of total deposits included on chain" # On block
logScope: topics = "chaindag"
proc putBlock*(
@ -747,6 +750,14 @@ proc updateHead*(dag: ChainDAGRef, newHead: BlockRef) =
finalizedHead = newHead.atEpochStart(
dag.headState.data.data.finalized_checkpoint.epoch)
# https://github.com/ethereum/eth2.0-metrics/blob/master/metrics.md#additional-metrics
if dag.headState.data.data.eth1_data.deposit_count < high(int64).uint64:
beacon_pending_deposits.set(
dag.headState.data.data.eth1_data.deposit_count.int64 -
dag.headState.data.data.eth1_deposit_index.int64)
beacon_processed_deposits_total.set(
dag.headState.data.data.eth1_deposit_index.int64)
doAssert (not finalizedHead.blck.isNil),
"Block graph should always lead to a finalized block"

View File

@ -37,8 +37,6 @@ import
# https://github.com/ethereum/eth2.0-metrics/blob/master/metrics.md#additional-metrics
declareGauge beacon_current_live_validators, "Number of active validators that successfully included attestation on chain for current epoch" # On block
declareGauge beacon_previous_live_validators, "Number of active validators that successfully included attestation on chain for previous epoch" # On block
declareGauge beacon_pending_deposits, "Number of pending deposits (state.eth1_data.deposit_count - state.eth1_deposit_index)" # On block
declareGauge beacon_processed_deposits_total, "Number of total deposits included on chain" # On block
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#block-header
func process_block_header*(
@ -326,13 +324,6 @@ proc process_block*(
# TODO when there's a failure, we should reset the state!
# TODO probably better to do all verification first, then apply state changes
# https://github.com/ethereum/eth2.0-metrics/blob/master/metrics.md#additional-metrics
# doesn't seem to specify at what point in block processing this metric is to be read,
# and this avoids the early-return issue (could also use defer, etc).
beacon_pending_deposits.set(
state.eth1_data.deposit_count.int64 - state.eth1_deposit_index.int64)
beacon_processed_deposits_total.set(state.eth1_deposit_index.int64)
# Adds nontrivial additional computation, but only does so when metrics
# enabled.
beacon_current_live_validators.set(toHashSet(