-
-
Notifications
You must be signed in to change notification settings - Fork 287
/
metrics.ts
84 lines (75 loc) · 3.14 KB
/
metrics.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import {Epoch} from "@lodestar/types";
import {Gauge, Histogram} from "@lodestar/utils";
import {CachedBeaconStateAllForks} from "./types.js";
import {StateCloneSource, StateHashTreeRootSource} from "./stateTransition.js";
import {EpochTransitionStep} from "./epoch/index.js";
export type BeaconStateTransitionMetrics = {
epochTransitionTime: Histogram;
epochTransitionCommitTime: Histogram;
epochTransitionStepTime: Histogram<{step: EpochTransitionStep}>;
processBlockTime: Histogram;
processBlockCommitTime: Histogram;
stateHashTreeRootTime: Histogram<{source: StateHashTreeRootSource}>;
numEffectiveBalanceUpdates: Gauge;
preStateBalancesNodesPopulatedMiss: Gauge<{source: StateCloneSource}>;
preStateBalancesNodesPopulatedHit: Gauge<{source: StateCloneSource}>;
preStateValidatorsNodesPopulatedMiss: Gauge<{source: StateCloneSource}>;
preStateValidatorsNodesPopulatedHit: Gauge<{source: StateCloneSource}>;
preStateClonedCount: Histogram;
postStateBalancesNodesPopulatedMiss: Gauge;
postStateBalancesNodesPopulatedHit: Gauge;
postStateValidatorsNodesPopulatedMiss: Gauge;
postStateValidatorsNodesPopulatedHit: Gauge;
registerValidatorStatuses: (
currentEpoch: Epoch,
inclusionDelays: number[],
flags: number[],
isActiveCurrEpoch: boolean[],
isActivePrevEpoch: boolean[],
balances?: number[]
) => void;
};
export type EpochCacheMetrics = {
finalizedPubkeyDuplicateInsert: Gauge;
newUnFinalizedPubkey: Gauge;
};
export function onStateCloneMetrics(
state: CachedBeaconStateAllForks,
metrics: BeaconStateTransitionMetrics,
source: StateCloneSource
): void {
metrics.preStateClonedCount.observe(state.clonedCount);
if (isBalancesNodesPopulated(state)) {
metrics.preStateBalancesNodesPopulatedHit.inc({source});
} else {
metrics.preStateBalancesNodesPopulatedMiss.inc({source});
}
if (isValidatorsNodesPopulated(state)) {
metrics.preStateValidatorsNodesPopulatedHit.inc({source});
} else {
metrics.preStateValidatorsNodesPopulatedMiss.inc({source});
}
}
export function onPostStateMetrics(postState: CachedBeaconStateAllForks, metrics: BeaconStateTransitionMetrics): void {
if (isBalancesNodesPopulated(postState)) {
metrics.postStateBalancesNodesPopulatedHit.inc();
} else {
metrics.postStateBalancesNodesPopulatedMiss.inc();
}
if (isValidatorsNodesPopulated(postState)) {
metrics.postStateValidatorsNodesPopulatedHit.inc();
} else {
metrics.postStateValidatorsNodesPopulatedMiss.inc();
}
}
// Given a CachedBeaconState, check if validators array internal cache is populated.
// This cache is populated during epoch transition, and should be preserved for performance.
// If the cache is missing too often, means that our clone strategy is not working well.
function isValidatorsNodesPopulated(state: CachedBeaconStateAllForks): boolean {
// biome-ignore lint/complexity/useLiteralKeys: It is a private attribute
return state.validators["nodesPopulated"] === true;
}
function isBalancesNodesPopulated(state: CachedBeaconStateAllForks): boolean {
// biome-ignore lint/complexity/useLiteralKeys: It is a private attribute
return state.balances["nodesPopulated"] === true;
}