@aztec/validator-ha-signer 0.0.1-commit.7d4e6cd → 0.0.1-commit.86469d5

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 +42 -37
  2. package/dest/config.d.ts +66 -17
  3. package/dest/config.d.ts.map +1 -1
  4. package/dest/config.js +41 -19
  5. package/dest/db/postgres.d.ts +20 -5
  6. package/dest/db/postgres.d.ts.map +1 -1
  7. package/dest/db/postgres.js +56 -19
  8. package/dest/db/schema.d.ts +11 -7
  9. package/dest/db/schema.d.ts.map +1 -1
  10. package/dest/db/schema.js +35 -15
  11. package/dest/db/types.d.ts +80 -23
  12. package/dest/db/types.d.ts.map +1 -1
  13. package/dest/db/types.js +34 -0
  14. package/dest/errors.d.ts +9 -5
  15. package/dest/errors.d.ts.map +1 -1
  16. package/dest/errors.js +7 -4
  17. package/dest/factory.d.ts +6 -14
  18. package/dest/factory.d.ts.map +1 -1
  19. package/dest/factory.js +6 -11
  20. package/dest/migrations.d.ts +1 -1
  21. package/dest/migrations.d.ts.map +1 -1
  22. package/dest/migrations.js +13 -2
  23. package/dest/slashing_protection_service.d.ts +9 -3
  24. package/dest/slashing_protection_service.d.ts.map +1 -1
  25. package/dest/slashing_protection_service.js +23 -11
  26. package/dest/test/pglite_pool.d.ts +92 -0
  27. package/dest/test/pglite_pool.d.ts.map +1 -0
  28. package/dest/test/pglite_pool.js +210 -0
  29. package/dest/types.d.ts +78 -14
  30. package/dest/types.d.ts.map +1 -1
  31. package/dest/types.js +21 -1
  32. package/dest/validator_ha_signer.d.ts +9 -12
  33. package/dest/validator_ha_signer.d.ts.map +1 -1
  34. package/dest/validator_ha_signer.js +31 -30
  35. package/package.json +9 -8
  36. package/src/config.ts +75 -50
  37. package/src/db/postgres.ts +76 -19
  38. package/src/db/schema.ts +35 -15
  39. package/src/db/types.ts +110 -21
  40. package/src/errors.ts +7 -2
  41. package/src/factory.ts +8 -13
  42. package/src/migrations.ts +17 -1
  43. package/src/slashing_protection_service.ts +55 -13
  44. package/src/test/pglite_pool.ts +256 -0
  45. package/src/types.ts +125 -19
  46. package/src/validator_ha_signer.ts +38 -40
