@aztec/validator-ha-signer 0.0.1-commit.9ef841308 → 0.0.1-commit.a5db02d
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 +2 -2
- package/dest/db/lmdb.d.ts +6 -2
- package/dest/db/lmdb.d.ts.map +1 -1
- package/dest/db/lmdb.js +37 -2
- 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 +1 -1
- package/dest/db/postgres.d.ts.map +1 -1
- package/dest/db/postgres.js +2 -0
- package/dest/db/schema.d.ts +6 -6
- package/dest/db/schema.d.ts.map +1 -1
- package/dest/db/schema.js +9 -4
- package/dest/db/types.d.ts +11 -5
- package/dest/db/types.d.ts.map +1 -1
- package/dest/db/types.js +2 -1
- 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 +7 -9
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +35 -9
- package/dest/slashing_protection_service.d.ts +4 -2
- package/dest/slashing_protection_service.d.ts.map +1 -1
- package/dest/slashing_protection_service.js +12 -9
- package/dest/types.d.ts +4 -3
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +2 -1
- package/dest/validator_ha_signer.d.ts +3 -2
- package/dest/validator_ha_signer.d.ts.map +1 -1
- package/dest/validator_ha_signer.js +33 -8
- package/package.json +7 -7
- package/src/db/lmdb.ts +46 -2
- 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 +2 -0
- package/src/db/schema.ts +9 -4
- package/src/db/types.ts +11 -9
- package/src/errors.ts +21 -0
- package/src/factory.ts +58 -13
- package/src/slashing_protection_service.ts +14 -9
- package/src/types.ts +6 -0
- package/src/validator_ha_signer.ts +47 -7
package/dest/factory.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Factory functions for creating validator HA signers
|
|
3
|
-
*/
|
|
4
1
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
5
2
|
import type { LocalSignerConfig, ValidatorHASignerConfig } from '@aztec/stdlib/ha-signing';
|
|
6
3
|
import type { CreateHASignerDeps, CreateLocalSignerWithProtectionDeps, SlashingProtectionDatabase } from './types.js';
|
|
@@ -22,7 +19,7 @@ import { ValidatorHASigner } from './validator_ha_signer.js';
|
|
|
22
19
|
* databaseUrl: process.env.DATABASE_URL,
|
|
23
20
|
* nodeId: 'validator-node-1',
|
|
24
21
|
* pollingIntervalMs: 100,
|
|
25
|
-
*
|
|
22
|
+
* peerSigningTimeoutMs: 3000,
|
|
26
23
|
* });
|
|
27
24
|
* signer.start(); // Start background cleanup
|
|
28
25
|
*
|
|
@@ -49,9 +46,10 @@ export declare function createHASigner(config: ValidatorHASignerConfig, deps?: C
|
|
|
49
46
|
* high-availability (multi-node) setup. It prevents a proposer from sending two
|
|
50
47
|
* proposals for the same slot if the node crashes and restarts mid-proposal.
|
|
51
48
|
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
49
|
+
* `config.dataDirectory` is required so the protection database is persisted to disk and survives
|
|
50
|
+
* crashes/restarts. Booting without it throws, since an ephemeral store silently drops all
|
|
51
|
+
* double-signing protection across restarts. Set `config.allowEphemeralSigningProtection` to opt
|
|
52
|
+
* into the ephemeral store anyway (dev/test networks only) — a loud warning is logged in that case.
|
|
55
53
|
*
|
|
56
54
|
* @param config - Local signer config
|
|
57
55
|
* @param deps - Optional dependencies (telemetry, date provider).
|
|
@@ -70,8 +68,8 @@ export declare function createSharedSlashingProtectionDb(dateProvider?: DateProv
|
|
|
70
68
|
* Create a ValidatorHASigner backed by a pre-existing SlashingProtectionDatabase.
|
|
71
69
|
* Used for testing HA setups where multiple nodes share the same protection database.
|
|
72
70
|
*/
|
|
73
|
-
export declare function createSignerFromSharedDb(db: SlashingProtectionDatabase, config: Pick<ValidatorHASignerConfig, 'nodeId' | 'pollingIntervalMs' | '
|
|
71
|
+
export declare function createSignerFromSharedDb(db: SlashingProtectionDatabase, config: Pick<ValidatorHASignerConfig, 'nodeId' | 'pollingIntervalMs' | 'peerSigningTimeoutMs' | 'maxStuckDutiesAgeMs' | 'rollupAddress'>, deps?: CreateLocalSignerWithProtectionDeps): {
|
|
74
72
|
signer: ValidatorHASigner;
|
|
75
73
|
db: SlashingProtectionDatabase;
|
|
76
74
|
};
|
|
77
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
75
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmFjdG9yeS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2ZhY3RvcnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBSUEsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBRXZELE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUFFLHVCQUF1QixFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFRM0YsT0FBTyxLQUFLLEVBQUUsa0JBQWtCLEVBQUUsbUNBQW1DLEVBQUUsMEJBQTBCLEVBQUUsTUFBTSxZQUFZLENBQUM7QUFDdEgsT0FBTyxFQUFFLGlCQUFpQixFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFFN0Q7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBZ0NHO0FBQ0gsd0JBQXNCLGNBQWMsQ0FDbEMsTUFBTSxFQUFFLHVCQUF1QixFQUMvQixJQUFJLENBQUMsRUFBRSxrQkFBa0IsR0FDeEIsT0FBTyxDQUFDO0lBQ1QsTUFBTSxFQUFFLGlCQUFpQixDQUFDO0lBQzFCLEVBQUUsRUFBRSwwQkFBMEIsQ0FBQztDQUNoQyxDQUFDLENBaUREO0FBRUQ7Ozs7Ozs7Ozs7Ozs7OztHQWVHO0FBQ0gsd0JBQXNCLCtCQUErQixDQUNuRCxNQUFNLEVBQUUsaUJBQWlCLEVBQ3pCLElBQUksQ0FBQyxFQUFFLG1DQUFtQyxHQUN6QyxPQUFPLENBQUM7SUFDVCxNQUFNLEVBQUUsaUJBQWlCLENBQUM7SUFDMUIsRUFBRSxFQUFFLDBCQUEwQixDQUFDO0NBQ2hDLENBQUMsQ0FzREQ7QUFFRDs7O0dBR0c7QUFDSCx3QkFBc0IsZ0NBQWdDLENBQ3BELFlBQVksR0FBRSxZQUFpQyxHQUM5QyxPQUFPLENBQUMsMEJBQTBCLENBQUMsQ0FLckM7QUFFRDs7O0dBR0c7QUFDSCx3QkFBZ0Isd0JBQXdCLENBQ3RDLEVBQUUsRUFBRSwwQkFBMEIsRUFDOUIsTUFBTSxFQUFFLElBQUksQ0FDVix1QkFBdUIsRUFDdkIsUUFBUSxHQUFHLG1CQUFtQixHQUFHLHNCQUFzQixHQUFHLHFCQUFxQixHQUFHLGVBQWUsQ0FDbEcsRUFDRCxJQUFJLENBQUMsRUFBRSxtQ0FBbUMsR0FDekM7SUFBRSxNQUFNLEVBQUUsaUJBQWlCLENBQUM7SUFBQyxFQUFFLEVBQUUsMEJBQTBCLENBQUE7Q0FBRSxDQU0vRCJ9
|
package/dest/factory.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAQ3F,OAAO,KAAK,EAAE,kBAAkB,EAAE,mCAAmC,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AACtH,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,uBAAuB,EAC/B,IAAI,CAAC,EAAE,kBAAkB,GACxB,OAAO,CAAC;IACT,MAAM,EAAE,iBAAiB,CAAC;IAC1B,EAAE,EAAE,0BAA0B,CAAC;CAChC,CAAC,CAiDD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,+BAA+B,CACnD,MAAM,EAAE,iBAAiB,EACzB,IAAI,CAAC,EAAE,mCAAmC,GACzC,OAAO,CAAC;IACT,MAAM,EAAE,iBAAiB,CAAC;IAC1B,EAAE,EAAE,0BAA0B,CAAC;CAChC,CAAC,CAsDD;AAED;;;GAGG;AACH,wBAAsB,gCAAgC,CACpD,YAAY,GAAE,YAAiC,GAC9C,OAAO,CAAC,0BAA0B,CAAC,CAKrC;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,EAAE,EAAE,0BAA0B,EAC9B,MAAM,EAAE,IAAI,CACV,uBAAuB,EACvB,QAAQ,GAAG,mBAAmB,GAAG,sBAAsB,GAAG,qBAAqB,GAAG,eAAe,CAClG,EACD,IAAI,CAAC,EAAE,mCAAmC,GACzC;IAAE,MAAM,EAAE,iBAAiB,CAAC;IAAC,EAAE,EAAE,0BAA0B,CAAA;CAAE,CAM/D"}
|
package/dest/factory.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Factory functions for creating validator HA signers
|
|
3
|
-
*/ import {
|
|
3
|
+
*/ import { createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
4
5
|
import { createStore } from '@aztec/kv-store/lmdb-v2';
|
|
5
6
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
6
7
|
import { Pool } from 'pg';
|
|
7
|
-
import { LmdbSlashingProtectionDatabase } from './db/lmdb.js';
|
|
8
|
+
import { LmdbSlashingProtectionDatabase, migrateLmdbSlashingProtectionDatabase } from './db/lmdb.js';
|
|
8
9
|
import { PostgresSlashingProtectionDatabase } from './db/postgres.js';
|
|
9
10
|
import { HASignerMetrics } from './metrics.js';
|
|
10
11
|
import { ValidatorHASigner } from './validator_ha_signer.js';
|
|
@@ -25,7 +26,7 @@ import { ValidatorHASigner } from './validator_ha_signer.js';
|
|
|
25
26
|
* databaseUrl: process.env.DATABASE_URL,
|
|
26
27
|
* nodeId: 'validator-node-1',
|
|
27
28
|
* pollingIntervalMs: 100,
|
|
28
|
-
*
|
|
29
|
+
* peerSigningTimeoutMs: 3000,
|
|
29
30
|
* });
|
|
30
31
|
* signer.start(); // Start background cleanup
|
|
31
32
|
*
|
|
@@ -42,7 +43,8 @@ import { ValidatorHASigner } from './validator_ha_signer.js';
|
|
|
42
43
|
* @returns An object containing the signer and database instances
|
|
43
44
|
*/ export async function createHASigner(config, deps) {
|
|
44
45
|
const { databaseUrl, poolMaxCount, poolMinCount, poolIdleTimeoutMs, poolConnectionTimeoutMs, ...signerConfig } = config;
|
|
45
|
-
|
|
46
|
+
const databaseUrlValue = databaseUrl?.getValue();
|
|
47
|
+
if (!databaseUrlValue) {
|
|
46
48
|
throw new Error('databaseUrl is required for createHASigner');
|
|
47
49
|
}
|
|
48
50
|
const telemetryClient = deps?.telemetryClient ?? getTelemetryClient();
|
|
@@ -51,7 +53,7 @@ import { ValidatorHASigner } from './validator_ha_signer.js';
|
|
|
51
53
|
let pool;
|
|
52
54
|
if (!deps?.pool) {
|
|
53
55
|
pool = new Pool({
|
|
54
|
-
connectionString:
|
|
56
|
+
connectionString: databaseUrlValue,
|
|
55
57
|
max: poolMaxCount ?? 10,
|
|
56
58
|
min: poolMinCount ?? 0,
|
|
57
59
|
idleTimeoutMillis: poolIdleTimeoutMs ?? 10_000,
|
|
@@ -60,6 +62,18 @@ import { ValidatorHASigner } from './validator_ha_signer.js';
|
|
|
60
62
|
} else {
|
|
61
63
|
pool = deps.pool;
|
|
62
64
|
}
|
|
65
|
+
// pg re-emits idle-client errors (e.g. a Postgres restart severing an idle connection) on the
|
|
66
|
+
// pool. Without an 'error' listener, Node escalates these to an uncaughtException and crashes the
|
|
67
|
+
// process - taking down every HA replica sharing the DB at once. pg destroys and replaces the
|
|
68
|
+
// errored client itself, so logging is the only action needed. Log just message/code, never the
|
|
69
|
+
// raw error object (it can carry connection metadata).
|
|
70
|
+
const log = createLogger('validator-ha-signer:factory');
|
|
71
|
+
pool.on('error', (err)=>{
|
|
72
|
+
log.warn('Postgres pool error on idle client', {
|
|
73
|
+
message: err.message,
|
|
74
|
+
code: err.code
|
|
75
|
+
});
|
|
76
|
+
});
|
|
63
77
|
// Create database instance
|
|
64
78
|
const db = new PostgresSlashingProtectionDatabase(pool);
|
|
65
79
|
// Verify database schema is initialized and version matches
|
|
@@ -83,9 +97,10 @@ import { ValidatorHASigner } from './validator_ha_signer.js';
|
|
|
83
97
|
* high-availability (multi-node) setup. It prevents a proposer from sending two
|
|
84
98
|
* proposals for the same slot if the node crashes and restarts mid-proposal.
|
|
85
99
|
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
100
|
+
* `config.dataDirectory` is required so the protection database is persisted to disk and survives
|
|
101
|
+
* crashes/restarts. Booting without it throws, since an ephemeral store silently drops all
|
|
102
|
+
* double-signing protection across restarts. Set `config.allowEphemeralSigningProtection` to opt
|
|
103
|
+
* into the ephemeral store anyway (dev/test networks only) — a loud warning is logged in that case.
|
|
89
104
|
*
|
|
90
105
|
* @param config - Local signer config
|
|
91
106
|
* @param deps - Optional dependencies (telemetry, date provider).
|
|
@@ -93,10 +108,21 @@ import { ValidatorHASigner } from './validator_ha_signer.js';
|
|
|
93
108
|
*/ export async function createLocalSignerWithProtection(config, deps) {
|
|
94
109
|
const telemetryClient = deps?.telemetryClient ?? getTelemetryClient();
|
|
95
110
|
const dateProvider = deps?.dateProvider ?? new DateProvider();
|
|
111
|
+
const log = createLogger('validator-ha-signer:factory');
|
|
112
|
+
if (!config.dataDirectory) {
|
|
113
|
+
if (!config.allowEphemeralSigningProtection) {
|
|
114
|
+
throw new Error('Local signing protection requires a persistent data directory, but none was configured. ' + 'Set DATA_DIRECTORY so double-signing protection survives restarts, or explicitly opt into an ' + 'ephemeral store (dev/test only) with VALIDATOR_ALLOW_EPHEMERAL_SIGNING_PROTECTION=true.');
|
|
115
|
+
}
|
|
116
|
+
log.warn('Local signing protection is running with an EPHEMERAL store: no data directory is configured. ' + 'Double-signing protection will NOT survive a restart. This is unsafe for production validators.');
|
|
117
|
+
}
|
|
96
118
|
const kvStore = await createStore('signing-protection', LmdbSlashingProtectionDatabase.SCHEMA_VERSION, {
|
|
97
119
|
dataDirectory: config.dataDirectory,
|
|
98
120
|
dataStoreMapSizeKb: config.signingProtectionMapSizeKb ?? config.dataStoreMapSizeKb,
|
|
99
|
-
|
|
121
|
+
rollupAddress: config.rollupAddress
|
|
122
|
+
}, undefined, {
|
|
123
|
+
onUpgrade: (dataDirectory, currentVersion, latestVersion)=>migrateLmdbSlashingProtectionDatabase(dataDirectory, currentVersion, latestVersion, config.signingProtectionMapSizeKb ?? config.dataStoreMapSizeKb),
|
|
124
|
+
schemaVersionMismatchPolicy: 'throw',
|
|
125
|
+
versionFileReadFailurePolicy: 'throw'
|
|
100
126
|
});
|
|
101
127
|
const db = new LmdbSlashingProtectionDatabase(kvStore, dateProvider);
|
|
102
128
|
const signerConfig = {
|
|
@@ -7,6 +7,8 @@ export interface SlashingProtectionServiceDeps {
|
|
|
7
7
|
metrics: HASignerMetrics;
|
|
8
8
|
dateProvider: DateProvider;
|
|
9
9
|
}
|
|
10
|
+
/** Default max age (ms) of a stuck SIGNING duty before cleanup reclaims it: 2x the 72s Aztec slot duration. */
|
|
11
|
+
export declare const DEFAULT_MAX_STUCK_DUTIES_AGE_MS = 144000;
|
|
10
12
|
/**
|
|
11
13
|
* Slashing Protection Service
|
|
12
14
|
*
|
|
@@ -27,7 +29,7 @@ export declare class SlashingProtectionService {
|
|
|
27
29
|
private readonly config;
|
|
28
30
|
private readonly log;
|
|
29
31
|
private readonly pollingIntervalMs;
|
|
30
|
-
private readonly
|
|
32
|
+
private readonly peerSigningTimeoutMs;
|
|
31
33
|
private readonly maxStuckDutiesAgeMs;
|
|
32
34
|
private readonly metrics;
|
|
33
35
|
private readonly dateProvider;
|
|
@@ -90,4 +92,4 @@ export declare class SlashingProtectionService {
|
|
|
90
92
|
close(): Promise<void>;
|
|
91
93
|
private cleanup;
|
|
92
94
|
}
|
|
93
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
95
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2xhc2hpbmdfcHJvdGVjdGlvbl9zZXJ2aWNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvc2xhc2hpbmdfcHJvdGVjdGlvbl9zZXJ2aWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQVNBLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBQzVELE9BQU8sS0FBSyxFQUFFLGdCQUFnQixFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFFakUsT0FBTyxFQUNMLEtBQUssb0JBQW9CLEVBQ3pCLEtBQUssZ0JBQWdCLEVBRXJCLEtBQUssbUJBQW1CLEVBRXpCLE1BQU0sZUFBZSxDQUFDO0FBRXZCLE9BQU8sS0FBSyxFQUFFLGVBQWUsRUFBRSxNQUFNLGNBQWMsQ0FBQztBQUNwRCxPQUFPLEtBQUssRUFBRSwwQkFBMEIsRUFBRSxNQUFNLFlBQVksQ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ozs7T0FNRztJQUNHLFVBQVUsQ0FBQyxNQUFNLEVBQUUsZ0JBQWdCLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQXdCM0Q7SUFFRDs7T0FFRztJQUNILElBQUksTUFBTSxJQUFJLE1BQU0sQ0FFbkI7SUFFRDs7O09BR0c7SUFDSDs7O09BR0c7SUFDRyxLQUFLLGtCQVlWO0lBRUQ7O09BRUc7SUFDRyxJQUFJLGtCQUdUO0lBRUQ7OztPQUdHO0lBQ0csS0FBSyxrQkFHVjtZQU1hLE9BQU87Q0FrQ3RCIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slashing_protection_service.d.ts","sourceRoot":"","sources":["../src/slashing_protection_service.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EAErB,KAAK,mBAAmB,EAEzB,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AAE7D,MAAM,WAAW,6BAA6B;IAC5C,OAAO,EAAE,eAAe,CAAC;IACzB,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,yBAAyB;IAalC,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAbzB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"slashing_protection_service.d.ts","sourceRoot":"","sources":["../src/slashing_protection_service.ts"],"names":[],"mappings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CA2BjE;IAED;;;;;;OAMG;IACG,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAwB3D;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;OAGG;IACH;;;OAGG;IACG,KAAK,kBAYV;IAED;;OAEG;IACG,IAAI,kBAGT;IAED;;;OAGG;IACG,KAAK,kBAGV;YAMa,OAAO;CAkCtB"}
|
|
@@ -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,7 +28,7 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
27
28
|
config;
|
|
28
29
|
log;
|
|
29
30
|
pollingIntervalMs;
|
|
30
|
-
|
|
31
|
+
peerSigningTimeoutMs;
|
|
31
32
|
maxStuckDutiesAgeMs;
|
|
32
33
|
metrics;
|
|
33
34
|
dateProvider;
|
|
@@ -38,9 +39,8 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
38
39
|
this.config = config;
|
|
39
40
|
this.log = createLogger('slashing-protection');
|
|
40
41
|
this.pollingIntervalMs = config.pollingIntervalMs;
|
|
41
|
-
this.
|
|
42
|
-
|
|
43
|
-
this.maxStuckDutiesAgeMs = config.maxStuckDutiesAgeMs ?? 144_000;
|
|
42
|
+
this.peerSigningTimeoutMs = config.peerSigningTimeoutMs;
|
|
43
|
+
this.maxStuckDutiesAgeMs = config.maxStuckDutiesAgeMs ?? DEFAULT_MAX_STUCK_DUTIES_AGE_MS;
|
|
44
44
|
this.cleanupRunningPromise = new RunningPromise(this.cleanup.bind(this), this.log, this.maxStuckDutiesAgeMs);
|
|
45
45
|
this.metrics = deps.metrics;
|
|
46
46
|
this.dateProvider = deps.dateProvider;
|
|
@@ -96,10 +96,10 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
96
96
|
throw new DutyAlreadySignedError(slot, dutyType, record.blockIndexWithinCheckpoint, record.nodeId);
|
|
97
97
|
} else if (record.status === DutyStatus.SIGNING) {
|
|
98
98
|
// Another node is currently signing - check for timeout
|
|
99
|
-
if (this.dateProvider.now() - startTime > this.
|
|
99
|
+
if (this.dateProvider.now() - startTime > this.peerSigningTimeoutMs) {
|
|
100
100
|
this.log.warn(`Timeout waiting for signing to complete for duty ${dutyType} at slot ${slot}`, {
|
|
101
101
|
validatorAddress: validatorAddress.toString(),
|
|
102
|
-
timeoutMs: this.
|
|
102
|
+
timeoutMs: this.peerSigningTimeoutMs,
|
|
103
103
|
signingNodeId: record.nodeId
|
|
104
104
|
});
|
|
105
105
|
this.metrics.recordDutyAlreadySigned(dutyType);
|
|
@@ -174,10 +174,10 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
174
174
|
* Also performs one-time cleanup of duties with outdated rollup addresses.
|
|
175
175
|
*/ async start() {
|
|
176
176
|
// One-time cleanup at startup: remove duties from previous rollup versions
|
|
177
|
-
const numOutdatedRollupDuties = await this.db.cleanupOutdatedRollupDuties(this.config.
|
|
177
|
+
const numOutdatedRollupDuties = await this.db.cleanupOutdatedRollupDuties(this.config.rollupAddress);
|
|
178
178
|
if (numOutdatedRollupDuties > 0) {
|
|
179
179
|
this.log.info(`Cleaned up ${numOutdatedRollupDuties} duties with outdated rollup address at startup`, {
|
|
180
|
-
currentRollupAddress: this.config.
|
|
180
|
+
currentRollupAddress: this.config.rollupAddress.toString()
|
|
181
181
|
});
|
|
182
182
|
this.metrics.recordCleanup('outdated_rollup', numOutdatedRollupDuties);
|
|
183
183
|
}
|
|
@@ -205,7 +205,10 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
205
205
|
* Periodic cleanup of stuck duties and optionally old signed duties.
|
|
206
206
|
* Runs in the background via RunningPromise.
|
|
207
207
|
*/ async cleanup() {
|
|
208
|
-
// 1. Clean up stuck duties (our own node's duties that got stuck in 'signing' status)
|
|
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.
|
|
209
212
|
const numStuckDuties = await this.db.cleanupOwnStuckDuties(this.config.nodeId, this.maxStuckDutiesAgeMs);
|
|
210
213
|
if (numStuckDuties > 0) {
|
|
211
214
|
this.log.verbose(`Cleaned up ${numStuckDuties} stuck duties`, {
|
package/dest/types.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
3
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
4
|
-
import { DutyType, type HAProtectedSigningContext, type SigningContext, type ValidatorHASignerConfig, getBlockNumberFromSigningContext as getBlockNumberFromSigningContextFromStdlib, isHAProtectedContext } from '@aztec/stdlib/ha-signing';
|
|
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
5
|
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
6
6
|
import type { Pool } from 'pg';
|
|
7
7
|
import type { BlockProposalDutyIdentifier, CheckAndRecordParams, DeleteDutyParams, DutyIdentifier, DutyRow, OtherDutyIdentifier, RecordSuccessParams, ValidatorDutyRecord } from './db/types.js';
|
|
8
|
-
export type { BlockProposalDutyIdentifier, CheckAndRecordParams, DeleteDutyParams, DutyIdentifier, DutyRow, HAProtectedSigningContext, OtherDutyIdentifier, RecordSuccessParams, SigningContext, ValidatorDutyRecord, ValidatorHASignerConfig, };
|
|
8
|
+
export type { AttestationSigningContext, BlockProposalDutyIdentifier, CheckAndRecordParams, CheckpointProposalSigningContext, DeleteDutyParams, DutyIdentifier, DutyRow, HAProtectedSigningContext, OtherDutyIdentifier, RecordSuccessParams, SigningContext, ValidatorDutyRecord, ValidatorHASignerConfig, };
|
|
9
9
|
export { DutyStatus, DutyType, getBlockIndexFromDutyIdentifier, normalizeBlockIndex } from './db/types.js';
|
|
10
10
|
export { isHAProtectedContext };
|
|
11
11
|
export { getBlockNumberFromSigningContextFromStdlib as getBlockNumberFromSigningContext };
|
|
12
|
+
export { getCheckpointNumberFromSigningContextFromStdlib as getCheckpointNumberFromSigningContext };
|
|
12
13
|
/**
|
|
13
14
|
* Result of tryInsertOrGetExisting operation
|
|
14
15
|
*/
|
|
@@ -96,4 +97,4 @@ export interface SlashingProtectionDatabase {
|
|
|
96
97
|
*/
|
|
97
98
|
close(): Promise<void>;
|
|
98
99
|
}
|
|
99
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
100
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy90eXBlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDN0QsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0sK0JBQStC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,EAAE,MAAM,EACjB,0BAA0B,EAAE,MAAM,GACjC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpB;;;;;;OAMG;IACH,UAAU,CACR,aAAa,EAAE,UAAU,EACzB,gBAAgB,EAAE,UAAU,EAC5B,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,MAAM,EACjB,0BAA0B,EAAE,MAAM,GACjC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpB;;;OAGG;IACH,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEzE;;;;;OAKG;IACH,2BAA2B,CAAC,oBAAoB,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE/E;;;;OAIG;IACH,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEpD;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}
|
package/dest/types.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { getBlockNumberFromSigningContext as getBlockNumberFromSigningContextFromStdlib, isHAProtectedContext } from '@aztec/stdlib/ha-signing';
|
|
1
|
+
import { getBlockNumberFromSigningContext as getBlockNumberFromSigningContextFromStdlib, getCheckpointNumberFromSigningContext as getCheckpointNumberFromSigningContextFromStdlib, isHAProtectedContext } from '@aztec/stdlib/ha-signing';
|
|
2
2
|
export { DutyStatus, DutyType, getBlockIndexFromDutyIdentifier, normalizeBlockIndex } from './db/types.js';
|
|
3
3
|
export { isHAProtectedContext };
|
|
4
4
|
export { getBlockNumberFromSigningContextFromStdlib as getBlockNumberFromSigningContext };
|
|
5
|
+
export { getCheckpointNumberFromSigningContextFromStdlib as getCheckpointNumberFromSigningContext };
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
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
|
-
import type
|
|
11
|
+
import { type DateProvider } from '@aztec/foundation/timer';
|
|
12
12
|
import { type BaseSignerConfig, type HAProtectedSigningContext } from '@aztec/stdlib/ha-signing';
|
|
13
13
|
import type { HASignerMetrics } from './metrics.js';
|
|
14
14
|
import type { SlashingProtectionDatabase } from './types.js';
|
|
@@ -42,6 +42,7 @@ export declare class ValidatorHASigner {
|
|
|
42
42
|
private readonly rollupAddress;
|
|
43
43
|
private readonly dateProvider;
|
|
44
44
|
private readonly metrics;
|
|
45
|
+
private readonly signerCallTimeoutMs;
|
|
45
46
|
constructor(db: SlashingProtectionDatabase, config: BaseSignerConfig, deps: ValidatorHASignerDeps);
|
|
46
47
|
/**
|
|
47
48
|
* Sign a message with slashing protection.
|
|
@@ -76,4 +77,4 @@ export declare class ValidatorHASigner {
|
|
|
76
77
|
*/
|
|
77
78
|
stop(): Promise<void>;
|
|
78
79
|
}
|
|
79
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
80
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsaWRhdG9yX2hhX3NpZ25lci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3ZhbGlkYXRvcl9oYV9zaWduZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBQ0gsT0FBTyxLQUFLLEVBQUUsUUFBUSxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFDekQsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLCtCQUErQixDQUFDO0FBQzNELE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBRWpFLE9BQU8sRUFBRSxLQUFLLFlBQVksRUFBa0IsTUFBTSx5QkF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BRSxRQUFRLEtBQUssT0FBTyxDQUFDLFNBQVMsQ0FBQyxHQUNwRCxPQUFPLENBQUMsU0FBUyxDQUFDLENBMkVwQjtJQUVEOztPQUVHO0lBQ0gsSUFBSSxNQUFNLElBQUksTUFBTSxDQUVuQjtJQUVEOzs7T0FHRztJQUNHLEtBQUssa0JBRVY7SUFFRDs7O09BR0c7SUFDRyxJQUFJLGtCQUdUO0NBQ0YifQ==
|
|
@@ -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,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAEjE,OAAO,KAAK,
|
|
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+B,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAEjE,OAAO,EAAE,KAAK,YAAY,EAAkB,MAAM,yBAAyB,CAAC;AAC5E,OAAO,EACL,KAAK,gBAAgB,EAErB,KAAK,yBAAyB,EAG/B,MAAM,0BAA0B,CAAC;AAIlC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AAE7D,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,eAAe,CAAC;IACzB,YAAY,EAAE,YAAY,CAAC;CAC5B;AAKD;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,iBAAiB;IAW1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAVzB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA4B;IAC/D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAa;IAE3C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAC5C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAC1C,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAS;IAE7C,YACE,EAAE,EAAE,0BAA0B,EACb,MAAM,EAAE,gBAAgB,EACzC,IAAI,EAAE,qBAAqB,EAiC5B;IAED;;;;;;;;;;;;;;;;OAgBG;IACG,kBAAkB,CACtB,gBAAgB,EAAE,UAAU,EAC5B,WAAW,EAAE,QAAQ,EACrB,OAAO,EAAE,yBAAyB,EAClC,MAAM,EAAE,CAAC,WAAW,EAAE,QAAQ,KAAK,OAAO,CAAC,SAAS,CAAC,GACpD,OAAO,CAAC,SAAS,CAAC,CA2EpB;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;OAGG;IACG,KAAK,kBAEV;IAED;;;OAGG;IACG,IAAI,kBAGT;CACF"}
|
|
@@ -5,8 +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 {
|
|
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;
|
|
10
13
|
/**
|
|
11
14
|
* Validator High Availability Signer
|
|
12
15
|
*
|
|
@@ -32,22 +35,32 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
|
32
35
|
rollupAddress;
|
|
33
36
|
dateProvider;
|
|
34
37
|
metrics;
|
|
38
|
+
signerCallTimeoutMs;
|
|
35
39
|
constructor(db, config, deps){
|
|
36
40
|
this.config = config;
|
|
37
41
|
this.log = createLogger('validator-ha-signer');
|
|
38
42
|
this.metrics = deps.metrics;
|
|
39
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.rollupAddress = config.
|
|
55
|
+
this.rollupAddress = config.rollupAddress;
|
|
44
56
|
this.slashingProtection = new SlashingProtectionService(db, config, {
|
|
45
57
|
metrics: deps.metrics,
|
|
46
58
|
dateProvider: deps.dateProvider
|
|
47
59
|
});
|
|
48
60
|
this.log.info('Validator HA Signer initialized with slashing protection', {
|
|
49
61
|
nodeId: config.nodeId,
|
|
50
|
-
rollupAddress: this.rollupAddress.toString()
|
|
62
|
+
rollupAddress: this.rollupAddress.toString(),
|
|
63
|
+
signerCallTimeoutMs: this.signerCallTimeoutMs
|
|
51
64
|
});
|
|
52
65
|
}
|
|
53
66
|
/**
|
|
@@ -89,16 +102,20 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
|
89
102
|
// Acquire lock and get the token for ownership verification
|
|
90
103
|
// DutyAlreadySignedError and SlashingProtectionError may be thrown here and are recorded in the service
|
|
91
104
|
const blockNumber = getBlockNumberFromSigningContext(context);
|
|
105
|
+
const checkpointNumber = getCheckpointNumberFromSigningContext(context);
|
|
92
106
|
const lockToken = await this.slashingProtection.checkAndRecord({
|
|
93
107
|
...dutyIdentifier,
|
|
94
108
|
blockNumber,
|
|
109
|
+
checkpointNumber,
|
|
95
110
|
messageHash: messageHash.toString(),
|
|
96
111
|
nodeId: this.config.nodeId
|
|
97
112
|
});
|
|
98
|
-
// 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.
|
|
99
116
|
let signature;
|
|
100
117
|
try {
|
|
101
|
-
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`));
|
|
102
119
|
} catch (error) {
|
|
103
120
|
// Delete duty to allow retry (only succeeds if we own the lock)
|
|
104
121
|
await this.slashingProtection.deleteDuty({
|
|
@@ -108,13 +125,21 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
|
108
125
|
this.metrics.recordSigningError(dutyType);
|
|
109
126
|
throw error;
|
|
110
127
|
}
|
|
111
|
-
// Record success (only succeeds if we own the lock)
|
|
112
|
-
|
|
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({
|
|
113
134
|
...dutyIdentifier,
|
|
114
135
|
signature,
|
|
115
136
|
nodeId: this.config.nodeId,
|
|
116
137
|
lockToken
|
|
117
138
|
});
|
|
139
|
+
if (!recorded) {
|
|
140
|
+
this.metrics.recordSigningError(dutyType);
|
|
141
|
+
throw new SigningLockLostError(context.slot, dutyType, this.config.nodeId);
|
|
142
|
+
}
|
|
118
143
|
const duration = this.dateProvider.now() - startTime;
|
|
119
144
|
this.metrics.recordSigningSuccess(dutyType, duration);
|
|
120
145
|
return signature;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/validator-ha-signer",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.a5db02d",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./db": "./dest/db/index.js",
|
|
@@ -75,15 +75,15 @@
|
|
|
75
75
|
]
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
79
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
80
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
81
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
82
|
-
"@aztec/telemetry-client": "0.0.1-commit.
|
|
78
|
+
"@aztec/ethereum": "0.0.1-commit.a5db02d",
|
|
79
|
+
"@aztec/foundation": "0.0.1-commit.a5db02d",
|
|
80
|
+
"@aztec/kv-store": "0.0.1-commit.a5db02d",
|
|
81
|
+
"@aztec/stdlib": "0.0.1-commit.a5db02d",
|
|
82
|
+
"@aztec/telemetry-client": "0.0.1-commit.a5db02d",
|
|
83
83
|
"node-pg-migrate": "^8.0.4",
|
|
84
84
|
"pg": "^8.11.3",
|
|
85
85
|
"tslib": "^2.4.0",
|
|
86
|
-
"zod": "^
|
|
86
|
+
"zod": "^4"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
89
89
|
"@electric-sql/pglite": "^0.3.14",
|
package/src/db/lmdb.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
13
13
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
14
14
|
import type { DateProvider } from '@aztec/foundation/timer';
|
|
15
15
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
16
|
+
import { openStoreAt } from '@aztec/kv-store/lmdb-v2';
|
|
16
17
|
|
|
17
18
|
import type { SlashingProtectionDatabase, TryInsertOrGetResult } from '../types.js';
|
|
18
19
|
import {
|
|
@@ -24,6 +25,48 @@ import {
|
|
|
24
25
|
recordFromFields,
|
|
25
26
|
} from './types.js';
|
|
26
27
|
|
|
28
|
+
const DUTIES_MAP_NAME = 'signing-protection-duties';
|
|
29
|
+
const LEGACY_CHECKPOINT_NUMBER = '0';
|
|
30
|
+
|
|
31
|
+
type StoredDutyRecordV1 = Omit<StoredDutyRecord, 'checkpointNumber'> & { checkpointNumber?: undefined };
|
|
32
|
+
type MigratableStoredDutyRecord = StoredDutyRecord | StoredDutyRecordV1;
|
|
33
|
+
|
|
34
|
+
function needsCheckpointNumberMigration(record: MigratableStoredDutyRecord): record is StoredDutyRecordV1 {
|
|
35
|
+
return record.checkpointNumber === undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Migrates local slashing-protection duties from schema 1 to schema 2.
|
|
40
|
+
*/
|
|
41
|
+
export async function migrateLmdbSlashingProtectionDatabase(
|
|
42
|
+
dataDirectory: string,
|
|
43
|
+
currentVersion: number,
|
|
44
|
+
latestVersion: number,
|
|
45
|
+
dbMapSizeKb?: number,
|
|
46
|
+
): Promise<void> {
|
|
47
|
+
if (currentVersion !== 1 || latestVersion !== LmdbSlashingProtectionDatabase.SCHEMA_VERSION) {
|
|
48
|
+
throw new Error(`Unsupported LMDB slashing-protection migration ${currentVersion} -> ${latestVersion}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const store = await openStoreAt(dataDirectory, dbMapSizeKb);
|
|
52
|
+
try {
|
|
53
|
+
const duties = store.openMap<string, MigratableStoredDutyRecord>(DUTIES_MAP_NAME);
|
|
54
|
+
const migratedRecords: { key: string; value: StoredDutyRecord }[] = [];
|
|
55
|
+
|
|
56
|
+
for await (const [key, record] of duties.entriesAsync()) {
|
|
57
|
+
if (needsCheckpointNumberMigration(record)) {
|
|
58
|
+
migratedRecords.push({ key, value: { ...record, checkpointNumber: LEGACY_CHECKPOINT_NUMBER } });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (migratedRecords.length > 0) {
|
|
63
|
+
await duties.setMany(migratedRecords);
|
|
64
|
+
}
|
|
65
|
+
} finally {
|
|
66
|
+
await store.close();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
27
70
|
function dutyKey(
|
|
28
71
|
rollupAddress: string,
|
|
29
72
|
validatorAddress: string,
|
|
@@ -41,7 +84,7 @@ function dutyKey(
|
|
|
41
84
|
* Does not provide cross-node coordination (that requires the PostgreSQL implementation).
|
|
42
85
|
*/
|
|
43
86
|
export class LmdbSlashingProtectionDatabase implements SlashingProtectionDatabase {
|
|
44
|
-
public static readonly SCHEMA_VERSION =
|
|
87
|
+
public static readonly SCHEMA_VERSION = 2;
|
|
45
88
|
|
|
46
89
|
private readonly duties: AztecAsyncMap<string, StoredDutyRecord>;
|
|
47
90
|
private readonly log: Logger;
|
|
@@ -51,7 +94,7 @@ export class LmdbSlashingProtectionDatabase implements SlashingProtectionDatabas
|
|
|
51
94
|
private readonly dateProvider: DateProvider,
|
|
52
95
|
) {
|
|
53
96
|
this.log = createLogger('slashing-protection:lmdb');
|
|
54
|
-
this.duties = store.openMap<string, StoredDutyRecord>(
|
|
97
|
+
this.duties = store.openMap<string, StoredDutyRecord>(DUTIES_MAP_NAME);
|
|
55
98
|
}
|
|
56
99
|
|
|
57
100
|
/**
|
|
@@ -83,6 +126,7 @@ export class LmdbSlashingProtectionDatabase implements SlashingProtectionDatabas
|
|
|
83
126
|
validatorAddress: params.validatorAddress.toString(),
|
|
84
127
|
slot: params.slot.toString(),
|
|
85
128
|
blockNumber: params.blockNumber.toString(),
|
|
129
|
+
checkpointNumber: params.checkpointNumber.toString(),
|
|
86
130
|
blockIndexWithinCheckpoint,
|
|
87
131
|
dutyType: params.dutyType,
|
|
88
132
|
status: DutyStatus.SIGNING,
|
|
@@ -1,21 +1,52 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Initial schema for validator HA slashing protection
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Note: this migration contains a fixed snapshot of the schema at the time it was created.
|
|
5
|
+
* It must NOT import from schema.ts, which evolves over time and would cause this migration
|
|
6
|
+
* to produce different results on fresh runs vs. re-runs.
|
|
5
7
|
*/
|
|
6
8
|
import type { MigrationBuilder } from 'node-pg-migrate';
|
|
7
9
|
|
|
8
|
-
import { DROP_SCHEMA_VERSION_TABLE, DROP_VALIDATOR_DUTIES_TABLE
|
|
10
|
+
import { DROP_SCHEMA_VERSION_TABLE, DROP_VALIDATOR_DUTIES_TABLE } from '../schema.js';
|
|
11
|
+
|
|
12
|
+
// Snapshot of the initial schema — does NOT include checkpoint_number (added in migration 2).
|
|
13
|
+
const INITIAL_SCHEMA_SETUP = [
|
|
14
|
+
`CREATE TABLE IF NOT EXISTS schema_version (
|
|
15
|
+
version INTEGER PRIMARY KEY,
|
|
16
|
+
applied_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
17
|
+
);`,
|
|
18
|
+
`CREATE TABLE IF NOT EXISTS validator_duties (
|
|
19
|
+
rollup_address VARCHAR(42) NOT NULL,
|
|
20
|
+
validator_address VARCHAR(42) NOT NULL,
|
|
21
|
+
slot BIGINT NOT NULL,
|
|
22
|
+
block_number BIGINT NOT NULL,
|
|
23
|
+
block_index_within_checkpoint INTEGER NOT NULL DEFAULT 0,
|
|
24
|
+
duty_type VARCHAR(30) NOT NULL CHECK (duty_type IN ('BLOCK_PROPOSAL', 'CHECKPOINT_PROPOSAL', 'ATTESTATION', 'ATTESTATIONS_AND_SIGNERS', 'GOVERNANCE_VOTE', 'SLASHING_VOTE')),
|
|
25
|
+
status VARCHAR(20) NOT NULL CHECK (status IN ('signing', 'signed')),
|
|
26
|
+
message_hash VARCHAR(66) NOT NULL,
|
|
27
|
+
signature VARCHAR(132),
|
|
28
|
+
node_id VARCHAR(255) NOT NULL,
|
|
29
|
+
lock_token VARCHAR(64) NOT NULL,
|
|
30
|
+
started_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
31
|
+
completed_at TIMESTAMP,
|
|
32
|
+
error_message TEXT,
|
|
33
|
+
|
|
34
|
+
PRIMARY KEY (rollup_address, validator_address, slot, duty_type, block_index_within_checkpoint),
|
|
35
|
+
CHECK (completed_at IS NULL OR completed_at >= started_at)
|
|
36
|
+
);`,
|
|
37
|
+
`CREATE INDEX IF NOT EXISTS idx_validator_duties_status ON validator_duties(status, started_at);`,
|
|
38
|
+
`CREATE INDEX IF NOT EXISTS idx_validator_duties_node ON validator_duties(node_id, started_at);`,
|
|
39
|
+
] as const;
|
|
9
40
|
|
|
10
41
|
export function up(pgm: MigrationBuilder): void {
|
|
11
|
-
for (const statement of
|
|
42
|
+
for (const statement of INITIAL_SCHEMA_SETUP) {
|
|
12
43
|
pgm.sql(statement);
|
|
13
44
|
}
|
|
14
45
|
|
|
15
46
|
// Insert initial schema version
|
|
16
47
|
pgm.sql(`
|
|
17
48
|
INSERT INTO schema_version (version)
|
|
18
|
-
VALUES (
|
|
49
|
+
VALUES (1)
|
|
19
50
|
ON CONFLICT (version) DO NOTHING;
|
|
20
51
|
`);
|
|
21
52
|
}
|