@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/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 type { ValidatorHASignerConfig } from '@aztec/stdlib/ha-signing';
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, { ...signerConfig, databaseUrl }, { metrics, dateProvider });
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 { ValidatorHASignerConfig } from '@aztec/stdlib/ha-signing';
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: ValidatorHASignerConfig,
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.info(`Acquired lock for duty ${dutyType} at slot ${slot}`, {
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.info(`Recorded successful signing for duty ${dutyType} at slot ${slot}`, {
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: ValidatorHASignerConfig,
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
  }