@aztec/validator-ha-signer 0.0.1-commit.d431d1c → 0.0.1-commit.d58ff9d0
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/README.md +12 -4
- package/dest/db/index.d.ts +2 -1
- package/dest/db/index.d.ts.map +1 -1
- package/dest/db/index.js +1 -0
- package/dest/db/lmdb.d.ts +70 -0
- package/dest/db/lmdb.d.ts.map +1 -0
- package/dest/db/lmdb.js +223 -0
- package/dest/db/migrations/1_initial-schema.d.ts +4 -2
- package/dest/db/migrations/1_initial-schema.d.ts.map +1 -1
- package/dest/db/migrations/1_initial-schema.js +34 -4
- package/dest/db/migrations/2_add-checkpoint-number.d.ts +7 -0
- package/dest/db/migrations/2_add-checkpoint-number.d.ts.map +1 -0
- package/dest/db/migrations/2_add-checkpoint-number.js +17 -0
- package/dest/db/postgres.d.ts +20 -4
- package/dest/db/postgres.d.ts.map +1 -1
- package/dest/db/postgres.js +46 -17
- package/dest/db/schema.d.ts +18 -11
- package/dest/db/schema.d.ts.map +1 -1
- package/dest/db/schema.js +45 -23
- package/dest/db/types.d.ts +52 -22
- package/dest/db/types.d.ts.map +1 -1
- package/dest/db/types.js +31 -15
- package/dest/errors.d.ts +14 -1
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +15 -0
- package/dest/factory.d.ts +38 -5
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +104 -8
- package/dest/metrics.d.ts +51 -0
- package/dest/metrics.d.ts.map +1 -0
- package/dest/metrics.js +103 -0
- package/dest/slashing_protection_service.d.ts +22 -7
- package/dest/slashing_protection_service.d.ts.map +1 -1
- package/dest/slashing_protection_service.js +65 -22
- package/dest/types.d.ts +33 -72
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +4 -20
- package/dest/validator_ha_signer.d.ts +16 -6
- package/dest/validator_ha_signer.d.ts.map +1 -1
- package/dest/validator_ha_signer.js +54 -16
- package/package.json +11 -6
- package/src/db/index.ts +1 -0
- package/src/db/lmdb.ts +308 -0
- package/src/db/migrations/1_initial-schema.ts +35 -4
- package/src/db/migrations/2_add-checkpoint-number.ts +19 -0
- package/src/db/postgres.ts +47 -12
- package/src/db/schema.ts +47 -23
- package/src/db/types.ts +72 -20
- package/src/errors.ts +21 -0
- package/src/factory.ts +141 -7
- package/src/metrics.ts +138 -0
- package/src/slashing_protection_service.ts +90 -27
- package/src/types.ts +56 -103
- package/src/validator_ha_signer.ts +85 -19
- package/dest/config.d.ts +0 -79
- package/dest/config.d.ts.map +0 -1
- package/dest/config.js +0 -73
- package/src/config.ts +0 -125
|
@@ -8,6 +8,7 @@ import { RunningPromise } from '@aztec/foundation/promise';
|
|
|
8
8
|
import { sleep } from '@aztec/foundation/sleep';
|
|
9
9
|
import { DutyStatus, getBlockIndexFromDutyIdentifier } from './db/types.js';
|
|
10
10
|
import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
11
|
+
/** Default max age (ms) of a stuck SIGNING duty before cleanup reclaims it: 2x the 72s Aztec slot duration. */ export const DEFAULT_MAX_STUCK_DUTIES_AGE_MS = 144_000;
|
|
11
12
|
/**
|
|
12
13
|
* Slashing Protection Service
|
|
13
14
|
*
|
|
@@ -27,18 +28,22 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
27
28
|
config;
|
|
28
29
|
log;
|
|
29
30
|
pollingIntervalMs;
|
|
30
|
-
|
|
31
|
+
peerSigningTimeoutMs;
|
|
31
32
|
maxStuckDutiesAgeMs;
|
|
33
|
+
metrics;
|
|
34
|
+
dateProvider;
|
|
32
35
|
cleanupRunningPromise;
|
|
33
|
-
|
|
36
|
+
lastOldDutiesCleanupAtMs;
|
|
37
|
+
constructor(db, config, deps){
|
|
34
38
|
this.db = db;
|
|
35
39
|
this.config = config;
|
|
36
40
|
this.log = createLogger('slashing-protection');
|
|
37
41
|
this.pollingIntervalMs = config.pollingIntervalMs;
|
|
38
|
-
this.
|
|
39
|
-
|
|
40
|
-
this.
|
|
41
|
-
this.
|
|
42
|
+
this.peerSigningTimeoutMs = config.peerSigningTimeoutMs;
|
|
43
|
+
this.maxStuckDutiesAgeMs = config.maxStuckDutiesAgeMs ?? DEFAULT_MAX_STUCK_DUTIES_AGE_MS;
|
|
44
|
+
this.cleanupRunningPromise = new RunningPromise(this.cleanup.bind(this), this.log, this.maxStuckDutiesAgeMs);
|
|
45
|
+
this.metrics = deps.metrics;
|
|
46
|
+
this.dateProvider = deps.dateProvider;
|
|
42
47
|
}
|
|
43
48
|
/**
|
|
44
49
|
* Check if a duty can be performed and acquire the lock if so.
|
|
@@ -49,7 +54,6 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
49
54
|
* 2. If insert succeeds, we acquired the lock - return the lockToken
|
|
50
55
|
* 3. If a record exists, handle based on status:
|
|
51
56
|
* - SIGNED: Throw appropriate error (already signed or slashing protection)
|
|
52
|
-
* - FAILED: Delete the failed record
|
|
53
57
|
* - SIGNING: Wait and poll until status changes, then handle result
|
|
54
58
|
*
|
|
55
59
|
* @returns The lockToken that must be used for recordSuccess/deleteDuty
|
|
@@ -57,7 +61,7 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
57
61
|
* @throws SlashingProtectionError if attempting to sign different data for same slot/duty
|
|
58
62
|
*/ async checkAndRecord(params) {
|
|
59
63
|
const { validatorAddress, slot, dutyType, messageHash, nodeId } = params;
|
|
60
|
-
const startTime =
|
|
64
|
+
const startTime = this.dateProvider.now();
|
|
61
65
|
this.log.debug(`Checking duty: ${dutyType} for slot ${slot}`, {
|
|
62
66
|
validatorAddress: validatorAddress.toString(),
|
|
63
67
|
nodeId
|
|
@@ -67,10 +71,11 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
67
71
|
const { isNew, record } = await this.db.tryInsertOrGetExisting(params);
|
|
68
72
|
if (isNew) {
|
|
69
73
|
// We successfully acquired the lock
|
|
70
|
-
this.log.
|
|
74
|
+
this.log.verbose(`Acquired lock for duty ${dutyType} at slot ${slot}`, {
|
|
71
75
|
validatorAddress: validatorAddress.toString(),
|
|
72
76
|
nodeId
|
|
73
77
|
});
|
|
78
|
+
this.metrics.recordLockAcquire(true);
|
|
74
79
|
return record.lockToken;
|
|
75
80
|
}
|
|
76
81
|
// Record already exists - handle based on status
|
|
@@ -84,17 +89,20 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
84
89
|
existingNodeId: record.nodeId,
|
|
85
90
|
attemptingNodeId: nodeId
|
|
86
91
|
});
|
|
92
|
+
this.metrics.recordSlashingProtection(dutyType);
|
|
87
93
|
throw new SlashingProtectionError(slot, dutyType, record.blockIndexWithinCheckpoint, record.messageHash, messageHash, record.nodeId);
|
|
88
94
|
}
|
|
95
|
+
this.metrics.recordDutyAlreadySigned(dutyType);
|
|
89
96
|
throw new DutyAlreadySignedError(slot, dutyType, record.blockIndexWithinCheckpoint, record.nodeId);
|
|
90
97
|
} else if (record.status === DutyStatus.SIGNING) {
|
|
91
98
|
// Another node is currently signing - check for timeout
|
|
92
|
-
if (
|
|
99
|
+
if (this.dateProvider.now() - startTime > this.peerSigningTimeoutMs) {
|
|
93
100
|
this.log.warn(`Timeout waiting for signing to complete for duty ${dutyType} at slot ${slot}`, {
|
|
94
101
|
validatorAddress: validatorAddress.toString(),
|
|
95
|
-
timeoutMs: this.
|
|
102
|
+
timeoutMs: this.peerSigningTimeoutMs,
|
|
96
103
|
signingNodeId: record.nodeId
|
|
97
104
|
});
|
|
105
|
+
this.metrics.recordDutyAlreadySigned(dutyType);
|
|
98
106
|
throw new DutyAlreadySignedError(slot, dutyType, record.blockIndexWithinCheckpoint, 'unknown (timeout)');
|
|
99
107
|
}
|
|
100
108
|
// Wait and poll
|
|
@@ -116,11 +124,11 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
116
124
|
*
|
|
117
125
|
* @returns true if the update succeeded, false if token didn't match
|
|
118
126
|
*/ async recordSuccess(params) {
|
|
119
|
-
const { validatorAddress, slot, dutyType, signature, nodeId, lockToken } = params;
|
|
127
|
+
const { rollupAddress, validatorAddress, slot, dutyType, signature, nodeId, lockToken } = params;
|
|
120
128
|
const blockIndexWithinCheckpoint = getBlockIndexFromDutyIdentifier(params);
|
|
121
|
-
const success = await this.db.updateDutySigned(validatorAddress, slot, dutyType, signature.toString(), lockToken, blockIndexWithinCheckpoint);
|
|
129
|
+
const success = await this.db.updateDutySigned(rollupAddress, validatorAddress, slot, dutyType, signature.toString(), lockToken, blockIndexWithinCheckpoint);
|
|
122
130
|
if (success) {
|
|
123
|
-
this.log.
|
|
131
|
+
this.log.verbose(`Recorded successful signing for duty ${dutyType} at slot ${slot}`, {
|
|
124
132
|
validatorAddress: validatorAddress.toString(),
|
|
125
133
|
nodeId
|
|
126
134
|
});
|
|
@@ -139,9 +147,9 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
139
147
|
*
|
|
140
148
|
* @returns true if the delete succeeded, false if token didn't match
|
|
141
149
|
*/ async deleteDuty(params) {
|
|
142
|
-
const { validatorAddress, slot, dutyType, lockToken } = params;
|
|
150
|
+
const { rollupAddress, validatorAddress, slot, dutyType, lockToken } = params;
|
|
143
151
|
const blockIndexWithinCheckpoint = getBlockIndexFromDutyIdentifier(params);
|
|
144
|
-
const success = await this.db.deleteDuty(validatorAddress, slot, dutyType, lockToken, blockIndexWithinCheckpoint);
|
|
152
|
+
const success = await this.db.deleteDuty(rollupAddress, validatorAddress, slot, dutyType, lockToken, blockIndexWithinCheckpoint);
|
|
145
153
|
if (success) {
|
|
146
154
|
this.log.info(`Deleted duty ${dutyType} at slot ${slot} to allow retry`, {
|
|
147
155
|
validatorAddress: validatorAddress.toString()
|
|
@@ -161,7 +169,18 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
161
169
|
/**
|
|
162
170
|
* Start running tasks.
|
|
163
171
|
* Cleanup runs immediately on start to recover from any previous crashes.
|
|
164
|
-
*/
|
|
172
|
+
*/ /**
|
|
173
|
+
* Start the background cleanup task.
|
|
174
|
+
* Also performs one-time cleanup of duties with outdated rollup addresses.
|
|
175
|
+
*/ async start() {
|
|
176
|
+
// One-time cleanup at startup: remove duties from previous rollup versions
|
|
177
|
+
const numOutdatedRollupDuties = await this.db.cleanupOutdatedRollupDuties(this.config.rollupAddress);
|
|
178
|
+
if (numOutdatedRollupDuties > 0) {
|
|
179
|
+
this.log.info(`Cleaned up ${numOutdatedRollupDuties} duties with outdated rollup address at startup`, {
|
|
180
|
+
currentRollupAddress: this.config.rollupAddress.toString()
|
|
181
|
+
});
|
|
182
|
+
this.metrics.recordCleanup('outdated_rollup', numOutdatedRollupDuties);
|
|
183
|
+
}
|
|
165
184
|
this.cleanupRunningPromise.start();
|
|
166
185
|
this.log.info('Slashing protection service started', {
|
|
167
186
|
nodeId: this.config.nodeId
|
|
@@ -183,14 +202,38 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
183
202
|
this.log.info('Slashing protection database connection closed');
|
|
184
203
|
}
|
|
185
204
|
/**
|
|
186
|
-
*
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
205
|
+
* Periodic cleanup of stuck duties and optionally old signed duties.
|
|
206
|
+
* Runs in the background via RunningPromise.
|
|
207
|
+
*/ async cleanup() {
|
|
208
|
+
// 1. Clean up stuck duties (our own node's duties that got stuck in 'signing' status).
|
|
209
|
+
// This cannot race an in-flight signing: every signing operation is hard-bounded by a timeout
|
|
210
|
+
// clamped below maxStuckDutiesAgeMs / 2 (see ValidatorHASigner), so a live SIGNING row is
|
|
211
|
+
// always released long before it can be considered stuck.
|
|
212
|
+
const numStuckDuties = await this.db.cleanupOwnStuckDuties(this.config.nodeId, this.maxStuckDutiesAgeMs);
|
|
213
|
+
if (numStuckDuties > 0) {
|
|
214
|
+
this.log.verbose(`Cleaned up ${numStuckDuties} stuck duties`, {
|
|
191
215
|
nodeId: this.config.nodeId,
|
|
192
216
|
maxStuckDutiesAgeMs: this.maxStuckDutiesAgeMs
|
|
193
217
|
});
|
|
218
|
+
this.metrics.recordCleanup('stuck', numStuckDuties);
|
|
219
|
+
}
|
|
220
|
+
// 2. Clean up old signed duties if configured
|
|
221
|
+
// we shouldn't run this as often as stuck duty cleanup.
|
|
222
|
+
if (this.config.cleanupOldDutiesAfterHours !== undefined) {
|
|
223
|
+
const maxAgeMs = this.config.cleanupOldDutiesAfterHours * 60 * 60 * 1000;
|
|
224
|
+
const nowMs = this.dateProvider.now();
|
|
225
|
+
const shouldRun = this.lastOldDutiesCleanupAtMs === undefined || nowMs - this.lastOldDutiesCleanupAtMs >= maxAgeMs;
|
|
226
|
+
if (shouldRun) {
|
|
227
|
+
const numOldDuties = await this.db.cleanupOldDuties(maxAgeMs);
|
|
228
|
+
this.lastOldDutiesCleanupAtMs = nowMs;
|
|
229
|
+
if (numOldDuties > 0) {
|
|
230
|
+
this.log.verbose(`Cleaned up ${numOldDuties} old signed duties`, {
|
|
231
|
+
cleanupOldDutiesAfterHours: this.config.cleanupOldDutiesAfterHours,
|
|
232
|
+
maxAgeMs
|
|
233
|
+
});
|
|
234
|
+
this.metrics.recordCleanup('old', numOldDuties);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
194
237
|
}
|
|
195
238
|
}
|
|
196
239
|
}
|
package/dest/types.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
4
|
+
import { type AttestationSigningContext, type CheckpointProposalSigningContext, DutyType, type HAProtectedSigningContext, type SigningContext, type ValidatorHASignerConfig, getBlockNumberFromSigningContext as getBlockNumberFromSigningContextFromStdlib, getCheckpointNumberFromSigningContext as getCheckpointNumberFromSigningContextFromStdlib, isHAProtectedContext } from '@aztec/stdlib/ha-signing';
|
|
5
|
+
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
3
6
|
import type { Pool } from 'pg';
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
export type { BlockProposalDutyIdentifier, CheckAndRecordParams, DeleteDutyParams, DutyIdentifier, OtherDutyIdentifier, RecordSuccessParams, ValidatorDutyRecord, ValidatorHASignerConfig, };
|
|
7
|
+
import type { BlockProposalDutyIdentifier, CheckAndRecordParams, DeleteDutyParams, DutyIdentifier, DutyRow, OtherDutyIdentifier, RecordSuccessParams, ValidatorDutyRecord } from './db/types.js';
|
|
8
|
+
export type { AttestationSigningContext, BlockProposalDutyIdentifier, CheckAndRecordParams, CheckpointProposalSigningContext, DeleteDutyParams, DutyIdentifier, DutyRow, HAProtectedSigningContext, OtherDutyIdentifier, RecordSuccessParams, SigningContext, ValidatorDutyRecord, ValidatorHASignerConfig, };
|
|
7
9
|
export { DutyStatus, DutyType, getBlockIndexFromDutyIdentifier, normalizeBlockIndex } from './db/types.js';
|
|
10
|
+
export { isHAProtectedContext };
|
|
11
|
+
export { getBlockNumberFromSigningContextFromStdlib as getBlockNumberFromSigningContext };
|
|
12
|
+
export { getCheckpointNumberFromSigningContextFromStdlib as getCheckpointNumberFromSigningContext };
|
|
8
13
|
/**
|
|
9
14
|
* Result of tryInsertOrGetExisting operation
|
|
10
15
|
*/
|
|
@@ -23,76 +28,19 @@ export interface CreateHASignerDeps {
|
|
|
23
28
|
* If provided, databaseUrl and poolConfig are ignored
|
|
24
29
|
*/
|
|
25
30
|
pool?: Pool;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Base context for signing operations
|
|
29
|
-
*/
|
|
30
|
-
interface BaseSigningContext {
|
|
31
|
-
/** Slot number for this duty */
|
|
32
|
-
slot: SlotNumber;
|
|
33
31
|
/**
|
|
34
|
-
*
|
|
35
|
-
* For block proposals, this is the block number.
|
|
36
|
-
* For checkpoint proposals, this is the checkpoint number.
|
|
32
|
+
* Optional telemetry client for metrics
|
|
37
33
|
*/
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
*/
|
|
44
|
-
export interface BlockProposalSigningContext extends BaseSigningContext {
|
|
45
|
-
/** Block index within checkpoint (0, 1, 2...). Required for block proposals. */
|
|
46
|
-
blockIndexWithinCheckpoint: IndexWithinCheckpoint;
|
|
47
|
-
dutyType: DutyType.BLOCK_PROPOSAL;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Signing context for non-block-proposal duties that require HA protection.
|
|
51
|
-
* blockIndexWithinCheckpoint is not applicable (internally always -1).
|
|
52
|
-
*/
|
|
53
|
-
export interface OtherSigningContext extends BaseSigningContext {
|
|
54
|
-
dutyType: DutyType.CHECKPOINT_PROPOSAL | DutyType.ATTESTATION | DutyType.ATTESTATIONS_AND_SIGNERS;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Signing context for governance/slashing votes which only need slot for HA protection.
|
|
58
|
-
* blockNumber is not applicable (internally always 0).
|
|
59
|
-
*/
|
|
60
|
-
export interface VoteSigningContext {
|
|
61
|
-
slot: SlotNumber;
|
|
62
|
-
dutyType: DutyType.GOVERNANCE_VOTE | DutyType.SLASHING_VOTE;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Signing context for duties which don't require slot/blockNumber
|
|
66
|
-
* as they don't need HA protection (AUTH_REQUEST, TXS).
|
|
67
|
-
*/
|
|
68
|
-
export interface NoHAProtectionSigningContext {
|
|
69
|
-
dutyType: DutyType.AUTH_REQUEST | DutyType.TXS;
|
|
34
|
+
telemetryClient?: TelemetryClient;
|
|
35
|
+
/**
|
|
36
|
+
* Optional date provider for timestamps
|
|
37
|
+
*/
|
|
38
|
+
dateProvider?: DateProvider;
|
|
70
39
|
}
|
|
71
40
|
/**
|
|
72
|
-
*
|
|
73
|
-
* Used by the HA signer's signWithProtection method.
|
|
74
|
-
*/
|
|
75
|
-
export type HAProtectedSigningContext = BlockProposalSigningContext | OtherSigningContext | VoteSigningContext;
|
|
76
|
-
/**
|
|
77
|
-
* Type guard to check if a SigningContext requires HA protection.
|
|
78
|
-
* Returns true for contexts that need HA protection, false for AUTH_REQUEST and TXS.
|
|
79
|
-
*/
|
|
80
|
-
export declare function isHAProtectedContext(context: SigningContext): context is HAProtectedSigningContext;
|
|
81
|
-
/**
|
|
82
|
-
* Gets the block number from a signing context.
|
|
83
|
-
* - Vote duties (GOVERNANCE_VOTE, SLASHING_VOTE): returns BlockNumber(0)
|
|
84
|
-
* - Other duties: returns the blockNumber from the context
|
|
85
|
-
*/
|
|
86
|
-
export declare function getBlockNumberFromSigningContext(context: HAProtectedSigningContext): BlockNumber | CheckpointNumber;
|
|
87
|
-
/**
|
|
88
|
-
* Context required for slashing protection during signing operations.
|
|
89
|
-
* Uses discriminated union to enforce type safety:
|
|
90
|
-
* - BLOCK_PROPOSAL duties MUST have blockIndexWithinCheckpoint >= 0
|
|
91
|
-
* - Other duty types do NOT have blockIndexWithinCheckpoint (internally -1)
|
|
92
|
-
* - Vote duties only need slot (blockNumber is internally 0)
|
|
93
|
-
* - AUTH_REQUEST and TXS duties don't need slot/blockNumber (no HA protection needed)
|
|
41
|
+
* deps for creating a local signing protection signer
|
|
94
42
|
*/
|
|
95
|
-
export type
|
|
43
|
+
export type CreateLocalSignerWithProtectionDeps = Omit<CreateHASignerDeps, 'pool'>;
|
|
96
44
|
/**
|
|
97
45
|
* Database interface for slashing protection operations
|
|
98
46
|
* This abstraction allows for different database implementations (PostgreSQL, SQLite, etc.)
|
|
@@ -116,7 +64,7 @@ export interface SlashingProtectionDatabase {
|
|
|
116
64
|
*
|
|
117
65
|
* @returns true if the update succeeded, false if token didn't match or duty not found
|
|
118
66
|
*/
|
|
119
|
-
updateDutySigned(validatorAddress: EthAddress, slot: SlotNumber, dutyType: DutyType, signature: string, lockToken: string, blockIndexWithinCheckpoint: number): Promise<boolean>;
|
|
67
|
+
updateDutySigned(rollupAddress: EthAddress, validatorAddress: EthAddress, slot: SlotNumber, dutyType: DutyType, signature: string, lockToken: string, blockIndexWithinCheckpoint: number): Promise<boolean>;
|
|
120
68
|
/**
|
|
121
69
|
* Delete a duty record.
|
|
122
70
|
* Only succeeds if the lockToken matches (caller must be the one who created the duty).
|
|
@@ -124,16 +72,29 @@ export interface SlashingProtectionDatabase {
|
|
|
124
72
|
*
|
|
125
73
|
* @returns true if the delete succeeded, false if token didn't match or duty not found
|
|
126
74
|
*/
|
|
127
|
-
deleteDuty(validatorAddress: EthAddress, slot: SlotNumber, dutyType: DutyType, lockToken: string, blockIndexWithinCheckpoint: number): Promise<boolean>;
|
|
75
|
+
deleteDuty(rollupAddress: EthAddress, validatorAddress: EthAddress, slot: SlotNumber, dutyType: DutyType, lockToken: string, blockIndexWithinCheckpoint: number): Promise<boolean>;
|
|
128
76
|
/**
|
|
129
77
|
* Cleanup own stuck duties
|
|
130
78
|
* @returns the number of duties cleaned up
|
|
131
79
|
*/
|
|
132
80
|
cleanupOwnStuckDuties(nodeId: string, maxAgeMs: number): Promise<number>;
|
|
81
|
+
/**
|
|
82
|
+
* Cleanup duties with outdated rollup address.
|
|
83
|
+
* Removes all duties where the rollup address doesn't match the current one.
|
|
84
|
+
* Used after a rollup upgrade to clean up duties for the old rollup.
|
|
85
|
+
* @returns the number of duties cleaned up
|
|
86
|
+
*/
|
|
87
|
+
cleanupOutdatedRollupDuties(currentRollupAddress: EthAddress): Promise<number>;
|
|
88
|
+
/**
|
|
89
|
+
* Cleanup old signed duties.
|
|
90
|
+
* Removes only signed duties older than the specified age.
|
|
91
|
+
* @returns the number of duties cleaned up
|
|
92
|
+
*/
|
|
93
|
+
cleanupOldDuties(maxAgeMs: number): Promise<number>;
|
|
133
94
|
/**
|
|
134
95
|
* Close the database connection.
|
|
135
96
|
* Should be called during graceful shutdown.
|
|
136
97
|
*/
|
|
137
98
|
close(): Promise<void>;
|
|
138
99
|
}
|
|
139
|
-
//# sourceMappingURL=data:application/json;base64,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AEpD;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}
|
package/dest/types.js
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DutyType } from './db/types.js';
|
|
1
|
+
import { getBlockNumberFromSigningContext as getBlockNumberFromSigningContextFromStdlib, getCheckpointNumberFromSigningContext as getCheckpointNumberFromSigningContextFromStdlib, isHAProtectedContext } from '@aztec/stdlib/ha-signing';
|
|
3
2
|
export { DutyStatus, DutyType, getBlockIndexFromDutyIdentifier, normalizeBlockIndex } from './db/types.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*/ export function isHAProtectedContext(context) {
|
|
8
|
-
return context.dutyType !== DutyType.AUTH_REQUEST && context.dutyType !== DutyType.TXS;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Gets the block number from a signing context.
|
|
12
|
-
* - Vote duties (GOVERNANCE_VOTE, SLASHING_VOTE): returns BlockNumber(0)
|
|
13
|
-
* - Other duties: returns the blockNumber from the context
|
|
14
|
-
*/ export function getBlockNumberFromSigningContext(context) {
|
|
15
|
-
// Check for duty types that have blockNumber
|
|
16
|
-
if (context.dutyType === DutyType.BLOCK_PROPOSAL || context.dutyType === DutyType.CHECKPOINT_PROPOSAL || context.dutyType === DutyType.ATTESTATION || context.dutyType === DutyType.ATTESTATIONS_AND_SIGNERS) {
|
|
17
|
-
return context.blockNumber;
|
|
18
|
-
}
|
|
19
|
-
// Vote duties (GOVERNANCE_VOTE, SLASHING_VOTE) don't have blockNumber
|
|
20
|
-
return BlockNumber(0);
|
|
21
|
-
}
|
|
3
|
+
export { isHAProtectedContext };
|
|
4
|
+
export { getBlockNumberFromSigningContextFromStdlib as getBlockNumberFromSigningContext };
|
|
5
|
+
export { getCheckpointNumberFromSigningContextFromStdlib as getCheckpointNumberFromSigningContext };
|
|
@@ -6,10 +6,16 @@
|
|
|
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
|
|
9
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
10
10
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
11
|
-
import type
|
|
12
|
-
import { type
|
|
11
|
+
import { type DateProvider } from '@aztec/foundation/timer';
|
|
12
|
+
import { type BaseSignerConfig, type HAProtectedSigningContext } from '@aztec/stdlib/ha-signing';
|
|
13
|
+
import type { HASignerMetrics } from './metrics.js';
|
|
14
|
+
import type { SlashingProtectionDatabase } from './types.js';
|
|
15
|
+
export interface ValidatorHASignerDeps {
|
|
16
|
+
metrics: HASignerMetrics;
|
|
17
|
+
dateProvider: DateProvider;
|
|
18
|
+
}
|
|
13
19
|
/**
|
|
14
20
|
* Validator High Availability Signer
|
|
15
21
|
*
|
|
@@ -33,7 +39,11 @@ export declare class ValidatorHASigner {
|
|
|
33
39
|
private readonly config;
|
|
34
40
|
private readonly log;
|
|
35
41
|
private readonly slashingProtection;
|
|
36
|
-
|
|
42
|
+
private readonly rollupAddress;
|
|
43
|
+
private readonly dateProvider;
|
|
44
|
+
private readonly metrics;
|
|
45
|
+
private readonly signerCallTimeoutMs;
|
|
46
|
+
constructor(db: SlashingProtectionDatabase, config: BaseSignerConfig, deps: ValidatorHASignerDeps);
|
|
37
47
|
/**
|
|
38
48
|
* Sign a message with slashing protection.
|
|
39
49
|
*
|
|
@@ -60,11 +70,11 @@ export declare class ValidatorHASigner {
|
|
|
60
70
|
* Start the HA signer background tasks (cleanup of stuck duties).
|
|
61
71
|
* Should be called after construction and before signing operations.
|
|
62
72
|
*/
|
|
63
|
-
start(): void
|
|
73
|
+
start(): Promise<void>;
|
|
64
74
|
/**
|
|
65
75
|
* Stop the HA signer background tasks and close database connection.
|
|
66
76
|
* Should be called during graceful shutdown.
|
|
67
77
|
*/
|
|
68
78
|
stop(): Promise<void>;
|
|
69
79
|
}
|
|
70
|
-
//# s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sUUFBUSxDQUFDLGFBQWEsQ0FBYTtJQUUzQyxPQUFPLENBQUMsUUFBUSxDQUFDLFlBQVksQ0FBZTtJQUM1QyxPQUFPLENBQUMsUUFBUSxDQUFDLE9BQU8sQ0FBa0I7SUFDMUMsT0FBTyxDQUFDLFFBQVEsQ0FBQyxtQkFBbUIsQ0FBUztJQUU3QyxZQUNFLEVBQUUsRUFBRSwwQkFBMEIsRUFDYixNQUFNLEVBQUUsZ0JBQWdCLEVBQ3pDLElBQUksRUFBRSxxQkFBcUIsRUFpQzVCO0lBRUQ7Ozs7Ozs7Ozs7Ozs7Ozs7T0FnQkc7SUFDRyxrQkFBa0IsQ0FDdEIsZ0JBQWdCLEVBQUUsVUFBVSxFQUM1QixXQUFXLEVBQUUsUUFBUSxFQUNyQixPQUFPLEVBQUUseUJBQXlCLEVBQ2xDLE1BQU0sRUFBRSxDQUFDLFdBQVcsRUFBRSxRQUFRLEtBQUssT0FBTyxDQUFDLFNBQVMsQ0FBQyxHQUNwRCxPQUFPLENBQUMsU0FBUyxDQUFDLENBMkVwQjtJQUVEOztPQUVHO0lBQ0gsSUFBSSxNQUFNLElBQUksTUFBTSxDQUVuQjtJQUVEOzs7T0FHRztJQUNHLEtBQUssa0JBRVY7SUFFRDs7O09BR0c7SUFDRyxJQUFJLGtCQUdUO0NBQ0YifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator_ha_signer.d.ts","sourceRoot":"","sources":["../src/validator_ha_signer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,
|
|
1
|
+
{"version":3,"file":"validator_ha_signer.d.ts","sourceRoot":"","sources":["../src/validator_ha_signer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA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@@ -5,9 +5,11 @@
|
|
|
5
5
|
* This ensures that even with multiple validator nodes running, only one
|
|
6
6
|
* node will sign for a given duty (slot + duty type).
|
|
7
7
|
*/ import { createLogger } from '@aztec/foundation/log';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
8
|
+
import { executeTimeout } from '@aztec/foundation/timer';
|
|
9
|
+
import { DutyType, getBlockNumberFromSigningContext, getCheckpointNumberFromSigningContext } from '@aztec/stdlib/ha-signing';
|
|
10
|
+
import { SigningLockLostError } from './errors.js';
|
|
11
|
+
import { DEFAULT_MAX_STUCK_DUTIES_AGE_MS, SlashingProtectionService } from './slashing_protection_service.js';
|
|
12
|
+
/** Default hard timeout (ms) for a single signer call when not configured. */ const DEFAULT_SIGNER_CALL_TIMEOUT_MS = 30_000;
|
|
11
13
|
/**
|
|
12
14
|
* Validator High Availability Signer
|
|
13
15
|
*
|
|
@@ -30,19 +32,35 @@ import { getBlockNumberFromSigningContext } from './types.js';
|
|
|
30
32
|
config;
|
|
31
33
|
log;
|
|
32
34
|
slashingProtection;
|
|
33
|
-
|
|
35
|
+
rollupAddress;
|
|
36
|
+
dateProvider;
|
|
37
|
+
metrics;
|
|
38
|
+
signerCallTimeoutMs;
|
|
39
|
+
constructor(db, config, deps){
|
|
34
40
|
this.config = config;
|
|
35
41
|
this.log = createLogger('validator-ha-signer');
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
this.metrics = deps.metrics;
|
|
43
|
+
this.dateProvider = deps.dateProvider;
|
|
44
|
+
// Clamp the signer-call timeout below half the stuck-duty max age. This maintains the
|
|
45
|
+
// invariant that an in-flight signing always times out and releases its SIGNING row well before
|
|
46
|
+
// stuck-duty cleanup could consider it stuck, so cleanup can never delete a live duty (only
|
|
47
|
+
// signWithProtection writes SIGNING rows, and every path through it is bounded by this timeout).
|
|
48
|
+
// If timers misbehave anyway, the recordSuccess-returns-false throw is the backstop: the duty
|
|
49
|
+
// fails instead of broadcasting an unprotected signature.
|
|
50
|
+
const maxStuckDutiesAgeMs = config.maxStuckDutiesAgeMs ?? DEFAULT_MAX_STUCK_DUTIES_AGE_MS;
|
|
51
|
+
this.signerCallTimeoutMs = Math.min(config.signerCallTimeoutMs ?? DEFAULT_SIGNER_CALL_TIMEOUT_MS, maxStuckDutiesAgeMs / 2);
|
|
40
52
|
if (!config.nodeId || config.nodeId === '') {
|
|
41
53
|
throw new Error('NODE_ID is required for high-availability setups');
|
|
42
54
|
}
|
|
43
|
-
this.
|
|
55
|
+
this.rollupAddress = config.rollupAddress;
|
|
56
|
+
this.slashingProtection = new SlashingProtectionService(db, config, {
|
|
57
|
+
metrics: deps.metrics,
|
|
58
|
+
dateProvider: deps.dateProvider
|
|
59
|
+
});
|
|
44
60
|
this.log.info('Validator HA Signer initialized with slashing protection', {
|
|
45
|
-
nodeId: config.nodeId
|
|
61
|
+
nodeId: config.nodeId,
|
|
62
|
+
rollupAddress: this.rollupAddress.toString(),
|
|
63
|
+
signerCallTimeoutMs: this.signerCallTimeoutMs
|
|
46
64
|
});
|
|
47
65
|
}
|
|
48
66
|
/**
|
|
@@ -62,9 +80,12 @@ import { getBlockNumberFromSigningContext } from './types.js';
|
|
|
62
80
|
* @throws DutyAlreadySignedError if the duty was already signed (expected in HA)
|
|
63
81
|
* @throws SlashingProtectionError if attempting to sign different data for same slot (expected in HA)
|
|
64
82
|
*/ async signWithProtection(validatorAddress, messageHash, context, signFn) {
|
|
83
|
+
const startTime = this.dateProvider.now();
|
|
84
|
+
const dutyType = context.dutyType;
|
|
65
85
|
let dutyIdentifier;
|
|
66
86
|
if (context.dutyType === DutyType.BLOCK_PROPOSAL) {
|
|
67
87
|
dutyIdentifier = {
|
|
88
|
+
rollupAddress: this.rollupAddress,
|
|
68
89
|
validatorAddress,
|
|
69
90
|
slot: context.slot,
|
|
70
91
|
blockIndexWithinCheckpoint: context.blockIndexWithinCheckpoint,
|
|
@@ -72,38 +93,55 @@ import { getBlockNumberFromSigningContext } from './types.js';
|
|
|
72
93
|
};
|
|
73
94
|
} else {
|
|
74
95
|
dutyIdentifier = {
|
|
96
|
+
rollupAddress: this.rollupAddress,
|
|
75
97
|
validatorAddress,
|
|
76
98
|
slot: context.slot,
|
|
77
99
|
dutyType: context.dutyType
|
|
78
100
|
};
|
|
79
101
|
}
|
|
80
102
|
// Acquire lock and get the token for ownership verification
|
|
103
|
+
// DutyAlreadySignedError and SlashingProtectionError may be thrown here and are recorded in the service
|
|
81
104
|
const blockNumber = getBlockNumberFromSigningContext(context);
|
|
105
|
+
const checkpointNumber = getCheckpointNumberFromSigningContext(context);
|
|
82
106
|
const lockToken = await this.slashingProtection.checkAndRecord({
|
|
83
107
|
...dutyIdentifier,
|
|
84
108
|
blockNumber,
|
|
109
|
+
checkpointNumber,
|
|
85
110
|
messageHash: messageHash.toString(),
|
|
86
111
|
nodeId: this.config.nodeId
|
|
87
112
|
});
|
|
88
|
-
// Perform signing
|
|
113
|
+
// Perform signing under a hard timeout. If the signer hangs, executeTimeout aborts and rejects;
|
|
114
|
+
// the orphaned signFn promise resolving later is discarded (never broadcast). A timeout takes the
|
|
115
|
+
// same failure path as any signing error: release the lock so the duty can be retried safely.
|
|
89
116
|
let signature;
|
|
90
117
|
try {
|
|
91
|
-
signature = await signFn(messageHash);
|
|
118
|
+
signature = await executeTimeout(()=>signFn(messageHash), this.signerCallTimeoutMs, ()=>new Error(`Signing operation for ${dutyType} at slot ${context.slot} timed out after ` + `${this.signerCallTimeoutMs}ms`));
|
|
92
119
|
} catch (error) {
|
|
93
120
|
// Delete duty to allow retry (only succeeds if we own the lock)
|
|
94
121
|
await this.slashingProtection.deleteDuty({
|
|
95
122
|
...dutyIdentifier,
|
|
96
123
|
lockToken
|
|
97
124
|
});
|
|
125
|
+
this.metrics.recordSigningError(dutyType);
|
|
98
126
|
throw error;
|
|
99
127
|
}
|
|
100
|
-
// Record success (only succeeds if we own the lock)
|
|
101
|
-
|
|
128
|
+
// Record success (only succeeds if we still own the lock).
|
|
129
|
+
// A false result means our SIGNING row is gone or no longer ours (e.g. deleted by stuck-duty
|
|
130
|
+
// cleanup while signing was slow). We must not broadcast this signature: without a protection
|
|
131
|
+
// record, a later attempt for the same duty with different data would sign freely (slashable).
|
|
132
|
+
// Do not delete the duty here - we no longer own it, and another node may legitimately hold it.
|
|
133
|
+
const recorded = await this.slashingProtection.recordSuccess({
|
|
102
134
|
...dutyIdentifier,
|
|
103
135
|
signature,
|
|
104
136
|
nodeId: this.config.nodeId,
|
|
105
137
|
lockToken
|
|
106
138
|
});
|
|
139
|
+
if (!recorded) {
|
|
140
|
+
this.metrics.recordSigningError(dutyType);
|
|
141
|
+
throw new SigningLockLostError(context.slot, dutyType, this.config.nodeId);
|
|
142
|
+
}
|
|
143
|
+
const duration = this.dateProvider.now() - startTime;
|
|
144
|
+
this.metrics.recordSigningSuccess(dutyType, duration);
|
|
107
145
|
return signature;
|
|
108
146
|
}
|
|
109
147
|
/**
|
|
@@ -114,8 +152,8 @@ import { getBlockNumberFromSigningContext } from './types.js';
|
|
|
114
152
|
/**
|
|
115
153
|
* Start the HA signer background tasks (cleanup of stuck duties).
|
|
116
154
|
* Should be called after construction and before signing operations.
|
|
117
|
-
*/ start() {
|
|
118
|
-
this.slashingProtection.start();
|
|
155
|
+
*/ async start() {
|
|
156
|
+
await this.slashingProtection.start();
|
|
119
157
|
}
|
|
120
158
|
/**
|
|
121
159
|
* Stop the HA signer background tasks and close database connection.
|
package/package.json
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/validator-ha-signer",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.d58ff9d0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
|
-
"./config": "./dest/config.js",
|
|
7
6
|
"./db": "./dest/db/index.js",
|
|
8
7
|
"./errors": "./dest/errors.js",
|
|
9
8
|
"./factory": "./dest/factory.js",
|
|
9
|
+
"./metrics": "./dest/metrics.js",
|
|
10
10
|
"./migrations": "./dest/migrations.js",
|
|
11
11
|
"./slashing-protection-service": "./dest/slashing_protection_service.js",
|
|
12
12
|
"./types": "./dest/types.js",
|
|
13
13
|
"./validator-ha-signer": "./dest/validator_ha_signer.js",
|
|
14
|
-
"./test": "./dest/test/pglite_pool.js"
|
|
14
|
+
"./test": "./dest/test/pglite_pool.js",
|
|
15
|
+
"./db/lmdb": "./dest/db/lmdb.js"
|
|
15
16
|
},
|
|
16
17
|
"typedocOptions": {
|
|
17
18
|
"entryPoints": [
|
|
18
|
-
"./src/config.ts",
|
|
19
19
|
"./src/db/index.ts",
|
|
20
20
|
"./src/errors.ts",
|
|
21
21
|
"./src/factory.ts",
|
|
22
|
+
"./src/metrics.ts",
|
|
22
23
|
"./src/migrations.ts",
|
|
23
24
|
"./src/slashing_protection_service.ts",
|
|
24
25
|
"./src/types.ts",
|
|
@@ -74,11 +75,15 @@
|
|
|
74
75
|
]
|
|
75
76
|
},
|
|
76
77
|
"dependencies": {
|
|
77
|
-
"@aztec/
|
|
78
|
+
"@aztec/ethereum": "0.0.1-commit.d58ff9d0",
|
|
79
|
+
"@aztec/foundation": "0.0.1-commit.d58ff9d0",
|
|
80
|
+
"@aztec/kv-store": "0.0.1-commit.d58ff9d0",
|
|
81
|
+
"@aztec/stdlib": "0.0.1-commit.d58ff9d0",
|
|
82
|
+
"@aztec/telemetry-client": "0.0.1-commit.d58ff9d0",
|
|
78
83
|
"node-pg-migrate": "^8.0.4",
|
|
79
84
|
"pg": "^8.11.3",
|
|
80
85
|
"tslib": "^2.4.0",
|
|
81
|
-
"zod": "^
|
|
86
|
+
"zod": "^4"
|
|
82
87
|
},
|
|
83
88
|
"devDependencies": {
|
|
84
89
|
"@electric-sql/pglite": "^0.3.14",
|
package/src/db/index.ts
CHANGED