@@ -0,0 +1,256 @@
1
+ /**
2
+ * Vendored pg-compatible Pool/Client wrapper for PGlite.
3
+ *
4
+ * Copied from @middle-management/pglite-pg-adapter v0.0.3
5
+ * https://www.npmjs.com/package/@middle-management/pglite-pg-adapter
6
+ *
7
+ * Modifications:
8
+ * - Converted to ESM and TypeScript
9
+ * - Uses PGliteInterface instead of PGlite class to avoid TypeScript
10
+ * type mismatches from ESM/CJS dual package resolution with private fields
11
+ * - Simplified rowCount calculation to handle CTEs properly
12
+ */
13
+ import type { PGliteInterface } from '@electric-sql/pglite';
14
+ import { EventEmitter } from 'events';
15
+ import type { QueryResult, QueryResultRow } from 'pg';
16
+ import { Readable, Writable } from 'stream';
17
+
18
+ export interface PoolConfig {
19
+ pglite: PGliteInterface;
20
+ max?: number;
21
+ min?: number;
22
+ }
23
+
24
+ interface ClientConfig {
25
+ pglite: PGliteInterface;
26
+ host?: string;
27
+ port?: number;
28
+ ssl?: boolean;
29
+ }
30
+
31
+ export class Client extends EventEmitter {
32
+ protected pglite: PGliteInterface;
33
+ protected _connected = false;
34
+ readonly host: string;
35
+ readonly port: number;
36
+ readonly ssl: boolean;
37
+ readonly connection: object;
38
+
39
+ // Stub implementations for pg compatibility
40
+ readonly copyFrom = (): Writable => new Writable();
41
+ readonly copyTo = (): Readable => new Readable();
42
+ readonly pauseDrain = (): void => {};
43
+ readonly resumeDrain = (): void => {};
44
+ readonly escapeLiteral = (str: string): string => `'${str.replace(/'/g, "''")}'`;
45
+ readonly escapeIdentifier = (str: string): string => `"${str.replace(/"/g, '""')}"`;
46
+ readonly setTypeParser = (): void => {};
47
+ readonly getTypeParser = (): ((value: string) => unknown) => (value: string) => value;
48
+
49
+ constructor(config: ClientConfig) {
50
+ super();
51
+ this.pglite = config.pglite;
52
+ this.host = config.host || 'localhost';
53
+ this.port = config.port || 5432;
54
+ this.ssl = typeof config.ssl === 'boolean' ? config.ssl : !!config.ssl;
55
+ this.connection = {};
56
+ }
57
+
58
+ connect(): Promise<void> {
59
+ if (this._connected) {
60
+ return Promise.resolve();
61
+ }
62
+ this._connected = true;
63
+ this.emit('connect');
64
+ return Promise.resolve();
65
+ }
66
+
67
+ end(): Promise<void> {
68
+ if (!this._connected) {
69
+ return Promise.resolve();
70
+ }
71
+ this._connected = false;
72
+ this.emit('end');
73
+ return Promise.resolve();
74
+ }
75
+
76
+ async query<R extends QueryResultRow = any>(text: string, values?: any[]): Promise<QueryResult<R>> {
77
+ if (!this._connected) {
78
+ throw new Error('Client is not connected');
79
+ }
80
+ const result = await this.pglite.query<R>(text, values);
81
+ return this.convertPGliteResult(result);
82
+ }
83
+
84
+ protected convertPGliteResult<R extends QueryResultRow>(result: {
85
+ rows: R[];
86
+ fields: Array<{ name: string; dataTypeID: number }>;
87
+ affectedRows?: number;
88
+ }): QueryResult<R> {
89
+ return {
90
+ command: '',
91
+ rowCount: 'affectedRows' in result ? (result.affectedRows ?? 0) : result.rows.length,
92
+ oid: 0,
93
+ fields: result.fields.map(field => ({
94
+ name: field.name,
95
+ tableID: 0,
96
+ columnID: 0,
97
+ dataTypeID: field.dataTypeID,
98
+ dataTypeSize: -1,
99
+ dataTypeModifier: -1,
100
+ format: 'text',
101
+ })),
102
+ rows: result.rows,
103
+ };
104
+ }
105
+
106
+ get connected(): boolean {
107
+ return this._connected;
108
+ }
109
+ }
110
+
111
+ export class Pool extends EventEmitter {
112
+ private clients: PoolClient[] = [];
113
+ private availableClients: PoolClient[] = [];
114
+ private waitingQueue: Array<(client: PoolClient) => void> = [];
115
+ private _ended = false;
116
+ private pglite: PGliteInterface;
117
+ private _config: PoolConfig;
118
+
119
+ readonly expiredCount = 0;
120
+ readonly options: PoolConfig;
121
+
122
+ constructor(config: PoolConfig) {
123
+ super();
124
+ this._config = { max: 10, min: 0, ...config };
125
+ this.pglite = config.pglite;
126
+ this.options = config;
127
+ }
128
+
129
+ get totalCount(): number {
130
+ return this.clients.length;
131
+ }
132
+
133
+ get idleCount(): number {
134
+ return this.availableClients.length;
135
+ }
136
+
137
+ get waitingCount(): number {
138
+ return this.waitingQueue.length;
139
+ }
140
+
141
+ get ending(): boolean {
142
+ return this._ended;
143
+ }
144
+
145
+ get ended(): boolean {
146
+ return this._ended;
147
+ }
148
+
149
+ connect(): Promise<PoolClient> {
150
+ if (this._ended) {
151
+ return Promise.reject(new Error('Pool is ended'));
152
+ }
153
+
154
+ if (this.availableClients.length > 0) {
155
+ const client = this.availableClients.pop()!;
156
+ client._markInUse();
157
+ return Promise.resolve(client);
158
+ }
159
+
160
+ if (this.clients.length < (this._config.max || 10)) {
161
+ const client = new PoolClient(this.pglite, this);
162
+ this.clients.push(client);
163
+ return Promise.resolve(client);
164
+ }
165
+
166
+ return new Promise(resolve => {
167
+ this.waitingQueue.push(resolve);
168
+ });
169
+ }
170
+
171
+ async query<R extends QueryResultRow = any>(text: string, values?: any[]): Promise<QueryResult<R>> {
172
+ const client = await this.connect();
173
+ try {
174
+ return await client.query<R>(text, values);
175
+ } finally {
176
+ client.release();
177
+ }
178
+ }
179
+
180
+ releaseClient(client: PoolClient): void {
181
+ const index = this.clients.indexOf(client);
182
+ if (index !== -1) {
183
+ client._markAvailable();
184
+ if (this.waitingQueue.length > 0) {
185
+ const resolve = this.waitingQueue.shift()!;
186
+ client._markInUse();
187
+ resolve(client);
188
+ } else {
189
+ this.availableClients.push(client);
190
+ }
191
+ }
192
+ }
193
+
194
+ end(): Promise<void> {
195
+ this._ended = true;
196
+ this.clients.forEach(client => client._markReleased());
197
+ this.clients = [];
198
+ this.availableClients = [];
199
+ this.emit('end');
200
+ return Promise.resolve();
201
+ }
202
+ }
203
+
204
+ export class PoolClient extends Client {
205
+ private pool: Pool;
206
+ private _released = false;
207
+ private _inUse = true;
208
+ private _userReleased = false;
209
+
210
+ constructor(pglite: PGliteInterface, pool: Pool) {
211
+ super({ pglite });
212
+ this.pool = pool;
213
+ this._connected = true;
214
+ }
215
+
216
+ override async query<R extends QueryResultRow = any>(text: string, values?: any[]): Promise<QueryResult<R>> {
217
+ if (this._userReleased && !this._inUse) {
218
+ throw new Error('Client has been released back to the pool');
219
+ }
220
+ const result = await this.pglite.query<R>(text, values);
221
+ return this.convertPGliteResult(result);
222
+ }
223
+
224
+ release(): void {
225
+ if (this._released || this._userReleased) {
226
+ return;
227
+ }
228
+ this._userReleased = true;
229
+ this.pool.releaseClient(this);
230
+ }
231
+
232
+ override end(): Promise<void> {
233
+ this.release();
234
+ return Promise.resolve();
235
+ }
236
+
237
+ _markInUse(): void {
238
+ this._inUse = true;
239
+ this._userReleased = false;
240
+ }
241
+
242
+ _markAvailable(): void {
243
+ this._inUse = false;
244
+ this._userReleased = false;
245
+ }
246
+
247
+ _markReleased(): void {
248
+ this._released = true;
249
+ this._inUse = false;
250
+ this._userReleased = true;
251
+ }
252
+
253
+ override get connected(): boolean {
254
+ return this._connected && !this._released;
255
+ }
256
+ }
package/src/types.ts CHANGED
@@ -1,27 +1,38 @@
1
+ import {
2
+ BlockNumber,
3
+ type CheckpointNumber,
4
+ type IndexWithinCheckpoint,
5
+ type SlotNumber,
6
+ } from '@aztec/foundation/branded-types';
1
7
  import type { EthAddress } from '@aztec/foundation/eth-address';
