@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.
@@ -7,8 +7,6 @@
7
7
  import { type Logger, createLogger } from '@aztec/foundation/log';
8
8
  import { RunningPromise } from '@aztec/foundation/promise';
9
9
  import { sleep } from '@aztec/foundation/sleep';
10
- import type { DateProvider } from '@aztec/foundation/timer';
11
- import type { ValidatorHASignerConfig } from '@aztec/stdlib/ha-signing';
12
10
 
13
11
  import {
14
12
  type CheckAndRecordParams,
@@ -18,13 +16,7 @@ import {
18
16
  getBlockIndexFromDutyIdentifier,
19
17
  } from './db/types.js';
20
18
  import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
21
- import type { HASignerMetrics } from './metrics.js';
22
- import type { SlashingProtectionDatabase } from './types.js';
23
-
24
- export interface SlashingProtectionServiceDeps {
25
- metrics: HASignerMetrics;
26
- dateProvider: DateProvider;
27
- }
19
+ import type { SlashingProtectionDatabase, ValidatorHASignerConfig } from './types.js';
28
20
 
29
21
  /**
30
22
  * Slashing Protection Service
@@ -47,16 +39,12 @@ export class SlashingProtectionService {
47
39
  private readonly signingTimeoutMs: number;
48
40
  private readonly maxStuckDutiesAgeMs: number;
49
41
 
50
- private readonly metrics: HASignerMetrics;
51
- private readonly dateProvider: DateProvider;
52
-
53
42
  private cleanupRunningPromise: RunningPromise;
54
43
  private lastOldDutiesCleanupAtMs?: number;
55
44
 
56
45
  constructor(
57
46
  private readonly db: SlashingProtectionDatabase,
58
47
  private readonly config: ValidatorHASignerConfig,
59
- deps: SlashingProtectionServiceDeps,
60
48
  ) {
61
49
  this.log = createLogger('slashing-protection');
62
50
  this.pollingIntervalMs = config.pollingIntervalMs;
@@ -65,8 +53,6 @@ export class SlashingProtectionService {
65
53
  this.maxStuckDutiesAgeMs = config.maxStuckDutiesAgeMs ?? 144_000;
66
54
 
67
55
  this.cleanupRunningPromise = new RunningPromise(this.cleanup.bind(this), this.log, this.maxStuckDutiesAgeMs);
68
- this.metrics = deps.metrics;
69
- this.dateProvider = deps.dateProvider;
70
56
  }
71
57
 
72
58
  /**
@@ -86,7 +72,7 @@ export class SlashingProtectionService {
86
72
  */
87
73
  async checkAndRecord(params: CheckAndRecordParams): Promise<string> {
88
74
  const { validatorAddress, slot, dutyType, messageHash, nodeId } = params;
89
- const startTime = this.dateProvider.now();
75
+ const startTime = Date.now();
90
76
 
91
77
  this.log.debug(`Checking duty: ${dutyType} for slot ${slot}`, {
92
78
  validatorAddress: validatorAddress.toString(),
@@ -99,11 +85,10 @@ export class SlashingProtectionService {
99
85
 
100
86
  if (isNew) {
101
87
  // We successfully acquired the lock
102
- this.log.info(`Acquired lock for duty ${dutyType} at slot ${slot}`, {
88
+ this.log.verbose(`Acquired lock for duty ${dutyType} at slot ${slot}`, {
103
89
  validatorAddress: validatorAddress.toString(),
104
90
  nodeId,
105
91
  });
106
- this.metrics.recordLockAcquire(true);
107
92
  return record.lockToken;
108
93
  }
109
94
 
@@ -118,7 +103,6 @@ export class SlashingProtectionService {
118
103
  existingNodeId: record.nodeId,
119
104
  attemptingNodeId: nodeId,
120
105
  });
121
- this.metrics.recordSlashingProtection(dutyType);
122
106
  throw new SlashingProtectionError(
123
107
  slot,
124
108
  dutyType,
@@ -128,17 +112,15 @@ export class SlashingProtectionService {
128
112
  record.nodeId,
129
113
  );
130
114
  }
131
- this.metrics.recordDutyAlreadySigned(dutyType);
132
115
  throw new DutyAlreadySignedError(slot, dutyType, record.blockIndexWithinCheckpoint, record.nodeId);
133
116
  } else if (record.status === DutyStatus.SIGNING) {
134
117
  // Another node is currently signing - check for timeout
135
- if (this.dateProvider.now() - startTime > this.signingTimeoutMs) {
118
+ if (Date.now() - startTime > this.signingTimeoutMs) {
136
119
  this.log.warn(`Timeout waiting for signing to complete for duty ${dutyType} at slot ${slot}`, {
137
120
  validatorAddress: validatorAddress.toString(),
138
121
  timeoutMs: this.signingTimeoutMs,
139
122
  signingNodeId: record.nodeId,
140
123
  });
141
- this.metrics.recordDutyAlreadySigned(dutyType);
142
124
  throw new DutyAlreadySignedError(slot, dutyType, record.blockIndexWithinCheckpoint, 'unknown (timeout)');
143
125
  }
144
126
 
@@ -177,7 +159,7 @@ export class SlashingProtectionService {
177
159
  );
178
160
 
179
161
  if (success) {
180
- this.log.info(`Recorded successful signing for duty ${dutyType} at slot ${slot}`, {
162
+ this.log.verbose(`Recorded successful signing for duty ${dutyType} at slot ${slot}`, {
181
163
  validatorAddress: validatorAddress.toString(),
182
164
  nodeId,
183
165
  });
@@ -246,7 +228,6 @@ export class SlashingProtectionService {
246
228
  this.log.info(`Cleaned up ${numOutdatedRollupDuties} duties with outdated rollup address at startup`, {
247
229
  currentRollupAddress: this.config.l1Contracts.rollupAddress.toString(),
248
230
  });
249
- this.metrics.recordCleanup('outdated_rollup', numOutdatedRollupDuties);
250
231
  }
251
232
 
252
233
  this.cleanupRunningPromise.start();
@@ -282,14 +263,13 @@ export class SlashingProtectionService {
282
263
  nodeId: this.config.nodeId,
283
264
  maxStuckDutiesAgeMs: this.maxStuckDutiesAgeMs,
284
265
  });
285
- this.metrics.recordCleanup('stuck', numStuckDuties);
286
266
  }
287
267
 
288
268
  // 2. Clean up old signed duties if configured
289
269
  // we shouldn't run this as often as stuck duty cleanup.
290
270
  if (this.config.cleanupOldDutiesAfterHours !== undefined) {
291
271
  const maxAgeMs = this.config.cleanupOldDutiesAfterHours * 60 * 60 * 1000;
292
- const nowMs = this.dateProvider.now();
272
+ const nowMs = Date.now();
293
273
  const shouldRun =
294
274
  this.lastOldDutiesCleanupAtMs === undefined || nowMs - this.lastOldDutiesCleanupAtMs >= maxAgeMs;
295
275
  if (shouldRun) {
@@ -300,7 +280,6 @@ export class SlashingProtectionService {
300
280
  cleanupOldDutiesAfterHours: this.config.cleanupOldDutiesAfterHours,
301
281
  maxAgeMs,
302
282
  });
303
- this.metrics.recordCleanup('old', numOldDuties);
304
283
  }
305
284
  }
306
285
  }
package/src/types.ts CHANGED
@@ -1,27 +1,24 @@
1
- import { SlotNumber } from '@aztec/foundation/branded-types';
2
- import type { EthAddress } from '@aztec/foundation/eth-address';
3
- import { DateProvider } from '@aztec/foundation/timer';
4
1
  import {
5
- DutyType,
6
- type HAProtectedSigningContext,
7
- type SigningContext,
8
- type ValidatorHASignerConfig,
9
- getBlockNumberFromSigningContext as getBlockNumberFromSigningContextFromStdlib,
10
- isHAProtectedContext,
11
- } from '@aztec/stdlib/ha-signing';
12
- import type { TelemetryClient } from '@aztec/telemetry-client';
2
+ BlockNumber,
3
+ type CheckpointNumber,
4
+ type IndexWithinCheckpoint,
5
+ type SlotNumber,
6
+ } from '@aztec/foundation/branded-types';
7
+ import type { EthAddress } from '@aztec/foundation/eth-address';
13
8
 
14
9
  import type { Pool } from 'pg';
15
10
 
16
- import type {
17
- BlockProposalDutyIdentifier,
18
- CheckAndRecordParams,
19
- DeleteDutyParams,
20
- DutyIdentifier,
21
- DutyRow,
22
- OtherDutyIdentifier,
23
- RecordSuccessParams,
24
- ValidatorDutyRecord,
11
+ import type { ValidatorHASignerConfig } from './config.js';
12
+ import {
13
+ type BlockProposalDutyIdentifier,
14
+ type CheckAndRecordParams,
15
+ type DeleteDutyParams,
16
+ type DutyIdentifier,
17
+ type DutyRow,
18
+ DutyType,
19
+ type OtherDutyIdentifier,
20
+ type RecordSuccessParams,
21
+ type ValidatorDutyRecord,
25
22
  } from './db/types.js';
26
23
 
27
24
  export type {
@@ -30,16 +27,12 @@ export type {
30
27
  DeleteDutyParams,
31
28
  DutyIdentifier,
32
29
  DutyRow,
33
- HAProtectedSigningContext,
34
30
  OtherDutyIdentifier,
35
31
  RecordSuccessParams,
36
- SigningContext,
37
32
  ValidatorDutyRecord,
38
33
  ValidatorHASignerConfig,
39
34
  };
40
35
  export { DutyStatus, DutyType, getBlockIndexFromDutyIdentifier, normalizeBlockIndex } from './db/types.js';
41
- export { isHAProtectedContext };
42
- export { getBlockNumberFromSigningContextFromStdlib as getBlockNumberFromSigningContext };
43
36
 
44
37
  /**
45
38
  * Result of tryInsertOrGetExisting operation
@@ -60,16 +53,100 @@ export interface CreateHASignerDeps {
60
53
  * If provided, databaseUrl and poolConfig are ignored
61
54
  */
62
55
  pool?: Pool;
56
+ }
57
+
58
+ /**
59
+ * Base context for signing operations
60
+ */
61
+ interface BaseSigningContext {
62
+ /** Slot number for this duty */
63
+ slot: SlotNumber;
63
64
  /**
64
- * Optional telemetry client for metrics
65
- */
66
- telemetryClient?: TelemetryClient;
67
- /**
68
- * Optional date provider for timestamps
65
+ * Block or checkpoint number for this duty.
66
+ * For block proposals, this is the block number.
67
+ * For checkpoint proposals, this is the checkpoint number.
69
68
  */
70
- dateProvider?: DateProvider;
69
+ blockNumber: BlockNumber | CheckpointNumber;
71
70
  }
72
71
 
72
+ /**
73
+ * Signing context for block proposals.
74
+ * blockIndexWithinCheckpoint is REQUIRED and must be >= 0.
75
+ */
76
+ export interface BlockProposalSigningContext extends BaseSigningContext {
77
+ /** Block index within checkpoint (0, 1, 2...). Required for block proposals. */
78
+ blockIndexWithinCheckpoint: IndexWithinCheckpoint;
79
+ dutyType: DutyType.BLOCK_PROPOSAL;
80
+ }
81
+
82
+ /**
83
+ * Signing context for non-block-proposal duties that require HA protection.
84
+ * blockIndexWithinCheckpoint is not applicable (internally always -1).
85
+ */
86
+ export interface OtherSigningContext extends BaseSigningContext {
87
+ dutyType: DutyType.CHECKPOINT_PROPOSAL | DutyType.ATTESTATION | DutyType.ATTESTATIONS_AND_SIGNERS;
88
+ }
89
+
90
+ /**
91
+ * Signing context for governance/slashing votes which only need slot for HA protection.
92
+ * blockNumber is not applicable (internally always 0).
93
+ */
94
+ export interface VoteSigningContext {
95
+ slot: SlotNumber;
96
+ dutyType: DutyType.GOVERNANCE_VOTE | DutyType.SLASHING_VOTE;
97
+ }
98
+
99
+ /**
100
+ * Signing context for duties which don't require slot/blockNumber
101
+ * as they don't need HA protection (AUTH_REQUEST, TXS).
102
+ */
103
+ export interface NoHAProtectionSigningContext {
104
+ dutyType: DutyType.AUTH_REQUEST | DutyType.TXS;
105
+ }
106
+
107
+ /**
108
+ * Signing contexts that require HA protection (excludes AUTH_REQUEST).
109
+ * Used by the HA signer's signWithProtection method.
110
+ */
111
+ export type HAProtectedSigningContext = BlockProposalSigningContext | OtherSigningContext | VoteSigningContext;
112
+
113
+ /**
114
+ * Type guard to check if a SigningContext requires HA protection.
115
+ * Returns true for contexts that need HA protection, false for AUTH_REQUEST and TXS.
116
+ */
117
+ export function isHAProtectedContext(context: SigningContext): context is HAProtectedSigningContext {
118
+ return context.dutyType !== DutyType.AUTH_REQUEST && context.dutyType !== DutyType.TXS;
119
+ }
120
+
121
+ /**
122
+ * Gets the block number from a signing context.
123
+ * - Vote duties (GOVERNANCE_VOTE, SLASHING_VOTE): returns BlockNumber(0)
124
+ * - Other duties: returns the blockNumber from the context
125
+ */
126
+ export function getBlockNumberFromSigningContext(context: HAProtectedSigningContext): BlockNumber | CheckpointNumber {
127
+ // Check for duty types that have blockNumber
128
+ if (
129
+ context.dutyType === DutyType.BLOCK_PROPOSAL ||
130
+ context.dutyType === DutyType.CHECKPOINT_PROPOSAL ||
131
+ context.dutyType === DutyType.ATTESTATION ||
132
+ context.dutyType === DutyType.ATTESTATIONS_AND_SIGNERS
133
+ ) {
134
+ return context.blockNumber;
135
+ }
136
+ // Vote duties (GOVERNANCE_VOTE, SLASHING_VOTE) don't have blockNumber
137
+ return BlockNumber(0);
138
+ }
139
+
140
+ /**
141
+ * Context required for slashing protection during signing operations.
142
+ * Uses discriminated union to enforce type safety:
143
+ * - BLOCK_PROPOSAL duties MUST have blockIndexWithinCheckpoint >= 0
144
+ * - Other duty types do NOT have blockIndexWithinCheckpoint (internally -1)
145
+ * - Vote duties only need slot (blockNumber is internally 0)
146
+ * - AUTH_REQUEST and TXS duties don't need slot/blockNumber (no HA protection needed)
147
+ */
148
+ export type SigningContext = HAProtectedSigningContext | NoHAProtectionSigningContext;
149
+
73
150
  /**
74
151
  * Database interface for slashing protection operations
75
152
  * This abstraction allows for different database implementations (PostgreSQL, SQLite, etc.)
@@ -9,23 +9,15 @@ import type { Buffer32 } from '@aztec/foundation/buffer';
9
9
  import { EthAddress } from '@aztec/foundation/eth-address';
10
10
  import type { Signature } from '@aztec/foundation/eth-signature';
11
11
  import { type Logger, createLogger } from '@aztec/foundation/log';
12
- import type { DateProvider } from '@aztec/foundation/timer';
12
+
13
+ import type { ValidatorHASignerConfig } from './config.js';
14
+ import { type DutyIdentifier, DutyType } from './db/types.js';
15
+ import { SlashingProtectionService } from './slashing_protection_service.js';
13
16
  import {
14
- DutyType,
15
17
  type HAProtectedSigningContext,
16
- type ValidatorHASignerConfig,
18
+ type SlashingProtectionDatabase,
17
19
  getBlockNumberFromSigningContext,
18
- } from '@aztec/stdlib/ha-signing';
19
-
20
- import type { DutyIdentifier } from './db/types.js';
21
- import type { HASignerMetrics } from './metrics.js';
22
- import { SlashingProtectionService } from './slashing_protection_service.js';
23
- import type { SlashingProtectionDatabase } from './types.js';
24
-
25
- export interface ValidatorHASignerDeps {
26
- metrics: HASignerMetrics;
27
- dateProvider: DateProvider;
28
- }
20
+ } from './types.js';
29
21
 
30
22
  /**
31
23
  * Validator High Availability Signer
@@ -51,19 +43,12 @@ export class ValidatorHASigner {
51
43
  private readonly slashingProtection: SlashingProtectionService;
52
44
  private readonly rollupAddress: EthAddress;
53
45
 
54
- private readonly dateProvider: DateProvider;
55
- private readonly metrics: HASignerMetrics;
56
-
57
46
  constructor(
58
47
  db: SlashingProtectionDatabase,
59
48
  private readonly config: ValidatorHASignerConfig,
60
- deps: ValidatorHASignerDeps,
61
49
  ) {
62
50
  this.log = createLogger('validator-ha-signer');
63
51
 
64
- this.metrics = deps.metrics;
65
- this.dateProvider = deps.dateProvider;
66
-
67
52
  if (!config.haSigningEnabled) {
68
53
  // this shouldn't happen, the validator should use different signer for non-HA setups
69
54
  throw new Error('Validator HA Signer is not enabled in config');
@@ -73,10 +58,7 @@ export class ValidatorHASigner {
73
58
  throw new Error('NODE_ID is required for high-availability setups');
74
59
  }
75
60
  this.rollupAddress = config.l1Contracts.rollupAddress;
76
- this.slashingProtection = new SlashingProtectionService(db, config, {
77
- metrics: deps.metrics,
78
- dateProvider: deps.dateProvider,
79
- });
61
+ this.slashingProtection = new SlashingProtectionService(db, config);
80
62
  this.log.info('Validator HA Signer initialized with slashing protection', {
81
63
  nodeId: config.nodeId,
82
64
  rollupAddress: this.rollupAddress.toString(),
@@ -106,9 +88,6 @@ export class ValidatorHASigner {
106
88
  context: HAProtectedSigningContext,
107
89
  signFn: (messageHash: Buffer32) => Promise<Signature>,
108
90
  ): Promise<Signature> {
109
- const startTime = this.dateProvider.now();
110
- const dutyType = context.dutyType;
111
-
112
91
  let dutyIdentifier: DutyIdentifier;
113
92
  if (context.dutyType === DutyType.BLOCK_PROPOSAL) {
114
93
  dutyIdentifier = {
@@ -128,7 +107,6 @@ export class ValidatorHASigner {
128
107
  }
129
108
 
130
109
  // Acquire lock and get the token for ownership verification
131
- // DutyAlreadySignedError and SlashingProtectionError may be thrown here and are recorded in the service
132
110
  const blockNumber = getBlockNumberFromSigningContext(context);
133
111
  const lockToken = await this.slashingProtection.checkAndRecord({
134
112
  ...dutyIdentifier,
@@ -144,7 +122,6 @@ export class ValidatorHASigner {
144
122
  } catch (error: any) {
145
123
  // Delete duty to allow retry (only succeeds if we own the lock)
146
124
  await this.slashingProtection.deleteDuty({ ...dutyIdentifier, lockToken });
147
- this.metrics.recordSigningError(dutyType);
148
125
  throw error;
149
126
  }
150
127
 
@@ -156,9 +133,6 @@ export class ValidatorHASigner {
156
133
  lockToken,
157
134
  });
158
135
 
159
- const duration = this.dateProvider.now() - startTime;
160
- this.metrics.recordSigningSuccess(dutyType, duration);
161
-
162
136
  return signature;
163
137
  }
164
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWV0cmljcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL21ldHJpY3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUlMLEtBQUssZUFBZSxFQUdyQixNQUFNLHlCQUF5QixDQUFDO0FBRWpDLE1BQU0sTUFBTSxhQU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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
- }