@aztec/validator-ha-signer 0.0.1-commit.d6f2b3f94 → 0.0.1-commit.dbf9cec

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/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>;