2
8
 
3
9
  import type { Pool } from 'pg';
4
10
 
5
- import type { CreateHASignerConfig, SlashingProtectionConfig } from './config.js';
6
- import type {
7
- CheckAndRecordParams,
8
- DeleteDutyParams,
9
- DutyIdentifier,
11
+ import type { ValidatorHASignerConfig } from './config.js';
12
+ import {
13
+ type BlockProposalDutyIdentifier,
14
+ type CheckAndRecordParams,
15
+ type DeleteDutyParams,
16
+ type DutyIdentifier,
17
+ type DutyRow,
10
18
  DutyType,
11
- RecordSuccessParams,
12
- ValidatorDutyRecord,
19
+ type OtherDutyIdentifier,
20
+ type RecordSuccessParams,
21
+ type ValidatorDutyRecord,
13
22
  } from './db/types.js';
14
23
 
15
24
  export type {
25
+ BlockProposalDutyIdentifier,
16
26
  CheckAndRecordParams,
17
- CreateHASignerConfig,
18
27
  DeleteDutyParams,
19
28
  DutyIdentifier,
29
+ DutyRow,
30
+ OtherDutyIdentifier,
20
31
  RecordSuccessParams,
21
- SlashingProtectionConfig,
22
32
  ValidatorDutyRecord,
33
+ ValidatorHASignerConfig,
23
34
  };
24
- export { DutyStatus, DutyType } from './db/types.js';
35
+ export { DutyStatus, DutyType, getBlockIndexFromDutyIdentifier, normalizeBlockIndex } from './db/types.js';
25
36
 
26
37
  /**
27
38
  * Result of tryInsertOrGetExisting operation
@@ -45,17 +56,97 @@ export interface CreateHASignerDeps {
45
56
  }
46
57
 
47
58
  /**
48
- * Context required for slashing protection during signing operations
59
+ * Base context for signing operations
49
60
  */
50
- export interface SigningContext {
61
+ interface BaseSigningContext {
51
62
  /** Slot number for this duty */
52
- slot: bigint;
53
- /** Block number for this duty */
54
- blockNumber: bigint;
55
- /** Type of duty being performed */
56
- dutyType: DutyType;
63
+ slot: SlotNumber;
64
+ /**
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.
68
+ */
69
+ blockNumber: BlockNumber | CheckpointNumber;
70
+ }
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);
57
138
  }
