@aztec/slasher 0.0.1-commit.fce3e4f → 0.0.1-commit.ff7989d6c
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 +23 -13
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +28 -16
- package/dest/empire_slasher_client.d.ts +2 -2
- package/dest/empire_slasher_client.d.ts.map +1 -1
- package/dest/empire_slasher_client.js +0 -8
- package/dest/factory/create_facade.d.ts +3 -2
- package/dest/factory/create_facade.d.ts.map +1 -1
- package/dest/factory/create_facade.js +1 -1
- package/dest/factory/create_implementation.d.ts +2 -2
- package/dest/factory/create_implementation.d.ts.map +1 -1
- package/dest/factory/get_settings.d.ts +2 -2
- package/dest/factory/get_settings.d.ts.map +1 -1
- package/dest/generated/slasher-defaults.d.ts +21 -0
- package/dest/generated/slasher-defaults.d.ts.map +1 -0
- package/dest/generated/slasher-defaults.js +21 -0
- package/dest/slasher_client_facade.d.ts +2 -2
- package/dest/slasher_client_facade.d.ts.map +1 -1
- package/dest/stores/offenses_store.d.ts +1 -1
- package/dest/stores/offenses_store.d.ts.map +1 -1
- package/dest/stores/offenses_store.js +4 -2
- package/dest/stores/payloads_store.d.ts +1 -1
- package/dest/stores/payloads_store.d.ts.map +1 -1
- package/dest/stores/payloads_store.js +6 -3
- package/dest/tally_slasher_client.d.ts +1 -1
- package/dest/tally_slasher_client.d.ts.map +1 -1
- package/dest/tally_slasher_client.js +10 -5
- 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 +56 -15
- package/package.json +16 -14
- package/src/config.ts +30 -16
- package/src/empire_slasher_client.ts +1 -9
- package/src/factory/create_facade.ts +3 -2
- package/src/factory/create_implementation.ts +1 -1
- package/src/factory/get_settings.ts +1 -1
- package/src/generated/slasher-defaults.ts +23 -0
- package/src/slasher_client_facade.ts +1 -1
- package/src/stores/offenses_store.ts +4 -2
- package/src/stores/payloads_store.ts +7 -4
- package/src/tally_slasher_client.ts +10 -5
- package/src/watcher.ts +1 -1
- package/src/watchers/attestations_block_watcher.ts +57 -44
- package/src/watchers/epoch_prune_watcher.ts +84 -24
|
@@ -5,7 +5,6 @@ import { maxBigint } from '@aztec/foundation/bigint';
|
|
|
5
5
|
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
6
6
|
import { compactArray, partition, times } from '@aztec/foundation/collection';
|
|
7
7
|
import { createLogger } from '@aztec/foundation/log';
|
|
8
|
-
import { sleep } from '@aztec/foundation/sleep';
|
|
9
8
|
import type { DateProvider } from '@aztec/foundation/timer';
|
|
10
9
|
import type { Prettify } from '@aztec/foundation/types';
|
|
11
10
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
@@ -138,8 +137,6 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
138
137
|
this.roundMonitor.stop();
|
|
139
138
|
await this.offensesCollector.stop();
|
|
140
139
|
|
|
141
|
-
// Sleeping to sidestep viem issue with unwatching events
|
|
142
|
-
await sleep(2000);
|
|
143
140
|
this.log.info('Tally Slasher client stopped');
|
|
144
141
|
}
|
|
145
142
|
|
|
@@ -281,8 +278,12 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
281
278
|
return undefined;
|
|
282
279
|
}
|
|
283
280
|
|
|
281
|
+
const slashActionsWithAmounts = slashActions.map(action => ({
|
|
282
|
+
validator: action.validator.toString(),
|
|
283
|
+
slashAmount: action.slashAmount.toString(),
|
|
284
|
+
}));
|
|
284
285
|
this.log.info(`Round ${executableRound} is ready to execute with ${slashActions.length} slashes`, {
|
|
285
|
-
slashActions,
|
|
286
|
+
slashActions: slashActionsWithAmounts,
|
|
286
287
|
payloadAddress: payload.address.toString(),
|
|
287
288
|
...logData,
|
|
288
289
|
});
|
|
@@ -348,11 +349,15 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
348
349
|
return undefined;
|
|
349
350
|
}
|
|
350
351
|
|
|
352
|
+
const offensesToSlashLog = offensesToSlash.map(offense => ({
|
|
353
|
+
...offense,
|
|
354
|
+
amount: offense.amount.toString(),
|
|
355
|
+
}));
|
|
351
356
|
this.log.info(`Voting to slash ${offensesToSlash.length} offenses`, {
|
|
352
357
|
slotNumber,
|
|
353
358
|
currentRound,
|
|
354
359
|
slashedRound,
|
|
355
|
-
offensesToSlash,
|
|
360
|
+
offensesToSlash: offensesToSlashLog,
|
|
356
361
|
});
|
|
357
362
|
|
|
358
363
|
const committees = await this.collectCommitteesActiveDuringRound(slashedRound);
|
package/src/watcher.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface WantToSlashArgs {
|
|
|
10
10
|
validator: EthAddress;
|
|
11
11
|
amount: bigint;
|
|
12
12
|
offenseType: OffenseType;
|
|
13
|
-
epochOrSlot: bigint; // Epoch number for epoch-based offenses,
|
|
13
|
+
epochOrSlot: bigint; // Epoch number for epoch-based offenses, slot number for slot-based
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
// Event map for specific, known events of a watcher
|
|
@@ -3,12 +3,12 @@ import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
|
3
3
|
import { merge, pick } from '@aztec/foundation/collection';
|
|
4
4
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
5
5
|
import {
|
|
6
|
-
type
|
|
7
|
-
type L2BlockInfo,
|
|
6
|
+
type InvalidCheckpointDetectedEvent,
|
|
8
7
|
type L2BlockSourceEventEmitter,
|
|
9
8
|
L2BlockSourceEvents,
|
|
10
|
-
type
|
|
9
|
+
type ValidateCheckpointNegativeResult,
|
|
11
10
|
} from '@aztec/stdlib/block';
|
|
11
|
+
import type { CheckpointInfo } from '@aztec/stdlib/checkpoint';
|
|
12
12
|
import { OffenseType } from '@aztec/stdlib/slashing';
|
|
13
13
|
|
|
14
14
|
import EventEmitter from 'node:events';
|
|
@@ -32,19 +32,19 @@ type AttestationsBlockWatcherConfig = Pick<SlasherConfig, (typeof AttestationsBl
|
|
|
32
32
|
export class AttestationsBlockWatcher extends (EventEmitter as new () => WatcherEmitter) implements Watcher {
|
|
33
33
|
private log: Logger = createLogger('attestations-block-watcher');
|
|
34
34
|
|
|
35
|
-
// Only keep track of the last N invalid
|
|
36
|
-
private
|
|
35
|
+
// Only keep track of the last N invalid checkpoints
|
|
36
|
+
private maxInvalidCheckpoints = 100;
|
|
37
37
|
|
|
38
38
|
// All invalid archive roots seen
|
|
39
39
|
private invalidArchiveRoots: Set<string> = new Set();
|
|
40
40
|
|
|
41
41
|
private config: AttestationsBlockWatcherConfig;
|
|
42
42
|
|
|
43
|
-
private
|
|
43
|
+
private boundHandleInvalidCheckpoint = (event: InvalidCheckpointDetectedEvent) => {
|
|
44
44
|
try {
|
|
45
|
-
this.
|
|
45
|
+
this.handleInvalidCheckpoint(event);
|
|
46
46
|
} catch (err) {
|
|
47
|
-
this.log.error('Error handling invalid
|
|
47
|
+
this.log.error('Error handling invalid checkpoint', err, {
|
|
48
48
|
...event.validationResult,
|
|
49
49
|
reason: event.validationResult.reason,
|
|
50
50
|
});
|
|
@@ -67,54 +67,61 @@ export class AttestationsBlockWatcher extends (EventEmitter as new () => Watcher
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
public start() {
|
|
70
|
-
this.l2BlockSource.on(
|
|
70
|
+
this.l2BlockSource.events.on(
|
|
71
|
+
L2BlockSourceEvents.InvalidAttestationsCheckpointDetected,
|
|
72
|
+
this.boundHandleInvalidCheckpoint,
|
|
73
|
+
);
|
|
71
74
|
return Promise.resolve();
|
|
72
75
|
}
|
|
73
76
|
|
|
74
77
|
public stop() {
|
|
75
|
-
this.l2BlockSource.removeListener(
|
|
76
|
-
L2BlockSourceEvents.
|
|
77
|
-
this.
|
|
78
|
+
this.l2BlockSource.events.removeListener(
|
|
79
|
+
L2BlockSourceEvents.InvalidAttestationsCheckpointDetected,
|
|
80
|
+
this.boundHandleInvalidCheckpoint,
|
|
78
81
|
);
|
|
79
82
|
return Promise.resolve();
|
|
80
83
|
}
|
|
81
84
|
|
|
82
|
-
|
|
85
|
+
/** Event handler for invalid checkpoints as reported by the archiver. Public for testing purposes. */
|
|
86
|
+
public handleInvalidCheckpoint(event: InvalidCheckpointDetectedEvent): void {
|
|
83
87
|
const { validationResult } = event;
|
|
84
|
-
const
|
|
88
|
+
const checkpoint = validationResult.checkpoint;
|
|
85
89
|
|
|
86
|
-
// Check if we already have processed this
|
|
87
|
-
if (this.invalidArchiveRoots.has(
|
|
88
|
-
this.log.trace(`Already processed invalid
|
|
90
|
+
// Check if we already have processed this checkpoint, archiver may emit the same event multiple times
|
|
91
|
+
if (this.invalidArchiveRoots.has(checkpoint.archive.toString())) {
|
|
92
|
+
this.log.trace(`Already processed invalid checkpoint ${checkpoint.checkpointNumber}`);
|
|
89
93
|
return;
|
|
90
94
|
}
|
|
91
95
|
|
|
92
|
-
this.log.verbose(`Detected invalid
|
|
93
|
-
...
|
|
96
|
+
this.log.verbose(`Detected invalid checkpoint ${checkpoint.checkpointNumber}`, {
|
|
97
|
+
...checkpoint,
|
|
94
98
|
reason: validationResult.valid === false ? validationResult.reason : 'unknown',
|
|
95
99
|
});
|
|
96
100
|
|
|
97
|
-
// Store the invalid
|
|
98
|
-
this.
|
|
101
|
+
// Store the invalid checkpoint
|
|
102
|
+
this.addInvalidCheckpoint(event.validationResult.checkpoint);
|
|
99
103
|
|
|
100
|
-
// Slash the proposer of the invalid
|
|
104
|
+
// Slash the proposer of the invalid checkpoint
|
|
101
105
|
this.slashProposer(event.validationResult);
|
|
102
106
|
|
|
103
|
-
// Check if the parent of this
|
|
107
|
+
// Check if the parent of this checkpoint is invalid as well, if so, we will slash its attestors as well
|
|
104
108
|
this.slashAttestorsOnAncestorInvalid(event.validationResult);
|
|
105
109
|
}
|
|
106
110
|
|
|
107
|
-
private slashAttestorsOnAncestorInvalid(validationResult:
|
|
108
|
-
const
|
|
111
|
+
private slashAttestorsOnAncestorInvalid(validationResult: ValidateCheckpointNegativeResult) {
|
|
112
|
+
const checkpoint = validationResult.checkpoint;
|
|
109
113
|
|
|
110
|
-
const parentArchive =
|
|
114
|
+
const parentArchive = checkpoint.lastArchive.toString();
|
|
111
115
|
if (this.invalidArchiveRoots.has(parentArchive)) {
|
|
112
116
|
const attestors = validationResult.attestors;
|
|
113
|
-
this.log.info(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
this.log.info(
|
|
118
|
+
`Want to slash attestors of checkpoint ${checkpoint.checkpointNumber} built on invalid checkpoint`,
|
|
119
|
+
{
|
|
120
|
+
...checkpoint,
|
|
121
|
+
...attestors,
|
|
122
|
+
parentArchive,
|
|
123
|
+
},
|
|
124
|
+
);
|
|
118
125
|
|
|
119
126
|
this.emit(
|
|
120
127
|
WANT_TO_SLASH_EVENT,
|
|
@@ -122,20 +129,26 @@ export class AttestationsBlockWatcher extends (EventEmitter as new () => Watcher
|
|
|
122
129
|
validator: attestor,
|
|
123
130
|
amount: this.config.slashAttestDescendantOfInvalidPenalty,
|
|
124
131
|
offenseType: OffenseType.ATTESTED_DESCENDANT_OF_INVALID,
|
|
125
|
-
epochOrSlot: BigInt(SlotNumber(
|
|
132
|
+
epochOrSlot: BigInt(SlotNumber(checkpoint.slotNumber)),
|
|
126
133
|
})),
|
|
127
134
|
);
|
|
128
135
|
}
|
|
129
136
|
}
|
|
130
137
|
|
|
131
|
-
private slashProposer(validationResult:
|
|
132
|
-
const { reason,
|
|
133
|
-
const
|
|
134
|
-
const slot =
|
|
135
|
-
const
|
|
138
|
+
private slashProposer(validationResult: ValidateCheckpointNegativeResult) {
|
|
139
|
+
const { reason, checkpoint } = validationResult;
|
|
140
|
+
const checkpointNumber = checkpoint.checkpointNumber;
|
|
141
|
+
const slot = checkpoint.slotNumber;
|
|
142
|
+
const epochCommitteeInfo = {
|
|
143
|
+
committee: validationResult.committee,
|
|
144
|
+
seed: validationResult.seed,
|
|
145
|
+
epoch: validationResult.epoch,
|
|
146
|
+
isEscapeHatchOpen: false,
|
|
147
|
+
};
|
|
148
|
+
const proposer = this.epochCache.getProposerFromEpochCommittee(epochCommitteeInfo, slot);
|
|
136
149
|
|
|
137
150
|
if (!proposer) {
|
|
138
|
-
this.log.warn(`No proposer found for
|
|
151
|
+
this.log.warn(`No proposer found for checkpoint ${checkpointNumber} at slot ${slot}`);
|
|
139
152
|
return;
|
|
140
153
|
}
|
|
141
154
|
|
|
@@ -148,15 +161,15 @@ export class AttestationsBlockWatcher extends (EventEmitter as new () => Watcher
|
|
|
148
161
|
epochOrSlot: BigInt(slot),
|
|
149
162
|
};
|
|
150
163
|
|
|
151
|
-
this.log.info(`Want to slash proposer of
|
|
152
|
-
...
|
|
164
|
+
this.log.info(`Want to slash proposer of checkpoint ${checkpointNumber} due to ${reason}`, {
|
|
165
|
+
...checkpoint,
|
|
153
166
|
...args,
|
|
154
167
|
});
|
|
155
168
|
|
|
156
169
|
this.emit(WANT_TO_SLASH_EVENT, [args]);
|
|
157
170
|
}
|
|
158
171
|
|
|
159
|
-
private getOffenseFromInvalidationReason(reason:
|
|
172
|
+
private getOffenseFromInvalidationReason(reason: ValidateCheckpointNegativeResult['reason']): OffenseType {
|
|
160
173
|
switch (reason) {
|
|
161
174
|
case 'invalid-attestation':
|
|
162
175
|
return OffenseType.PROPOSED_INCORRECT_ATTESTATIONS;
|
|
@@ -169,11 +182,11 @@ export class AttestationsBlockWatcher extends (EventEmitter as new () => Watcher
|
|
|
169
182
|
}
|
|
170
183
|
}
|
|
171
184
|
|
|
172
|
-
private
|
|
173
|
-
this.invalidArchiveRoots.add(
|
|
185
|
+
private addInvalidCheckpoint(checkpoint: CheckpointInfo) {
|
|
186
|
+
this.invalidArchiveRoots.add(checkpoint.archive.toString());
|
|
174
187
|
|
|
175
188
|
// Prune old entries if we exceed the maximum
|
|
176
|
-
if (this.invalidArchiveRoots.size > this.
|
|
189
|
+
if (this.invalidArchiveRoots.size > this.maxInvalidCheckpoints) {
|
|
177
190
|
const oldestKey = this.invalidArchiveRoots.keys().next().value!;
|
|
178
191
|
this.invalidArchiveRoots.delete(oldestKey);
|
|
179
192
|
}
|
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
2
|
-
import { EpochNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
import { merge, pick } from '@aztec/foundation/collection';
|
|
2
|
+
import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { chunkBy, merge, pick } from '@aztec/foundation/collection';
|
|
4
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
5
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
5
6
|
import {
|
|
6
7
|
EthAddress,
|
|
7
8
|
L2Block,
|
|
8
|
-
type L2BlockPruneEvent,
|
|
9
9
|
type L2BlockSourceEventEmitter,
|
|
10
10
|
L2BlockSourceEvents,
|
|
11
|
+
type L2PruneUnprovenEvent,
|
|
11
12
|
} from '@aztec/stdlib/block';
|
|
12
13
|
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
13
14
|
import type {
|
|
14
|
-
|
|
15
|
+
ICheckpointBlockBuilder,
|
|
16
|
+
ICheckpointsBuilder,
|
|
15
17
|
ITxProvider,
|
|
16
18
|
MerkleTreeWriteOperations,
|
|
17
19
|
SlasherConfig,
|
|
18
20
|
} from '@aztec/stdlib/interfaces/server';
|
|
19
|
-
import type
|
|
21
|
+
import { type L1ToL2MessageSource, computeCheckpointOutHash } from '@aztec/stdlib/messaging';
|
|
20
22
|
import { OffenseType, getOffenseTypeName } from '@aztec/stdlib/slashing';
|
|
23
|
+
import type { CheckpointGlobalVariables } from '@aztec/stdlib/tx';
|
|
21
24
|
import {
|
|
22
25
|
ReExFailedTxsError,
|
|
23
26
|
ReExStateMismatchError,
|
|
@@ -52,7 +55,7 @@ export class EpochPruneWatcher extends (EventEmitter as new () => WatcherEmitter
|
|
|
52
55
|
private l1ToL2MessageSource: L1ToL2MessageSource,
|
|
53
56
|
private epochCache: EpochCache,
|
|
54
57
|
private txProvider: Pick<ITxProvider, 'getAvailableTxs'>,
|
|
55
|
-
private
|
|
58
|
+
private checkpointsBuilder: ICheckpointsBuilder,
|
|
56
59
|
penalties: EpochPruneWatcherPenalties,
|
|
57
60
|
) {
|
|
58
61
|
super();
|
|
@@ -63,12 +66,12 @@ export class EpochPruneWatcher extends (EventEmitter as new () => WatcherEmitter
|
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
public start() {
|
|
66
|
-
this.l2BlockSource.on(L2BlockSourceEvents.
|
|
69
|
+
this.l2BlockSource.events.on(L2BlockSourceEvents.L2PruneUnproven, this.boundHandlePruneL2Blocks);
|
|
67
70
|
return Promise.resolve();
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
public stop() {
|
|
71
|
-
this.l2BlockSource.removeListener(L2BlockSourceEvents.
|
|
74
|
+
this.l2BlockSource.events.removeListener(L2BlockSourceEvents.L2PruneUnproven, this.boundHandlePruneL2Blocks);
|
|
72
75
|
return Promise.resolve();
|
|
73
76
|
}
|
|
74
77
|
|
|
@@ -77,7 +80,7 @@ export class EpochPruneWatcher extends (EventEmitter as new () => WatcherEmitter
|
|
|
77
80
|
this.log.verbose('EpochPruneWatcher config updated', this.penalties);
|
|
78
81
|
}
|
|
79
82
|
|
|
80
|
-
private handlePruneL2Blocks(event:
|
|
83
|
+
private handlePruneL2Blocks(event: L2PruneUnprovenEvent): void {
|
|
81
84
|
const { blocks, epochNumber } = event;
|
|
82
85
|
void this.processPruneL2Blocks(blocks, epochNumber).catch(err =>
|
|
83
86
|
this.log.error('Error processing pruned L2 blocks', err, { epochNumber }),
|
|
@@ -98,13 +101,13 @@ export class EpochPruneWatcher extends (EventEmitter as new () => WatcherEmitter
|
|
|
98
101
|
private async processPruneL2Blocks(blocks: L2Block[], epochNumber: EpochNumber): Promise<void> {
|
|
99
102
|
try {
|
|
100
103
|
const l1Constants = this.epochCache.getL1Constants();
|
|
101
|
-
const epochBlocks = blocks.filter(b => getEpochAtSlot(b.
|
|
104
|
+
const epochBlocks = blocks.filter(b => getEpochAtSlot(b.header.getSlot(), l1Constants) === epochNumber);
|
|
102
105
|
this.log.info(
|
|
103
106
|
`Detected chain prune. Validating epoch ${epochNumber} with blocks ${epochBlocks[0]?.number} to ${epochBlocks[epochBlocks.length - 1]?.number}.`,
|
|
104
107
|
{ blocks: epochBlocks.map(b => b.toBlockInfo()) },
|
|
105
108
|
);
|
|
106
109
|
|
|
107
|
-
await this.validateBlocks(epochBlocks);
|
|
110
|
+
await this.validateBlocks(epochBlocks, epochNumber);
|
|
108
111
|
this.log.info(`Pruned epoch ${epochNumber} was valid. Want to slash committee for not having it proven.`);
|
|
109
112
|
await this.emitSlashForEpoch(OffenseType.VALID_EPOCH_PRUNED, epochNumber);
|
|
110
113
|
} catch (error) {
|
|
@@ -119,21 +122,83 @@ export class EpochPruneWatcher extends (EventEmitter as new () => WatcherEmitter
|
|
|
119
122
|
}
|
|
120
123
|
}
|
|
121
124
|
|
|
122
|
-
public async validateBlocks(blocks: L2Block[]): Promise<void> {
|
|
125
|
+
public async validateBlocks(blocks: L2Block[], epochNumber: EpochNumber): Promise<void> {
|
|
123
126
|
if (blocks.length === 0) {
|
|
124
127
|
return;
|
|
125
128
|
}
|
|
126
|
-
|
|
129
|
+
|
|
130
|
+
// Sort blocks by block number and group by checkpoint
|
|
131
|
+
const sortedBlocks = [...blocks].sort((a, b) => a.number - b.number);
|
|
132
|
+
const blocksByCheckpoint = chunkBy(sortedBlocks, b => b.checkpointNumber);
|
|
133
|
+
|
|
134
|
+
// Get prior checkpoints in the epoch (in case this was a partial prune) to extract the out hashes
|
|
135
|
+
const priorCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(epochNumber))
|
|
136
|
+
.filter(c => c.checkpointNumber < sortedBlocks[0].checkpointNumber)
|
|
137
|
+
.map(c => c.checkpointOutHash);
|
|
138
|
+
let previousCheckpointOutHashes: Fr[] = [...priorCheckpointOutHashes];
|
|
139
|
+
|
|
140
|
+
const fork = await this.checkpointsBuilder.getFork(
|
|
141
|
+
BlockNumber(sortedBlocks[0].header.globalVariables.blockNumber - 1),
|
|
142
|
+
);
|
|
127
143
|
try {
|
|
128
|
-
for (const
|
|
129
|
-
await this.
|
|
144
|
+
for (const checkpointBlocks of blocksByCheckpoint) {
|
|
145
|
+
await this.validateCheckpoint(checkpointBlocks, previousCheckpointOutHashes, fork);
|
|
146
|
+
|
|
147
|
+
// Compute checkpoint out hash from all blocks in this checkpoint
|
|
148
|
+
const checkpointOutHash = computeCheckpointOutHash(
|
|
149
|
+
checkpointBlocks.map(b => b.body.txEffects.map(tx => tx.l2ToL1Msgs)),
|
|
150
|
+
);
|
|
151
|
+
previousCheckpointOutHashes = [...previousCheckpointOutHashes, checkpointOutHash];
|
|
130
152
|
}
|
|
131
153
|
} finally {
|
|
132
154
|
await fork.close();
|
|
133
155
|
}
|
|
134
156
|
}
|
|
135
157
|
|
|
136
|
-
|
|
158
|
+
private async validateCheckpoint(
|
|
159
|
+
checkpointBlocks: L2Block[],
|
|
160
|
+
previousCheckpointOutHashes: Fr[],
|
|
161
|
+
fork: MerkleTreeWriteOperations,
|
|
162
|
+
): Promise<void> {
|
|
163
|
+
const checkpointNumber = checkpointBlocks[0].checkpointNumber;
|
|
164
|
+
this.log.debug(`Validating pruned checkpoint ${checkpointNumber} with ${checkpointBlocks.length} blocks`);
|
|
165
|
+
|
|
166
|
+
// Get L1ToL2Messages once for the entire checkpoint
|
|
167
|
+
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
168
|
+
|
|
169
|
+
// Build checkpoint constants from first block's global variables
|
|
170
|
+
const gv = checkpointBlocks[0].header.globalVariables;
|
|
171
|
+
const constants: CheckpointGlobalVariables = {
|
|
172
|
+
chainId: gv.chainId,
|
|
173
|
+
version: gv.version,
|
|
174
|
+
slotNumber: gv.slotNumber,
|
|
175
|
+
timestamp: gv.timestamp,
|
|
176
|
+
coinbase: gv.coinbase,
|
|
177
|
+
feeRecipient: gv.feeRecipient,
|
|
178
|
+
gasFees: gv.gasFees,
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// Start checkpoint builder once for all blocks in this checkpoint
|
|
182
|
+
const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(
|
|
183
|
+
checkpointNumber,
|
|
184
|
+
constants,
|
|
185
|
+
0n, // feeAssetPriceModifier is not used for validation of the checkpoint content
|
|
186
|
+
l1ToL2Messages,
|
|
187
|
+
previousCheckpointOutHashes,
|
|
188
|
+
fork,
|
|
189
|
+
this.log.getBindings(),
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
// Validate all blocks in the checkpoint sequentially
|
|
193
|
+
for (const block of checkpointBlocks) {
|
|
194
|
+
await this.validateBlockInCheckpoint(block, checkpointBuilder);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
private async validateBlockInCheckpoint(
|
|
199
|
+
blockFromL1: L2Block,
|
|
200
|
+
checkpointBuilder: ICheckpointBlockBuilder,
|
|
201
|
+
): Promise<void> {
|
|
137
202
|
this.log.debug(`Validating pruned block ${blockFromL1.header.globalVariables.blockNumber}`);
|
|
138
203
|
const txHashes = blockFromL1.body.txEffects.map(txEffect => txEffect.txHash);
|
|
139
204
|
// We load txs from the mempool directly, since the TxCollector running in the background has already been
|
|
@@ -145,14 +210,9 @@ export class EpochPruneWatcher extends (EventEmitter as new () => WatcherEmitter
|
|
|
145
210
|
throw new TransactionsNotAvailableError(missingTxs);
|
|
146
211
|
}
|
|
147
212
|
|
|
148
|
-
const
|
|
149
|
-
const { block, failedTxs, numTxs } = await
|
|
150
|
-
|
|
151
|
-
l1ToL2Messages,
|
|
152
|
-
blockFromL1.header.globalVariables,
|
|
153
|
-
{},
|
|
154
|
-
fork,
|
|
155
|
-
);
|
|
213
|
+
const gv = blockFromL1.header.globalVariables;
|
|
214
|
+
const { block, failedTxs, numTxs } = await checkpointBuilder.buildBlock(txs, gv.blockNumber, gv.timestamp, {});
|
|
215
|
+
|
|
156
216
|
if (numTxs !== txs.length) {
|
|
157
217
|
// This should be detected by state mismatch, but this makes it easier to debug.
|
|
158
218
|
throw new ValidatorError(`Built block with ${numTxs} txs, expected ${txs.length}`);
|