@aztec/validator-ha-signer 0.0.1-commit.ffe5b04ea → 0.0.1-commit.fff30aa

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.
Files changed (46) hide show
  1. package/README.md +2 -0
  2. package/dest/config.d.ts +101 -0
  3. package/dest/config.d.ts.map +1 -0
  4. package/dest/config.js +92 -0
  5. package/dest/db/in_memory.d.ts +20 -0
  6. package/dest/db/in_memory.d.ts.map +1 -0
  7. package/dest/db/in_memory.js +73 -0
  8. package/dest/db/index.d.ts +1 -2
  9. package/dest/db/index.d.ts.map +1 -1
  10. package/dest/db/index.js +0 -1
  11. package/dest/db/postgres.d.ts +2 -4
  12. package/dest/db/postgres.d.ts.map +1 -1
  13. package/dest/db/postgres.js +13 -13
  14. package/dest/db/types.d.ts +18 -37
  15. package/dest/db/types.d.ts.map +1 -1
  16. package/dest/db/types.js +15 -30
  17. package/dest/factory.d.ts +13 -18
  18. package/dest/factory.d.ts.map +1 -1
  19. package/dest/factory.js +22 -42
  20. package/dest/slashing_protection_service.d.ts +3 -12
  21. package/dest/slashing_protection_service.d.ts.map +1 -1
  22. package/dest/slashing_protection_service.js +6 -17
  23. package/dest/types.d.ts +70 -17
  24. package/dest/types.d.ts.map +1 -1
  25. package/dest/types.js +20 -3
  26. package/dest/validator_ha_signer.d.ts +4 -12
  27. package/dest/validator_ha_signer.d.ts.map +1 -1
  28. package/dest/validator_ha_signer.js +8 -16
  29. package/package.json +6 -10
  30. package/src/config.ts +149 -0
  31. package/src/db/in_memory.ts +107 -0
  32. package/src/db/index.ts +0 -1
  33. package/src/db/postgres.ts +11 -13
  34. package/src/db/types.ts +16 -61
  35. package/src/factory.ts +28 -53
  36. package/src/slashing_protection_service.ts +7 -28
  37. package/src/types.ts +104 -32
  38. package/src/validator_ha_signer.ts +12 -33
  39. package/dest/db/lmdb.d.ts +0 -66
  40. package/dest/db/lmdb.d.ts.map +0 -1
  41. package/dest/db/lmdb.js +0 -188
  42. package/dest/metrics.d.ts +0 -51
  43. package/dest/metrics.d.ts.map +0 -1
  44. package/dest/metrics.js +0 -103
  45. package/src/db/lmdb.ts +0 -264
  46. package/src/metrics.ts +0 -138
