Skip to content

Commit

Permalink
Track attestation publish delay second in metric and log
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths committed Apr 10, 2022
1 parent a485015 commit 757863b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
24 changes: 15 additions & 9 deletions packages/lodestar/src/metrics/validatorMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,9 @@ export interface IValidatorMonitor {
registerValidatorStatuses(currentEpoch: Epoch, statuses: IAttesterStatus[], balances?: number[]): void;
registerBeaconBlock(src: OpSource, seenTimestampSec: Seconds, block: allForks.BeaconBlock): void;
submitUnaggregatedAttestation(indexedAttestation: IndexedAttestation, subnet: number, sentPeers: number): void;
registerUnaggregatedAttestation(
src: OpSource,
seenTimestampSec: Seconds,
indexedAttestation: IndexedAttestation
): void;
registerGossipUnaggregatedAttestation(seenTimestampSec: Seconds, indexedAttestation: IndexedAttestation): void;
submitAggregatedAttestation(indexedAttestation: IndexedAttestation, sentPeers: number): void;
registerAggregatedAttestation(
src: OpSource,
registerGossipAggregatedAttestation(
seenTimestampSec: Seconds,
signedAggregateAndProof: SignedAggregateAndProof,
indexedAttestation: IndexedAttestation
Expand Down Expand Up @@ -282,24 +277,29 @@ export function createValidatorMonitor(

submitUnaggregatedAttestation(indexedAttestation, subnet, sentPeers) {
const data = indexedAttestation.data;
// Returns the duration between when the attestation `data` could be produced (1/3rd through the slot) and `seenTimestamp`.
const delaySec = Math.floor(Date.now() / 1000) - (genesisTime + (data.slot + 1 / 3) * config.SECONDS_PER_SLOT);
for (const index of indexedAttestation.attestingIndices) {
const validator = validators.get(index);
if (validator) {
if (sentPeers <= 0) {
metrics.validatorMonitor.unaggregatedAttestationSubmittedSentPeers.observe({index}, sentPeers);
}
metrics.validatorMonitor.unaggregatedAttestationDelaySeconds.observe({src: OpSource.api, index}, delaySec);
logger.verbose("Local validator published unaggregated attestation", {
validatorIndex: validator.index,
slot: data.slot,
committeeIndex: data.index,
subnet,
sentPeers,
delaySec,
});
}
}
},

registerUnaggregatedAttestation(src, seenTimestampSec, indexedAttestation) {
registerGossipUnaggregatedAttestation(seenTimestampSec, indexedAttestation) {
const src = OpSource.gossip;
const data = indexedAttestation.data;
const epoch = computeEpochAtSlot(data.slot);
// Returns the duration between when the attestation `data` could be produced (1/3rd through the slot) and `seenTimestamp`.
Expand All @@ -320,20 +320,26 @@ export function createValidatorMonitor(

submitAggregatedAttestation(indexedAttestation, sentPeers) {
const data = indexedAttestation.data;
// Returns the duration between when a `AggregateAndproof` with `data` could be produced (2/3rd through the slot) and `seenTimestamp`.
const delaySec = Math.floor(Date.now() / 1000) - (genesisTime + (data.slot + 2 / 3) * config.SECONDS_PER_SLOT);

for (const index of indexedAttestation.attestingIndices) {
const validator = validators.get(index);
if (validator) {
metrics.validatorMonitor.aggregatedAttestationDelaySeconds.observe({src: OpSource.api, index}, delaySec);
logger.verbose("Local validator published aggregated attestation", {
validatorIndex: validator.index,
slot: data.slot,
committeeIndex: data.index,
sentPeers,
delaySec,
});
}
}
},

registerAggregatedAttestation(src, seenTimestampSec, signedAggregateAndProof, indexedAttestation) {
registerGossipAggregatedAttestation(seenTimestampSec, signedAggregateAndProof, indexedAttestation) {
const src = OpSource.gossip;
const data = indexedAttestation.data;
const epoch = computeEpochAtSlot(data.slot);
// Returns the duration between when a `AggregateAndproof` with `data` could be produced (2/3rd through the slot) and `seenTimestamp`.
Expand Down
9 changes: 2 additions & 7 deletions packages/lodestar/src/network/gossip/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,7 @@ export function getGossipHandlers(modules: ValidatorFnsModules, options: GossipH

// Handler
const {indexedAttestation, committeeIndices} = validationResult;
metrics?.registerAggregatedAttestation(
OpSource.gossip,
seenTimestampSec,
signedAggregateAndProof,
indexedAttestation
);
metrics?.registerGossipAggregatedAttestation(seenTimestampSec, signedAggregateAndProof, indexedAttestation);
const aggregatedAttestation = signedAggregateAndProof.message.aggregate;

chain.aggregatedAttestationPool.add(
Expand Down Expand Up @@ -206,7 +201,7 @@ export function getGossipHandlers(modules: ValidatorFnsModules, options: GossipH

// Handler
const {indexedAttestation} = validationResult;
metrics?.registerUnaggregatedAttestation(OpSource.gossip, seenTimestampSec, indexedAttestation);
metrics?.registerGossipUnaggregatedAttestation(seenTimestampSec, indexedAttestation);

// Node may be subscribe to extra subnets (long-lived random subnets). For those, validate the messages
// but don't import them, to save CPU and RAM
Expand Down

0 comments on commit 757863b

Please sign in to comment.