58
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
+
59
150
  /**
60
151
  * Database interface for slashing protection operations
61
152
  * This abstraction allows for different database implementations (PostgreSQL, SQLite, etc.)
@@ -81,11 +172,13 @@ export interface SlashingProtectionDatabase {
81
172
  * @returns true if the update succeeded, false if token didn't match or duty not found
82
173
  */
83
174
  updateDutySigned(
175
+ rollupAddress: EthAddress,
84
176
  validatorAddress: EthAddress,
85
- slot: bigint,
177
+ slot: SlotNumber,
86
178
  dutyType: DutyType,
87
179
  signature: string,
88
180
  lockToken: string,
181
+ blockIndexWithinCheckpoint: number,
89
182
  ): Promise<boolean>;
90
183
 
91
184
  /**
@@ -95,11 +188,24 @@ export interface SlashingProtectionDatabase {
95
188
  *
96
189
  * @returns true if the delete succeeded, false if token didn't match or duty not found
97
190
  */
98
- deleteDuty(validatorAddress: EthAddress, slot: bigint, dutyType: DutyType, lockToken: string): Promise<boolean>;
191
+ deleteDuty(
192
+ rollupAddress: EthAddress,
193
+ validatorAddress: EthAddress,
194
+ slot: SlotNumber,
195
+ dutyType: DutyType,
196
+ lockToken: string,
197
+ blockIndexWithinCheckpoint: number,
198
+ ): Promise<boolean>;
99
199
 
100
200
  /**
101
201
  * Cleanup own stuck duties
102
202
  * @returns the number of duties cleaned up
103
203
  */
104
204
  cleanupOwnStuckDuties(nodeId: string, maxAgeMs: number): Promise<number>;
205
+
206
+ /**
207
+ * Close the database connection.
208
+ * Should be called during graceful shutdown.
209
+ */
210
+ close(): Promise<void>;
105
211
  }
@@ -6,13 +6,18 @@
6
6
  * node will sign for a given duty (slot + duty type).
7
7
  */
8
8
  import type { Buffer32 } from '@aztec/foundation/buffer';
9
- import type { EthAddress } from '@aztec/foundation/eth-address';
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
12
 
13
- import type { CreateHASignerConfig } from './config.js';
13
+ import type { ValidatorHASignerConfig } from './config.js';
14
+ import { type DutyIdentifier, DutyType } from './db/types.js';
14
15
  import { SlashingProtectionService } from './slashing_protection_service.js';
15
- import type { SigningContext, SlashingProtectionDatabase } from './types.js';
16
+ import {
17
+ type HAProtectedSigningContext,
18
+ type SlashingProtectionDatabase,
19
+ getBlockNumberFromSigningContext,
20
+ } from './types.js';
16
21
 
17
22
  /**
18
23
  * Validator High Availability Signer
@@ -35,15 +40,16 @@ import type { SigningContext, SlashingProtectionDatabase } from './types.js';
35
40
  */
