@aztec/validator-ha-signer 0.0.1-commit.181e2d196 → 0.0.1-commit.1a421b1a1
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 +0 -2
- 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 +66 -0
- package/dest/db/lmdb.d.ts.map +1 -0
- package/dest/db/lmdb.js +188 -0
- package/dest/db/postgres.d.ts +4 -2
- package/dest/db/postgres.d.ts.map +1 -1
- package/dest/db/postgres.js +13 -13
- package/dest/db/types.d.ts +35 -4
- package/dest/db/types.d.ts.map +1 -1
- package/dest/db/types.js +25 -0
- package/dest/factory.d.ts +22 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +40 -5
- package/dest/slashing_protection_service.d.ts +3 -3
- package/dest/slashing_protection_service.d.ts.map +1 -1
- package/dest/slashing_protection_service.js +2 -2
- package/dest/types.d.ts +5 -1
- package/dest/types.d.ts.map +1 -1
- package/dest/validator_ha_signer.d.ts +3 -3
- package/dest/validator_ha_signer.d.ts.map +1 -1
- package/dest/validator_ha_signer.js +0 -4
- package/package.json +8 -6
- package/src/db/index.ts +1 -0
- package/src/db/lmdb.ts +264 -0
- package/src/db/postgres.ts +13 -11
- package/src/db/types.ts +58 -3
- package/src/factory.ts +50 -4
- package/src/slashing_protection_service.ts +4 -4
- package/src/types.ts +5 -0
- package/src/validator_ha_signer.ts +2 -7
package/src/factory.ts
CHANGED
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
* Factory functions for creating validator HA signers
|
|
3
3
|
*/
|
|
4
4
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
5
|
-
import
|
|
5
|
+
import { createStore } from '@aztec/kv-store/lmdb-v2';
|
|
6
|
+
import type { LocalSignerConfig, ValidatorHASignerConfig } from '@aztec/stdlib/ha-signing';
|
|
6
7
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
7
8
|
|
|
8
9
|
import { Pool } from 'pg';
|
|
9
10
|
|
|
11
|
+
import { LmdbSlashingProtectionDatabase } from './db/lmdb.js';
|
|
10
12
|
import { PostgresSlashingProtectionDatabase } from './db/postgres.js';
|
|
11
13
|
import { HASignerMetrics } from './metrics.js';
|
|
12
|
-
import type { CreateHASignerDeps, SlashingProtectionDatabase } from './types.js';
|
|
14
|
+
import type { CreateHASignerDeps, CreateLocalSignerWithProtectionDeps, SlashingProtectionDatabase } from './types.js';
|
|
13
15
|
import { ValidatorHASigner } from './validator_ha_signer.js';
|
|
14
16
|
|
|
15
17
|
/**
|
|
@@ -27,7 +29,6 @@ import { ValidatorHASigner } from './validator_ha_signer.js';
|
|
|
27
29
|
* ```typescript
|
|
28
30
|
* const { signer, db } = await createHASigner({
|
|
29
31
|
* databaseUrl: process.env.DATABASE_URL,
|
|
30
|
-
* haSigningEnabled: true,
|
|
31
32
|
* nodeId: 'validator-node-1',
|
|
32
33
|
* pollingIntervalMs: 100,
|
|
33
34
|
* signingTimeoutMs: 3000,
|
|
@@ -87,7 +88,52 @@ export async function createHASigner(
|
|
|
87
88
|
const metrics = new HASignerMetrics(telemetryClient, signerConfig.nodeId);
|
|
88
89
|
|
|
89
90
|
// Create signer
|
|
90
|
-
const signer = new ValidatorHASigner(db,
|
|
91
|
+
const signer = new ValidatorHASigner(db, signerConfig, { metrics, dateProvider });
|
|
92
|
+
|
|
93
|
+
return { signer, db };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Create a local (single-node) signing protection signer backed by LMDB.
|
|
98
|
+
*
|
|
99
|
+
* This provides double-signing protection for nodes that are NOT running in a
|
|
100
|
+
* high-availability (multi-node) setup. It prevents a proposer from sending two
|
|
101
|
+
* proposals for the same slot if the node crashes and restarts mid-proposal.
|
|
102
|
+
*
|
|
103
|
+
* When `config.dataDirectory` is set, the protection database is persisted to disk
|
|
104
|
+
* and survives crashes/restarts. When unset, an ephemeral in-memory store is
|
|
105
|
+
* used which protects within a single run but not across restarts.
|
|
106
|
+
*
|
|
107
|
+
* @param config - Local signer config
|
|
108
|
+
* @param deps - Optional dependencies (telemetry, date provider).
|
|
109
|
+
* @returns An object containing the signer and database instances.
|
|
110
|
+
*/
|
|
111
|
+
export async function createLocalSignerWithProtection(
|
|
112
|
+
config: LocalSignerConfig,
|
|
113
|
+
deps?: CreateLocalSignerWithProtectionDeps,
|
|
114
|
+
): Promise<{
|
|
115
|
+
signer: ValidatorHASigner;
|
|
116
|
+
db: SlashingProtectionDatabase;
|
|
117
|
+
}> {
|
|
118
|
+
const telemetryClient = deps?.telemetryClient ?? getTelemetryClient();
|
|
119
|
+
const dateProvider = deps?.dateProvider ?? new DateProvider();
|
|
120
|
+
|
|
121
|
+
const kvStore = await createStore('signing-protection', LmdbSlashingProtectionDatabase.SCHEMA_VERSION, {
|
|
122
|
+
dataDirectory: config.dataDirectory,
|
|
123
|
+
dataStoreMapSizeKb: config.signingProtectionMapSizeKb ?? config.dataStoreMapSizeKb,
|
|
124
|
+
l1Contracts: config.l1Contracts,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const db = new LmdbSlashingProtectionDatabase(kvStore, dateProvider);
|
|
128
|
+
|
|
129
|
+
const signerConfig = {
|
|
130
|
+
...config,
|
|
131
|
+
nodeId: config.nodeId || 'local',
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const metrics = new HASignerMetrics(telemetryClient, signerConfig.nodeId, 'LocalSigningProtectionMetrics');
|
|
135
|
+
|
|
136
|
+
const signer = new ValidatorHASigner(db, signerConfig, { metrics, dateProvider });
|
|
91
137
|
|
|
92
138
|
return { signer, db };
|
|
93
139
|
}
|
|
@@ -8,7 +8,7 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
|
8
8
|
import { RunningPromise } from '@aztec/foundation/promise';
|
|
9
9
|
import { sleep } from '@aztec/foundation/sleep';
|
|
10
10
|
import type { DateProvider } from '@aztec/foundation/timer';
|
|
11
|
-
import type {
|
|
11
|
+
import type { BaseSignerConfig } from '@aztec/stdlib/ha-signing';
|
|
12
12
|
|
|
13
13
|
import {
|
|
14
14
|
type CheckAndRecordParams,
|
|
@@ -55,7 +55,7 @@ export class SlashingProtectionService {
|
|
|
55
55
|
|
|
56
56
|
constructor(
|
|
57
57
|
private readonly db: SlashingProtectionDatabase,
|
|
58
|
-
private readonly config:
|
|
58
|
+
private readonly config: BaseSignerConfig,
|
|
59
59
|
deps: SlashingProtectionServiceDeps,
|
|
60
60
|
) {
|
|
61
61
|
this.log = createLogger('slashing-protection');
|
|
@@ -99,7 +99,7 @@ export class SlashingProtectionService {
|
|
|
99
99
|
|
|
100
100
|
if (isNew) {
|
|
101
101
|
// We successfully acquired the lock
|
|
102
|
-
this.log.
|
|
102
|
+
this.log.verbose(`Acquired lock for duty ${dutyType} at slot ${slot}`, {
|
|
103
103
|
validatorAddress: validatorAddress.toString(),
|
|
104
104
|
nodeId,
|
|
105
105
|
});
|
|
@@ -177,7 +177,7 @@ export class SlashingProtectionService {
|
|
|
177
177
|
);
|
|
178
178
|
|
|
179
179
|
if (success) {
|
|
180
|
-
this.log.
|
|
180
|
+
this.log.verbose(`Recorded successful signing for duty ${dutyType} at slot ${slot}`, {
|
|
181
181
|
validatorAddress: validatorAddress.toString(),
|
|
182
182
|
nodeId,
|
|
183
183
|
});
|
package/src/types.ts
CHANGED
|
@@ -70,6 +70,11 @@ export interface CreateHASignerDeps {
|
|
|
70
70
|
dateProvider?: DateProvider;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* deps for creating a local signing protection signer
|
|
75
|
+
*/
|
|
76
|
+
export type CreateLocalSignerWithProtectionDeps = Omit<CreateHASignerDeps, 'pool'>;
|
|
77
|
+
|
|
73
78
|
/**
|
|
74
79
|
* Database interface for slashing protection operations
|
|
75
80
|
* This abstraction allows for different database implementations (PostgreSQL, SQLite, etc.)
|
|
@@ -11,9 +11,9 @@ import type { Signature } from '@aztec/foundation/eth-signature';
|
|
|
11
11
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
12
12
|
import type { DateProvider } from '@aztec/foundation/timer';
|
|
13
13
|
import {
|
|
14
|
+
type BaseSignerConfig,
|
|
14
15
|
DutyType,
|
|
15
16
|
type HAProtectedSigningContext,
|
|
16
|
-
type ValidatorHASignerConfig,
|
|
17
17
|
getBlockNumberFromSigningContext,
|
|
18
18
|
} from '@aztec/stdlib/ha-signing';
|
|
19
19
|
|
|
@@ -56,7 +56,7 @@ export class ValidatorHASigner {
|
|
|
56
56
|
|
|
57
57
|
constructor(
|
|
58
58
|
db: SlashingProtectionDatabase,
|
|
59
|
-
private readonly config:
|
|
59
|
+
private readonly config: BaseSignerConfig,
|
|
60
60
|
deps: ValidatorHASignerDeps,
|
|
61
61
|
) {
|
|
62
62
|
this.log = createLogger('validator-ha-signer');
|
|
@@ -64,11 +64,6 @@ export class ValidatorHASigner {
|
|
|
64
64
|
this.metrics = deps.metrics;
|
|
65
65
|
this.dateProvider = deps.dateProvider;
|
|
66
66
|
|
|
67
|
-
if (!config.haSigningEnabled) {
|
|
68
|
-
// this shouldn't happen, the validator should use different signer for non-HA setups
|
|
69
|
-
throw new Error('Validator HA Signer is not enabled in config');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
67
|
if (!config.nodeId || config.nodeId === '') {
|
|
73
68
|
throw new Error('NODE_ID is required for high-availability setups');
|
|
74
69
|
}
|