@aztec/validator-ha-signer 0.0.1-commit.fffb133c → 0.0.2-commit.217f559981
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 -0
- package/dest/db/postgres.d.ts +17 -3
- package/dest/db/postgres.d.ts.map +1 -1
- package/dest/db/postgres.js +32 -5
- package/dest/db/schema.d.ts +17 -10
- package/dest/db/schema.d.ts.map +1 -1
- package/dest/db/schema.js +39 -22
- package/dest/db/types.d.ts +9 -16
- package/dest/db/types.d.ts.map +1 -1
- package/dest/db/types.js +5 -15
- package/dest/factory.d.ts +2 -2
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +11 -1
- 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 +19 -6
- package/dest/slashing_protection_service.d.ts.map +1 -1
- package/dest/slashing_protection_service.js +55 -15
- package/dest/types.d.ts +30 -74
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +3 -20
- package/dest/validator_ha_signer.d.ts +15 -6
- package/dest/validator_ha_signer.d.ts.map +1 -1
- package/dest/validator_ha_signer.js +24 -7
- package/package.json +7 -4
- package/src/db/postgres.ts +33 -2
- package/src/db/schema.ts +41 -22
- package/src/db/types.ts +10 -15
- package/src/factory.ts +13 -2
- package/src/metrics.ts +138 -0
- package/src/slashing_protection_service.ts +76 -18
- package/src/types.ts +48 -106
- package/src/validator_ha_signer.ts +41 -10
- package/dest/config.d.ts +0 -79
- package/dest/config.d.ts.map +0 -1
- package/dest/config.js +0 -73
- package/src/config.ts +0 -125
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
2
|
+
export type HACleanupType = 'stuck' | 'old' | 'outdated_rollup';
|
|
3
|
+
/**
|
|
4
|
+
* Metrics for HA signer tracking signing operations, lock acquisition, and cleanup.
|
|
5
|
+
*/
|
|
6
|
+
export declare class HASignerMetrics {
|
|
7
|
+
private nodeId;
|
|
8
|
+
private signingDuration;
|
|
9
|
+
private signingSuccessCount;
|
|
10
|
+
private dutyAlreadySignedCount;
|
|
11
|
+
private slashingProtectionCount;
|
|
12
|
+
private signingErrorCount;
|
|
13
|
+
private lockAcquiredCount;
|
|
14
|
+
private cleanupStuckDutiesCount;
|
|
15
|
+
private cleanupOldDutiesCount;
|
|
16
|
+
private cleanupOutdatedRollupDutiesCount;
|
|
17
|
+
constructor(client: TelemetryClient, nodeId: string, name?: string);
|
|
18
|
+
/**
|
|
19
|
+
* Record a successful signing operation.
|
|
20
|
+
* @param dutyType - The type of duty signed
|
|
21
|
+
* @param durationMs - Duration from start of signWithProtection to completion
|
|
22
|
+
*/
|
|
23
|
+
recordSigningSuccess(dutyType: string, durationMs: number): void;
|
|
24
|
+
/**
|
|
25
|
+
* Record a DutyAlreadySignedError (expected in HA; another node signed first).
|
|
26
|
+
* @param dutyType - The type of duty
|
|
27
|
+
*/
|
|
28
|
+
recordDutyAlreadySigned(dutyType: string): void;
|
|
29
|
+
/**
|
|
30
|
+
* Record a SlashingProtectionError (attempted to sign different data for same duty).
|
|
31
|
+
* @param dutyType - The type of duty
|
|
32
|
+
*/
|
|
33
|
+
recordSlashingProtection(dutyType: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Record a signing function failure (lock will be deleted for retry).
|
|
36
|
+
* @param dutyType - The type of duty
|
|
37
|
+
*/
|
|
38
|
+
recordSigningError(dutyType: string): void;
|
|
39
|
+
/**
|
|
40
|
+
* Record lock acquisition.
|
|
41
|
+
* @param acquired - Whether a new lock was acquired (true) or existing record found (false)
|
|
42
|
+
*/
|
|
43
|
+
recordLockAcquire(acquired: boolean): void;
|
|
44
|
+
/**
|
|
45
|
+
* Record cleanup metrics.
|
|
46
|
+
* @param type - Type of cleanup
|
|
47
|
+
* @param count - Number of duties cleaned up
|
|
48
|
+
*/
|
|
49
|
+
recordCleanup(type: HACleanupType, count: number): void;
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I,CAMrD;IAED;;;OAGG;IACI,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAMtD;IAED;;;OAGG;IACI,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAMhD;IAED;;;OAGG;IACI,iBAAiB,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAOhD;IAED;;;;OAIG;IACI,aAAa,CAAC,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAY7D;CACF"}
|
package/dest/metrics.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Attributes, Metrics, createUpDownCounterWithDefault } from '@aztec/telemetry-client';
|
|
2
|
+
/**
|
|
3
|
+
* Metrics for HA signer tracking signing operations, lock acquisition, and cleanup.
|
|
4
|
+
*/ export class HASignerMetrics {
|
|
5
|
+
nodeId;
|
|
6
|
+
// Signing lifecycle metrics
|
|
7
|
+
signingDuration;
|
|
8
|
+
signingSuccessCount;
|
|
9
|
+
dutyAlreadySignedCount;
|
|
10
|
+
slashingProtectionCount;
|
|
11
|
+
signingErrorCount;
|
|
12
|
+
// Lock acquisition metrics
|
|
13
|
+
lockAcquiredCount;
|
|
14
|
+
// Cleanup metrics
|
|
15
|
+
cleanupStuckDutiesCount;
|
|
16
|
+
cleanupOldDutiesCount;
|
|
17
|
+
cleanupOutdatedRollupDutiesCount;
|
|
18
|
+
constructor(client, nodeId, name = 'HASignerMetrics'){
|
|
19
|
+
this.nodeId = nodeId;
|
|
20
|
+
const meter = client.getMeter(name);
|
|
21
|
+
// Signing lifecycle
|
|
22
|
+
this.signingDuration = meter.createHistogram(Metrics.HA_SIGNER_SIGNING_DURATION);
|
|
23
|
+
this.signingSuccessCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_SIGNING_SUCCESS_COUNT);
|
|
24
|
+
this.dutyAlreadySignedCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_DUTY_ALREADY_SIGNED_COUNT);
|
|
25
|
+
this.slashingProtectionCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_SLASHING_PROTECTION_COUNT);
|
|
26
|
+
this.signingErrorCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_SIGNING_ERROR_COUNT);
|
|
27
|
+
// Lock acquisition
|
|
28
|
+
this.lockAcquiredCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_LOCK_ACQUIRED_COUNT);
|
|
29
|
+
// Cleanup
|
|
30
|
+
this.cleanupStuckDutiesCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_CLEANUP_STUCK_DUTIES_COUNT);
|
|
31
|
+
this.cleanupOldDutiesCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_CLEANUP_OLD_DUTIES_COUNT);
|
|
32
|
+
this.cleanupOutdatedRollupDutiesCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_CLEANUP_OUTDATED_ROLLUP_DUTIES_COUNT);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Record a successful signing operation.
|
|
36
|
+
* @param dutyType - The type of duty signed
|
|
37
|
+
* @param durationMs - Duration from start of signWithProtection to completion
|
|
38
|
+
*/ recordSigningSuccess(dutyType, durationMs) {
|
|
39
|
+
const attributes = {
|
|
40
|
+
[Attributes.HA_DUTY_TYPE]: dutyType,
|
|
41
|
+
[Attributes.HA_NODE_ID]: this.nodeId
|
|
42
|
+
};
|
|
43
|
+
this.signingSuccessCount.add(1, attributes);
|
|
44
|
+
this.signingDuration.record(durationMs, attributes);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Record a DutyAlreadySignedError (expected in HA; another node signed first).
|
|
48
|
+
* @param dutyType - The type of duty
|
|
49
|
+
*/ recordDutyAlreadySigned(dutyType) {
|
|
50
|
+
const attributes = {
|
|
51
|
+
[Attributes.HA_DUTY_TYPE]: dutyType,
|
|
52
|
+
[Attributes.HA_NODE_ID]: this.nodeId
|
|
53
|
+
};
|
|
54
|
+
this.dutyAlreadySignedCount.add(1, attributes);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Record a SlashingProtectionError (attempted to sign different data for same duty).
|
|
58
|
+
* @param dutyType - The type of duty
|
|
59
|
+
*/ recordSlashingProtection(dutyType) {
|
|
60
|
+
const attributes = {
|
|
61
|
+
[Attributes.HA_DUTY_TYPE]: dutyType,
|
|
62
|
+
[Attributes.HA_NODE_ID]: this.nodeId
|
|
63
|
+
};
|
|
64
|
+
this.slashingProtectionCount.add(1, attributes);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Record a signing function failure (lock will be deleted for retry).
|
|
68
|
+
* @param dutyType - The type of duty
|
|
69
|
+
*/ recordSigningError(dutyType) {
|
|
70
|
+
const attributes = {
|
|
71
|
+
[Attributes.HA_DUTY_TYPE]: dutyType,
|
|
72
|
+
[Attributes.HA_NODE_ID]: this.nodeId
|
|
73
|
+
};
|
|
74
|
+
this.signingErrorCount.add(1, attributes);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Record lock acquisition.
|
|
78
|
+
* @param acquired - Whether a new lock was acquired (true) or existing record found (false)
|
|
79
|
+
*/ recordLockAcquire(acquired) {
|
|
80
|
+
if (acquired) {
|
|
81
|
+
const attributes = {
|
|
82
|
+
[Attributes.HA_NODE_ID]: this.nodeId
|
|
83
|
+
};
|
|
84
|
+
this.lockAcquiredCount.add(1, attributes);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Record cleanup metrics.
|
|
89
|
+
* @param type - Type of cleanup
|
|
90
|
+
* @param count - Number of duties cleaned up
|
|
91
|
+
*/ recordCleanup(type, count) {
|
|
92
|
+
const attributes = {
|
|
93
|
+
[Attributes.HA_NODE_ID]: this.nodeId
|
|
94
|
+
};
|
|
95
|
+
if (type === 'stuck') {
|
|
96
|
+
this.cleanupStuckDutiesCount.add(count, attributes);
|
|
97
|
+
} else if (type === 'old') {
|
|
98
|
+
this.cleanupOldDutiesCount.add(count, attributes);
|
|
99
|
+
} else if (type === 'outdated_rollup') {
|
|
100
|
+
this.cleanupOutdatedRollupDutiesCount.add(count, attributes);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
2
|
+
import type { ValidatorHASignerConfig } from '@aztec/stdlib/ha-signing';
|
|
1
3
|
import { type CheckAndRecordParams, type DeleteDutyParams, type RecordSuccessParams } from './db/types.js';
|
|
2
|
-
import type {
|
|
4
|
+
import type { HASignerMetrics } from './metrics.js';
|
|
5
|
+
import type { SlashingProtectionDatabase } from './types.js';
|
|
6
|
+
export interface SlashingProtectionServiceDeps {
|
|
7
|
+
metrics: HASignerMetrics;
|
|
8
|
+
dateProvider: DateProvider;
|
|
9
|
+
}
|
|
3
10
|
/**
|
|
4
11
|
* Slashing Protection Service
|
|
5
12
|
*
|
|
@@ -22,8 +29,11 @@ export declare class SlashingProtectionService {
|
|
|
22
29
|
private readonly pollingIntervalMs;
|
|
23
30
|
private readonly signingTimeoutMs;
|
|
24
31
|
private readonly maxStuckDutiesAgeMs;
|
|
32
|
+
private readonly metrics;
|
|
33
|
+
private readonly dateProvider;
|
|
25
34
|
private cleanupRunningPromise;
|
|
26
|
-
|
|
35
|
+
private lastOldDutiesCleanupAtMs?;
|
|
36
|
+
constructor(db: SlashingProtectionDatabase, config: ValidatorHASignerConfig, deps: SlashingProtectionServiceDeps);
|
|
27
37
|
/**
|
|
28
38
|
* Check if a duty can be performed and acquire the lock if so.
|
|
29
39
|
*
|
|
@@ -33,7 +43,6 @@ export declare class SlashingProtectionService {
|
|
|
33
43
|
* 2. If insert succeeds, we acquired the lock - return the lockToken
|
|
34
44
|
* 3. If a record exists, handle based on status:
|
|
35
45
|
* - SIGNED: Throw appropriate error (already signed or slashing protection)
|
|
36
|
-
* - FAILED: Delete the failed record
|
|
37
46
|
* - SIGNING: Wait and poll until status changes, then handle result
|
|
38
47
|
*
|
|
39
48
|
* @returns The lockToken that must be used for recordSuccess/deleteDuty
|
|
@@ -65,7 +74,11 @@ export declare class SlashingProtectionService {
|
|
|
65
74
|
* Start running tasks.
|
|
66
75
|
* Cleanup runs immediately on start to recover from any previous crashes.
|
|
67
76
|
*/
|
|
68
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Start the background cleanup task.
|
|
79
|
+
* Also performs one-time cleanup of duties with outdated rollup addresses.
|
|
80
|
+
*/
|
|
81
|
+
start(): Promise<void>;
|
|
69
82
|
/**
|
|
70
83
|
* Stop the background cleanup task.
|
|
71
84
|
*/
|
|
@@ -75,6 +88,6 @@ export declare class SlashingProtectionService {
|
|
|
75
88
|
* Should be called after stop() during graceful shutdown.
|
|
76
89
|
*/
|
|
77
90
|
close(): Promise<void>;
|
|
78
|
-
private
|
|
91
|
+
private cleanup;
|
|
79
92
|
}
|
|
80
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
93
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2xhc2hpbmdfcHJvdGVjdGlvbl9zZXJ2aWNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvc2xhc2hpbmdfcHJvdGVjdGlvbl9zZXJ2aWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQVNBLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBQzVELE9BQU8sS0FBSyxFQUFFLHVCQUF1QixFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFFeEUsT0FBTyxFQUNMLEtBQUssb0JBQW9CLEVBQ3pCLEtBQUssZ0JBQWdCLEVBRXJCLEtBQUssbUJBQW1CLEVBRXpCLE1BQU0sZUFBZSxDQUFDO0FBRXZCLE9BQU8sS0FBSyxFQUFFLGVBQWUsRUFBRSxNQUFNLGNBQWMsQ0FBQ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PQU1HO0lBQ0csVUFBVSxDQUFDLE1BQU0sRUFBRSxnQkFBZ0IsR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBd0IzRDtJQUVEOztPQUVHO0lBQ0gsSUFBSSxNQUFNLElBQUksTUFBTSxDQUVuQjtJQUVEOzs7T0FHRztJQUNIOzs7T0FHRztJQUNHLEtBQUssa0JBWVY7SUFFRDs7T0FFRztJQUNHLElBQUksa0JBR1Q7SUFFRDs7O09BR0c7SUFDRyxLQUFLLGtCQUdWO1lBTWEsT0FBTztDQStCdEIifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slashing_protection_service.d.ts","sourceRoot":"","sources":["../src/slashing_protection_service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"slashing_protection_service.d.ts","sourceRoot":"","sources":["../src/slashing_protection_service.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAExE,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EAErB,KAAK,mBAAmB,EAEzB,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AAE7D,MAAM,WAAW,6BAA6B;IAC5C,OAAO,EAAE,eAAe,CAAC;IACzB,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,yBAAyB;IAalC,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAbzB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAS;IAE7C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAC1C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAE5C,OAAO,CAAC,qBAAqB,CAAiB;IAC9C,OAAO,CAAC,wBAAwB,CAAC,CAAS;IAE1C,YACmB,EAAE,EAAE,0BAA0B,EAC9B,MAAM,EAAE,uBAAuB,EAChD,IAAI,EAAE,6BAA6B,EAWpC;IAED;;;;;;;;;;;;;;OAcG;IACG,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,CAqElE;IAED;;;;;;OAMG;IACG,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,CA2BjE;IAED;;;;;;OAMG;IACG,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAwB3D;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;OAGG;IACH;;;OAGG;IACG,KAAK,kBAYV;IAED;;OAEG;IACG,IAAI,kBAGT;IAED;;;OAGG;IACG,KAAK,kBAGV;YAMa,OAAO;CA+BtB"}
|
|
@@ -29,8 +29,11 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
29
29
|
pollingIntervalMs;
|
|
30
30
|
signingTimeoutMs;
|
|
31
31
|
maxStuckDutiesAgeMs;
|
|
32
|
+
metrics;
|
|
33
|
+
dateProvider;
|
|
32
34
|
cleanupRunningPromise;
|
|
33
|
-
|
|
35
|
+
lastOldDutiesCleanupAtMs;
|
|
36
|
+
constructor(db, config, deps){
|
|
34
37
|
this.db = db;
|
|
35
38
|
this.config = config;
|
|
36
39
|
this.log = createLogger('slashing-protection');
|
|
@@ -38,7 +41,9 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
38
41
|
this.signingTimeoutMs = config.signingTimeoutMs;
|
|
39
42
|
// Default to 144s (2x 72s Aztec slot duration) if not explicitly configured
|
|
40
43
|
this.maxStuckDutiesAgeMs = config.maxStuckDutiesAgeMs ?? 144_000;
|
|
41
|
-
this.cleanupRunningPromise = new RunningPromise(this.
|
|
44
|
+
this.cleanupRunningPromise = new RunningPromise(this.cleanup.bind(this), this.log, this.maxStuckDutiesAgeMs);
|
|
45
|
+
this.metrics = deps.metrics;
|
|
46
|
+
this.dateProvider = deps.dateProvider;
|
|
42
47
|
}
|
|
43
48
|
/**
|
|
44
49
|
* Check if a duty can be performed and acquire the lock if so.
|
|
@@ -49,7 +54,6 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
49
54
|
* 2. If insert succeeds, we acquired the lock - return the lockToken
|
|
50
55
|
* 3. If a record exists, handle based on status:
|
|
51
56
|
* - SIGNED: Throw appropriate error (already signed or slashing protection)
|
|
52
|
-
* - FAILED: Delete the failed record
|
|
53
57
|
* - SIGNING: Wait and poll until status changes, then handle result
|
|
54
58
|
*
|
|
55
59
|
* @returns The lockToken that must be used for recordSuccess/deleteDuty
|
|
@@ -57,7 +61,7 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
57
61
|
* @throws SlashingProtectionError if attempting to sign different data for same slot/duty
|
|
58
62
|
*/ async checkAndRecord(params) {
|
|
59
63
|
const { validatorAddress, slot, dutyType, messageHash, nodeId } = params;
|
|
60
|
-
const startTime =
|
|
64
|
+
const startTime = this.dateProvider.now();
|
|
61
65
|
this.log.debug(`Checking duty: ${dutyType} for slot ${slot}`, {
|
|
62
66
|
validatorAddress: validatorAddress.toString(),
|
|
63
67
|
nodeId
|
|
@@ -71,6 +75,7 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
71
75
|
validatorAddress: validatorAddress.toString(),
|
|
72
76
|
nodeId
|
|
73
77
|
});
|
|
78
|
+
this.metrics.recordLockAcquire(true);
|
|
74
79
|
return record.lockToken;
|
|
75
80
|
}
|
|
76
81
|
// Record already exists - handle based on status
|
|
@@ -84,17 +89,20 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
84
89
|
existingNodeId: record.nodeId,
|
|
85
90
|
attemptingNodeId: nodeId
|
|
86
91
|
});
|
|
92
|
+
this.metrics.recordSlashingProtection(dutyType);
|
|
87
93
|
throw new SlashingProtectionError(slot, dutyType, record.blockIndexWithinCheckpoint, record.messageHash, messageHash, record.nodeId);
|
|
88
94
|
}
|
|
95
|
+
this.metrics.recordDutyAlreadySigned(dutyType);
|
|
89
96
|
throw new DutyAlreadySignedError(slot, dutyType, record.blockIndexWithinCheckpoint, record.nodeId);
|
|
90
97
|
} else if (record.status === DutyStatus.SIGNING) {
|
|
91
98
|
// Another node is currently signing - check for timeout
|
|
92
|
-
if (
|
|
99
|
+
if (this.dateProvider.now() - startTime > this.signingTimeoutMs) {
|
|
93
100
|
this.log.warn(`Timeout waiting for signing to complete for duty ${dutyType} at slot ${slot}`, {
|
|
94
101
|
validatorAddress: validatorAddress.toString(),
|
|
95
102
|
timeoutMs: this.signingTimeoutMs,
|
|
96
103
|
signingNodeId: record.nodeId
|
|
97
104
|
});
|
|
105
|
+
this.metrics.recordDutyAlreadySigned(dutyType);
|
|
98
106
|
throw new DutyAlreadySignedError(slot, dutyType, record.blockIndexWithinCheckpoint, 'unknown (timeout)');
|
|
99
107
|
}
|
|
100
108
|
// Wait and poll
|
|
@@ -116,9 +124,9 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
116
124
|
*
|
|
117
125
|
* @returns true if the update succeeded, false if token didn't match
|
|
118
126
|
*/ async recordSuccess(params) {
|
|
119
|
-
const { validatorAddress, slot, dutyType, signature, nodeId, lockToken } = params;
|
|
127
|
+
const { rollupAddress, validatorAddress, slot, dutyType, signature, nodeId, lockToken } = params;
|
|
120
128
|
const blockIndexWithinCheckpoint = getBlockIndexFromDutyIdentifier(params);
|
|
121
|
-
const success = await this.db.updateDutySigned(validatorAddress, slot, dutyType, signature.toString(), lockToken, blockIndexWithinCheckpoint);
|
|
129
|
+
const success = await this.db.updateDutySigned(rollupAddress, validatorAddress, slot, dutyType, signature.toString(), lockToken, blockIndexWithinCheckpoint);
|
|
122
130
|
if (success) {
|
|
123
131
|
this.log.info(`Recorded successful signing for duty ${dutyType} at slot ${slot}`, {
|
|
124
132
|
validatorAddress: validatorAddress.toString(),
|
|
@@ -139,9 +147,9 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
139
147
|
*
|
|
140
148
|
* @returns true if the delete succeeded, false if token didn't match
|
|
141
149
|
*/ async deleteDuty(params) {
|
|
142
|
-
const { validatorAddress, slot, dutyType, lockToken } = params;
|
|
150
|
+
const { rollupAddress, validatorAddress, slot, dutyType, lockToken } = params;
|
|
143
151
|
const blockIndexWithinCheckpoint = getBlockIndexFromDutyIdentifier(params);
|
|
144
|
-
const success = await this.db.deleteDuty(validatorAddress, slot, dutyType, lockToken, blockIndexWithinCheckpoint);
|
|
152
|
+
const success = await this.db.deleteDuty(rollupAddress, validatorAddress, slot, dutyType, lockToken, blockIndexWithinCheckpoint);
|
|
145
153
|
if (success) {
|
|
146
154
|
this.log.info(`Deleted duty ${dutyType} at slot ${slot} to allow retry`, {
|
|
147
155
|
validatorAddress: validatorAddress.toString()
|
|
@@ -161,7 +169,18 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
161
169
|
/**
|
|
162
170
|
* Start running tasks.
|
|
163
171
|
* Cleanup runs immediately on start to recover from any previous crashes.
|
|
164
|
-
*/
|
|
172
|
+
*/ /**
|
|
173
|
+
* Start the background cleanup task.
|
|
174
|
+
* Also performs one-time cleanup of duties with outdated rollup addresses.
|
|
175
|
+
*/ async start() {
|
|
176
|
+
// One-time cleanup at startup: remove duties from previous rollup versions
|
|
177
|
+
const numOutdatedRollupDuties = await this.db.cleanupOutdatedRollupDuties(this.config.l1Contracts.rollupAddress);
|
|
178
|
+
if (numOutdatedRollupDuties > 0) {
|
|
179
|
+
this.log.info(`Cleaned up ${numOutdatedRollupDuties} duties with outdated rollup address at startup`, {
|
|
180
|
+
currentRollupAddress: this.config.l1Contracts.rollupAddress.toString()
|
|
181
|
+
});
|
|
182
|
+
this.metrics.recordCleanup('outdated_rollup', numOutdatedRollupDuties);
|
|
183
|
+
}
|
|
165
184
|
this.cleanupRunningPromise.start();
|
|
166
185
|
this.log.info('Slashing protection service started', {
|
|
167
186
|
nodeId: this.config.nodeId
|
|
@@ -183,14 +202,35 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
183
202
|
this.log.info('Slashing protection database connection closed');
|
|
184
203
|
}
|
|
185
204
|
/**
|
|
186
|
-
*
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
205
|
+
* Periodic cleanup of stuck duties and optionally old signed duties.
|
|
206
|
+
* Runs in the background via RunningPromise.
|
|
207
|
+
*/ async cleanup() {
|
|
208
|
+
// 1. Clean up stuck duties (our own node's duties that got stuck in 'signing' status)
|
|
209
|
+
const numStuckDuties = await this.db.cleanupOwnStuckDuties(this.config.nodeId, this.maxStuckDutiesAgeMs);
|
|
210
|
+
if (numStuckDuties > 0) {
|
|
211
|
+
this.log.verbose(`Cleaned up ${numStuckDuties} stuck duties`, {
|
|
191
212
|
nodeId: this.config.nodeId,
|
|
192
213
|
maxStuckDutiesAgeMs: this.maxStuckDutiesAgeMs
|
|
193
214
|
});
|
|
215
|
+
this.metrics.recordCleanup('stuck', numStuckDuties);
|
|
216
|
+
}
|
|
217
|
+
// 2. Clean up old signed duties if configured
|
|
218
|
+
// we shouldn't run this as often as stuck duty cleanup.
|
|
219
|
+
if (this.config.cleanupOldDutiesAfterHours !== undefined) {
|
|
220
|
+
const maxAgeMs = this.config.cleanupOldDutiesAfterHours * 60 * 60 * 1000;
|
|
221
|
+
const nowMs = this.dateProvider.now();
|
|
222
|
+
const shouldRun = this.lastOldDutiesCleanupAtMs === undefined || nowMs - this.lastOldDutiesCleanupAtMs >= maxAgeMs;
|
|
223
|
+
if (shouldRun) {
|
|
224
|
+
const numOldDuties = await this.db.cleanupOldDuties(maxAgeMs);
|
|
225
|
+
this.lastOldDutiesCleanupAtMs = nowMs;
|
|
226
|
+
if (numOldDuties > 0) {
|
|
227
|
+
this.log.verbose(`Cleaned up ${numOldDuties} old signed duties`, {
|
|
228
|
+
cleanupOldDutiesAfterHours: this.config.cleanupOldDutiesAfterHours,
|
|
229
|
+
maxAgeMs
|
|
230
|
+
});
|
|
231
|
+
this.metrics.recordCleanup('old', numOldDuties);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
194
234
|
}
|
|
195
235
|
}
|
|
196
236
|
}
|
package/dest/types.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
4
|
+
import { DutyType, type HAProtectedSigningContext, type SigningContext, type ValidatorHASignerConfig, getBlockNumberFromSigningContext as getBlockNumberFromSigningContextFromStdlib, isHAProtectedContext } from '@aztec/stdlib/ha-signing';
|
|
5
|
+
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
3
6
|
import type { Pool } from 'pg';
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
export type { BlockProposalDutyIdentifier, CheckAndRecordParams, DeleteDutyParams, DutyIdentifier, OtherDutyIdentifier, RecordSuccessParams, ValidatorDutyRecord, ValidatorHASignerConfig, };
|
|
7
|
+
import type { BlockProposalDutyIdentifier, CheckAndRecordParams, DeleteDutyParams, DutyIdentifier, DutyRow, OtherDutyIdentifier, RecordSuccessParams, ValidatorDutyRecord } from './db/types.js';
|
|
8
|
+
export type { BlockProposalDutyIdentifier, CheckAndRecordParams, DeleteDutyParams, DutyIdentifier, DutyRow, HAProtectedSigningContext, OtherDutyIdentifier, RecordSuccessParams, SigningContext, ValidatorDutyRecord, ValidatorHASignerConfig, };
|
|
7
9
|
export { DutyStatus, DutyType, getBlockIndexFromDutyIdentifier, normalizeBlockIndex } from './db/types.js';
|
|
10
|
+
export { isHAProtectedContext };
|
|
11
|
+
export { getBlockNumberFromSigningContextFromStdlib as getBlockNumberFromSigningContext };
|
|
8
12
|
/**
|
|
9
13
|
* Result of tryInsertOrGetExisting operation
|
|
10
14
|
*/
|
|
@@ -23,76 +27,15 @@ export interface CreateHASignerDeps {
|
|
|
23
27
|
* If provided, databaseUrl and poolConfig are ignored
|
|
24
28
|
*/
|
|
25
29
|
pool?: Pool;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Base context for signing operations
|
|
29
|
-
*/
|
|
30
|
-
interface BaseSigningContext {
|
|
31
|
-
/** Slot number for this duty */
|
|
32
|
-
slot: SlotNumber;
|
|
33
30
|
/**
|
|
34
|
-
*
|
|
35
|
-
* For block proposals, this is the block number.
|
|
36
|
-
* For checkpoint proposals, this is the checkpoint number.
|
|
31
|
+
* Optional telemetry client for metrics
|
|
37
32
|
*/
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
*/
|
|
44
|
-
export interface BlockProposalSigningContext extends BaseSigningContext {
|
|
45
|
-
/** Block index within checkpoint (0, 1, 2...). Required for block proposals. */
|
|
46
|
-
blockIndexWithinCheckpoint: IndexWithinCheckpoint;
|
|
47
|
-
dutyType: DutyType.BLOCK_PROPOSAL;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Signing context for non-block-proposal duties that require HA protection.
|
|
51
|
-
* blockIndexWithinCheckpoint is not applicable (internally always -1).
|
|
52
|
-
*/
|
|
53
|
-
export interface OtherSigningContext extends BaseSigningContext {
|
|
54
|
-
dutyType: DutyType.CHECKPOINT_PROPOSAL | DutyType.ATTESTATION | DutyType.ATTESTATIONS_AND_SIGNERS;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Signing context for governance/slashing votes which only need slot for HA protection.
|
|
58
|
-
* blockNumber is not applicable (internally always 0).
|
|
59
|
-
*/
|
|
60
|
-
export interface VoteSigningContext {
|
|
61
|
-
slot: SlotNumber;
|
|
62
|
-
dutyType: DutyType.GOVERNANCE_VOTE | DutyType.SLASHING_VOTE;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Signing context for duties which don't require slot/blockNumber
|
|
66
|
-
* as they don't need HA protection (AUTH_REQUEST, TXS).
|
|
67
|
-
*/
|
|
68
|
-
export interface NoHAProtectionSigningContext {
|
|
69
|
-
dutyType: DutyType.AUTH_REQUEST | DutyType.TXS;
|
|
33
|
+
telemetryClient?: TelemetryClient;
|
|
34
|
+
/**
|
|
35
|
+
* Optional date provider for timestamps
|
|
36
|
+
*/
|
|
37
|
+
dateProvider?: DateProvider;
|
|
70
38
|
}
|
|
71
|
-
/**
|
|
72
|
-
* Signing contexts that require HA protection (excludes AUTH_REQUEST).
|
|
73
|
-
* Used by the HA signer's signWithProtection method.
|
|
74
|
-
*/
|
|
75
|
-
export type HAProtectedSigningContext = BlockProposalSigningContext | OtherSigningContext | VoteSigningContext;
|
|
76
|
-
/**
|
|
77
|
-
* Type guard to check if a SigningContext requires HA protection.
|
|
78
|
-
* Returns true for contexts that need HA protection, false for AUTH_REQUEST and TXS.
|
|
79
|
-
*/
|
|
80
|
-
export declare function isHAProtectedContext(context: SigningContext): context is HAProtectedSigningContext;
|
|
81
|
-
/**
|
|
82
|
-
* Gets the block number from a signing context.
|
|
83
|
-
* - Vote duties (GOVERNANCE_VOTE, SLASHING_VOTE): returns BlockNumber(0)
|
|
84
|
-
* - Other duties: returns the blockNumber from the context
|
|
85
|
-
*/
|
|
86
|
-
export declare function getBlockNumberFromSigningContext(context: HAProtectedSigningContext): BlockNumber | CheckpointNumber;
|
|
87
|
-
/**
|
|
88
|
-
* Context required for slashing protection during signing operations.
|
|
89
|
-
* Uses discriminated union to enforce type safety:
|
|
90
|
-
* - BLOCK_PROPOSAL duties MUST have blockIndexWithinCheckpoint >= 0
|
|
91
|
-
* - Other duty types do NOT have blockIndexWithinCheckpoint (internally -1)
|
|
92
|
-
* - Vote duties only need slot (blockNumber is internally 0)
|
|
93
|
-
* - AUTH_REQUEST and TXS duties don't need slot/blockNumber (no HA protection needed)
|
|
94
|
-
*/
|
|
95
|
-
export type SigningContext = HAProtectedSigningContext | NoHAProtectionSigningContext;
|
|
96
39
|
/**
|
|
97
40
|
* Database interface for slashing protection operations
|
|
98
41
|
* This abstraction allows for different database implementations (PostgreSQL, SQLite, etc.)
|
|
@@ -116,7 +59,7 @@ export interface SlashingProtectionDatabase {
|
|
|
116
59
|
*
|
|
117
60
|
* @returns true if the update succeeded, false if token didn't match or duty not found
|
|
118
61
|
*/
|
|
119
|
-
updateDutySigned(validatorAddress: EthAddress, slot: SlotNumber, dutyType: DutyType, signature: string, lockToken: string, blockIndexWithinCheckpoint: number): Promise<boolean>;
|
|
62
|
+
updateDutySigned(rollupAddress: EthAddress, validatorAddress: EthAddress, slot: SlotNumber, dutyType: DutyType, signature: string, lockToken: string, blockIndexWithinCheckpoint: number): Promise<boolean>;
|
|
120
63
|
/**
|
|
121
64
|
* Delete a duty record.
|
|
122
65
|
* Only succeeds if the lockToken matches (caller must be the one who created the duty).
|
|
@@ -124,16 +67,29 @@ export interface SlashingProtectionDatabase {
|
|
|
124
67
|
*
|
|
125
68
|
* @returns true if the delete succeeded, false if token didn't match or duty not found
|
|
126
69
|
*/
|
|
127
|
-
deleteDuty(validatorAddress: EthAddress, slot: SlotNumber, dutyType: DutyType, lockToken: string, blockIndexWithinCheckpoint: number): Promise<boolean>;
|
|
70
|
+
deleteDuty(rollupAddress: EthAddress, validatorAddress: EthAddress, slot: SlotNumber, dutyType: DutyType, lockToken: string, blockIndexWithinCheckpoint: number): Promise<boolean>;
|
|
128
71
|
/**
|
|
129
72
|
* Cleanup own stuck duties
|
|
130
73
|
* @returns the number of duties cleaned up
|
|
131
74
|
*/
|
|
132
75
|
cleanupOwnStuckDuties(nodeId: string, maxAgeMs: number): Promise<number>;
|
|
76
|
+
/**
|
|
77
|
+
* Cleanup duties with outdated rollup address.
|
|
78
|
+
* Removes all duties where the rollup address doesn't match the current one.
|
|
79
|
+
* Used after a rollup upgrade to clean up duties for the old rollup.
|
|
80
|
+
* @returns the number of duties cleaned up
|
|
81
|
+
*/
|
|
82
|
+
cleanupOutdatedRollupDuties(currentRollupAddress: EthAddress): Promise<number>;
|
|
83
|
+
/**
|
|
84
|
+
* Cleanup old signed duties.
|
|
85
|
+
* Removes only signed duties older than the specified age.
|
|
86
|
+
* @returns the number of duties cleaned up
|
|
87
|
+
*/
|
|
88
|
+
cleanupOldDuties(maxAgeMs: number): Promise<number>;
|
|
133
89
|
/**
|
|
134
90
|
* Close the database connection.
|
|
135
91
|
* Should be called during graceful shutdown.
|
|
136
92
|
*/
|
|
137
93
|
close(): Promise<void>;
|
|
138
94
|
}
|
|
139
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
95
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy90eXBlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDN0QsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0sK0JBQStCLENBQUM7QUFDaEUsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBQ3ZELE9BQU8sRUFDTCxRQUFRLEVBQ1IsS0FBSyx5QkFBeUIsRUFDOUIsS0FBSyxjQUFjLEVBQ25CLEtBQUssdUJBQXVCLEVBQzVCLGdDQUFnQyxJQUFJLDBDQUEwQyxFQUM5RSxvQkFBb0IsRUFDckIsTUFBT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BQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFDO0lBRXBEOzs7T0FHRztJQUNILEtBQUssSUFBSSxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUM7Q0FDeEIifQ==
|
package/dest/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EACL,QAAQ,EACR,KAAK,yBAAyB,EAC9B,KAAK,cAAc,EACnB,KAAK,uBAAuB,EAC5B,gCAAgC,IAAI,0CAA0C,EAC9E,oBAAoB,EACrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE/D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE/B,OAAO,KAAK,EACV,2BAA2B,EAC3B,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,EACd,OAAO,EACP,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,eAAe,CAAC;AAEvB,YAAY,EACV,2BAA2B,EAC3B,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,EACd,OAAO,EACP,yBAAyB,EACzB,mBAAmB,EACnB,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACnB,uBAAuB,GACxB,CAAC;AACF,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,+BAA+B,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAC3G,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAChC,O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MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEpD;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}
|
package/dest/types.js
CHANGED
|
@@ -1,21 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DutyType } from './db/types.js';
|
|
1
|
+
import { getBlockNumberFromSigningContext as getBlockNumberFromSigningContextFromStdlib, isHAProtectedContext } from '@aztec/stdlib/ha-signing';
|
|
3
2
|
export { DutyStatus, DutyType, getBlockIndexFromDutyIdentifier, normalizeBlockIndex } from './db/types.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* Returns true for contexts that need HA protection, false for AUTH_REQUEST and TXS.
|
|
7
|
-
*/ export function isHAProtectedContext(context) {
|
|
8
|
-
return context.dutyType !== DutyType.AUTH_REQUEST && context.dutyType !== DutyType.TXS;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Gets the block number from a signing context.
|
|
12
|
-
* - Vote duties (GOVERNANCE_VOTE, SLASHING_VOTE): returns BlockNumber(0)
|
|
13
|
-
* - Other duties: returns the blockNumber from the context
|
|
14
|
-
*/ export function getBlockNumberFromSigningContext(context) {
|
|
15
|
-
// Check for duty types that have blockNumber
|
|
16
|
-
if (context.dutyType === DutyType.BLOCK_PROPOSAL || context.dutyType === DutyType.CHECKPOINT_PROPOSAL || context.dutyType === DutyType.ATTESTATION || context.dutyType === DutyType.ATTESTATIONS_AND_SIGNERS) {
|
|
17
|
-
return context.blockNumber;
|
|
18
|
-
}
|
|
19
|
-
// Vote duties (GOVERNANCE_VOTE, SLASHING_VOTE) don't have blockNumber
|
|
20
|
-
return BlockNumber(0);
|
|
21
|
-
}
|
|
3
|
+
export { isHAProtectedContext };
|
|
4
|
+
export { getBlockNumberFromSigningContextFromStdlib as getBlockNumberFromSigningContext };
|
|
@@ -6,10 +6,16 @@
|
|
|
6
6
|
* node will sign for a given duty (slot + duty type).
|
|
7
7
|
*/
|
|
8
8
|
import type { Buffer32 } from '@aztec/foundation/buffer';
|
|
9
|
-
import
|
|
9
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
10
10
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
11
|
-
import type {
|
|
12
|
-
import { type HAProtectedSigningContext, type
|
|
11
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
12
|
+
import { type HAProtectedSigningContext, type ValidatorHASignerConfig } from '@aztec/stdlib/ha-signing';
|
|
13
|
+
import type { HASignerMetrics } from './metrics.js';
|
|
14
|
+
import type { SlashingProtectionDatabase } from './types.js';
|
|
15
|
+
export interface ValidatorHASignerDeps {
|
|
16
|
+
metrics: HASignerMetrics;
|
|
17
|
+
dateProvider: DateProvider;
|
|
18
|
+
}
|
|
13
19
|
/**
|
|
14
20
|
* Validator High Availability Signer
|
|
15
21
|
*
|
|
@@ -33,7 +39,10 @@ export declare class ValidatorHASigner {
|
|
|
33
39
|
private readonly config;
|
|
34
40
|
private readonly log;
|
|
35
41
|
private readonly slashingProtection;
|
|
36
|
-
|
|
42
|
+
private readonly rollupAddress;
|
|
43
|
+
private readonly dateProvider;
|
|
44
|
+
private readonly metrics;
|
|
45
|
+
constructor(db: SlashingProtectionDatabase, config: ValidatorHASignerConfig, deps: ValidatorHASignerDeps);
|
|
37
46
|
/**
|
|
38
47
|
* Sign a message with slashing protection.
|
|
39
48
|
*
|
|
@@ -60,11 +69,11 @@ export declare class ValidatorHASigner {
|
|
|
60
69
|
* Start the HA signer background tasks (cleanup of stuck duties).
|
|
61
70
|
* Should be called after construction and before signing operations.
|
|
62
71
|
*/
|
|
63
|
-
start(): void
|
|
72
|
+
start(): Promise<void>;
|
|
64
73
|
/**
|
|
65
74
|
* Stop the HA signer background tasks and close database connection.
|
|
66
75
|
* Should be called during graceful shutdown.
|
|
67
76
|
*/
|
|
68
77
|
stop(): Promise<void>;
|
|
69
78
|
}
|
|
70
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
79
|
+
//#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9BQU8sQ0FBQyxRQUFRLENBQUMsWUFBWSxDQUFlO0lBQzVDLE9BQU8sQ0FBQyxRQUFRLENBQUMsT0FBTyxDQUFrQjtJQUUxQyxZQUNFLEVBQUUsRUFBRSwwQkFBMEIsRUFDYixNQUFNLEVBQUUsdUJBQXVCLEVBQ2hELElBQUksRUFBRSxxQkFBcUIsRUF3QjVCO0lBRUQ7Ozs7Ozs7Ozs7Ozs7Ozs7T0FnQkc7SUFDRyxrQkFBa0IsQ0FDdEIsZ0JBQWdCLEVBQUUsVUFBVSxFQUM1QixXQUFXLEVBQUUsUUFBUSxFQUNyQixPQUFPLEVBQUUseUJBQXlCLEVBQ2xDLE1BQU0sRUFBRSxDQUFDLFdBQVcsRUFBRSxRQUFRLEtBQUssT0FBTyxDQUFDLFNBQVMsQ0FBQyxHQUNwRCxPQUFPLENBQUMsU0FBUyxDQUFDLENBdURwQjtJQUVEOztPQUVHO0lBQ0gsSUFBSSxNQUFNLElBQUksTUFBTSxDQUVuQjtJQUVEOzs7T0FHRztJQUNHLEtBQUssa0JBRVY7SUFFRDs7O09BR0c7SUFDRyxJQUFJLGtCQUdUO0NBQ0YifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator_ha_signer.d.ts","sourceRoot":"","sources":["../src/validator_ha_signer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,
|
|
1
|
+
{"version":3,"file":"validator_ha_signer.d.ts","sourceRoot":"","sources":["../src/validator_ha_signer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAEjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM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