@aztec/validator-ha-signer 0.0.1-commit.f504929 → 0.0.1-commit.f81dbcf

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/metrics.ts DELETED
@@ -1,138 +0,0 @@
1
- import {
2
- Attributes,
3
- type Histogram,
4
- Metrics,
5
- type TelemetryClient,
6
- type UpDownCounter,
7
- createUpDownCounterWithDefault,
8
- } from '@aztec/telemetry-client';
9
-
10
- export type HACleanupType = 'stuck' | 'old' | 'outdated_rollup';
11
-
12
- /**
13
- * Metrics for HA signer tracking signing operations, lock acquisition, and cleanup.
14
- */
15
- export class HASignerMetrics {
16
- // Signing lifecycle metrics
17
- private signingDuration: Histogram;
18
- private signingSuccessCount: UpDownCounter;
19
- private dutyAlreadySignedCount: UpDownCounter;
20
- private slashingProtectionCount: UpDownCounter;
21
- private signingErrorCount: UpDownCounter;
22
-
23
- // Lock acquisition metrics
24
- private lockAcquiredCount: UpDownCounter;
25
-
26
- // Cleanup metrics
27
- private cleanupStuckDutiesCount: UpDownCounter;
28
- private cleanupOldDutiesCount: UpDownCounter;
29
- private cleanupOutdatedRollupDutiesCount: UpDownCounter;
30
-
31
- constructor(
32
- client: TelemetryClient,
33
- private nodeId: string,
34
- name = 'HASignerMetrics',
35
- ) {
36
- const meter = client.getMeter(name);
37
-
38
- // Signing lifecycle
39
- this.signingDuration = meter.createHistogram(Metrics.HA_SIGNER_SIGNING_DURATION);
40
- this.signingSuccessCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_SIGNING_SUCCESS_COUNT);
41
- this.dutyAlreadySignedCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_DUTY_ALREADY_SIGNED_COUNT);
42
- this.slashingProtectionCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_SLASHING_PROTECTION_COUNT);
43
- this.signingErrorCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_SIGNING_ERROR_COUNT);
44
-
45
- // Lock acquisition
46
- this.lockAcquiredCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_LOCK_ACQUIRED_COUNT);
47
-
48
- // Cleanup
49
- this.cleanupStuckDutiesCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_CLEANUP_STUCK_DUTIES_COUNT);
50
- this.cleanupOldDutiesCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_CLEANUP_OLD_DUTIES_COUNT);
51
- this.cleanupOutdatedRollupDutiesCount = createUpDownCounterWithDefault(
52
- meter,
53
- Metrics.HA_SIGNER_CLEANUP_OUTDATED_ROLLUP_DUTIES_COUNT,
54
- );
55
- }
56
-
57
- /**
58
- * Record a successful signing operation.
59
- * @param dutyType - The type of duty signed
60
- * @param durationMs - Duration from start of signWithProtection to completion
61
- */
62
- public recordSigningSuccess(dutyType: string, durationMs: number): void {
63
- const attributes = {
64
- [Attributes.HA_DUTY_TYPE]: dutyType,
65
- [Attributes.HA_NODE_ID]: this.nodeId,
66
- };
67
- this.signingSuccessCount.add(1, attributes);
68
- this.signingDuration.record(durationMs, attributes);
69
- }
70
-
71
- /**
72
- * Record a DutyAlreadySignedError (expected in HA; another node signed first).
73
- * @param dutyType - The type of duty
74
- */
75
- public recordDutyAlreadySigned(dutyType: string): void {
76
- const attributes = {
77
- [Attributes.HA_DUTY_TYPE]: dutyType,
78
- [Attributes.HA_NODE_ID]: this.nodeId,
79
- };
80
- this.dutyAlreadySignedCount.add(1, attributes);
81
- }
82
-
83
- /**
84
- * Record a SlashingProtectionError (attempted to sign different data for same duty).
85
- * @param dutyType - The type of duty
86
- */
87
- public recordSlashingProtection(dutyType: string): void {
88
- const attributes = {
89
- [Attributes.HA_DUTY_TYPE]: dutyType,
90
- [Attributes.HA_NODE_ID]: this.nodeId,
91
- };
92
- this.slashingProtectionCount.add(1, attributes);
93
- }
94
-
95
- /**
96
- * Record a signing function failure (lock will be deleted for retry).
97
- * @param dutyType - The type of duty
98
- */
99
- public recordSigningError(dutyType: string): void {
100
- const attributes = {
101
- [Attributes.HA_DUTY_TYPE]: dutyType,
102
- [Attributes.HA_NODE_ID]: this.nodeId,
103
- };
104
- this.signingErrorCount.add(1, attributes);
105
- }
106
-
107
- /**
108
- * Record lock acquisition.
109
- * @param acquired - Whether a new lock was acquired (true) or existing record found (false)
110
- */
111
- public recordLockAcquire(acquired: boolean): void {
112
- if (acquired) {
113
- const attributes = {
114
- [Attributes.HA_NODE_ID]: this.nodeId,
115
- };
116
- this.lockAcquiredCount.add(1, attributes);
117
- }
118
- }
119
-
120
- /**
121
- * Record cleanup metrics.
122
- * @param type - Type of cleanup
123
- * @param count - Number of duties cleaned up
124
- */
125
- public recordCleanup(type: HACleanupType, count: number): void {
126
- const attributes = {
127
- [Attributes.HA_NODE_ID]: this.nodeId,
128
- };
129
-
130
- if (type === 'stuck') {
131
- this.cleanupStuckDutiesCount.add(count, attributes);
132
- } else if (type === 'old') {
133
- this.cleanupOldDutiesCount.add(count, attributes);
134
- } else if (type === 'outdated_rollup') {
135
- this.cleanupOutdatedRollupDutiesCount.add(count, attributes);
136
- }
137
- }
138
- }