36
41
  export class ValidatorHASigner {
37
42
  private readonly log: Logger;
38
- private readonly slashingProtection: SlashingProtectionService | undefined;
43
+ private readonly slashingProtection: SlashingProtectionService;
44
+ private readonly rollupAddress: EthAddress;
39
45
 
40
46
  constructor(
41
47
  db: SlashingProtectionDatabase,
42
- private readonly config: CreateHASignerConfig,
48
+ private readonly config: ValidatorHASignerConfig,
43
49
  ) {
44
50
  this.log = createLogger('validator-ha-signer');
45
51
 
46
- if (!config.enabled) {
52
+ if (!config.haSigningEnabled) {
47
53
  // this shouldn't happen, the validator should use different signer for non-HA setups
48
54
  throw new Error('Validator HA Signer is not enabled in config');
49
55
  }
@@ -51,9 +57,11 @@ export class ValidatorHASigner {
51
57
  if (!config.nodeId || config.nodeId === '') {
52
58
  throw new Error('NODE_ID is required for high-availability setups');
53
59
  }
60
+ this.rollupAddress = config.l1Contracts.rollupAddress;
54
61
  this.slashingProtection = new SlashingProtectionService(db, config);
55
62
  this.log.info('Validator HA Signer initialized with slashing protection', {
56
63
  nodeId: config.nodeId,
64
+ rollupAddress: this.rollupAddress.toString(),
57
65
  });
58
66
  }
59
67
 
@@ -67,7 +75,7 @@ export class ValidatorHASigner {
67
75
  *
68
76
  * @param validatorAddress - The validator's Ethereum address
69
77
  * @param messageHash - The hash to be signed
70
- * @param context - The signing context (slot, block number, duty type)
78
+ * @param context - The signing context (HA-protected duty types only)
71
79
  * @param signFn - Function that performs the actual signing
72
80
  * @returns The signature
73
81
  *
@@ -77,29 +85,32 @@ export class ValidatorHASigner {
77
85
  async signWithProtection(
78
86
  validatorAddress: EthAddress,
79
87
  messageHash: Buffer32,
80
- context: SigningContext,
88
+ context: HAProtectedSigningContext,
81
89
  signFn: (messageHash: Buffer32) => Promise<Signature>,
82
90
  ): Promise<Signature> {
83
- // If slashing protection is disabled, just sign directly
84
- if (!this.slashingProtection) {
85
- this.log.info('Signing without slashing protection enabled', {
86
- validatorAddress: validatorAddress.toString(),
87
- nodeId: this.config.nodeId,
91
+ let dutyIdentifier: DutyIdentifier;
92
+ if (context.dutyType === DutyType.BLOCK_PROPOSAL) {
93
+ dutyIdentifier = {
94
+ rollupAddress: this.rollupAddress,
95
+ validatorAddress,
96
+ slot: context.slot,
97
+ blockIndexWithinCheckpoint: context.blockIndexWithinCheckpoint,
88
98
  dutyType: context.dutyType,
99
+ };
100
+ } else {
101
+ dutyIdentifier = {
102
+ rollupAddress: this.rollupAddress,
103
+ validatorAddress,
89
104
  slot: context.slot,
90
- blockNumber: context.blockNumber,
91
- });
92
- return await signFn(messageHash);
105
+ dutyType: context.dutyType,
106
+ };
93
107
  }
94
108
 
95
- const { slot, blockNumber, dutyType } = context;
96
-
97
109
  // Acquire lock and get the token for ownership verification
110
+ const blockNumber = getBlockNumberFromSigningContext(context);
98
111
  const lockToken = await this.slashingProtection.checkAndRecord({
99
- validatorAddress,
100
- slot,
112
+ ...dutyIdentifier,
101
113
  blockNumber,
102
- dutyType,
103
114
  messageHash: messageHash.toString(),
104
115
  nodeId: this.config.nodeId,
105
116
  });
@@ -110,20 +121,13 @@ export class ValidatorHASigner {
110
121
  signature = await signFn(messageHash);
111
122
  } catch (error: any) {
112
123
  // Delete duty to allow retry (only succeeds if we own the lock)
113
- await this.slashingProtection.deleteDuty({
114
- validatorAddress,
115
- slot,
116
- dutyType,
117
- lockToken,
118
- });
124
+ await this.slashingProtection.deleteDuty({ ...dutyIdentifier, lockToken });
119
125
  throw error;
120
126
  }
121
127
 
122
128
  // Record success (only succeeds if we own the lock)
123
129
  await this.slashingProtection.recordSuccess({
124
- validatorAddress,
125
- slot,
126
- dutyType,
130
+ ...dutyIdentifier,
127
131
  signature,
128
132
  nodeId: this.config.nodeId,
129
133
  lockToken,
@@ -132,13 +136,6 @@ export class ValidatorHASigner {
132
136
  return signature;
133
137
  }
134
138
 
135
- /**
136
- * Check if slashing protection is enabled
137
- */
138
- get isEnabled(): boolean {
139
- return this.slashingProtection !== undefined;
140
- }
141
-
142
139
  /**
143
140
  * Get the node ID for this signer
144
141
  */
@@ -151,14 +148,15 @@ export class ValidatorHASigner {
151
148
  * Should be called after construction and before signing operations.
152
149
  */
153
150
  start() {
154
- this.slashingProtection?.start();
151
+ this.slashingProtection.start();
155
152
  }
156
153
 
157
154
  /**
158
- * Stop the HA signer background tasks.
155
+ * Stop the HA signer background tasks and close database connection.
159
156
  * Should be called during graceful shutdown.
160
157
  */
161
158
  async stop() {
162
- await this.slashingProtection?.stop();
159
+ await this.slashingProtection.stop();
160
+ await this.slashingProtection.close();
163
161
  }
164
162
  }