@aztec/validator-ha-signer 0.0.1-commit.96bb3f7 → 0.0.1-commit.96dac018d
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 +52 -37
- package/dest/db/postgres.d.ts +34 -5
- package/dest/db/postgres.d.ts.map +1 -1
- package/dest/db/postgres.js +80 -22
- package/dest/db/schema.d.ts +21 -10
- package/dest/db/schema.d.ts.map +1 -1
- package/dest/db/schema.js +49 -20
- package/dest/db/types.d.ts +76 -31
- package/dest/db/types.d.ts.map +1 -1
- package/dest/db/types.js +32 -8
- package/dest/errors.d.ts +9 -5
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +7 -4
- package/dest/factory.d.ts +6 -14
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +17 -12
- package/dest/metrics.d.ts +51 -0
- package/dest/metrics.d.ts.map +1 -0
- package/dest/metrics.js +103 -0
- package/dest/migrations.d.ts +1 -1
- package/dest/migrations.d.ts.map +1 -1
- package/dest/migrations.js +13 -2
- package/dest/slashing_protection_service.d.ts +25 -6
- package/dest/slashing_protection_service.d.ts.map +1 -1
- package/dest/slashing_protection_service.js +72 -20
- package/dest/test/pglite_pool.d.ts +92 -0
- package/dest/test/pglite_pool.d.ts.map +1 -0
- package/dest/test/pglite_pool.js +210 -0
- package/dest/types.d.ts +38 -18
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +4 -1
- package/dest/validator_ha_signer.d.ts +18 -13
- package/dest/validator_ha_signer.d.ts.map +1 -1
- package/dest/validator_ha_signer.js +46 -33
- package/package.json +13 -10
- package/src/db/postgres.ts +101 -21
- package/src/db/schema.ts +51 -20
- package/src/db/types.ts +110 -31
- package/src/errors.ts +7 -2
- package/src/factory.ts +20 -14
- package/src/metrics.ts +138 -0
- package/src/migrations.ts +17 -1
- package/src/slashing_protection_service.ts +117 -25
- package/src/test/pglite_pool.ts +256 -0
- package/src/types.ts +63 -19
- package/src/validator_ha_signer.ts +66 -42
- package/dest/config.d.ts +0 -47
- package/dest/config.d.ts.map +0 -1
- package/dest/config.js +0 -64
- package/src/config.ts +0 -116
package/README.md
CHANGED
|
@@ -9,39 +9,21 @@ Distributed locking and slashing protection for Aztec validators running in high
|
|
|
9
9
|
- **Automatic Retry**: Failed signing attempts are cleared, allowing other nodes to retry
|
|
10
10
|
- **PostgreSQL Backend**: Shared database for coordination across nodes
|
|
11
11
|
|
|
12
|
-
##
|
|
12
|
+
## Integration with Validator Client
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
The HA signer is automatically integrated into the validator client when `VALIDATOR_HA_SIGNING_ENABLED=true` is set. The validator client will:
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// Migrations run automatically on startup
|
|
20
|
-
const { signer, db } = await createHASigner({
|
|
21
|
-
databaseUrl: process.env.DATABASE_URL,
|
|
22
|
-
enabled: true,
|
|
23
|
-
nodeId: 'validator-node-1',
|
|
24
|
-
pollingIntervalMs: 100,
|
|
25
|
-
signingTimeoutMs: 3000,
|
|
26
|
-
});
|
|
16
|
+
1. Create the HA signer using `createHASigner()` from the factory
|
|
17
|
+
2. Wrap the base keystore with `HAKeyStore` to provide HA-protected signing
|
|
18
|
+
3. Automatically start/stop the signer lifecycle
|
|
27
19
|
|
|
28
|
-
|
|
29
|
-
signer.start();
|
|
20
|
+
No manual integration is required when using the validator client.
|
|
30
21
|
|
|
31
|
-
|
|
32
|
-
const signature = await signer.signWithProtection(
|
|
33
|
-
validatorAddress,
|
|
34
|
-
messageHash,
|
|
35
|
-
{ slot: 100n, blockNumber: 50n, dutyType: 'BLOCK_PROPOSAL' },
|
|
36
|
-
async root => localSigner.signMessage(root),
|
|
37
|
-
);
|
|
22
|
+
## Manual Usage
|
|
38
23
|
|
|
39
|
-
|
|
40
|
-
await signer.stop();
|
|
41
|
-
await db.close();
|
|
42
|
-
```
|
|
24
|
+
For advanced use cases or testing, you can use the HA signer directly. **Note**: Database migrations must be run separately before creating the signer (see [Database Migrations](#database-migrations) below).
|
|
43
25
|
|
|
44
|
-
###
|
|
26
|
+
### Basic Usage
|
|
45
27
|
|
|
46
28
|
```bash
|
|
47
29
|
# 1. Run migrations separately (once per deployment)
|
|
@@ -54,7 +36,7 @@ import { createHASigner } from '@aztec/validator-ha-signer/factory';
|
|
|
54
36
|
|
|
55
37
|
const { signer, db } = await createHASigner({
|
|
56
38
|
databaseUrl: process.env.DATABASE_URL,
|
|
57
|
-
|
|
39
|
+
haSigningEnabled: true,
|
|
58
40
|
nodeId: 'validator-node-1',
|
|
59
41
|
pollingIntervalMs: 100,
|
|
60
42
|
signingTimeoutMs: 3000,
|
|
@@ -63,6 +45,14 @@ const { signer, db } = await createHASigner({
|
|
|
63
45
|
// Start background cleanup tasks
|
|
64
46
|
signer.start();
|
|
65
47
|
|
|
48
|
+
// Sign with protection
|
|
49
|
+
const signature = await signer.signWithProtection(
|
|
50
|
+
validatorAddress,
|
|
51
|
+
messageHash,
|
|
52
|
+
{ slot: 100n, blockNumber: 50n, blockIndexWithinCheckpoint: 0, dutyType: 'BLOCK_PROPOSAL' },
|
|
53
|
+
async root => localSigner.signMessage(root),
|
|
54
|
+
);
|
|
55
|
+
|
|
66
56
|
// On shutdown
|
|
67
57
|
await signer.stop();
|
|
68
58
|
await db.close();
|
|
@@ -73,7 +63,7 @@ await db.close();
|
|
|
73
63
|
If you need custom pool configuration (e.g., max connections, idle timeout) or want to share a connection pool across multiple components:
|
|
74
64
|
|
|
75
65
|
> **Note**: You still need to run migrations separately before using this approach.
|
|
76
|
-
> See [
|
|
66
|
+
> See [Database Migrations](#database-migrations) below.
|
|
77
67
|
|
|
78
68
|
```typescript
|
|
79
69
|
import { PostgresSlashingProtectionDatabase } from '@aztec/validator-ha-signer/db';
|
|
@@ -91,11 +81,11 @@ const db = new PostgresSlashingProtectionDatabase(pool);
|
|
|
91
81
|
await db.initialize();
|
|
92
82
|
|
|
93
83
|
const signer = new ValidatorHASigner(db, {
|
|
94
|
-
|
|
84
|
+
haSigningEnabled: true,
|
|
95
85
|
nodeId: 'validator-node-1',
|
|
96
86
|
pollingIntervalMs: 100,
|
|
97
87
|
signingTimeoutMs: 3000,
|
|
98
|
-
maxStuckDutiesAgeMs:
|
|
88
|
+
maxStuckDutiesAgeMs: 144000,
|
|
99
89
|
});
|
|
100
90
|
|
|
101
91
|
// Start background cleanup tasks
|
|
@@ -111,11 +101,15 @@ await pool.end(); // You manage the pool lifecycle
|
|
|
111
101
|
Set via environment variables or config object:
|
|
112
102
|
|
|
113
103
|
- `VALIDATOR_HA_DATABASE_URL`: PostgreSQL connection string (e.g., `postgresql://user:pass@host:port/db`)
|
|
114
|
-
- `
|
|
115
|
-
- `
|
|
116
|
-
- `
|
|
117
|
-
- `
|
|
118
|
-
- `
|
|
104
|
+
- `VALIDATOR_HA_SIGNING_ENABLED`: Whether HA signing / slashing protection is enabled (default: false)
|
|
105
|
+
- `VALIDATOR_HA_NODE_ID`: Unique identifier for this validator node (required when enabled)
|
|
106
|
+
- `VALIDATOR_HA_POLLING_INTERVAL_MS`: How often to check duty status (default: 100)
|
|
107
|
+
- `VALIDATOR_HA_SIGNING_TIMEOUT_MS`: Max wait for in-progress signing (default: 3000)
|
|
108
|
+
- `VALIDATOR_HA_MAX_STUCK_DUTIES_AGE_MS`: Max age of stuck duties before cleanup (default: 2 \* aztecSlotDuration)
|
|
109
|
+
- `VALIDATOR_HA_POOL_MAX`: Maximum number of connections in the pool (default: 10)
|
|
110
|
+
- `VALIDATOR_HA_POOL_MIN`: Minimum number of connections in the pool (default: 0)
|
|
111
|
+
- `VALIDATOR_HA_POOL_IDLE_TIMEOUT_MS`: Idle timeout for pool connections (default: 10000)
|
|
112
|
+
- `VALIDATOR_HA_POOL_CONNECTION_TIMEOUT_MS`: Connection timeout (default: 0, no timeout)
|
|
119
113
|
|
|
120
114
|
## Database Migrations
|
|
121
115
|
|
|
@@ -170,9 +164,30 @@ When multiple validator nodes attempt to sign:
|
|
|
170
164
|
|
|
171
165
|
1. First node acquires lock and signs
|
|
172
166
|
2. Other nodes receive `DutyAlreadySignedError` (expected)
|
|
173
|
-
3. If different data detected: `SlashingProtectionError` (
|
|
167
|
+
3. If different data detected: `SlashingProtectionError` (prevents slashing)
|
|
174
168
|
4. Failed attempts are auto-cleaned, allowing retry
|
|
175
169
|
|
|
170
|
+
### Signing Context
|
|
171
|
+
|
|
172
|
+
All signing operations require a `SigningContext` that includes:
|
|
173
|
+
|
|
174
|
+
- `slot`: The slot number
|
|
175
|
+
- `blockNumber`: The block number within the checkpoint
|
|
176
|
+
- `blockIndexWithinCheckpoint`: The index of the block within the checkpoint (use `-1` for N/A contexts)
|
|
177
|
+
- `dutyType`: The type of duty (e.g., `BLOCK_PROPOSAL`, `CHECKPOINT_ATTESTATION`, `AUTH_REQUEST`)
|
|
178
|
+
|
|
179
|
+
Note: `AUTH_REQUEST` duties bypass HA protection since signing multiple times is safe for authentication requests.
|
|
180
|
+
|
|
181
|
+
## Important Limitations
|
|
182
|
+
|
|
183
|
+
### Database Isolation Per Rollup Version
|
|
184
|
+
|
|
185
|
+
**You cannot use the same database to provide slashing protection for validator nodes running on different rollup versions** (e.g., current rollup and old rollup simultaneously).
|
|
186
|
+
|
|
187
|
+
When the HA signer performs background cleanup via `cleanupOutdatedRollupDuties()`, it removes all duties where the rollup address doesn't match the current rollup address. If two validators running on different rollup versions share the same database, they will delete each other's duties during cleanup.
|
|
188
|
+
|
|
189
|
+
**Solution**: Use separate databases for validators running on different rollup versions. Each rollup version requires its own isolated slashing protection database.
|
|
190
|
+
|
|
176
191
|
## Development
|
|
177
192
|
|
|
178
193
|
```bash
|
package/dest/db/postgres.d.ts
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostgreSQL implementation of SlashingProtectionDatabase
|
|
3
|
+
*/
|
|
4
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
5
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
-
import type {
|
|
6
|
+
import type { QueryResult, QueryResultRow } from 'pg';
|
|
3
7
|
import type { SlashingProtectionDatabase, TryInsertOrGetResult } from '../types.js';
|
|
4
8
|
import type { CheckAndRecordParams, DutyType } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Minimal pool interface for database operations.
|
|
11
|
+
* Both pg.Pool and test adapters (e.g., PGlite) satisfy this interface.
|
|
12
|
+
*/
|
|
13
|
+
export interface QueryablePool {
|
|
14
|
+
query<R extends QueryResultRow = any>(text: string, values?: any[]): Promise<QueryResult<R>>;
|
|
15
|
+
end(): Promise<void>;
|
|
16
|
+
}
|
|
5
17
|
/**
|
|
6
18
|
* PostgreSQL implementation of the slashing protection database
|
|
7
19
|
*/
|
|
8
20
|
export declare class PostgresSlashingProtectionDatabase implements SlashingProtectionDatabase {
|
|
9
21
|
private readonly pool;
|
|
10
22
|
private readonly log;
|
|
11
|
-
constructor(pool:
|
|
23
|
+
constructor(pool: QueryablePool);
|
|
12
24
|
/**
|
|
13
25
|
* Verify that database migrations have been run and schema version matches.
|
|
14
26
|
* Should be called once at startup.
|
|
@@ -21,6 +33,9 @@ export declare class PostgresSlashingProtectionDatabase implements SlashingProte
|
|
|
21
33
|
*
|
|
22
34
|
* @returns { isNew: true, record } if we successfully inserted and acquired the lock
|
|
23
35
|
* @returns { isNew: false, record } if a record already exists. lock_token is empty if the record already exists.
|
|
36
|
+
*
|
|
37
|
+
* Retries if no rows are returned, which can happen under high concurrency
|
|
38
|
+
* when another transaction just committed the row but it's not yet visible.
|
|
24
39
|
*/
|
|
25
40
|
tryInsertOrGetExisting(params: CheckAndRecordParams): Promise<TryInsertOrGetResult>;
|
|
26
41
|
/**
|
|
@@ -29,7 +44,7 @@ export declare class PostgresSlashingProtectionDatabase implements SlashingProte
|
|
|
29
44
|
*
|
|
30
45
|
* @returns true if the update succeeded, false if token didn't match or duty not found
|
|
31
46
|
*/
|
|
32
|
-
updateDutySigned(validatorAddress: EthAddress, slot:
|
|
47
|
+
updateDutySigned(rollupAddress: EthAddress, validatorAddress: EthAddress, slot: SlotNumber, dutyType: DutyType, signature: string, lockToken: string, blockIndexWithinCheckpoint: number): Promise<boolean>;
|
|
33
48
|
/**
|
|
34
49
|
* Delete a duty record.
|
|
35
50
|
* Only succeeds if the lockToken matches (caller must be the one who created the duty).
|
|
@@ -37,7 +52,7 @@ export declare class PostgresSlashingProtectionDatabase implements SlashingProte
|
|
|
37
52
|
*
|
|
38
53
|
* @returns true if the delete succeeded, false if token didn't match or duty not found
|
|
39
54
|
*/
|
|
40
|
-
deleteDuty(validatorAddress: EthAddress, slot:
|
|
55
|
+
deleteDuty(rollupAddress: EthAddress, validatorAddress: EthAddress, slot: SlotNumber, dutyType: DutyType, lockToken: string, blockIndexWithinCheckpoint: number): Promise<boolean>;
|
|
41
56
|
/**
|
|
42
57
|
* Convert a database row to a ValidatorDutyRecord
|
|
43
58
|
*/
|
|
@@ -51,5 +66,19 @@ export declare class PostgresSlashingProtectionDatabase implements SlashingProte
|
|
|
51
66
|
* @returns the number of duties cleaned up
|
|
52
67
|
*/
|
|
53
68
|
cleanupOwnStuckDuties(nodeId: string, maxAgeMs: number): Promise<number>;
|
|
69
|
+
/**
|
|
70
|
+
* Cleanup duties with outdated rollup address.
|
|
71
|
+
* Removes all duties where the rollup address doesn't match the current one.
|
|
72
|
+
* Used after a rollup upgrade to clean up duties for the old rollup.
|
|
73
|
+
* @returns the number of duties cleaned up
|
|
74
|
+
*/
|
|
75
|
+
cleanupOutdatedRollupDuties(currentRollupAddress: EthAddress): Promise<number>;
|
|
76
|
+
/**
|
|
77
|
+
* Cleanup old signed duties.
|
|
78
|
+
* Removes only signed duties older than the specified age.
|
|
79
|
+
* Does not remove 'signing' duties as they may be in progress.
|
|
80
|
+
* @returns the number of duties cleaned up
|
|
81
|
+
*/
|
|
82
|
+
cleanupOldDuties(maxAgeMs: number): Promise<number>;
|
|
54
83
|
}
|
|
55
|
-
//# sourceMappingURL=data:application/json;base64,
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ENBQUMsQ0FHbkY7SUFFRDs7Ozs7T0FLRztJQUNHLGdCQUFnQixDQUFDLFFBQVEsRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUd4RDtDQUNGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/db/postgres.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/db/postgres.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAe,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAE1E,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAI3D,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,IAAI,CAAC;AAEtD,OAAO,KAAK,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAUpF,OAAO,KAAK,EAAE,oBAAoB,EAAW,QAAQ,EAAuC,MAAM,YAAY,CAAC;AAG/G;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,CAAC,SAAS,cAAc,GAAG,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7F,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACtB;AAED;;GAEG;AACH,qBAAa,kCAAmC,YAAW,0BAA0B;IAGvE,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAE7B,YAA6B,IAAI,EAAE,aAAa,EAE/C;IAED;;;;;OAKG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAgChC;IAED;;;;;;;;OAQG;IACG,sBAAsB,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAoDxF;IAED;;;;;OAKG;IACG,gBAAgB,CACpB,aAAa,EAAE,UAAU,EACzB,gBAAgB,EAAE,UAAU,EAC5B,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,0BAA0B,EAAE,MAAM,GACjC,OAAO,CAAC,OAAO,CAAC,CAsBlB;IAED;;;;;;OAMG;IACG,UAAU,CACd,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,CAqBlB;IAED;;OAEG;IACH,OAAO,CAAC,WAAW;IAmBnB;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAG3B;IAED;;;OAGG;IACG,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAG7E;IAED;;;;;OAKG;IACG,2BAA2B,CAAC,oBAAoB,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAGnF;IAED;;;;;OAKG;IACG,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAGxD;CACF"}
|
package/dest/db/postgres.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* PostgreSQL implementation of SlashingProtectionDatabase
|
|
3
|
-
*/ import {
|
|
3
|
+
*/ import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import { randomBytes } from '@aztec/foundation/crypto/random';
|
|
4
5
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
6
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
-
import {
|
|
7
|
+
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
8
|
+
import { CLEANUP_OLD_DUTIES, CLEANUP_OUTDATED_ROLLUP_DUTIES, CLEANUP_OWN_STUCK_DUTIES, DELETE_DUTY, INSERT_OR_GET_DUTY, SCHEMA_VERSION, UPDATE_DUTY_SIGNED } from './schema.js';
|
|
9
|
+
import { getBlockIndexFromDutyIdentifier } from './types.js';
|
|
7
10
|
/**
|
|
8
11
|
* PostgreSQL implementation of the slashing protection database
|
|
9
12
|
*/ export class PostgresSlashingProtectionDatabase {
|
|
@@ -27,10 +30,10 @@ import { CLEANUP_OWN_STUCK_DUTIES, DELETE_DUTY, INSERT_OR_GET_DUTY, SCHEMA_VERSI
|
|
|
27
30
|
}
|
|
28
31
|
dbVersion = result.rows[0].version;
|
|
29
32
|
} catch {
|
|
30
|
-
throw new Error('Database schema not initialized. Please run migrations first: aztec migrate up --database-url <url>');
|
|
33
|
+
throw new Error('Database schema not initialized. Please run migrations first: aztec migrate-ha-db up --database-url <url>');
|
|
31
34
|
}
|
|
32
35
|
if (dbVersion < SCHEMA_VERSION) {
|
|
33
|
-
throw new Error(`Database schema version ${dbVersion} is outdated (expected ${SCHEMA_VERSION}). Please run migrations: aztec migrate up --database-url <url>`);
|
|
36
|
+
throw new Error(`Database schema version ${dbVersion} is outdated (expected ${SCHEMA_VERSION}). Please run migrations: aztec migrate-ha-db up --database-url <url>`);
|
|
34
37
|
}
|
|
35
38
|
if (dbVersion > SCHEMA_VERSION) {
|
|
36
39
|
throw new Error(`Database schema version ${dbVersion} is newer than expected (${SCHEMA_VERSION}). Please update your application.`);
|
|
@@ -44,21 +47,45 @@ import { CLEANUP_OWN_STUCK_DUTIES, DELETE_DUTY, INSERT_OR_GET_DUTY, SCHEMA_VERSI
|
|
|
44
47
|
*
|
|
45
48
|
* @returns { isNew: true, record } if we successfully inserted and acquired the lock
|
|
46
49
|
* @returns { isNew: false, record } if a record already exists. lock_token is empty if the record already exists.
|
|
50
|
+
*
|
|
51
|
+
* Retries if no rows are returned, which can happen under high concurrency
|
|
52
|
+
* when another transaction just committed the row but it's not yet visible.
|
|
47
53
|
*/ async tryInsertOrGetExisting(params) {
|
|
48
54
|
// create a token for ownership verification
|
|
49
55
|
const lockToken = randomBytes(16).toString('hex');
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
params.messageHash,
|
|
56
|
-
params.nodeId,
|
|
57
|
-
lockToken
|
|
56
|
+
// Use fast retries with custom backoff: 10ms, 20ms, 30ms (then stop)
|
|
57
|
+
const fastBackoff = makeBackoff([
|
|
58
|
+
0.01,
|
|
59
|
+
0.02,
|
|
60
|
+
0.03
|
|
58
61
|
]);
|
|
62
|
+
// Get the normalized block index using type-safe helper
|
|
63
|
+
const blockIndexWithinCheckpoint = getBlockIndexFromDutyIdentifier(params);
|
|
64
|
+
const result = await retry(async ()=>{
|
|
65
|
+
const queryResult = await this.pool.query(INSERT_OR_GET_DUTY, [
|
|
66
|
+
params.rollupAddress.toString(),
|
|
67
|
+
params.validatorAddress.toString(),
|
|
68
|
+
params.slot.toString(),
|
|
69
|
+
params.blockNumber.toString(),
|
|
70
|
+
blockIndexWithinCheckpoint,
|
|
71
|
+
params.dutyType,
|
|
72
|
+
params.messageHash,
|
|
73
|
+
params.nodeId,
|
|
74
|
+
lockToken
|
|
75
|
+
]);
|
|
76
|
+
// Throw error if no rows to trigger retry
|
|
77
|
+
if (queryResult.rows.length === 0) {
|
|
78
|
+
throw new Error('INSERT_OR_GET_DUTY returned no rows');
|
|
79
|
+
}
|
|
80
|
+
return queryResult;
|
|
81
|
+
}, `INSERT_OR_GET_DUTY for node ${params.nodeId}`, fastBackoff, this.log, true);
|
|
59
82
|
if (result.rows.length === 0) {
|
|
60
|
-
//
|
|
61
|
-
throw new Error('INSERT_OR_GET_DUTY returned no rows');
|
|
83
|
+
// this should never happen as the retry function should throw if it still fails after retries
|
|
84
|
+
throw new Error('INSERT_OR_GET_DUTY returned no rows after retries');
|
|
85
|
+
}
|
|
86
|
+
if (result.rows.length > 1) {
|
|
87
|
+
// this should never happen if database constraints are correct (PRIMARY KEY should prevent duplicates)
|
|
88
|
+
throw new Error(`INSERT_OR_GET_DUTY returned ${result.rows.length} rows (expected exactly 1).`);
|
|
62
89
|
}
|
|
63
90
|
const row = result.rows[0];
|
|
64
91
|
return {
|
|
@@ -71,19 +98,23 @@ import { CLEANUP_OWN_STUCK_DUTIES, DELETE_DUTY, INSERT_OR_GET_DUTY, SCHEMA_VERSI
|
|
|
71
98
|
* Only succeeds if the lockToken matches (caller must be the one who created the duty).
|
|
72
99
|
*
|
|
73
100
|
* @returns true if the update succeeded, false if token didn't match or duty not found
|
|
74
|
-
*/ async updateDutySigned(validatorAddress, slot, dutyType, signature, lockToken) {
|
|
101
|
+
*/ async updateDutySigned(rollupAddress, validatorAddress, slot, dutyType, signature, lockToken, blockIndexWithinCheckpoint) {
|
|
75
102
|
const result = await this.pool.query(UPDATE_DUTY_SIGNED, [
|
|
76
103
|
signature,
|
|
104
|
+
rollupAddress.toString(),
|
|
77
105
|
validatorAddress.toString(),
|
|
78
106
|
slot.toString(),
|
|
79
107
|
dutyType,
|
|
108
|
+
blockIndexWithinCheckpoint,
|
|
80
109
|
lockToken
|
|
81
110
|
]);
|
|
82
111
|
if (result.rowCount === 0) {
|
|
83
112
|
this.log.warn('Failed to update duty to signed status: invalid token or duty not found', {
|
|
113
|
+
rollupAddress: rollupAddress.toString(),
|
|
84
114
|
validatorAddress: validatorAddress.toString(),
|
|
85
115
|
slot: slot.toString(),
|
|
86
|
-
dutyType
|
|
116
|
+
dutyType,
|
|
117
|
+
blockIndexWithinCheckpoint
|
|
87
118
|
});
|
|
88
119
|
return false;
|
|
89
120
|
}
|
|
@@ -95,18 +126,22 @@ import { CLEANUP_OWN_STUCK_DUTIES, DELETE_DUTY, INSERT_OR_GET_DUTY, SCHEMA_VERSI
|
|
|
95
126
|
* Used when signing fails to allow another node/attempt to retry.
|
|
96
127
|
*
|
|
97
128
|
* @returns true if the delete succeeded, false if token didn't match or duty not found
|
|
98
|
-
*/ async deleteDuty(validatorAddress, slot, dutyType, lockToken) {
|
|
129
|
+
*/ async deleteDuty(rollupAddress, validatorAddress, slot, dutyType, lockToken, blockIndexWithinCheckpoint) {
|
|
99
130
|
const result = await this.pool.query(DELETE_DUTY, [
|
|
131
|
+
rollupAddress.toString(),
|
|
100
132
|
validatorAddress.toString(),
|
|
101
133
|
slot.toString(),
|
|
102
134
|
dutyType,
|
|
135
|
+
blockIndexWithinCheckpoint,
|
|
103
136
|
lockToken
|
|
104
137
|
]);
|
|
105
138
|
if (result.rowCount === 0) {
|
|
106
139
|
this.log.warn('Failed to delete duty: invalid token or duty not found', {
|
|
140
|
+
rollupAddress: rollupAddress.toString(),
|
|
107
141
|
validatorAddress: validatorAddress.toString(),
|
|
108
142
|
slot: slot.toString(),
|
|
109
|
-
dutyType
|
|
143
|
+
dutyType,
|
|
144
|
+
blockIndexWithinCheckpoint
|
|
110
145
|
});
|
|
111
146
|
return false;
|
|
112
147
|
}
|
|
@@ -116,9 +151,11 @@ import { CLEANUP_OWN_STUCK_DUTIES, DELETE_DUTY, INSERT_OR_GET_DUTY, SCHEMA_VERSI
|
|
|
116
151
|
* Convert a database row to a ValidatorDutyRecord
|
|
117
152
|
*/ rowToRecord(row) {
|
|
118
153
|
return {
|
|
154
|
+
rollupAddress: EthAddress.fromString(row.rollup_address),
|
|
119
155
|
validatorAddress: EthAddress.fromString(row.validator_address),
|
|
120
|
-
slot:
|
|
121
|
-
blockNumber:
|
|
156
|
+
slot: SlotNumber.fromString(row.slot),
|
|
157
|
+
blockNumber: BlockNumber.fromString(row.block_number),
|
|
158
|
+
blockIndexWithinCheckpoint: row.block_index_within_checkpoint,
|
|
122
159
|
dutyType: row.duty_type,
|
|
123
160
|
status: row.status,
|
|
124
161
|
messageHash: row.message_hash,
|
|
@@ -140,10 +177,31 @@ import { CLEANUP_OWN_STUCK_DUTIES, DELETE_DUTY, INSERT_OR_GET_DUTY, SCHEMA_VERSI
|
|
|
140
177
|
* Cleanup own stuck duties
|
|
141
178
|
* @returns the number of duties cleaned up
|
|
142
179
|
*/ async cleanupOwnStuckDuties(nodeId, maxAgeMs) {
|
|
143
|
-
const cutoff = new Date(Date.now() - maxAgeMs);
|
|
144
180
|
const result = await this.pool.query(CLEANUP_OWN_STUCK_DUTIES, [
|
|
145
181
|
nodeId,
|
|
146
|
-
|
|
182
|
+
maxAgeMs
|
|
183
|
+
]);
|
|
184
|
+
return result.rowCount ?? 0;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Cleanup duties with outdated rollup address.
|
|
188
|
+
* Removes all duties where the rollup address doesn't match the current one.
|
|
189
|
+
* Used after a rollup upgrade to clean up duties for the old rollup.
|
|
190
|
+
* @returns the number of duties cleaned up
|
|
191
|
+
*/ async cleanupOutdatedRollupDuties(currentRollupAddress) {
|
|
192
|
+
const result = await this.pool.query(CLEANUP_OUTDATED_ROLLUP_DUTIES, [
|
|
193
|
+
currentRollupAddress.toString()
|
|
194
|
+
]);
|
|
195
|
+
return result.rowCount ?? 0;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Cleanup old signed duties.
|
|
199
|
+
* Removes only signed duties older than the specified age.
|
|
200
|
+
* Does not remove 'signing' duties as they may be in progress.
|
|
201
|
+
* @returns the number of duties cleaned up
|
|
202
|
+
*/ async cleanupOldDuties(maxAgeMs) {
|
|
203
|
+
const result = await this.pool.query(CLEANUP_OLD_DUTIES, [
|
|
204
|
+
maxAgeMs
|
|
147
205
|
]);
|
|
148
206
|
return result.rowCount ?? 0;
|
|
149
207
|
}
|
package/dest/db/schema.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare const SCHEMA_VERSION = 1;
|
|
|
12
12
|
/**
|
|
13
13
|
* SQL to create the validator_duties table
|
|
14
14
|
*/
|
|
15
|
-
export declare const CREATE_VALIDATOR_DUTIES_TABLE = "\nCREATE TABLE IF NOT EXISTS validator_duties (\n validator_address VARCHAR(42) NOT NULL,\n slot BIGINT NOT NULL,\n block_number BIGINT NOT NULL,\n duty_type VARCHAR(30) NOT NULL CHECK (duty_type IN ('BLOCK_PROPOSAL', 'ATTESTATION', 'ATTESTATIONS_AND_SIGNERS')),\n status VARCHAR(20) NOT NULL CHECK (status IN ('signing', 'signed'
|
|
15
|
+
export declare const CREATE_VALIDATOR_DUTIES_TABLE = "\nCREATE TABLE IF NOT EXISTS validator_duties (\n rollup_address VARCHAR(42) NOT NULL,\n validator_address VARCHAR(42) NOT NULL,\n slot BIGINT NOT NULL,\n block_number BIGINT NOT NULL,\n block_index_within_checkpoint INTEGER NOT NULL DEFAULT 0,\n duty_type VARCHAR(30) NOT NULL CHECK (duty_type IN ('BLOCK_PROPOSAL', 'CHECKPOINT_PROPOSAL', 'ATTESTATION', 'ATTESTATIONS_AND_SIGNERS', 'GOVERNANCE_VOTE', 'SLASHING_VOTE')),\n status VARCHAR(20) NOT NULL CHECK (status IN ('signing', 'signed')),\n message_hash VARCHAR(66) NOT NULL,\n signature VARCHAR(132),\n node_id VARCHAR(255) NOT NULL,\n lock_token VARCHAR(64) NOT NULL,\n started_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n completed_at TIMESTAMP,\n error_message TEXT,\n\n PRIMARY KEY (rollup_address, validator_address, slot, duty_type, block_index_within_checkpoint),\n CHECK (completed_at IS NULL OR completed_at >= started_at)\n);\n";
|
|
16
16
|
/**
|
|
17
17
|
* SQL to create index on status and started_at for cleanup queries
|
|
18
18
|
*/
|
|
@@ -32,7 +32,7 @@ export declare const INSERT_SCHEMA_VERSION = "\nINSERT INTO schema_version (vers
|
|
|
32
32
|
/**
|
|
33
33
|
* Complete schema setup - all statements in order
|
|
34
34
|
*/
|
|
35
|
-
export declare const SCHEMA_SETUP: readonly ["\nCREATE TABLE IF NOT EXISTS schema_version (\n version INTEGER PRIMARY KEY,\n applied_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP\n);\n", "\nCREATE TABLE IF NOT EXISTS validator_duties (\n validator_address VARCHAR(42) NOT NULL,\n slot BIGINT NOT NULL,\n block_number BIGINT NOT NULL,\n duty_type VARCHAR(30) NOT NULL CHECK (duty_type IN ('BLOCK_PROPOSAL', 'ATTESTATION', 'ATTESTATIONS_AND_SIGNERS')),\n status VARCHAR(20) NOT NULL CHECK (status IN ('signing', 'signed'
|
|
35
|
+
export declare const SCHEMA_SETUP: readonly ["\nCREATE TABLE IF NOT EXISTS schema_version (\n version INTEGER PRIMARY KEY,\n applied_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP\n);\n", "\nCREATE TABLE IF NOT EXISTS validator_duties (\n rollup_address VARCHAR(42) NOT NULL,\n validator_address VARCHAR(42) NOT NULL,\n slot BIGINT NOT NULL,\n block_number BIGINT NOT NULL,\n block_index_within_checkpoint INTEGER NOT NULL DEFAULT 0,\n duty_type VARCHAR(30) NOT NULL CHECK (duty_type IN ('BLOCK_PROPOSAL', 'CHECKPOINT_PROPOSAL', 'ATTESTATION', 'ATTESTATIONS_AND_SIGNERS', 'GOVERNANCE_VOTE', 'SLASHING_VOTE')),\n status VARCHAR(20) NOT NULL CHECK (status IN ('signing', 'signed')),\n message_hash VARCHAR(66) NOT NULL,\n signature VARCHAR(132),\n node_id VARCHAR(255) NOT NULL,\n lock_token VARCHAR(64) NOT NULL,\n started_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n completed_at TIMESTAMP,\n error_message TEXT,\n\n PRIMARY KEY (rollup_address, validator_address, slot, duty_type, block_index_within_checkpoint),\n CHECK (completed_at IS NULL OR completed_at >= started_at)\n);\n", "\nCREATE INDEX IF NOT EXISTS idx_validator_duties_status\nON validator_duties(status, started_at);\n", "\nCREATE INDEX IF NOT EXISTS idx_validator_duties_node\nON validator_duties(node_id, started_at);\n"];
|
|
36
36
|
/**
|
|
37
37
|
* Query to get current schema version
|
|
38
38
|
*/
|
|
@@ -43,17 +43,21 @@ export declare const GET_SCHEMA_VERSION = "\nSELECT version FROM schema_version
|
|
|
43
43
|
* returns the existing record instead.
|
|
44
44
|
*
|
|
45
45
|
* Returns the record with an `is_new` flag indicating whether we inserted or got existing.
|
|
46
|
+
*
|
|
47
|
+
* Note: In high concurrency scenarios, if the INSERT conflicts and another transaction
|
|
48
|
+
* just committed the row, there's a small window where the SELECT might not see it yet.
|
|
49
|
+
* The application layer should retry if no rows are returned.
|
|
46
50
|
*/
|
|
47
|
-
export declare const INSERT_OR_GET_DUTY = "\nWITH inserted AS (\n INSERT INTO validator_duties (\n validator_address,\n slot,\n block_number,\n duty_type,\n status,\n message_hash,\n node_id,\n lock_token,\n started_at\n ) VALUES ($1, $2, $3, $4, 'signing', $
|
|
51
|
+
export declare const INSERT_OR_GET_DUTY = "\nWITH inserted AS (\n INSERT INTO validator_duties (\n rollup_address,\n validator_address,\n slot,\n block_number,\n block_index_within_checkpoint,\n duty_type,\n status,\n message_hash,\n node_id,\n lock_token,\n started_at\n ) VALUES ($1, $2, $3, $4, $5, $6, 'signing', $7, $8, $9, CURRENT_TIMESTAMP)\n ON CONFLICT (rollup_address, validator_address, slot, duty_type, block_index_within_checkpoint) DO NOTHING\n RETURNING\n rollup_address,\n validator_address,\n slot,\n block_number,\n block_index_within_checkpoint,\n duty_type,\n status,\n message_hash,\n signature,\n node_id,\n lock_token,\n started_at,\n completed_at,\n error_message,\n TRUE as is_new\n)\nSELECT * FROM inserted\nUNION ALL\nSELECT\n rollup_address,\n validator_address,\n slot,\n block_number,\n block_index_within_checkpoint,\n duty_type,\n status,\n message_hash,\n signature,\n node_id,\n '' as lock_token,\n started_at,\n completed_at,\n error_message,\n FALSE as is_new\nFROM validator_duties\nWHERE rollup_address = $1\n AND validator_address = $2\n AND slot = $3\n AND duty_type = $6\n AND block_index_within_checkpoint = $5\n AND NOT EXISTS (SELECT 1 FROM inserted);\n";
|
|
48
52
|
/**
|
|
49
53
|
* Query to update a duty to 'signed' status
|
|
50
54
|
*/
|
|
51
|
-
export declare const UPDATE_DUTY_SIGNED = "\nUPDATE validator_duties\nSET status = 'signed',\n signature = $1,\n completed_at = CURRENT_TIMESTAMP\nWHERE
|
|
55
|
+
export declare const UPDATE_DUTY_SIGNED = "\nUPDATE validator_duties\nSET status = 'signed',\n signature = $1,\n completed_at = CURRENT_TIMESTAMP\nWHERE rollup_address = $2\n AND validator_address = $3\n AND slot = $4\n AND duty_type = $5\n AND block_index_within_checkpoint = $6\n AND status = 'signing'\n AND lock_token = $7;\n";
|
|
52
56
|
/**
|
|
53
57
|
* Query to delete a duty
|
|
54
58
|
* Only deletes if the lockToken matches
|
|
55
59
|
*/
|
|
56
|
-
export declare const DELETE_DUTY = "\nDELETE FROM validator_duties\nWHERE
|
|
60
|
+
export declare const DELETE_DUTY = "\nDELETE FROM validator_duties\nWHERE rollup_address = $1\n AND validator_address = $2\n AND slot = $3\n AND duty_type = $4\n AND block_index_within_checkpoint = $5\n AND status = 'signing'\n AND lock_token = $6;\n";
|
|
57
61
|
/**
|
|
58
62
|
* Query to clean up old signed duties (for maintenance)
|
|
59
63
|
* Removes signed duties older than a specified timestamp
|
|
@@ -61,14 +65,21 @@ export declare const DELETE_DUTY = "\nDELETE FROM validator_duties\nWHERE valida
|
|
|
61
65
|
export declare const CLEANUP_OLD_SIGNED_DUTIES = "\nDELETE FROM validator_duties\nWHERE status = 'signed'\n AND completed_at < $1;\n";
|
|
62
66
|
/**
|
|
63
67
|
* Query to clean up old duties (for maintenance)
|
|
64
|
-
* Removes duties older than a specified
|
|
68
|
+
* Removes SIGNED duties older than a specified age (in milliseconds)
|
|
65
69
|
*/
|
|
66
|
-
export declare const CLEANUP_OLD_DUTIES = "\nDELETE FROM validator_duties\nWHERE status
|
|
70
|
+
export declare const CLEANUP_OLD_DUTIES = "\nDELETE FROM validator_duties\nWHERE status = 'signed'\n AND started_at < CURRENT_TIMESTAMP - ($1 || ' milliseconds')::INTERVAL;\n";
|
|
67
71
|
/**
|
|
68
72
|
* Query to cleanup own stuck duties
|
|
69
73
|
* Removes duties in 'signing' status for a specific node that are older than maxAgeMs
|
|
74
|
+
* Uses DB's CURRENT_TIMESTAMP to avoid clock skew issues between nodes
|
|
75
|
+
*/
|
|
76
|
+
export declare const CLEANUP_OWN_STUCK_DUTIES = "\nDELETE FROM validator_duties\nWHERE node_id = $1\n AND status = 'signing'\n AND started_at < CURRENT_TIMESTAMP - ($2 || ' milliseconds')::INTERVAL;\n";
|
|
77
|
+
/**
|
|
78
|
+
* Query to cleanup duties with outdated rollup address
|
|
79
|
+
* Removes all duties where the rollup address doesn't match the current one
|
|
80
|
+
* Used after a rollup upgrade to clean up duties for the old rollup
|
|
70
81
|
*/
|
|
71
|
-
export declare const
|
|
82
|
+
export declare const CLEANUP_OUTDATED_ROLLUP_DUTIES = "\nDELETE FROM validator_duties\nWHERE rollup_address != $1;\n";
|
|
72
83
|
/**
|
|
73
84
|
* SQL to drop the validator_duties table
|
|
74
85
|
*/
|
|
@@ -81,5 +92,5 @@ export declare const DROP_SCHEMA_VERSION_TABLE = "DROP TABLE IF EXISTS schema_ve
|
|
|
81
92
|
* Query to get stuck duties (for monitoring/alerting)
|
|
82
93
|
* Returns duties in 'signing' status that have been stuck for too long
|
|
83
94
|
*/
|
|
84
|
-
export declare const GET_STUCK_DUTIES = "\nSELECT\n validator_address,\n slot,\n block_number,\n duty_type,\n status,\n message_hash,\n node_id,\n started_at,\n EXTRACT(EPOCH FROM (CURRENT_TIMESTAMP - started_at)) as age_seconds\nFROM validator_duties\nWHERE status = 'signing'\n AND started_at < $1\nORDER BY started_at ASC;\n";
|
|
85
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
95
|
+
export declare const GET_STUCK_DUTIES = "\nSELECT\n rollup_address,\n validator_address,\n slot,\n block_number,\n block_index_within_checkpoint,\n duty_type,\n status,\n message_hash,\n node_id,\n started_at,\n EXTRACT(EPOCH FROM (CURRENT_TIMESTAMP - started_at)) as age_seconds\nFROM validator_duties\nWHERE status = 'signing'\n AND started_at < $1\nORD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QkFBd0IsOEpBS3BDLENBQUM7QUFFRjs7OztHQUlHO0FBQ0gsZUFBTyxNQUFNLDhCQUE4QixrRUFHMUMsQ0FBQztBQUVGOztHQUVHO0FBQ0gsZUFBTyxNQUFNLDJCQUEyQiwyQ0FBMkMsQ0FBQztBQUVwRjs7R0FFRztBQUNILGVBQU8sTUFBTSx5QkFBeUIseUNBQXlDLENBQUM7QUFFaEY7OztHQUdHO0FBQ0gsZUFBTyxNQUFNLGdCQUFnQixrV0FpQjVCLENBQUMifQ==
|
package/dest/db/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/db/schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC;;GAEG;AACH,eAAO,MAAM,6BAA6B,
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/db/schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC;;GAEG;AACH,eAAO,MAAM,6BAA6B,s5BAoBzC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,yGAG/B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,wGAG7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,2BAA2B,mJAKvC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,qBAAqB,6FAIjC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,iwCAKf,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,kBAAkB,0EAE9B,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB,6uCA0D9B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,+SAY9B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,iOASvB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,yBAAyB,wFAIrC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,yIAI9B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,8JAKpC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,8BAA8B,kEAG1C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,2BAA2B,2CAA2C,CAAC;AAEpF;;GAEG;AACH,eAAO,MAAM,yBAAyB,yCAAyC,CAAC;AAEhF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,kWAiB5B,CAAC"}
|