@aztec/slasher 0.0.1-commit.9b94fc1 → 0.0.1-commit.9badcec54
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 +51 -65
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +28 -28
- package/dest/factory/create_facade.d.ts +5 -4
- package/dest/factory/create_facade.d.ts.map +1 -1
- package/dest/factory/create_facade.js +26 -3
- package/dest/factory/create_implementation.d.ts +7 -8
- package/dest/factory/create_implementation.d.ts.map +1 -1
- package/dest/factory/create_implementation.js +8 -56
- package/dest/factory/get_settings.d.ts +4 -4
- package/dest/factory/get_settings.d.ts.map +1 -1
- package/dest/factory/get_settings.js +3 -3
- package/dest/factory/index.d.ts +2 -2
- package/dest/factory/index.d.ts.map +1 -1
- package/dest/factory/index.js +1 -1
- package/dest/generated/slasher-defaults.d.ts +19 -0
- package/dest/generated/slasher-defaults.d.ts.map +1 -0
- package/dest/generated/slasher-defaults.js +19 -0
- package/dest/index.d.ts +2 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/null_slasher_client.d.ts +3 -4
- package/dest/null_slasher_client.d.ts.map +1 -1
- package/dest/null_slasher_client.js +1 -4
- package/dest/slash_offenses_collector.d.ts +5 -8
- package/dest/slash_offenses_collector.d.ts.map +1 -1
- package/dest/slash_offenses_collector.js +9 -18
- package/dest/slasher_client.d.ts +112 -0
- package/dest/slasher_client.d.ts.map +1 -0
- package/dest/{tally_slasher_client.js → slasher_client.js} +30 -39
- package/dest/slasher_client_facade.d.ts +7 -9
- package/dest/slasher_client_facade.d.ts.map +1 -1
- package/dest/slasher_client_facade.js +6 -9
- package/dest/slasher_client_interface.d.ts +7 -21
- package/dest/slasher_client_interface.d.ts.map +1 -1
- package/dest/slasher_client_interface.js +1 -4
- package/dest/stores/offenses_store.d.ts +6 -12
- package/dest/stores/offenses_store.d.ts.map +1 -1
- package/dest/stores/offenses_store.js +8 -25
- package/dest/watchers/attestations_block_watcher.d.ts +7 -6
- package/dest/watchers/attestations_block_watcher.d.ts.map +1 -1
- package/dest/watchers/attestations_block_watcher.js +40 -34
- package/dest/watchers/epoch_prune_watcher.d.ts +9 -7
- package/dest/watchers/epoch_prune_watcher.d.ts.map +1 -1
- package/dest/watchers/epoch_prune_watcher.js +59 -15
- package/package.json +16 -14
- package/src/config.ts +31 -28
- package/src/factory/create_facade.ts +35 -6
- package/src/factory/create_implementation.ts +25 -106
- package/src/factory/get_settings.ts +8 -8
- package/src/factory/index.ts +1 -1
- package/src/generated/slasher-defaults.ts +21 -0
- package/src/index.ts +1 -2
- package/src/null_slasher_client.ts +2 -6
- package/src/slash_offenses_collector.ts +16 -20
- package/src/{tally_slasher_client.ts → slasher_client.ts} +37 -48
- package/src/slasher_client_facade.ts +7 -12
- package/src/slasher_client_interface.ts +6 -21
- package/src/stores/offenses_store.ts +11 -34
- package/src/watcher.ts +1 -1
- package/src/watchers/attestations_block_watcher.ts +57 -44
- package/src/watchers/epoch_prune_watcher.ts +87 -24
- package/dest/empire_slasher_client.d.ts +0 -190
- package/dest/empire_slasher_client.d.ts.map +0 -1
- package/dest/empire_slasher_client.js +0 -572
- package/dest/stores/payloads_store.d.ts +0 -29
- package/dest/stores/payloads_store.d.ts.map +0 -1
- package/dest/stores/payloads_store.js +0 -125
- package/dest/tally_slasher_client.d.ts +0 -125
- package/dest/tally_slasher_client.d.ts.map +0 -1
- package/src/empire_slasher_client.ts +0 -657
- package/src/stores/payloads_store.ts +0 -146
|
@@ -1,31 +1,17 @@
|
|
|
1
1
|
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
3
|
-
import type { Offense, ProposerSlashAction
|
|
4
|
-
/**
|
|
5
|
-
* Common interface for slasher clients used by the Aztec node.
|
|
6
|
-
* Both Empire and Consensus slasher clients implement this interface.
|
|
7
|
-
*/
|
|
3
|
+
import type { Offense, ProposerSlashAction } from '@aztec/stdlib/slashing';
|
|
4
|
+
/** Common interface for slasher clients used by the Aztec node. */
|
|
8
5
|
export interface SlasherClientInterface {
|
|
9
6
|
/** Start the slasher client */
|
|
10
7
|
start(): Promise<void>;
|
|
11
8
|
/** Stop the slasher client */
|
|
12
9
|
stop(): Promise<void>;
|
|
13
|
-
/**
|
|
14
|
-
* Get slash payloads for the Empire model.
|
|
15
|
-
* The Consensus model should throw an error when this is called.
|
|
16
|
-
*/
|
|
17
|
-
getSlashPayloads(): Promise<SlashPayloadRound[]>;
|
|
18
|
-
/**
|
|
19
|
-
* Gather offenses for a given round, defaults to current.
|
|
20
|
-
* Used by both Empire and Consensus models.
|
|
21
|
-
*/
|
|
10
|
+
/** Gather offenses for a given round, defaults to current. */
|
|
22
11
|
gatherOffensesForRound(round?: bigint): Promise<Offense[]>;
|
|
23
|
-
/** Returns all
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Update the configuration.
|
|
27
|
-
* Used by both Empire and Consensus models.
|
|
28
|
-
*/
|
|
12
|
+
/** Returns all offenses */
|
|
13
|
+
getOffenses(): Promise<Offense[]>;
|
|
14
|
+
/** Update the configuration. */
|
|
29
15
|
updateConfig(config: Partial<SlasherConfig>): void;
|
|
30
16
|
/**
|
|
31
17
|
* Get the actions the proposer should take for slashing.
|
|
@@ -36,4 +22,4 @@ export interface SlasherClientInterface {
|
|
|
36
22
|
/** Returns the current config */
|
|
37
23
|
getConfig(): SlasherConfig;
|
|
38
24
|
}
|
|
39
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
25
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2xhc2hlcl9jbGllbnRfaW50ZXJmYWNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvc2xhc2hlcl9jbGllbnRfaW50ZXJmYWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJB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,MAAM,iCAAiC,CAAC;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"slasher_client_interface.d.ts","sourceRoot":"","sources":["../src/slasher_client_interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE3E,mEAAmE;AACnE,MAAM,WAAW,sBAAsB;IACrC,+BAA+B;IAC/B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB,8BAA8B;IAC9B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtB,8DAA8D;IAC9D,sBAAsB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAE3D,2BAA2B;IAC3B,WAAW,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAElC,gCAAgC;IAChC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC;IAEnD;;;;OAIG;IACH,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAAC;IAE3E,iCAAiC;IACjC,SAAS,IAAI,aAAa,CAAC;CAC5B"}
|
|
@@ -6,9 +6,7 @@ export declare class SlasherOffensesStore {
|
|
|
6
6
|
private settings;
|
|
7
7
|
/** Map from offense key to offense data */
|
|
8
8
|
private offenses;
|
|
9
|
-
/**
|
|
10
|
-
private offensesSlashed;
|
|
11
|
-
/** Multimap from round to offense keys (only used for consensus based slashing) */
|
|
9
|
+
/** Multimap from round to offense keys */
|
|
12
10
|
private roundsOffenses;
|
|
13
11
|
private log;
|
|
14
12
|
constructor(kvStore: AztecAsyncKVStore, settings: {
|
|
@@ -16,22 +14,18 @@ export declare class SlasherOffensesStore {
|
|
|
16
14
|
epochDuration: number;
|
|
17
15
|
slashOffenseExpirationRounds?: number;
|
|
18
16
|
});
|
|
19
|
-
/** Returns all offenses
|
|
20
|
-
|
|
17
|
+
/** Returns all offenses */
|
|
18
|
+
getOffenses(): Promise<Offense[]>;
|
|
21
19
|
/** Returns all offenses tracked for the given round */
|
|
22
20
|
getOffensesForRound(round: bigint): Promise<Offense[]>;
|
|
23
|
-
/** Returns whether an offense is pending (ie not marked as slashed) */
|
|
24
|
-
hasPendingOffense(offense: OffenseIdentifier): Promise<boolean>;
|
|
25
21
|
/** Returns whether we have seen this offense */
|
|
26
22
|
hasOffense(offense: OffenseIdentifier): Promise<boolean>;
|
|
27
|
-
/** Adds a new offense
|
|
28
|
-
|
|
29
|
-
/** Marks the given offenses as slashed (regardless of whether they are known or not) */
|
|
30
|
-
markAsSlashed(offenses: OffenseIdentifier[]): Promise<void>;
|
|
23
|
+
/** Adds a new offense */
|
|
24
|
+
addOffense(offense: Offense): Promise<void>;
|
|
31
25
|
/** Prunes all offenses expired from the store */
|
|
32
26
|
clearExpiredOffenses(currentRound: bigint): Promise<number>;
|
|
33
27
|
/** Generate a unique key for an offense */
|
|
34
28
|
private getOffenseKey;
|
|
35
29
|
private getRoundKey;
|
|
36
30
|
}
|
|
37
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
31
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib2ZmZW5zZXNfc3RvcmUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zdG9yZXMvb2ZmZW5zZXNfc3RvcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQXFDLE1BQU0saUJBQWlCLENBQUM7QUFDNUYsT0FBTyxFQUNMLEtBQUssT0F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DLGFBQWE7SUFJckIsT0FBTyxDQUFDLFdBQVc7Q0FHcEIifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"offenses_store.d.ts","sourceRoot":"","sources":["../../src/stores/offenses_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"offenses_store.d.ts","sourceRoot":"","sources":["../../src/stores/offenses_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAqC,MAAM,iBAAiB,CAAC;AAC5F,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,iBAAiB,EAIvB,MAAM,wBAAwB,CAAC;AAEhC,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC,qBAAa,oBAAoB;IAU7B,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,QAAQ;IAVlB,2CAA2C;IAC3C,OAAO,CAAC,QAAQ,CAAgC;IAEhD,0CAA0C;IAC1C,OAAO,CAAC,cAAc,CAAqC;IAE3D,OAAO,CAAC,GAAG,CAA0C;IAErD,YACU,OAAO,EAAE,iBAAiB,EAC1B,QAAQ,EAAE;QAChB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,aAAa,EAAE,MAAM,CAAC;QACtB,4BAA4B,CAAC,EAAE,MAAM,CAAC;KACvC,EAIF;IAED,2BAA2B;IACd,WAAW,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,CAM7C;IAED,uDAAuD;IAC1C,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAUlE;IAED,gDAAgD;IACnC,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,CAGpE;IAED,yBAAyB;IACZ,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAQvD;IAED,iDAAiD;IACpC,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAsCvE;IAED,2CAA2C;IAC3C,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,WAAW;CAGpB"}
|
|
@@ -5,8 +5,7 @@ export class SlasherOffensesStore {
|
|
|
5
5
|
kvStore;
|
|
6
6
|
settings;
|
|
7
7
|
/** Map from offense key to offense data */ offenses;
|
|
8
|
-
/**
|
|
9
|
-
/** Multimap from round to offense keys (only used for consensus based slashing) */ roundsOffenses;
|
|
8
|
+
/** Multimap from round to offense keys */ roundsOffenses;
|
|
10
9
|
log;
|
|
11
10
|
constructor(kvStore, settings){
|
|
12
11
|
this.kvStore = kvStore;
|
|
@@ -14,16 +13,11 @@ export class SlasherOffensesStore {
|
|
|
14
13
|
this.log = createLogger('slasher:store:offenses');
|
|
15
14
|
this.offenses = kvStore.openMap('offenses');
|
|
16
15
|
this.roundsOffenses = kvStore.openMultiMap('rounds-offenses');
|
|
17
|
-
this.offensesSlashed = kvStore.openSet('offenses-slashed');
|
|
18
16
|
}
|
|
19
|
-
/** Returns all offenses
|
|
17
|
+
/** Returns all offenses */ async getOffenses() {
|
|
20
18
|
const offenses = [];
|
|
21
|
-
for await (const [
|
|
22
|
-
|
|
23
|
-
continue; // Skip executed offenses
|
|
24
|
-
}
|
|
25
|
-
const offense = deserializeOffense(buffer);
|
|
26
|
-
offenses.push(offense);
|
|
19
|
+
for await (const [, buffer] of this.offenses.entriesAsync()){
|
|
20
|
+
offenses.push(deserializeOffense(buffer));
|
|
27
21
|
}
|
|
28
22
|
return offenses;
|
|
29
23
|
}
|
|
@@ -38,28 +32,18 @@ export class SlasherOffensesStore {
|
|
|
38
32
|
}
|
|
39
33
|
return offenses;
|
|
40
34
|
}
|
|
41
|
-
/** Returns whether an offense is pending (ie not marked as slashed) */ async hasPendingOffense(offense) {
|
|
42
|
-
const key = this.getOffenseKey(offense);
|
|
43
|
-
return await this.offenses.getAsync(key) !== undefined && !await this.offensesSlashed.hasAsync(key);
|
|
44
|
-
}
|
|
45
35
|
/** Returns whether we have seen this offense */ async hasOffense(offense) {
|
|
46
36
|
const key = this.getOffenseKey(offense);
|
|
47
37
|
return await this.offenses.getAsync(key) !== undefined;
|
|
48
38
|
}
|
|
49
|
-
/** Adds a new offense
|
|
39
|
+
/** Adds a new offense */ async addOffense(offense) {
|
|
50
40
|
const key = this.getOffenseKey(offense);
|
|
51
|
-
await this.offenses.set(key, serializeOffense(offense));
|
|
52
41
|
const round = getRoundForOffense(offense, this.settings);
|
|
53
|
-
await this.roundsOffenses.set(this.getRoundKey(round), key);
|
|
54
|
-
this.log.trace(`Adding pending offense ${key} for round ${round}`);
|
|
55
|
-
}
|
|
56
|
-
/** Marks the given offenses as slashed (regardless of whether they are known or not) */ async markAsSlashed(offenses) {
|
|
57
42
|
await this.kvStore.transactionAsync(async ()=>{
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
await this.offensesSlashed.add(key);
|
|
61
|
-
}
|
|
43
|
+
await this.offenses.set(key, serializeOffense(offense));
|
|
44
|
+
await this.roundsOffenses.set(this.getRoundKey(round), key);
|
|
62
45
|
});
|
|
46
|
+
this.log.trace(`Adding pending offense ${key} for round ${round}`);
|
|
63
47
|
}
|
|
64
48
|
/** Prunes all offenses expired from the store */ async clearExpiredOffenses(currentRound) {
|
|
65
49
|
const expirationRounds = this.settings.slashOffenseExpirationRounds ?? 0;
|
|
@@ -87,7 +71,6 @@ export class SlasherOffensesStore {
|
|
|
87
71
|
for (const key of expiredOffenseKeys){
|
|
88
72
|
this.log.trace(`Deleting offense ${key}`);
|
|
89
73
|
await this.offenses.delete(key);
|
|
90
|
-
await this.offensesSlashed.delete(key);
|
|
91
74
|
}
|
|
92
75
|
for (const roundKey of expiredRoundKeys){
|
|
93
76
|
this.log.trace(`Deleting round info for ${roundKey}`);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
2
|
-
import { type L2BlockSourceEventEmitter } from '@aztec/stdlib/block';
|
|
2
|
+
import { type InvalidCheckpointDetectedEvent, type L2BlockSourceEventEmitter } from '@aztec/stdlib/block';
|
|
3
3
|
import type { SlasherConfig } from '../config.js';
|
|
4
4
|
import { type Watcher, type WatcherEmitter } from '../watcher.js';
|
|
5
5
|
declare const AttestationsBlockWatcherConfigKeys: readonly ["slashAttestDescendantOfInvalidPenalty", "slashProposeInvalidAttestationsPenalty"];
|
|
@@ -15,19 +15,20 @@ export declare class AttestationsBlockWatcher extends AttestationsBlockWatcher_b
|
|
|
15
15
|
private l2BlockSource;
|
|
16
16
|
private epochCache;
|
|
17
17
|
private log;
|
|
18
|
-
private
|
|
18
|
+
private maxInvalidCheckpoints;
|
|
19
19
|
private invalidArchiveRoots;
|
|
20
20
|
private config;
|
|
21
|
-
private
|
|
21
|
+
private boundHandleInvalidCheckpoint;
|
|
22
22
|
constructor(l2BlockSource: L2BlockSourceEventEmitter, epochCache: EpochCache, config: AttestationsBlockWatcherConfig);
|
|
23
23
|
updateConfig(newConfig: Partial<AttestationsBlockWatcherConfig>): void;
|
|
24
24
|
start(): Promise<void>;
|
|
25
25
|
stop(): Promise<void>;
|
|
26
|
-
|
|
26
|
+
/** Event handler for invalid checkpoints as reported by the archiver. Public for testing purposes. */
|
|
27
|
+
handleInvalidCheckpoint(event: InvalidCheckpointDetectedEvent): void;
|
|
27
28
|
private slashAttestorsOnAncestorInvalid;
|
|
28
29
|
private slashProposer;
|
|
29
30
|
private getOffenseFromInvalidationReason;
|
|
30
|
-
private
|
|
31
|
+
private addInvalidCheckpoint;
|
|
31
32
|
}
|
|
32
33
|
export {};
|
|
33
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
34
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXR0ZXN0YXRpb25zX2Jsb2NrX3dhdGNoZXIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy93YXRjaGVycy9hdHRlc3RhdGlvbnNfYmxvY2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Qsc0dBQXNHO0lBQy9GLHVCQUF1QixDQUFDLEtBQUssRUFBRSw4QkFBOEIsR0FBRyxJQUFJLENBdUIxRTtJQUVELE9BQU8sQ0FBQywrQkFBK0I7SUEyQnZDLE9BQU8sQ0FBQyxhQUFhO0lBa0NyQixPQUFPLENBQUMsZ0NBQWdDO0lBYXhDLE9BQU8sQ0FBQyxvQkFBb0I7Q0FTN0IifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attestations_block_watcher.d.ts","sourceRoot":"","sources":["../../src/watchers/attestations_block_watcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIhD,OAAO,
|
|
1
|
+
{"version":3,"file":"attestations_block_watcher.d.ts","sourceRoot":"","sources":["../../src/watchers/attestations_block_watcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIhD,OAAO,EACL,KAAK,8BAA8B,EACnC,KAAK,yBAAyB,EAG/B,MAAM,qBAAqB,CAAC;AAM7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAA6C,KAAK,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAE7G,QAAA,MAAM,kCAAkC,8FAG9B,CAAC;AAEX,KAAK,8BAA8B,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC,OAAO,kCAAkC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;;AAE/G;;;;;GAKG;AACH,qBAAa,wBAAyB,SAAQ,6BAA2C,YAAW,OAAO;IAuBvG,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,UAAU;IAvBpB,OAAO,CAAC,GAAG,CAAsD;IAGjE,OAAO,CAAC,qBAAqB,CAAO;IAGpC,OAAO,CAAC,mBAAmB,CAA0B;IAErD,OAAO,CAAC,MAAM,CAAiC;IAE/C,OAAO,CAAC,4BAA4B,CASlC;IAEF,YACU,aAAa,EAAE,yBAAyB,EACxC,UAAU,EAAE,UAAU,EAC9B,MAAM,EAAE,8BAA8B,EAKvC;IAEM,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,8BAA8B,CAAC,QAGrE;IAEM,KAAK,kBAMX;IAEM,IAAI,kBAMV;IAED,sGAAsG;IAC/F,uBAAuB,CAAC,KAAK,EAAE,8BAA8B,GAAG,IAAI,CAuB1E;IAED,OAAO,CAAC,+BAA+B;IA2BvC,OAAO,CAAC,aAAa;IAkCrB,OAAO,CAAC,gCAAgC;IAaxC,OAAO,CAAC,oBAAoB;CAS7B"}
|
|
@@ -18,18 +18,18 @@ const AttestationsBlockWatcherConfigKeys = [
|
|
|
18
18
|
l2BlockSource;
|
|
19
19
|
epochCache;
|
|
20
20
|
log;
|
|
21
|
-
// Only keep track of the last N invalid
|
|
22
|
-
|
|
21
|
+
// Only keep track of the last N invalid checkpoints
|
|
22
|
+
maxInvalidCheckpoints;
|
|
23
23
|
// All invalid archive roots seen
|
|
24
24
|
invalidArchiveRoots;
|
|
25
25
|
config;
|
|
26
|
-
|
|
26
|
+
boundHandleInvalidCheckpoint;
|
|
27
27
|
constructor(l2BlockSource, epochCache, config){
|
|
28
|
-
super(), this.l2BlockSource = l2BlockSource, this.epochCache = epochCache, this.log = createLogger('attestations-block-watcher'), this.
|
|
28
|
+
super(), this.l2BlockSource = l2BlockSource, this.epochCache = epochCache, this.log = createLogger('attestations-block-watcher'), this.maxInvalidCheckpoints = 100, this.invalidArchiveRoots = new Set(), this.boundHandleInvalidCheckpoint = (event)=>{
|
|
29
29
|
try {
|
|
30
|
-
this.
|
|
30
|
+
this.handleInvalidCheckpoint(event);
|
|
31
31
|
} catch (err) {
|
|
32
|
-
this.log.error('Error handling invalid
|
|
32
|
+
this.log.error('Error handling invalid checkpoint', err, {
|
|
33
33
|
...event.validationResult,
|
|
34
34
|
reason: event.validationResult.reason
|
|
35
35
|
});
|
|
@@ -43,39 +43,39 @@ const AttestationsBlockWatcherConfigKeys = [
|
|
|
43
43
|
this.log.verbose('AttestationsBlockWatcher config updated', this.config);
|
|
44
44
|
}
|
|
45
45
|
start() {
|
|
46
|
-
this.l2BlockSource.on(L2BlockSourceEvents.
|
|
46
|
+
this.l2BlockSource.events.on(L2BlockSourceEvents.InvalidAttestationsCheckpointDetected, this.boundHandleInvalidCheckpoint);
|
|
47
47
|
return Promise.resolve();
|
|
48
48
|
}
|
|
49
49
|
stop() {
|
|
50
|
-
this.l2BlockSource.removeListener(L2BlockSourceEvents.
|
|
50
|
+
this.l2BlockSource.events.removeListener(L2BlockSourceEvents.InvalidAttestationsCheckpointDetected, this.boundHandleInvalidCheckpoint);
|
|
51
51
|
return Promise.resolve();
|
|
52
52
|
}
|
|
53
|
-
|
|
53
|
+
/** Event handler for invalid checkpoints as reported by the archiver. Public for testing purposes. */ handleInvalidCheckpoint(event) {
|
|
54
54
|
const { validationResult } = event;
|
|
55
|
-
const
|
|
56
|
-
// Check if we already have processed this
|
|
57
|
-
if (this.invalidArchiveRoots.has(
|
|
58
|
-
this.log.trace(`Already processed invalid
|
|
55
|
+
const checkpoint = validationResult.checkpoint;
|
|
56
|
+
// Check if we already have processed this checkpoint, archiver may emit the same event multiple times
|
|
57
|
+
if (this.invalidArchiveRoots.has(checkpoint.archive.toString())) {
|
|
58
|
+
this.log.trace(`Already processed invalid checkpoint ${checkpoint.checkpointNumber}`);
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
|
-
this.log.verbose(`Detected invalid
|
|
62
|
-
...
|
|
61
|
+
this.log.verbose(`Detected invalid checkpoint ${checkpoint.checkpointNumber}`, {
|
|
62
|
+
...checkpoint,
|
|
63
63
|
reason: validationResult.valid === false ? validationResult.reason : 'unknown'
|
|
64
64
|
});
|
|
65
|
-
// Store the invalid
|
|
66
|
-
this.
|
|
67
|
-
// Slash the proposer of the invalid
|
|
65
|
+
// Store the invalid checkpoint
|
|
66
|
+
this.addInvalidCheckpoint(event.validationResult.checkpoint);
|
|
67
|
+
// Slash the proposer of the invalid checkpoint
|
|
68
68
|
this.slashProposer(event.validationResult);
|
|
69
|
-
// Check if the parent of this
|
|
69
|
+
// Check if the parent of this checkpoint is invalid as well, if so, we will slash its attestors as well
|
|
70
70
|
this.slashAttestorsOnAncestorInvalid(event.validationResult);
|
|
71
71
|
}
|
|
72
72
|
slashAttestorsOnAncestorInvalid(validationResult) {
|
|
73
|
-
const
|
|
74
|
-
const parentArchive =
|
|
73
|
+
const checkpoint = validationResult.checkpoint;
|
|
74
|
+
const parentArchive = checkpoint.lastArchive.toString();
|
|
75
75
|
if (this.invalidArchiveRoots.has(parentArchive)) {
|
|
76
76
|
const attestors = validationResult.attestors;
|
|
77
|
-
this.log.info(`Want to slash attestors of
|
|
78
|
-
...
|
|
77
|
+
this.log.info(`Want to slash attestors of checkpoint ${checkpoint.checkpointNumber} built on invalid checkpoint`, {
|
|
78
|
+
...checkpoint,
|
|
79
79
|
...attestors,
|
|
80
80
|
parentArchive
|
|
81
81
|
});
|
|
@@ -83,17 +83,23 @@ const AttestationsBlockWatcherConfigKeys = [
|
|
|
83
83
|
validator: attestor,
|
|
84
84
|
amount: this.config.slashAttestDescendantOfInvalidPenalty,
|
|
85
85
|
offenseType: OffenseType.ATTESTED_DESCENDANT_OF_INVALID,
|
|
86
|
-
epochOrSlot: BigInt(SlotNumber(
|
|
86
|
+
epochOrSlot: BigInt(SlotNumber(checkpoint.slotNumber))
|
|
87
87
|
})));
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
slashProposer(validationResult) {
|
|
91
|
-
const { reason,
|
|
92
|
-
const
|
|
93
|
-
const slot =
|
|
94
|
-
const
|
|
91
|
+
const { reason, checkpoint } = validationResult;
|
|
92
|
+
const checkpointNumber = checkpoint.checkpointNumber;
|
|
93
|
+
const slot = checkpoint.slotNumber;
|
|
94
|
+
const epochCommitteeInfo = {
|
|
95
|
+
committee: validationResult.committee,
|
|
96
|
+
seed: validationResult.seed,
|
|
97
|
+
epoch: validationResult.epoch,
|
|
98
|
+
isEscapeHatchOpen: false
|
|
99
|
+
};
|
|
100
|
+
const proposer = this.epochCache.getProposerFromEpochCommittee(epochCommitteeInfo, slot);
|
|
95
101
|
if (!proposer) {
|
|
96
|
-
this.log.warn(`No proposer found for
|
|
102
|
+
this.log.warn(`No proposer found for checkpoint ${checkpointNumber} at slot ${slot}`);
|
|
97
103
|
return;
|
|
98
104
|
}
|
|
99
105
|
const offense = this.getOffenseFromInvalidationReason(reason);
|
|
@@ -104,8 +110,8 @@ const AttestationsBlockWatcherConfigKeys = [
|
|
|
104
110
|
offenseType: offense,
|
|
105
111
|
epochOrSlot: BigInt(slot)
|
|
106
112
|
};
|
|
107
|
-
this.log.info(`Want to slash proposer of
|
|
108
|
-
...
|
|
113
|
+
this.log.info(`Want to slash proposer of checkpoint ${checkpointNumber} due to ${reason}`, {
|
|
114
|
+
...checkpoint,
|
|
109
115
|
...args
|
|
110
116
|
});
|
|
111
117
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
@@ -125,10 +131,10 @@ const AttestationsBlockWatcherConfigKeys = [
|
|
|
125
131
|
}
|
|
126
132
|
}
|
|
127
133
|
}
|
|
128
|
-
|
|
129
|
-
this.invalidArchiveRoots.add(
|
|
134
|
+
addInvalidCheckpoint(checkpoint) {
|
|
135
|
+
this.invalidArchiveRoots.add(checkpoint.archive.toString());
|
|
130
136
|
// Prune old entries if we exceed the maximum
|
|
131
|
-
if (this.invalidArchiveRoots.size > this.
|
|
137
|
+
if (this.invalidArchiveRoots.size > this.maxInvalidCheckpoints) {
|
|
132
138
|
const oldestKey = this.invalidArchiveRoots.keys().next().value;
|
|
133
139
|
this.invalidArchiveRoots.delete(oldestKey);
|
|
134
140
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
2
|
+
import { EpochNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import { L2Block, type L2BlockSourceEventEmitter } from '@aztec/stdlib/block';
|
|
3
|
-
import type {
|
|
4
|
-
import type
|
|
4
|
+
import type { ICheckpointsBuilder, ITxProvider, SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
5
|
+
import { type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
5
6
|
import { type Watcher, type WatcherEmitter } from '../watcher.js';
|
|
6
7
|
declare const EpochPruneWatcherPenaltiesConfigKeys: readonly ["slashPrunePenalty", "slashDataWithholdingPenalty"];
|
|
7
8
|
type EpochPruneWatcherPenalties = Pick<SlasherConfig, (typeof EpochPruneWatcherPenaltiesConfigKeys)[number]>;
|
|
@@ -17,21 +18,22 @@ export declare class EpochPruneWatcher extends EpochPruneWatcher_base implements
|
|
|
17
18
|
private l1ToL2MessageSource;
|
|
18
19
|
private epochCache;
|
|
19
20
|
private txProvider;
|
|
20
|
-
private
|
|
21
|
+
private checkpointsBuilder;
|
|
21
22
|
private log;
|
|
22
23
|
private boundHandlePruneL2Blocks;
|
|
23
24
|
private penalties;
|
|
24
|
-
constructor(l2BlockSource: L2BlockSourceEventEmitter, l1ToL2MessageSource: L1ToL2MessageSource, epochCache: EpochCache, txProvider: Pick<ITxProvider, 'getAvailableTxs'>,
|
|
25
|
+
constructor(l2BlockSource: L2BlockSourceEventEmitter, l1ToL2MessageSource: L1ToL2MessageSource, epochCache: EpochCache, txProvider: Pick<ITxProvider, 'getAvailableTxs'>, checkpointsBuilder: ICheckpointsBuilder, penalties: EpochPruneWatcherPenalties);
|
|
25
26
|
start(): Promise<void>;
|
|
26
27
|
stop(): Promise<void>;
|
|
27
28
|
updateConfig(config: Partial<SlasherConfig>): void;
|
|
28
29
|
private handlePruneL2Blocks;
|
|
29
30
|
private emitSlashForEpoch;
|
|
30
31
|
private processPruneL2Blocks;
|
|
31
|
-
validateBlocks(blocks: L2Block[]): Promise<void>;
|
|
32
|
-
|
|
32
|
+
validateBlocks(blocks: L2Block[], epochNumber: EpochNumber): Promise<void>;
|
|
33
|
+
private validateCheckpoint;
|
|
34
|
+
private validateBlockInCheckpoint;
|
|
33
35
|
private getValidatorsForEpoch;
|
|
34
36
|
private validatorsToSlashingArgs;
|
|
35
37
|
}
|
|
36
38
|
export {};
|
|
37
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
39
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXBvY2hfcHJ1bmVfd2F0Y2hlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3dhdGNoZXJzL2Vwb2NoX3BydW5lX3dhdGNoZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLG9CQUFvQixDQUFDO0FBQ2hELE9BQU8sRUFBZSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUkzRSxPQUFPLEVBRUwsT0FBTyxFQUNQLEtBQUsseUJBQXlCLEVBRy9CLE1BQU0scUJBQXFCLENBQUM7QUFFN0IsT0FBTyxLQUFLLEVBRVYsbUJBQW1CLEVBQ25CLFdBQVcsRUFFWCxhQUFhLEVBQ2QsTUFBTSxpQ0FBaUMsQ0FBQztBQUN6QyxPQUFPLEVBQUUsS0FBSyxtQkFBbUIsRUFBNEIsTUFBTSx5QkFBeUIsQ0FBQztBQVk3RixPQUFPLEVBQTZDLEtBQUssT0FBTyxFQUFFLEtBQUssY0FBYyxFQUFFLE1BQU0sZUFBZSxDQUFDO0FBRTdHLFFBQUEsTUFBTSxvQ0FBb0MsK0RBQWdFLENBQUM7QUFFM0csS0FBSywwQkFBMEIsR0FBRyxJQUFJLENBQUMsYUFBYSxFQUFFLENBQUMsT0FBTyxvQ0FBb0MsQ0FBQyxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUM7O0FBRTdHOzs7OztHQUtHO0FBQ0gscUJBQWEsaUJBQWtCLFNBQVEsc0JBQTJDLFlBQVcsT0FBTztJQVNoRyxPQUFP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I,CAGxD;IAED,OAAO,CAAC,mBAAmB;YAOb,iBAAiB;YAWjB,oBAAoB;IAwBrB,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CA+BtF;YAEa,kBAAkB;YAwClB,yBAAyB;YAiCzB,qBAAqB;IASnC,OAAO,CAAC,wBAAwB;CAgBjC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { chunkBy, merge, pick } from '@aztec/foundation/collection';
|
|
2
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
4
|
import { L2BlockSourceEvents } from '@aztec/stdlib/block';
|
|
4
5
|
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
6
|
+
import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
|
|
5
7
|
import { OffenseType, getOffenseTypeName } from '@aztec/stdlib/slashing';
|
|
6
8
|
import { ReExFailedTxsError, ReExStateMismatchError, TransactionsNotAvailableError, ValidatorError } from '@aztec/stdlib/validators';
|
|
7
9
|
import EventEmitter from 'node:events';
|
|
@@ -20,22 +22,22 @@ const EpochPruneWatcherPenaltiesConfigKeys = [
|
|
|
20
22
|
l1ToL2MessageSource;
|
|
21
23
|
epochCache;
|
|
22
24
|
txProvider;
|
|
23
|
-
|
|
25
|
+
checkpointsBuilder;
|
|
24
26
|
log;
|
|
25
27
|
// Store bound function reference for proper listener removal
|
|
26
28
|
boundHandlePruneL2Blocks;
|
|
27
29
|
penalties;
|
|
28
|
-
constructor(l2BlockSource, l1ToL2MessageSource, epochCache, txProvider,
|
|
29
|
-
super(), this.l2BlockSource = l2BlockSource, this.l1ToL2MessageSource = l1ToL2MessageSource, this.epochCache = epochCache, this.txProvider = txProvider, this.
|
|
30
|
+
constructor(l2BlockSource, l1ToL2MessageSource, epochCache, txProvider, checkpointsBuilder, penalties){
|
|
31
|
+
super(), this.l2BlockSource = l2BlockSource, this.l1ToL2MessageSource = l1ToL2MessageSource, this.epochCache = epochCache, this.txProvider = txProvider, this.checkpointsBuilder = checkpointsBuilder, this.log = createLogger('epoch-prune-watcher'), this.boundHandlePruneL2Blocks = this.handlePruneL2Blocks.bind(this);
|
|
30
32
|
this.penalties = pick(penalties, ...EpochPruneWatcherPenaltiesConfigKeys);
|
|
31
33
|
this.log.verbose(`EpochPruneWatcher initialized with penalties: valid epoch pruned=${penalties.slashPrunePenalty} data withholding=${penalties.slashDataWithholdingPenalty}`);
|
|
32
34
|
}
|
|
33
35
|
start() {
|
|
34
|
-
this.l2BlockSource.on(L2BlockSourceEvents.
|
|
36
|
+
this.l2BlockSource.events.on(L2BlockSourceEvents.L2PruneUnproven, this.boundHandlePruneL2Blocks);
|
|
35
37
|
return Promise.resolve();
|
|
36
38
|
}
|
|
37
39
|
stop() {
|
|
38
|
-
this.l2BlockSource.removeListener(L2BlockSourceEvents.
|
|
40
|
+
this.l2BlockSource.events.removeListener(L2BlockSourceEvents.L2PruneUnproven, this.boundHandlePruneL2Blocks);
|
|
39
41
|
return Promise.resolve();
|
|
40
42
|
}
|
|
41
43
|
updateConfig(config) {
|
|
@@ -61,11 +63,11 @@ const EpochPruneWatcherPenaltiesConfigKeys = [
|
|
|
61
63
|
async processPruneL2Blocks(blocks, epochNumber) {
|
|
62
64
|
try {
|
|
63
65
|
const l1Constants = this.epochCache.getL1Constants();
|
|
64
|
-
const epochBlocks = blocks.filter((b)=>getEpochAtSlot(b.
|
|
66
|
+
const epochBlocks = blocks.filter((b)=>getEpochAtSlot(b.header.getSlot(), l1Constants) === epochNumber);
|
|
65
67
|
this.log.info(`Detected chain prune. Validating epoch ${epochNumber} with blocks ${epochBlocks[0]?.number} to ${epochBlocks[epochBlocks.length - 1]?.number}.`, {
|
|
66
68
|
blocks: epochBlocks.map((b)=>b.toBlockInfo())
|
|
67
69
|
});
|
|
68
|
-
await this.validateBlocks(epochBlocks);
|
|
70
|
+
await this.validateBlocks(epochBlocks, epochNumber);
|
|
69
71
|
this.log.info(`Pruned epoch ${epochNumber} was valid. Want to slash committee for not having it proven.`);
|
|
70
72
|
await this.emitSlashForEpoch(OffenseType.VALID_EPOCH_PRUNED, epochNumber);
|
|
71
73
|
} catch (error) {
|
|
@@ -79,20 +81,59 @@ const EpochPruneWatcherPenaltiesConfigKeys = [
|
|
|
79
81
|
}
|
|
80
82
|
}
|
|
81
83
|
}
|
|
82
|
-
async validateBlocks(blocks) {
|
|
84
|
+
async validateBlocks(blocks, epochNumber) {
|
|
83
85
|
if (blocks.length === 0) {
|
|
84
86
|
return;
|
|
85
87
|
}
|
|
86
|
-
|
|
88
|
+
// Sort blocks by block number and group by checkpoint
|
|
89
|
+
const sortedBlocks = [
|
|
90
|
+
...blocks
|
|
91
|
+
].sort((a, b)=>a.number - b.number);
|
|
92
|
+
const blocksByCheckpoint = chunkBy(sortedBlocks, (b)=>b.checkpointNumber);
|
|
93
|
+
// Get prior checkpoints in the epoch (in case this was a partial prune) to extract the out hashes
|
|
94
|
+
const priorCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(epochNumber)).filter((c)=>c.checkpointNumber < sortedBlocks[0].checkpointNumber).map((c)=>c.checkpointOutHash);
|
|
95
|
+
let previousCheckpointOutHashes = [
|
|
96
|
+
...priorCheckpointOutHashes
|
|
97
|
+
];
|
|
98
|
+
const fork = await this.checkpointsBuilder.getFork(BlockNumber(sortedBlocks[0].header.globalVariables.blockNumber - 1));
|
|
87
99
|
try {
|
|
88
|
-
for (const
|
|
89
|
-
await this.
|
|
100
|
+
for (const checkpointBlocks of blocksByCheckpoint){
|
|
101
|
+
await this.validateCheckpoint(checkpointBlocks, previousCheckpointOutHashes, fork);
|
|
102
|
+
// Compute checkpoint out hash from all blocks in this checkpoint
|
|
103
|
+
const checkpointOutHash = computeCheckpointOutHash(checkpointBlocks.map((b)=>b.body.txEffects.map((tx)=>tx.l2ToL1Msgs)));
|
|
104
|
+
previousCheckpointOutHashes = [
|
|
105
|
+
...previousCheckpointOutHashes,
|
|
106
|
+
checkpointOutHash
|
|
107
|
+
];
|
|
90
108
|
}
|
|
91
109
|
} finally{
|
|
92
110
|
await fork.close();
|
|
93
111
|
}
|
|
94
112
|
}
|
|
95
|
-
async
|
|
113
|
+
async validateCheckpoint(checkpointBlocks, previousCheckpointOutHashes, fork) {
|
|
114
|
+
const checkpointNumber = checkpointBlocks[0].checkpointNumber;
|
|
115
|
+
this.log.debug(`Validating pruned checkpoint ${checkpointNumber} with ${checkpointBlocks.length} blocks`);
|
|
116
|
+
// Get L1ToL2Messages once for the entire checkpoint
|
|
117
|
+
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
118
|
+
// Build checkpoint constants from first block's global variables
|
|
119
|
+
const gv = checkpointBlocks[0].header.globalVariables;
|
|
120
|
+
const constants = {
|
|
121
|
+
chainId: gv.chainId,
|
|
122
|
+
version: gv.version,
|
|
123
|
+
slotNumber: gv.slotNumber,
|
|
124
|
+
timestamp: gv.timestamp,
|
|
125
|
+
coinbase: gv.coinbase,
|
|
126
|
+
feeRecipient: gv.feeRecipient,
|
|
127
|
+
gasFees: gv.gasFees
|
|
128
|
+
};
|
|
129
|
+
// Start checkpoint builder once for all blocks in this checkpoint
|
|
130
|
+
const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(checkpointNumber, constants, 0n, l1ToL2Messages, previousCheckpointOutHashes, fork, this.log.getBindings());
|
|
131
|
+
// Validate all blocks in the checkpoint sequentially
|
|
132
|
+
for (const block of checkpointBlocks){
|
|
133
|
+
await this.validateBlockInCheckpoint(block, checkpointBuilder);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
async validateBlockInCheckpoint(blockFromL1, checkpointBuilder) {
|
|
96
137
|
this.log.debug(`Validating pruned block ${blockFromL1.header.globalVariables.blockNumber}`);
|
|
97
138
|
const txHashes = blockFromL1.body.txEffects.map((txEffect)=>txEffect.txHash);
|
|
98
139
|
// We load txs from the mempool directly, since the TxCollector running in the background has already been
|
|
@@ -102,8 +143,11 @@ const EpochPruneWatcherPenaltiesConfigKeys = [
|
|
|
102
143
|
if (missingTxs && missingTxs.length > 0) {
|
|
103
144
|
throw new TransactionsNotAvailableError(missingTxs);
|
|
104
145
|
}
|
|
105
|
-
const
|
|
106
|
-
const { block, failedTxs, numTxs } = await
|
|
146
|
+
const gv = blockFromL1.header.globalVariables;
|
|
147
|
+
const { block, failedTxs, numTxs } = await checkpointBuilder.buildBlock(txs, gv.blockNumber, gv.timestamp, {
|
|
148
|
+
isBuildingProposal: false,
|
|
149
|
+
minValidTxs: 0
|
|
150
|
+
});
|
|
107
151
|
if (numTxs !== txs.length) {
|
|
108
152
|
// This should be detected by state mismatch, but this makes it easier to debug.
|
|
109
153
|
throw new ValidatorError(`Built block with ${numTxs} txs, expected ${txs.length}`);
|
package/package.json
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/slasher",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.9badcec54",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
7
7
|
"./config": "./dest/config.js"
|
|
8
8
|
},
|
|
9
9
|
"inherits": [
|
|
10
|
-
"../package.common.json"
|
|
10
|
+
"../package.common.json",
|
|
11
|
+
"./package.local.json"
|
|
11
12
|
],
|
|
12
13
|
"scripts": {
|
|
13
|
-
"build": "yarn clean &&
|
|
14
|
-
"build:dev": "
|
|
14
|
+
"build": "yarn clean && ../scripts/tsc.sh",
|
|
15
|
+
"build:dev": "../scripts/tsc.sh --watch",
|
|
15
16
|
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
16
17
|
"bb": "node --no-warnings ./dest/bb/index.js",
|
|
17
|
-
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
18
|
+
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}",
|
|
19
|
+
"generate": "./scripts/generate.sh"
|
|
18
20
|
},
|
|
19
21
|
"jest": {
|
|
20
22
|
"moduleNameMapper": {
|
|
@@ -54,25 +56,25 @@
|
|
|
54
56
|
]
|
|
55
57
|
},
|
|
56
58
|
"dependencies": {
|
|
57
|
-
"@aztec/epoch-cache": "0.0.1-commit.
|
|
58
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
59
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
60
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
61
|
-
"@aztec/l1-artifacts": "0.0.1-commit.
|
|
62
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
63
|
-
"@aztec/telemetry-client": "0.0.1-commit.
|
|
59
|
+
"@aztec/epoch-cache": "0.0.1-commit.9badcec54",
|
|
60
|
+
"@aztec/ethereum": "0.0.1-commit.9badcec54",
|
|
61
|
+
"@aztec/foundation": "0.0.1-commit.9badcec54",
|
|
62
|
+
"@aztec/kv-store": "0.0.1-commit.9badcec54",
|
|
63
|
+
"@aztec/l1-artifacts": "0.0.1-commit.9badcec54",
|
|
64
|
+
"@aztec/stdlib": "0.0.1-commit.9badcec54",
|
|
65
|
+
"@aztec/telemetry-client": "0.0.1-commit.9badcec54",
|
|
64
66
|
"source-map-support": "^0.5.21",
|
|
65
67
|
"tslib": "^2.4.0",
|
|
66
68
|
"viem": "npm:@aztec/viem@2.38.2",
|
|
67
69
|
"zod": "^3.23.8"
|
|
68
70
|
},
|
|
69
71
|
"devDependencies": {
|
|
70
|
-
"@aztec/aztec.js": "0.0.1-commit.
|
|
72
|
+
"@aztec/aztec.js": "0.0.1-commit.9badcec54",
|
|
71
73
|
"@jest/globals": "^30.0.0",
|
|
72
74
|
"@types/jest": "^30.0.0",
|
|
73
75
|
"@types/node": "^22.15.17",
|
|
74
76
|
"@types/source-map-support": "^0.5.10",
|
|
75
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
77
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
76
78
|
"jest": "^30.0.0",
|
|
77
79
|
"jest-mock-extended": "^4.0.0",
|
|
78
80
|
"ts-node": "^10.9.1",
|