@aztec/validator-ha-signer 0.0.1-commit.96dac018d → 0.0.1-commit.993d52e

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/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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWV0cmljcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL21ldHJpY3MudHMiXSwibmFtZXMiOltdLC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G,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/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
- }