@aztec/validator-ha-signer 0.0.1-commit.e558bd1c → 0.0.1-commit.e5a3663dd
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 +10 -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 +189 -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 +4 -2
- package/dest/db/postgres.d.ts.map +1 -1
- package/dest/db/postgres.js +17 -17
- package/dest/db/schema.d.ts +10 -9
- package/dest/db/schema.d.ts.map +1 -1
- package/dest/db/schema.js +13 -7
- package/dest/db/types.d.ts +46 -21
- package/dest/db/types.d.ts.map +1 -1
- package/dest/db/types.js +31 -15
- package/dest/factory.d.ts +39 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +78 -7
- 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 +12 -3
- package/dest/slashing_protection_service.d.ts.map +1 -1
- package/dest/slashing_protection_service.js +17 -6
- package/dest/types.d.ts +18 -70
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +4 -20
- package/dest/validator_ha_signer.d.ts +12 -4
- package/dest/validator_ha_signer.d.ts.map +1 -1
- package/dest/validator_ha_signer.js +18 -8
- package/package.json +10 -6
- package/src/db/index.ts +1 -0
- package/src/db/lmdb.ts +265 -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 +17 -15
- package/src/db/schema.ts +13 -7
- package/src/db/types.ts +66 -19
- package/src/factory.ts +96 -6
- package/src/metrics.ts +138 -0
- package/src/slashing_protection_service.ts +28 -7
- package/src/types.ts +38 -104
- package/src/validator_ha_signer.ts +36 -12
- package/dest/config.d.ts +0 -101
- package/dest/config.d.ts.map +0 -1
- package/dest/config.js +0 -92
- package/src/config.ts +0 -149
|
@@ -9,15 +9,24 @@ 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
11
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
12
|
-
|
|
13
|
-
import type { ValidatorHASignerConfig } from './config.js';
|
|
14
|
-
import { type DutyIdentifier, DutyType } from './db/types.js';
|
|
15
|
-
import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
12
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
16
13
|
import {
|
|
14
|
+
type BaseSignerConfig,
|
|
15
|
+
DutyType,
|
|
17
16
|
type HAProtectedSigningContext,
|
|
18
|
-
type SlashingProtectionDatabase,
|
|
19
17
|
getBlockNumberFromSigningContext,
|
|
20
|
-
|
|
18
|
+
getCheckpointNumberFromSigningContext,
|
|
19
|
+
} from '@aztec/stdlib/ha-signing';
|
|
20
|
+
|
|
21
|
+
import type { DutyIdentifier } from './db/types.js';
|
|
22
|
+
import type { HASignerMetrics } from './metrics.js';
|
|
23
|
+
import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
24
|
+
import type { SlashingProtectionDatabase } from './types.js';
|
|
25
|
+
|
|
26
|
+
export interface ValidatorHASignerDeps {
|
|
27
|
+
metrics: HASignerMetrics;
|
|
28
|
+
dateProvider: DateProvider;
|
|
29
|
+
}
|
|
21
30
|
|
|
22
31
|
/**
|
|
23
32
|
* Validator High Availability Signer
|
|
@@ -43,22 +52,27 @@ export class ValidatorHASigner {
|
|
|
43
52
|
private readonly slashingProtection: SlashingProtectionService;
|
|
44
53
|
private readonly rollupAddress: EthAddress;
|
|
45
54
|
|
|
55
|
+
private readonly dateProvider: DateProvider;
|
|
56
|
+
private readonly metrics: HASignerMetrics;
|
|
57
|
+
|
|
46
58
|
constructor(
|
|
47
59
|
db: SlashingProtectionDatabase,
|
|
48
|
-
private readonly config:
|
|
60
|
+
private readonly config: BaseSignerConfig,
|
|
61
|
+
deps: ValidatorHASignerDeps,
|
|
49
62
|
) {
|
|
50
63
|
this.log = createLogger('validator-ha-signer');
|
|
51
64
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
throw new Error('Validator HA Signer is not enabled in config');
|
|
55
|
-
}
|
|
65
|
+
this.metrics = deps.metrics;
|
|
66
|
+
this.dateProvider = deps.dateProvider;
|
|
56
67
|
|
|
57
68
|
if (!config.nodeId || config.nodeId === '') {
|
|
58
69
|
throw new Error('NODE_ID is required for high-availability setups');
|
|
59
70
|
}
|
|
60
71
|
this.rollupAddress = config.l1Contracts.rollupAddress;
|
|
61
|
-
this.slashingProtection = new SlashingProtectionService(db, config
|
|
72
|
+
this.slashingProtection = new SlashingProtectionService(db, config, {
|
|
73
|
+
metrics: deps.metrics,
|
|
74
|
+
dateProvider: deps.dateProvider,
|
|
75
|
+
});
|
|
62
76
|
this.log.info('Validator HA Signer initialized with slashing protection', {
|
|
63
77
|
nodeId: config.nodeId,
|
|
64
78
|
rollupAddress: this.rollupAddress.toString(),
|
|
@@ -88,6 +102,9 @@ export class ValidatorHASigner {
|
|
|
88
102
|
context: HAProtectedSigningContext,
|
|
89
103
|
signFn: (messageHash: Buffer32) => Promise<Signature>,
|
|
90
104
|
): Promise<Signature> {
|
|
105
|
+
const startTime = this.dateProvider.now();
|
|
106
|
+
const dutyType = context.dutyType;
|
|
107
|
+
|
|
91
108
|
let dutyIdentifier: DutyIdentifier;
|
|
92
109
|
if (context.dutyType === DutyType.BLOCK_PROPOSAL) {
|
|
93
110
|
dutyIdentifier = {
|
|
@@ -107,10 +124,13 @@ export class ValidatorHASigner {
|
|
|
107
124
|
}
|
|
108
125
|
|
|
109
126
|
// Acquire lock and get the token for ownership verification
|
|
127
|
+
// DutyAlreadySignedError and SlashingProtectionError may be thrown here and are recorded in the service
|
|
110
128
|
const blockNumber = getBlockNumberFromSigningContext(context);
|
|
129
|
+
const checkpointNumber = getCheckpointNumberFromSigningContext(context);
|
|
111
130
|
const lockToken = await this.slashingProtection.checkAndRecord({
|
|
112
131
|
...dutyIdentifier,
|
|
113
132
|
blockNumber,
|
|
133
|
+
checkpointNumber,
|
|
114
134
|
messageHash: messageHash.toString(),
|
|
115
135
|
nodeId: this.config.nodeId,
|
|
116
136
|
});
|
|
@@ -122,6 +142,7 @@ export class ValidatorHASigner {
|
|
|
122
142
|
} catch (error: any) {
|
|
123
143
|
// Delete duty to allow retry (only succeeds if we own the lock)
|
|
124
144
|
await this.slashingProtection.deleteDuty({ ...dutyIdentifier, lockToken });
|
|
145
|
+
this.metrics.recordSigningError(dutyType);
|
|
125
146
|
throw error;
|
|
126
147
|
}
|
|
127
148
|
|
|
@@ -133,6 +154,9 @@ export class ValidatorHASigner {
|
|
|
133
154
|
lockToken,
|
|
134
155
|
});
|
|
135
156
|
|
|
157
|
+
const duration = this.dateProvider.now() - startTime;
|
|
158
|
+
this.metrics.recordSigningSuccess(dutyType, duration);
|
|
159
|
+
|
|
136
160
|
return signature;
|
|
137
161
|
}
|
|
138
162
|
|
package/dest/config.d.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
2
|
-
import { type ConfigMappingsType } from '@aztec/foundation/config';
|
|
3
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
|
-
import { z } from 'zod';
|
|
5
|
-
/**
|
|
6
|
-
* Configuration for the Validator HA Signer
|
|
7
|
-
*
|
|
8
|
-
* This config is used for distributed locking and slashing protection
|
|
9
|
-
* when running multiple validator nodes in a high-availability setup.
|
|
10
|
-
*/
|
|
11
|
-
export interface ValidatorHASignerConfig {
|
|
12
|
-
/** Whether HA signing / slashing protection is enabled */
|
|
13
|
-
haSigningEnabled: boolean;
|
|
14
|
-
/** L1 contract addresses (rollup address required) */
|
|
15
|
-
l1Contracts: Pick<L1ContractAddresses, 'rollupAddress'>;
|
|
16
|
-
/** Unique identifier for this node */
|
|
17
|
-
nodeId: string;
|
|
18
|
-
/** How long to wait between polls when a duty is being signed (ms) */
|
|
19
|
-
pollingIntervalMs: number;
|
|
20
|
-
/** Maximum time to wait for a duty being signed to complete (ms) */
|
|
21
|
-
signingTimeoutMs: number;
|
|
22
|
-
/** Maximum age of a stuck duty in ms (defaults to 2x hardcoded Aztec slot duration if not set) */
|
|
23
|
-
maxStuckDutiesAgeMs?: number;
|
|
24
|
-
/** Optional: clean up old duties after this many hours (disabled if not set) */
|
|
25
|
-
cleanupOldDutiesAfterHours?: number;
|
|
26
|
-
/**
|
|
27
|
-
* PostgreSQL connection string
|
|
28
|
-
* Format: postgresql://user:password@host:port/database
|
|
29
|
-
*/
|
|
30
|
-
databaseUrl?: string;
|
|
31
|
-
/**
|
|
32
|
-
* PostgreSQL connection pool configuration
|
|
33
|
-
*/
|
|
34
|
-
/** Maximum number of clients in the pool (default: 10) */
|
|
35
|
-
poolMaxCount?: number;
|
|
36
|
-
/** Minimum number of clients in the pool (default: 0) */
|
|
37
|
-
poolMinCount?: number;
|
|
38
|
-
/** Idle timeout in milliseconds (default: 10000) */
|
|
39
|
-
poolIdleTimeoutMs?: number;
|
|
40
|
-
/** Connection timeout in milliseconds (default: 0, no timeout) */
|
|
41
|
-
poolConnectionTimeoutMs?: number;
|
|
42
|
-
}
|
|
43
|
-
export declare const validatorHASignerConfigMappings: ConfigMappingsType<ValidatorHASignerConfig>;
|
|
44
|
-
export declare const defaultValidatorHASignerConfig: ValidatorHASignerConfig;
|
|
45
|
-
/**
|
|
46
|
-
* Returns the validator HA signer configuration from environment variables.
|
|
47
|
-
* Note: If an environment variable is not set, the default value is used.
|
|
48
|
-
* @returns The validator HA signer configuration.
|
|
49
|
-
*/
|
|
50
|
-
export declare function getConfigEnvVars(): ValidatorHASignerConfig;
|
|
51
|
-
export declare const ValidatorHASignerConfigSchema: z.ZodObject<{
|
|
52
|
-
haSigningEnabled: z.ZodBoolean;
|
|
53
|
-
l1Contracts: z.ZodObject<{
|
|
54
|
-
rollupAddress: z.ZodType<EthAddress, z.ZodTypeDef, EthAddress>;
|
|
55
|
-
}, "strip", z.ZodTypeAny, {
|
|
56
|
-
rollupAddress: EthAddress;
|
|
57
|
-
}, {
|
|
58
|
-
rollupAddress: EthAddress;
|
|
59
|
-
}>;
|
|
60
|
-
nodeId: z.ZodString;
|
|
61
|
-
pollingIntervalMs: z.ZodNumber;
|
|
62
|
-
signingTimeoutMs: z.ZodNumber;
|
|
63
|
-
maxStuckDutiesAgeMs: z.ZodOptional<z.ZodNumber>;
|
|
64
|
-
cleanupOldDutiesAfterHours: z.ZodOptional<z.ZodNumber>;
|
|
65
|
-
databaseUrl: z.ZodOptional<z.ZodString>;
|
|
66
|
-
poolMaxCount: z.ZodOptional<z.ZodNumber>;
|
|
67
|
-
poolMinCount: z.ZodOptional<z.ZodNumber>;
|
|
68
|
-
poolIdleTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
69
|
-
poolConnectionTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
70
|
-
}, "strip", z.ZodTypeAny, {
|
|
71
|
-
haSigningEnabled: boolean;
|
|
72
|
-
l1Contracts: {
|
|
73
|
-
rollupAddress: EthAddress;
|
|
74
|
-
};
|
|
75
|
-
nodeId: string;
|
|
76
|
-
pollingIntervalMs: number;
|
|
77
|
-
signingTimeoutMs: number;
|
|
78
|
-
maxStuckDutiesAgeMs?: number | undefined;
|
|
79
|
-
cleanupOldDutiesAfterHours?: number | undefined;
|
|
80
|
-
databaseUrl?: string | undefined;
|
|
81
|
-
poolMaxCount?: number | undefined;
|
|
82
|
-
poolMinCount?: number | undefined;
|
|
83
|
-
poolIdleTimeoutMs?: number | undefined;
|
|
84
|
-
poolConnectionTimeoutMs?: number | undefined;
|
|
85
|
-
}, {
|
|
86
|
-
haSigningEnabled: boolean;
|
|
87
|
-
l1Contracts: {
|
|
88
|
-
rollupAddress: EthAddress;
|
|
89
|
-
};
|
|
90
|
-
nodeId: string;
|
|
91
|
-
pollingIntervalMs: number;
|
|
92
|
-
signingTimeoutMs: number;
|
|
93
|
-
maxStuckDutiesAgeMs?: number | undefined;
|
|
94
|
-
cleanupOldDutiesAfterHours?: number | undefined;
|
|
95
|
-
databaseUrl?: string | undefined;
|
|
96
|
-
poolMaxCount?: number | undefined;
|
|
97
|
-
poolMinCount?: number | undefined;
|
|
98
|
-
poolIdleTimeoutMs?: number | undefined;
|
|
99
|
-
poolConnectionTimeoutMs?: number | undefined;
|
|
100
|
-
}>;
|
|
101
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uZmlnLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvY29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLG1CQUFtQixFQUFFLE1BQU0sdUNBQXVDLENBQUM7QUFDakYsT0FBTyxFQUNMLEtBQUssa0JBQWtCLEVBTXhCLE1BQU0sMEJBQTBCLENBQUM7QUFDbEMsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLCtCQUErQixDQUFDO0FBRzNELE9BQU8sRUFBRSxDQUFDLEVBQUUsTUFBTSxLQUFLLENBQUM7QUFFeEI7Ozs7O0dBS0c7QUFDSCxNQUFNLFdBQVcsdUJBQXVCO0lBQ3RDLDBEQUEwRDtJQUMxRCxnQkFBZ0IsRUFBRSxPQUFPLENBQUM7SUFDMUIsc0RBQXNEO0lBQ3RELFdBQ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|
package/dest/config.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { booleanConfigHelper, getConfigFromMappings, getDefaultConfig, numberConfigHelper, optionalNumberConfigHelper } from '@aztec/foundation/config';
|
|
2
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
export const validatorHASignerConfigMappings = {
|
|
5
|
-
haSigningEnabled: {
|
|
6
|
-
env: 'VALIDATOR_HA_SIGNING_ENABLED',
|
|
7
|
-
description: 'Whether HA signing / slashing protection is enabled',
|
|
8
|
-
...booleanConfigHelper(false)
|
|
9
|
-
},
|
|
10
|
-
l1Contracts: {
|
|
11
|
-
description: 'L1 contract addresses (rollup address required)',
|
|
12
|
-
nested: {
|
|
13
|
-
rollupAddress: {
|
|
14
|
-
description: 'The Ethereum address of the rollup contract (must be set programmatically)',
|
|
15
|
-
parseEnv: (val)=>EthAddress.fromString(val)
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
nodeId: {
|
|
20
|
-
env: 'VALIDATOR_HA_NODE_ID',
|
|
21
|
-
description: 'The unique identifier for this node',
|
|
22
|
-
defaultValue: ''
|
|
23
|
-
},
|
|
24
|
-
pollingIntervalMs: {
|
|
25
|
-
env: 'VALIDATOR_HA_POLLING_INTERVAL_MS',
|
|
26
|
-
description: 'The number of ms to wait between polls when a duty is being signed',
|
|
27
|
-
...numberConfigHelper(100)
|
|
28
|
-
},
|
|
29
|
-
signingTimeoutMs: {
|
|
30
|
-
env: 'VALIDATOR_HA_SIGNING_TIMEOUT_MS',
|
|
31
|
-
description: 'The maximum time to wait for a duty being signed to complete',
|
|
32
|
-
...numberConfigHelper(3_000)
|
|
33
|
-
},
|
|
34
|
-
maxStuckDutiesAgeMs: {
|
|
35
|
-
env: 'VALIDATOR_HA_MAX_STUCK_DUTIES_AGE_MS',
|
|
36
|
-
description: 'The maximum age of a stuck duty in ms (defaults to 2x Aztec slot duration)',
|
|
37
|
-
...optionalNumberConfigHelper()
|
|
38
|
-
},
|
|
39
|
-
cleanupOldDutiesAfterHours: {
|
|
40
|
-
env: 'VALIDATOR_HA_OLD_DUTIES_MAX_AGE_H',
|
|
41
|
-
description: 'Optional: clean up old duties after this many hours (disabled if not set)',
|
|
42
|
-
...optionalNumberConfigHelper()
|
|
43
|
-
},
|
|
44
|
-
databaseUrl: {
|
|
45
|
-
env: 'VALIDATOR_HA_DATABASE_URL',
|
|
46
|
-
description: 'PostgreSQL connection string for validator HA signer (format: postgresql://user:password@host:port/database)'
|
|
47
|
-
},
|
|
48
|
-
poolMaxCount: {
|
|
49
|
-
env: 'VALIDATOR_HA_POOL_MAX',
|
|
50
|
-
description: 'Maximum number of clients in the pool',
|
|
51
|
-
...numberConfigHelper(10)
|
|
52
|
-
},
|
|
53
|
-
poolMinCount: {
|
|
54
|
-
env: 'VALIDATOR_HA_POOL_MIN',
|
|
55
|
-
description: 'Minimum number of clients in the pool',
|
|
56
|
-
...numberConfigHelper(0)
|
|
57
|
-
},
|
|
58
|
-
poolIdleTimeoutMs: {
|
|
59
|
-
env: 'VALIDATOR_HA_POOL_IDLE_TIMEOUT_MS',
|
|
60
|
-
description: 'Idle timeout in milliseconds',
|
|
61
|
-
...numberConfigHelper(10_000)
|
|
62
|
-
},
|
|
63
|
-
poolConnectionTimeoutMs: {
|
|
64
|
-
env: 'VALIDATOR_HA_POOL_CONNECTION_TIMEOUT_MS',
|
|
65
|
-
description: 'Connection timeout in milliseconds (0 means no timeout)',
|
|
66
|
-
...numberConfigHelper(0)
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
export const defaultValidatorHASignerConfig = getDefaultConfig(validatorHASignerConfigMappings);
|
|
70
|
-
/**
|
|
71
|
-
* Returns the validator HA signer configuration from environment variables.
|
|
72
|
-
* Note: If an environment variable is not set, the default value is used.
|
|
73
|
-
* @returns The validator HA signer configuration.
|
|
74
|
-
*/ export function getConfigEnvVars() {
|
|
75
|
-
return getConfigFromMappings(validatorHASignerConfigMappings);
|
|
76
|
-
}
|
|
77
|
-
export const ValidatorHASignerConfigSchema = z.object({
|
|
78
|
-
haSigningEnabled: z.boolean(),
|
|
79
|
-
l1Contracts: z.object({
|
|
80
|
-
rollupAddress: z.instanceof(EthAddress)
|
|
81
|
-
}),
|
|
82
|
-
nodeId: z.string(),
|
|
83
|
-
pollingIntervalMs: z.number().min(0),
|
|
84
|
-
signingTimeoutMs: z.number().min(0),
|
|
85
|
-
maxStuckDutiesAgeMs: z.number().min(0).optional(),
|
|
86
|
-
cleanupOldDutiesAfterHours: z.number().min(0).optional(),
|
|
87
|
-
databaseUrl: z.string().optional(),
|
|
88
|
-
poolMaxCount: z.number().min(0).optional(),
|
|
89
|
-
poolMinCount: z.number().min(0).optional(),
|
|
90
|
-
poolIdleTimeoutMs: z.number().min(0).optional(),
|
|
91
|
-
poolConnectionTimeoutMs: z.number().min(0).optional()
|
|
92
|
-
});
|
package/src/config.ts
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
2
|
-
import {
|
|
3
|
-
type ConfigMappingsType,
|
|
4
|
-
booleanConfigHelper,
|
|
5
|
-
getConfigFromMappings,
|
|
6
|
-
getDefaultConfig,
|
|
7
|
-
numberConfigHelper,
|
|
8
|
-
optionalNumberConfigHelper,
|
|
9
|
-
} from '@aztec/foundation/config';
|
|
10
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
11
|
-
import type { ZodFor } from '@aztec/foundation/schemas';
|
|
12
|
-
|
|
13
|
-
import { z } from 'zod';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Configuration for the Validator HA Signer
|
|
17
|
-
*
|
|
18
|
-
* This config is used for distributed locking and slashing protection
|
|
19
|
-
* when running multiple validator nodes in a high-availability setup.
|
|
20
|
-
*/
|
|
21
|
-
export interface ValidatorHASignerConfig {
|
|
22
|
-
/** Whether HA signing / slashing protection is enabled */
|
|
23
|
-
haSigningEnabled: boolean;
|
|
24
|
-
/** L1 contract addresses (rollup address required) */
|
|
25
|
-
l1Contracts: Pick<L1ContractAddresses, 'rollupAddress'>;
|
|
26
|
-
/** Unique identifier for this node */
|
|
27
|
-
nodeId: string;
|
|
28
|
-
/** How long to wait between polls when a duty is being signed (ms) */
|
|
29
|
-
pollingIntervalMs: number;
|
|
30
|
-
/** Maximum time to wait for a duty being signed to complete (ms) */
|
|
31
|
-
signingTimeoutMs: number;
|
|
32
|
-
/** Maximum age of a stuck duty in ms (defaults to 2x hardcoded Aztec slot duration if not set) */
|
|
33
|
-
maxStuckDutiesAgeMs?: number;
|
|
34
|
-
/** Optional: clean up old duties after this many hours (disabled if not set) */
|
|
35
|
-
cleanupOldDutiesAfterHours?: number;
|
|
36
|
-
/**
|
|
37
|
-
* PostgreSQL connection string
|
|
38
|
-
* Format: postgresql://user:password@host:port/database
|
|
39
|
-
*/
|
|
40
|
-
databaseUrl?: string;
|
|
41
|
-
/**
|
|
42
|
-
* PostgreSQL connection pool configuration
|
|
43
|
-
*/
|
|
44
|
-
/** Maximum number of clients in the pool (default: 10) */
|
|
45
|
-
poolMaxCount?: number;
|
|
46
|
-
/** Minimum number of clients in the pool (default: 0) */
|
|
47
|
-
poolMinCount?: number;
|
|
48
|
-
/** Idle timeout in milliseconds (default: 10000) */
|
|
49
|
-
poolIdleTimeoutMs?: number;
|
|
50
|
-
/** Connection timeout in milliseconds (default: 0, no timeout) */
|
|
51
|
-
poolConnectionTimeoutMs?: number;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export const validatorHASignerConfigMappings: ConfigMappingsType<ValidatorHASignerConfig> = {
|
|
55
|
-
haSigningEnabled: {
|
|
56
|
-
env: 'VALIDATOR_HA_SIGNING_ENABLED',
|
|
57
|
-
description: 'Whether HA signing / slashing protection is enabled',
|
|
58
|
-
...booleanConfigHelper(false),
|
|
59
|
-
},
|
|
60
|
-
l1Contracts: {
|
|
61
|
-
description: 'L1 contract addresses (rollup address required)',
|
|
62
|
-
nested: {
|
|
63
|
-
rollupAddress: {
|
|
64
|
-
description: 'The Ethereum address of the rollup contract (must be set programmatically)',
|
|
65
|
-
parseEnv: (val: string) => EthAddress.fromString(val),
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
nodeId: {
|
|
70
|
-
env: 'VALIDATOR_HA_NODE_ID',
|
|
71
|
-
description: 'The unique identifier for this node',
|
|
72
|
-
defaultValue: '',
|
|
73
|
-
},
|
|
74
|
-
pollingIntervalMs: {
|
|
75
|
-
env: 'VALIDATOR_HA_POLLING_INTERVAL_MS',
|
|
76
|
-
description: 'The number of ms to wait between polls when a duty is being signed',
|
|
77
|
-
...numberConfigHelper(100),
|
|
78
|
-
},
|
|
79
|
-
signingTimeoutMs: {
|
|
80
|
-
env: 'VALIDATOR_HA_SIGNING_TIMEOUT_MS',
|
|
81
|
-
description: 'The maximum time to wait for a duty being signed to complete',
|
|
82
|
-
...numberConfigHelper(3_000),
|
|
83
|
-
},
|
|
84
|
-
maxStuckDutiesAgeMs: {
|
|
85
|
-
env: 'VALIDATOR_HA_MAX_STUCK_DUTIES_AGE_MS',
|
|
86
|
-
description: 'The maximum age of a stuck duty in ms (defaults to 2x Aztec slot duration)',
|
|
87
|
-
...optionalNumberConfigHelper(),
|
|
88
|
-
},
|
|
89
|
-
cleanupOldDutiesAfterHours: {
|
|
90
|
-
env: 'VALIDATOR_HA_OLD_DUTIES_MAX_AGE_H',
|
|
91
|
-
description: 'Optional: clean up old duties after this many hours (disabled if not set)',
|
|
92
|
-
...optionalNumberConfigHelper(),
|
|
93
|
-
},
|
|
94
|
-
databaseUrl: {
|
|
95
|
-
env: 'VALIDATOR_HA_DATABASE_URL',
|
|
96
|
-
description:
|
|
97
|
-
'PostgreSQL connection string for validator HA signer (format: postgresql://user:password@host:port/database)',
|
|
98
|
-
},
|
|
99
|
-
poolMaxCount: {
|
|
100
|
-
env: 'VALIDATOR_HA_POOL_MAX',
|
|
101
|
-
description: 'Maximum number of clients in the pool',
|
|
102
|
-
...numberConfigHelper(10),
|
|
103
|
-
},
|
|
104
|
-
poolMinCount: {
|
|
105
|
-
env: 'VALIDATOR_HA_POOL_MIN',
|
|
106
|
-
description: 'Minimum number of clients in the pool',
|
|
107
|
-
...numberConfigHelper(0),
|
|
108
|
-
},
|
|
109
|
-
poolIdleTimeoutMs: {
|
|
110
|
-
env: 'VALIDATOR_HA_POOL_IDLE_TIMEOUT_MS',
|
|
111
|
-
description: 'Idle timeout in milliseconds',
|
|
112
|
-
...numberConfigHelper(10_000),
|
|
113
|
-
},
|
|
114
|
-
poolConnectionTimeoutMs: {
|
|
115
|
-
env: 'VALIDATOR_HA_POOL_CONNECTION_TIMEOUT_MS',
|
|
116
|
-
description: 'Connection timeout in milliseconds (0 means no timeout)',
|
|
117
|
-
...numberConfigHelper(0),
|
|
118
|
-
},
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
export const defaultValidatorHASignerConfig: ValidatorHASignerConfig = getDefaultConfig(
|
|
122
|
-
validatorHASignerConfigMappings,
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Returns the validator HA signer configuration from environment variables.
|
|
127
|
-
* Note: If an environment variable is not set, the default value is used.
|
|
128
|
-
* @returns The validator HA signer configuration.
|
|
129
|
-
*/
|
|
130
|
-
export function getConfigEnvVars(): ValidatorHASignerConfig {
|
|
131
|
-
return getConfigFromMappings<ValidatorHASignerConfig>(validatorHASignerConfigMappings);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export const ValidatorHASignerConfigSchema = z.object({
|
|
135
|
-
haSigningEnabled: z.boolean(),
|
|
136
|
-
l1Contracts: z.object({
|
|
137
|
-
rollupAddress: z.instanceof(EthAddress),
|
|
138
|
-
}),
|
|
139
|
-
nodeId: z.string(),
|
|
140
|
-
pollingIntervalMs: z.number().min(0),
|
|
141
|
-
signingTimeoutMs: z.number().min(0),
|
|
142
|
-
maxStuckDutiesAgeMs: z.number().min(0).optional(),
|
|
143
|
-
cleanupOldDutiesAfterHours: z.number().min(0).optional(),
|
|
144
|
-
databaseUrl: z.string().optional(),
|
|
145
|
-
poolMaxCount: z.number().min(0).optional(),
|
|
146
|
-
poolMinCount: z.number().min(0).optional(),
|
|
147
|
-
poolIdleTimeoutMs: z.number().min(0).optional(),
|
|
148
|
-
poolConnectionTimeoutMs: z.number().min(0).optional(),
|
|
149
|
-
}) satisfies ZodFor<ValidatorHASignerConfig>;
|