From dbb058682c7c3ddd7f71c33549fb0e62d9c54ccc Mon Sep 17 00:00:00 2001 From: cheatfate Date: Wed, 11 Nov 2020 14:14:09 +0200 Subject: [PATCH] Add beacon_attestation_sent_delay metric. --- beacon_chain/validator_duties.nim | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/beacon_chain/validator_duties.nim b/beacon_chain/validator_duties.nim index 62db3be15..5a214a344 100644 --- a/beacon_chain/validator_duties.nim +++ b/beacon_chain/validator_duties.nim @@ -28,8 +28,14 @@ import validator_slashing_protection # Metrics for tracking attestation and beacon block loss +const delayBuckets = [-Inf, -8.0, -4.0, -2.0, -1.0, -0.5, -0.1, -0.05, + 0.05, 0.1, 0.5, 1.0, 2.0, 4.0, 8.0, Inf] + declareCounter beacon_attestations_sent, "Number of beacon chain attestations sent by this peer" +declareHistogram beacon_attestation_sent_delay, + "Time(s) between slot start and attestation sent moment", + buckets = delayBuckets declareCounter beacon_blocks_proposed, "Number of beacon chain blocks sent by this peer" @@ -162,10 +168,23 @@ proc createAndSendAttestation(node: BeaconNode, if node.config.dumpEnabled: dump(node.config.dumpDirOutgoing, attestation.data, validator.pubKey) - notice "Attestation sent", - attestation = shortLog(attestation), - validator = shortLog(validator), - indexInCommittee = indexInCommittee + let wallTime = node.beaconClock.now() + let deadline = attestationData.slot.toBeaconTime() + + seconds(int(SECONDS_PER_SLOT div 3)) + + let (delayStr, delayMillis) = + if wallTime < deadline: + ("-" & $(deadline - wallTime), + -float(milliseconds(deadline - wallTime)) / 1000.0) + else: + ($(wallTime - deadline), + float(milliseconds(wallTime - deadline)) / 1000.0) + + notice "Attestation sent", attestation = shortLog(attestation), + validator = shortLog(validator), delay = delayStr, + indexInCommittee = indexInCommittee + + beacon_attestation_sent_delay.observe(delayMillis) proc makeBeaconBlockForHeadAndSlot*(node: BeaconNode, randao_reveal: ValidatorSig,