package/dest/metrics.d.ts DELETED
@@ -1,51 +0,0 @@
1
- import { type TelemetryClient } from '@aztec/telemetry-client';
2
- export type HACleanupType = 'stuck' | 'old' | 'outdated_rollup';
3
- /**
4
- * Metrics for HA signer tracking signing operations, lock acquisition, and cleanup.
5
- */
6
- export declare class HASignerMetrics {
7
- private nodeId;
8
- private signingDuration;
9
- private signingSuccessCount;
10
- private dutyAlreadySignedCount;
11
- private slashingProtectionCount;
12
- private signingErrorCount;
13
- private lockAcquiredCount;
14
- private cleanupStuckDutiesCount;
15
- private cleanupOldDutiesCount;
16
- private cleanupOutdatedRollupDutiesCount;
17
- constructor(client: TelemetryClient, nodeId: string, name?: string);
18
- /**
19
- * Record a successful signing operation.
20
- * @param dutyType - The type of duty signed
21
- * @param durationMs - Duration from start of signWithProtection to completion
22
- */
23
- recordSigningSuccess(dutyType: string, durationMs: number): void;
24
- /**
25
- * Record a DutyAlreadySignedError (expected in HA; another node signed first).
26
- * @param dutyType - The type of duty
27
- */
28
- recordDutyAlreadySigned(dutyType: string): void;
29
- /**
30
- * Record a SlashingProtectionError (attempted to sign different data for same duty).
31
- * @param dutyType - The type of duty
32
- */
33
- recordSlashingProtection(dutyType: string): void;
34
- /**
35
- * Record a signing function failure (lock will be deleted for retry).
36
- * @param dutyType - The type of duty
37
- */
38
- recordSigningError(dutyType: string): void;
39
- /**
40
- * Record lock acquisition.
41
- * @param acquired - Whether a new lock was acquired (true) or existing record found (false)
42
- */
43
- recordLockAcquire(acquired: boolean): void;
44
- /**
45
- * Record cleanup metrics.
46
- * @param type - Type of cleanup
47
- * @param count - Number of duties cleaned up
48
- */
49
- recordCleanup(type: HACleanupType, count: number): void;
50
- }
51
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib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AAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAMhD;IAED;;;OAGG;IACI,iBAAiB,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAOhD;IAED;;;;OAIG;IACI,aAAa,CAAC,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAY7D;CACF"}
package/dest/metrics.js DELETED
@@ -1,103 +0,0 @@
1
- import { Attributes, Metrics, createUpDownCounterWithDefault } from '@aztec/telemetry-client';
2
- /**
3
- * Metrics for HA signer tracking signing operations, lock acquisition, and cleanup.
4
- */ export class HASignerMetrics {
5
- nodeId;
6
- // Signing lifecycle metrics
7
- signingDuration;
8
- signingSuccessCount;
9
- dutyAlreadySignedCount;
10
- slashingProtectionCount;
11
- signingErrorCount;
12
- // Lock acquisition metrics
13
- lockAcquiredCount;
14
- // Cleanup metrics
15
- cleanupStuckDutiesCount;
16
- cleanupOldDutiesCount;
17
- cleanupOutdatedRollupDutiesCount;
18
- constructor(client, nodeId, name = 'HASignerMetrics'){
19
- this.nodeId = nodeId;
20
- const meter = client.getMeter(name);
21
- // Signing lifecycle
22
- this.signingDuration = meter.createHistogram(Metrics.HA_SIGNER_SIGNING_DURATION);
23
- this.signingSuccessCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_SIGNING_SUCCESS_COUNT);
24
- this.dutyAlreadySignedCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_DUTY_ALREADY_SIGNED_COUNT);
25
- this.slashingProtectionCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_SLASHING_PROTECTION_COUNT);
26
- this.signingErrorCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_SIGNING_ERROR_COUNT);
27
- // Lock acquisition
28
- this.lockAcquiredCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_LOCK_ACQUIRED_COUNT);
29
- // Cleanup
30
- this.cleanupStuckDutiesCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_CLEANUP_STUCK_DUTIES_COUNT);
31
- this.cleanupOldDutiesCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_CLEANUP_OLD_DUTIES_COUNT);
32
- this.cleanupOutdatedRollupDutiesCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_CLEANUP_OUTDATED_ROLLUP_DUTIES_COUNT);
33
- }
34
- /**
35
- * Record a successful signing operation.
36
- * @param dutyType - The type of duty signed
37
- * @param durationMs - Duration from start of signWithProtection to completion
38
- */ recordSigningSuccess(dutyType, durationMs) {
39
- const attributes = {
40
- [Attributes.HA_DUTY_TYPE]: dutyType,
41
- [Attributes.HA_NODE_ID]: this.nodeId
42
- };
43
- this.signingSuccessCount.add(1, attributes);
44
- this.signingDuration.record(durationMs, attributes);
45
- }
46
- /**
47
- * Record a DutyAlreadySignedError (expected in HA; another node signed first).
48
- * @param dutyType - The type of duty
49
- */ recordDutyAlreadySigned(dutyType) {
50
- const attributes = {
51
- [Attributes.HA_DUTY_TYPE]: dutyType,
52
- [Attributes.HA_NODE_ID]: this.nodeId
53
- };
54
- this.dutyAlreadySignedCount.add(1, attributes);
55
- }
56
- /**
57
- * Record a SlashingProtectionError (attempted to sign different data for same duty).
58
- * @param dutyType - The type of duty
59
- */ recordSlashingProtection(dutyType) {
60
- const attributes = {
61
- [Attributes.HA_DUTY_TYPE]: dutyType,
62
- [Attributes.HA_NODE_ID]: this.nodeId
63
- };
64
- this.slashingProtectionCount.add(1, attributes);
65
- }
66
- /**
67
- * Record a signing function failure (lock will be deleted for retry).
68
- * @param dutyType - The type of duty
69
- */ recordSigningError(dutyType) {
70
- const attributes = {
71
- [Attributes.HA_DUTY_TYPE]: dutyType,
72
- [Attributes.HA_NODE_ID]: this.nodeId
73
- };
74
- this.signingErrorCount.add(1, attributes);
75
- }
76
- /**
77
- * Record lock acquisition.
78
- * @param acquired - Whether a new lock was acquired (true) or existing record found (false)
79
- */ recordLockAcquire(acquired) {
80
- if (acquired) {
81
- const attributes = {
82
- [Attributes.HA_NODE_ID]: this.nodeId
83
- };
84
- this.lockAcquiredCount.add(1, attributes);
85
- }
86
- }
87
- /**
88
- * Record cleanup metrics.
89
- * @param type - Type of cleanup
90
- * @param count - Number of duties cleaned up
91
- */ recordCleanup(type, count) {
92
- const attributes = {
93
- [Attributes.HA_NODE_ID]: this.nodeId
94
- };
95
- if (type === 'stuck') {
96
- this.cleanupStuckDutiesCount.add(count, attributes);
97
- } else if (type === 'old') {
98
- this.cleanupOldDutiesCount.add(count, attributes);
99
- } else if (type === 'outdated_rollup') {
100
- this.cleanupOutdatedRollupDutiesCount.add(count, attributes);
101
- }
102
- }
103
- }
package/src/db/lmdb.ts DELETED
@@ -1,264 +0,0 @@
1
- /**
2
- * LMDB implementation of SlashingProtectionDatabase
3
- *
4
- * Provides local (single-node) double-signing protection using LMDB as the backend.
5
- * Suitable for nodes that do NOT run in a high-availability multi-node setup.
6
- *
7
- * The LMDB store is single-writer, making setIfNotExists inherently atomic.
8
- * This means we get crash-restart protection without needing an external database.
9
- */
10
- import { SlotNumber } from '@aztec/foundation/branded-types';
11
- import { randomBytes } from '@aztec/foundation/crypto/random';
12
- import { EthAddress } from '@aztec/foundation/eth-address';
13
- import { type Logger, createLogger } from '@aztec/foundation/log';
14
- import type { DateProvider } from '@aztec/foundation/timer';
15
- import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
16
-
17
- import type { SlashingProtectionDatabase, TryInsertOrGetResult } from '../types.js';
18
- import {
19
- type CheckAndRecordParams,
20
- DutyStatus,
21
- DutyType,
22
- type StoredDutyRecord,
23
- getBlockIndexFromDutyIdentifier,
24
- recordFromFields,
25
- } from './types.js';
26
-
27
- function dutyKey(
28
- rollupAddress: string,
29
- validatorAddress: string,
30
- slot: string,
31
- dutyType: string,
32
- blockIndexWithinCheckpoint: number,
33
- ): string {
34
- return `${rollupAddress}:${validatorAddress}:${slot}:${dutyType}:${blockIndexWithinCheckpoint}`;
35
- }
36
-
37
- /**
38
- * LMDB-backed implementation of SlashingProtectionDatabase.
39
- *
40
- * Provides single-node double-signing protection that survives crashes and restarts.
41
- * Does not provide cross-node coordination (that requires the PostgreSQL implementation).
42
- */
43
- export class LmdbSlashingProtectionDatabase implements SlashingProtectionDatabase {
44
- public static readonly SCHEMA_VERSION = 1;
45
-
46
- private readonly duties: AztecAsyncMap<string, StoredDutyRecord>;
47
- private readonly log: Logger;
48
-
49
- constructor(
50
- private readonly store: AztecAsyncKVStore,
51
- private readonly dateProvider: DateProvider,
52
- ) {
53
- this.log = createLogger('slashing-protection:lmdb');
54
- this.duties = store.openMap<string, StoredDutyRecord>('signing-protection-duties');
55
- }
56
-
57
- /**
58
- * Atomically try to insert a new duty record, or get the existing one if present.
59
- *
60
- * LMDB is single-writer so the read-then-write inside transactionAsync is naturally atomic.
61
- */
62
- public async tryInsertOrGetExisting(params: CheckAndRecordParams): Promise<TryInsertOrGetResult> {
63
- const blockIndexWithinCheckpoint = getBlockIndexFromDutyIdentifier(params);
64
- const key = dutyKey(
65
- params.rollupAddress.toString(),
66
- params.validatorAddress.toString(),
67
- params.slot.toString(),
68
- params.dutyType,
69
- blockIndexWithinCheckpoint,
70
- );
71
-
72
- const lockToken = randomBytes(16).toString('hex');
73
- const now = this.dateProvider.now();
74
-
75
- const result = await this.store.transactionAsync(async () => {
76
- const existing = await this.duties.getAsync(key);
77
- if (existing) {
78
- return { isNew: false as const, record: { ...existing, lockToken: '' } };
79
- }
80
-
81
- const newRecord: StoredDutyRecord = {
82
- rollupAddress: params.rollupAddress.toString(),
83
- validatorAddress: params.validatorAddress.toString(),
84
- slot: params.slot.toString(),
85
- blockNumber: params.blockNumber.toString(),
86
- blockIndexWithinCheckpoint,
87
- dutyType: params.dutyType,
88
- status: DutyStatus.SIGNING,
89
- messageHash: params.messageHash,
90
- nodeId: params.nodeId,
91
- lockToken,
92
- startedAtMs: now,
93
- };
94
- await this.duties.set(key, newRecord);
95
- return { isNew: true as const, record: newRecord };
96
- });
97
-
98
- if (result.isNew) {
99
- this.log.debug(`Acquired lock for duty ${params.dutyType} at slot ${params.slot}`, {
100
- validatorAddress: params.validatorAddress.toString(),
101
- nodeId: params.nodeId,
102
- });
103
- }
104
-
105
- return { isNew: result.isNew, record: recordFromFields(result.record) };
106
- }
107
-
108
- /**
109
- * Update a duty to 'signed' status with the signature.
110
- * Only succeeds if the lockToken matches.
111
- */
112
- public updateDutySigned(
113
- rollupAddress: EthAddress,
114
- validatorAddress: EthAddress,
115
- slot: SlotNumber,
116
- dutyType: DutyType,
117
- signature: string,
118
- lockToken: string,
119
- blockIndexWithinCheckpoint: number,
120
- ): Promise<boolean> {
121
- const key = dutyKey(
122
- rollupAddress.toString(),
123
- validatorAddress.toString(),
124
- slot.toString(),
125
- dutyType,
126
- blockIndexWithinCheckpoint,
127
- );
128
-
129
- return this.store.transactionAsync(async () => {
130
- const existing = await this.duties.getAsync(key);
131
- if (!existing) {
132
- this.log.warn('Failed to update duty to signed: duty not found', {
133
- rollupAddress: rollupAddress.toString(),
134
- validatorAddress: validatorAddress.toString(),
135
- slot: slot.toString(),
136
- dutyType,
137
- blockIndexWithinCheckpoint,
138
- });
139
- return false;
140
- }
141
-
142
- if (existing.lockToken !== lockToken) {
143
- this.log.warn('Failed to update duty to signed: invalid token', {
144
- rollupAddress: rollupAddress.toString(),
145
- validatorAddress: validatorAddress.toString(),
146
- slot: slot.toString(),
147
- dutyType,
148
- blockIndexWithinCheckpoint,
149
- });
150
- return false;
151
- }
152
-
153
- await this.duties.set(key, {
154
- ...existing,
155
- status: DutyStatus.SIGNED,
156
- signature,
157
- completedAtMs: this.dateProvider.now(),
158
- });
159
-
160
- return true;
161
- });
162
- }
163
-
164
- /**
165
- * Delete a duty record.
166
- * Only succeeds if the lockToken matches.
167
- */
168
- public deleteDuty(
169
- rollupAddress: EthAddress,
170
- validatorAddress: EthAddress,
171
- slot: SlotNumber,
172
- dutyType: DutyType,
173
- lockToken: string,
174
- blockIndexWithinCheckpoint: number,
175
- ): Promise<boolean> {
176
- const key = dutyKey(
177
- rollupAddress.toString(),
178
- validatorAddress.toString(),
179
- slot.toString(),
180
- dutyType,
181
- blockIndexWithinCheckpoint,
182
- );
183
-
184
- return this.store.transactionAsync(async () => {
185
- const existing = await this.duties.getAsync(key);
186
- if (!existing || existing.lockToken !== lockToken) {
187
- this.log.warn('Failed to delete duty: invalid token or duty not found', {
188
- rollupAddress: rollupAddress.toString(),
189
- validatorAddress: validatorAddress.toString(),
190
- slot: slot.toString(),
191
- dutyType,
192
- blockIndexWithinCheckpoint,
193
- });
194
- return false;
195
- }
196
-
197
- await this.duties.delete(key);
198
- return true;
199
- });
200
- }
201
-
202
- /**
203
- * Cleanup own stuck duties (SIGNING status older than maxAgeMs).
204
- */
205
- public cleanupOwnStuckDuties(nodeId: string, maxAgeMs: number): Promise<number> {
206
- const cutoffMs = this.dateProvider.now() - maxAgeMs;
207
-
208
- return this.store.transactionAsync(async () => {
209
- const keysToDelete: string[] = [];
210
- for await (const [key, record] of this.duties.entriesAsync()) {
211
- if (record.nodeId === nodeId && record.status === DutyStatus.SIGNING && record.startedAtMs < cutoffMs) {
212
- keysToDelete.push(key);
213
- }
214
- }
215
- for (const key of keysToDelete) {
216
- await this.duties.delete(key);
217
- }
218
- return keysToDelete.length;
219
- });
220
- }
221
-
222
- /**
223
- * Cleanup duties with outdated rollup address.
224
- *
225
- * This is always a no-op for the LMDB implementation: the underlying store is created via
226
- * DatabaseVersionManager (in factory.ts), which already resets the entire data directory at
227
- * startup whenever the rollup address changes.
228
- */
229
- public cleanupOutdatedRollupDuties(_currentRollupAddress: EthAddress): Promise<number> {
230
- return Promise.resolve(0);
231
- }
232
-
233
- /**
234
- * Cleanup old signed duties older than maxAgeMs.
235
- */
236
- public cleanupOldDuties(maxAgeMs: number): Promise<number> {
237
- const cutoffMs = this.dateProvider.now() - maxAgeMs;
238
-
239
- return this.store.transactionAsync(async () => {
240
- const keysToDelete: string[] = [];
241
- for await (const [key, record] of this.duties.entriesAsync()) {
242
- if (
243
- record.status === DutyStatus.SIGNED &&
244
- record.completedAtMs !== undefined &&
245
- record.completedAtMs < cutoffMs
246
- ) {
247
- keysToDelete.push(key);
248
- }
249
- }
250
- for (const key of keysToDelete) {
251
- await this.duties.delete(key);
252
- }
253
- return keysToDelete.length;
254
- });
255
- }
256
-
257
- /**
258
- * Close the underlying LMDB store.
259
- */
260
- public async close(): Promise<void> {
261
- await this.store.close();
262
- this.log.debug('LMDB slashing protection database closed');
263
- }
264
- }
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
- }