From 3da4c02bb359960846387c9bcd635aa856af1774 Mon Sep 17 00:00:00 2001 From: Dustin Brody Date: Mon, 21 Oct 2019 10:11:54 +0200 Subject: [PATCH] implement beacon_current_live_validators and beacon_previous_live_validators metrics --- beacon_chain/beacon_node.nim | 2 -- beacon_chain/spec/state_transition_block.nim | 9 +++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/beacon_chain/beacon_node.nim b/beacon_chain/beacon_node.nim index d1ff9b4c4..f6805751b 100644 --- a/beacon_chain/beacon_node.nim +++ b/beacon_chain/beacon_node.nim @@ -27,8 +27,6 @@ declareGauge beacon_slot, "Latest slot of the beacon chain state" declareGauge beacon_head_slot, "Slot of the head block of the beacon chain" declareGauge beacon_head_root, "Root of the head block of the beacon chain" -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_exits, "Number of pending voluntary exits in local operation pool" # On slot declareCounter beacon_reorgs_total, "Total occurrences of reorganizations of the chain" # On fork choice diff --git a/beacon_chain/spec/state_transition_block.nim b/beacon_chain/spec/state_transition_block.nim index 45640ba74..1cbc3d93a 100644 --- a/beacon_chain/spec/state_transition_block.nim +++ b/beacon_chain/spec/state_transition_block.nim @@ -39,6 +39,8 @@ import # TODO - cleanup imports state_transition_helpers # 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 @@ -474,6 +476,13 @@ proc processBlock*( 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(toSet( + mapIt(state.current_epoch_attestations, it.proposerIndex)).len.int64) + beacon_previous_live_validators.set(toSet( + mapIt(state.previous_epoch_attestations, it.proposerIndex)).len.int64) + if not process_block_header(state, blck, flags, stateCache): notice "Block header not valid", slot = shortLog(state.slot) return false