@aztec/prover-node 5.0.0-private.20260319 → 5.0.0-rc.1
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 +506 -0
- package/dest/actions/download-epoch-proving-job.js +1 -1
- package/dest/actions/rerun-epoch-proving-job.d.ts +4 -3
- package/dest/actions/rerun-epoch-proving-job.d.ts.map +1 -1
- package/dest/actions/rerun-epoch-proving-job.js +103 -21
- package/dest/bin/run-failed-epoch.js +1 -3
- package/dest/checkpoint-store.d.ts +83 -0
- package/dest/checkpoint-store.d.ts.map +1 -0
- package/dest/checkpoint-store.js +181 -0
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +1 -1
- package/dest/factory.d.ts +1 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +22 -8
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/job/checkpoint-prover.d.ts +134 -0
- package/dest/job/checkpoint-prover.d.ts.map +1 -0
- package/dest/job/checkpoint-prover.js +350 -0
- package/dest/job/epoch-session.d.ts +146 -0
- package/dest/job/epoch-session.d.ts.map +1 -0
- package/dest/job/epoch-session.js +709 -0
- package/dest/job/top-tree-job.d.ts +82 -0
- package/dest/job/top-tree-job.d.ts.map +1 -0
- package/dest/job/top-tree-job.js +152 -0
- package/dest/metrics.d.ts +29 -5
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +73 -9
- package/dest/monitors/epoch-monitor.js +6 -2
- package/dest/proof-publishing-service.d.ts +159 -0
- package/dest/proof-publishing-service.d.ts.map +1 -0
- package/dest/proof-publishing-service.js +334 -0
- package/dest/prover-node-publisher.d.ts +18 -11
- package/dest/prover-node-publisher.d.ts.map +1 -1
- package/dest/prover-node-publisher.js +195 -57
- package/dest/prover-node.d.ts +96 -68
- package/dest/prover-node.d.ts.map +1 -1
- package/dest/prover-node.js +382 -227
- package/dest/prover-publisher-factory.d.ts +2 -2
- package/dest/prover-publisher-factory.d.ts.map +1 -1
- package/dest/prover-publisher-factory.js +3 -3
- package/dest/session-manager.d.ts +158 -0
- package/dest/session-manager.d.ts.map +1 -0
- package/dest/session-manager.js +452 -0
- package/dest/test/index.d.ts +7 -6
- package/dest/test/index.d.ts.map +1 -1
- package/package.json +23 -23
- package/src/actions/download-epoch-proving-job.ts +1 -1
- package/src/actions/rerun-epoch-proving-job.ts +114 -28
- package/src/bin/run-failed-epoch.ts +1 -2
- package/src/checkpoint-store.ts +213 -0
- package/src/config.ts +2 -1
- package/src/factory.ts +18 -10
- package/src/index.ts +1 -0
- package/src/job/checkpoint-prover.ts +465 -0
- package/src/job/epoch-session.ts +424 -0
- package/src/job/top-tree-job.ts +227 -0
- package/src/metrics.ts +88 -12
- package/src/monitors/epoch-monitor.ts +2 -2
- package/src/proof-publishing-service.ts +424 -0
- package/src/prover-node-publisher.ts +220 -67
- package/src/prover-node.ts +439 -249
- package/src/prover-publisher-factory.ts +3 -3
- package/src/session-manager.ts +552 -0
- package/src/test/index.ts +6 -6
- package/dest/job/epoch-proving-job.d.ts +0 -63
- package/dest/job/epoch-proving-job.d.ts.map +0 -1
- package/dest/job/epoch-proving-job.js +0 -762
- package/src/job/epoch-proving-job.ts +0 -465
|
@@ -1,465 +0,0 @@
|
|
|
1
|
-
import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
2
|
-
import { asyncPool } from '@aztec/foundation/async-pool';
|
|
3
|
-
import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
4
|
-
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
5
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
|
-
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
7
|
-
import { RunningPromise, promiseWithResolvers } from '@aztec/foundation/promise';
|
|
8
|
-
import { Timer } from '@aztec/foundation/timer';
|
|
9
|
-
import { AVM_MAX_CONCURRENT_SIMULATIONS } from '@aztec/native';
|
|
10
|
-
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
11
|
-
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
12
|
-
import { buildFinalBlobChallenges } from '@aztec/prover-client/helpers';
|
|
13
|
-
import type { PublicProcessor, PublicProcessorFactory } from '@aztec/simulator/server';
|
|
14
|
-
import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
15
|
-
import type { L2Block, L2BlockSource } from '@aztec/stdlib/block';
|
|
16
|
-
import type { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
17
|
-
import {
|
|
18
|
-
type EpochProver,
|
|
19
|
-
type EpochProvingJobState,
|
|
20
|
-
EpochProvingJobTerminalState,
|
|
21
|
-
type ForkMerkleTreeOperations,
|
|
22
|
-
} from '@aztec/stdlib/interfaces/server';
|
|
23
|
-
import { CheckpointConstantData } from '@aztec/stdlib/rollup';
|
|
24
|
-
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
25
|
-
import type { ProcessedTx, Tx } from '@aztec/stdlib/tx';
|
|
26
|
-
import { Attributes, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';
|
|
27
|
-
|
|
28
|
-
import * as crypto from 'node:crypto';
|
|
29
|
-
|
|
30
|
-
import type { ProverNodeJobMetrics } from '../metrics.js';
|
|
31
|
-
import type { ProverNodePublisher } from '../prover-node-publisher.js';
|
|
32
|
-
import { type EpochProvingJobData, validateEpochProvingJobData } from './epoch-proving-job-data.js';
|
|
33
|
-
|
|
34
|
-
export type EpochProvingJobOptions = {
|
|
35
|
-
parallelBlockLimit?: number;
|
|
36
|
-
skipEpochCheck?: boolean;
|
|
37
|
-
skipSubmitProof?: boolean;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Job that grabs a range of blocks from the unfinalized chain from L1, gets their txs given their hashes,
|
|
42
|
-
* re-executes their public calls, generates a rollup proof, and submits it to L1. This job will update the
|
|
43
|
-
* world state as part of public call execution via the public processor.
|
|
44
|
-
*/
|
|
45
|
-
export class EpochProvingJob implements Traceable {
|
|
46
|
-
private state: EpochProvingJobState = 'initialized';
|
|
47
|
-
private log: Logger;
|
|
48
|
-
private uuid: string;
|
|
49
|
-
|
|
50
|
-
private runPromise: Promise<void> | undefined;
|
|
51
|
-
private epochCheckPromise: RunningPromise | undefined;
|
|
52
|
-
private deadlineTimeoutHandler: NodeJS.Timeout | undefined;
|
|
53
|
-
|
|
54
|
-
public readonly tracer: Tracer;
|
|
55
|
-
|
|
56
|
-
constructor(
|
|
57
|
-
private data: EpochProvingJobData,
|
|
58
|
-
private dbProvider: Pick<ForkMerkleTreeOperations, 'fork'>,
|
|
59
|
-
private prover: EpochProver,
|
|
60
|
-
private publicProcessorFactory: PublicProcessorFactory,
|
|
61
|
-
private publisher: Pick<ProverNodePublisher, 'submitEpochProof'>,
|
|
62
|
-
private l2BlockSource: L2BlockSource | undefined,
|
|
63
|
-
private metrics: ProverNodeJobMetrics,
|
|
64
|
-
private deadline: Date | undefined,
|
|
65
|
-
private config: EpochProvingJobOptions,
|
|
66
|
-
bindings?: LoggerBindings,
|
|
67
|
-
) {
|
|
68
|
-
validateEpochProvingJobData(data);
|
|
69
|
-
this.uuid = crypto.randomUUID();
|
|
70
|
-
this.log = createLogger('prover-node:epoch-proving-job', {
|
|
71
|
-
...bindings,
|
|
72
|
-
instanceId: `epoch-${data.epochNumber}`,
|
|
73
|
-
});
|
|
74
|
-
this.tracer = metrics.tracer;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
public getId(): string {
|
|
78
|
-
return this.uuid;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
public getState(): EpochProvingJobState {
|
|
82
|
-
return this.state;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public getEpochNumber(): EpochNumber {
|
|
86
|
-
return this.data.epochNumber;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
public getDeadline(): Date | undefined {
|
|
90
|
-
return this.deadline;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
public getProvingData(): EpochProvingJobData {
|
|
94
|
-
return this.data;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
private get epochNumber() {
|
|
98
|
-
return this.data.epochNumber;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
private get checkpoints() {
|
|
102
|
-
return this.data.checkpoints;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
private get txs() {
|
|
106
|
-
return this.data.txs;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
private get attestations() {
|
|
110
|
-
return this.data.attestations;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Proves the given epoch and submits the proof to L1.
|
|
115
|
-
*/
|
|
116
|
-
@trackSpan('EpochProvingJob.run', function () {
|
|
117
|
-
return { [Attributes.EPOCH_NUMBER]: this.data.epochNumber };
|
|
118
|
-
})
|
|
119
|
-
public async run() {
|
|
120
|
-
this.scheduleDeadlineStop();
|
|
121
|
-
if (!this.config.skipEpochCheck) {
|
|
122
|
-
await this.scheduleEpochCheck();
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const attestations = this.attestations.map(attestation => attestation.toViem());
|
|
126
|
-
const epochNumber = this.epochNumber;
|
|
127
|
-
const epochSizeCheckpoints = this.checkpoints.length;
|
|
128
|
-
const epochSizeBlocks = this.checkpoints.reduce((accum, checkpoint) => accum + checkpoint.blocks.length, 0);
|
|
129
|
-
const epochSizeTxs = this.checkpoints.reduce(
|
|
130
|
-
(accum, checkpoint) =>
|
|
131
|
-
accum + checkpoint.blocks.reduce((accumC, block) => accumC + block.body.txEffects.length, 0),
|
|
132
|
-
0,
|
|
133
|
-
);
|
|
134
|
-
const fromCheckpoint = this.checkpoints[0].number;
|
|
135
|
-
const toCheckpoint = this.checkpoints.at(-1)!.number;
|
|
136
|
-
const fromBlock = this.checkpoints[0].blocks[0].number;
|
|
137
|
-
const toBlock = this.checkpoints.at(-1)!.blocks.at(-1)!.number;
|
|
138
|
-
this.log.info(`Starting epoch ${epochNumber} proving job with checkpoints ${fromCheckpoint} to ${toCheckpoint}`, {
|
|
139
|
-
fromBlock,
|
|
140
|
-
toBlock,
|
|
141
|
-
epochSizeTxs,
|
|
142
|
-
epochNumber,
|
|
143
|
-
uuid: this.uuid,
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
this.progressState('processing');
|
|
147
|
-
const timer = new Timer();
|
|
148
|
-
const { promise, resolve } = promiseWithResolvers<void>();
|
|
149
|
-
this.runPromise = promise;
|
|
150
|
-
|
|
151
|
-
try {
|
|
152
|
-
const blobTimer = new Timer();
|
|
153
|
-
const blobFieldsPerCheckpoint = this.checkpoints.map(checkpoint => checkpoint.toBlobFields());
|
|
154
|
-
const finalBlobBatchingChallenges = await buildFinalBlobChallenges(blobFieldsPerCheckpoint);
|
|
155
|
-
this.metrics.recordBlobProcessing(blobTimer.ms());
|
|
156
|
-
|
|
157
|
-
this.prover.startNewEpoch(epochNumber, epochSizeCheckpoints, finalBlobBatchingChallenges);
|
|
158
|
-
const chonkTimer = new Timer();
|
|
159
|
-
await this.prover.startChonkVerifierCircuits(Array.from(this.txs.values()));
|
|
160
|
-
this.metrics.recordChonkVerifier(chonkTimer.ms());
|
|
161
|
-
|
|
162
|
-
// Everything in the epoch should have the same chainId and version.
|
|
163
|
-
const { chainId, version } = this.checkpoints[0].blocks[0].header.globalVariables;
|
|
164
|
-
|
|
165
|
-
const previousBlockHeaders = this.gatherPreviousBlockHeaders();
|
|
166
|
-
|
|
167
|
-
const allCheckpointsTimer = new Timer();
|
|
168
|
-
|
|
169
|
-
const parallelism = this.config.parallelBlockLimit
|
|
170
|
-
? this.config.parallelBlockLimit
|
|
171
|
-
: AVM_MAX_CONCURRENT_SIMULATIONS > 0
|
|
172
|
-
? AVM_MAX_CONCURRENT_SIMULATIONS
|
|
173
|
-
: this.checkpoints.length;
|
|
174
|
-
|
|
175
|
-
await asyncPool(parallelism, this.checkpoints, async checkpoint => {
|
|
176
|
-
this.checkState();
|
|
177
|
-
const checkpointTimer = new Timer();
|
|
178
|
-
|
|
179
|
-
const checkpointIndex = checkpoint.number - fromCheckpoint;
|
|
180
|
-
const checkpointConstants = CheckpointConstantData.from({
|
|
181
|
-
chainId,
|
|
182
|
-
version,
|
|
183
|
-
vkTreeRoot: getVKTreeRoot(),
|
|
184
|
-
protocolContractsHash: protocolContractsHash,
|
|
185
|
-
proverId: this.prover.getProverId().toField(),
|
|
186
|
-
slotNumber: checkpoint.header.slotNumber,
|
|
187
|
-
coinbase: checkpoint.header.coinbase,
|
|
188
|
-
feeRecipient: checkpoint.header.feeRecipient,
|
|
189
|
-
gasFees: checkpoint.header.gasFees,
|
|
190
|
-
});
|
|
191
|
-
const previousHeader = previousBlockHeaders[checkpointIndex];
|
|
192
|
-
const l1ToL2Messages = this.getL1ToL2Messages(checkpoint);
|
|
193
|
-
|
|
194
|
-
this.log.verbose(`Starting processing checkpoint ${checkpoint.number}`, {
|
|
195
|
-
number: checkpoint.number,
|
|
196
|
-
checkpointHash: checkpoint.hash().toString(),
|
|
197
|
-
lastArchive: checkpoint.header.lastArchiveRoot,
|
|
198
|
-
previousHeader: previousHeader.hash(),
|
|
199
|
-
uuid: this.uuid,
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
await this.prover.startNewCheckpoint(
|
|
203
|
-
checkpointIndex,
|
|
204
|
-
checkpointConstants,
|
|
205
|
-
l1ToL2Messages,
|
|
206
|
-
checkpoint.blocks.length,
|
|
207
|
-
previousHeader,
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
for (let blockIndex = 0; blockIndex < checkpoint.blocks.length; blockIndex++) {
|
|
211
|
-
const blockTimer = new Timer();
|
|
212
|
-
const block = checkpoint.blocks[blockIndex];
|
|
213
|
-
const globalVariables = block.header.globalVariables;
|
|
214
|
-
const txs = this.getTxs(block);
|
|
215
|
-
|
|
216
|
-
this.log.verbose(`Starting processing block ${block.number}`, {
|
|
217
|
-
number: block.number,
|
|
218
|
-
blockHash: (await block.hash()).toString(),
|
|
219
|
-
lastArchive: block.header.lastArchive.root,
|
|
220
|
-
noteHashTreeRoot: block.header.state.partial.noteHashTree.root,
|
|
221
|
-
nullifierTreeRoot: block.header.state.partial.nullifierTree.root,
|
|
222
|
-
publicDataTreeRoot: block.header.state.partial.publicDataTree.root,
|
|
223
|
-
...globalVariables,
|
|
224
|
-
numTxs: txs.length,
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
// Start block proving
|
|
228
|
-
await this.prover.startNewBlock(block.number, globalVariables.timestamp, txs.length);
|
|
229
|
-
|
|
230
|
-
// Process public fns. L1 to L2 messages are only inserted for the first block of a checkpoint,
|
|
231
|
-
// as the fork for subsequent blocks already includes them from the previous block's synced state.
|
|
232
|
-
const db = await this.createFork(
|
|
233
|
-
BlockNumber(block.number - 1),
|
|
234
|
-
blockIndex === 0 ? l1ToL2Messages : undefined,
|
|
235
|
-
);
|
|
236
|
-
const config = PublicSimulatorConfig.from({
|
|
237
|
-
proverId: this.prover.getProverId().toField(),
|
|
238
|
-
skipFeeEnforcement: false,
|
|
239
|
-
collectDebugLogs: false,
|
|
240
|
-
collectHints: true,
|
|
241
|
-
collectPublicInputs: true,
|
|
242
|
-
collectStatistics: false,
|
|
243
|
-
});
|
|
244
|
-
const publicProcessor = this.publicProcessorFactory.create(db, globalVariables, config);
|
|
245
|
-
const processed = await this.processTxs(publicProcessor, txs);
|
|
246
|
-
await this.prover.addTxs(processed);
|
|
247
|
-
await db.close();
|
|
248
|
-
this.log.verbose(`Processed all ${txs.length} txs for block ${block.number}`, {
|
|
249
|
-
blockNumber: block.number,
|
|
250
|
-
blockHash: (await block.hash()).toString(),
|
|
251
|
-
uuid: this.uuid,
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
// Mark block as completed to pad it
|
|
255
|
-
const expectedBlockHeader = block.header;
|
|
256
|
-
await this.prover.setBlockCompleted(block.number, expectedBlockHeader);
|
|
257
|
-
this.metrics.recordBlockProcessing(blockTimer.ms());
|
|
258
|
-
}
|
|
259
|
-
this.metrics.recordCheckpointProcessing(checkpointTimer.ms());
|
|
260
|
-
});
|
|
261
|
-
this.metrics.recordAllCheckpointsProcessing(allCheckpointsTimer.ms());
|
|
262
|
-
|
|
263
|
-
const executionTime = timer.ms();
|
|
264
|
-
|
|
265
|
-
this.progressState('awaiting-prover');
|
|
266
|
-
const { publicInputs, proof, batchedBlobInputs } = await this.prover.finalizeEpoch();
|
|
267
|
-
this.log.info(`Finalized proof for epoch ${epochNumber}`, { epochNumber, uuid: this.uuid, duration: timer.ms() });
|
|
268
|
-
|
|
269
|
-
this.progressState('publishing-proof');
|
|
270
|
-
|
|
271
|
-
if (this.config.skipSubmitProof) {
|
|
272
|
-
this.log.info(
|
|
273
|
-
`Proof publishing is disabled. Dropping valid proof for epoch ${epochNumber} (checkpoints ${fromCheckpoint} to ${toCheckpoint})`,
|
|
274
|
-
);
|
|
275
|
-
this.state = 'completed';
|
|
276
|
-
this.metrics.recordProvingJob(executionTime, timer.ms(), epochSizeCheckpoints, epochSizeBlocks, epochSizeTxs);
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
const success = await this.publisher.submitEpochProof({
|
|
281
|
-
fromCheckpoint,
|
|
282
|
-
toCheckpoint,
|
|
283
|
-
epochNumber,
|
|
284
|
-
publicInputs,
|
|
285
|
-
proof,
|
|
286
|
-
batchedBlobInputs,
|
|
287
|
-
attestations,
|
|
288
|
-
});
|
|
289
|
-
if (!success) {
|
|
290
|
-
throw new Error('Failed to submit epoch proof to L1');
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
this.log.info(`Submitted proof for epoch ${epochNumber} (checkpoints ${fromCheckpoint} to ${toCheckpoint})`, {
|
|
294
|
-
epochNumber,
|
|
295
|
-
uuid: this.uuid,
|
|
296
|
-
});
|
|
297
|
-
this.state = 'completed';
|
|
298
|
-
this.metrics.recordProvingJob(executionTime, timer.ms(), epochSizeCheckpoints, epochSizeBlocks, epochSizeTxs);
|
|
299
|
-
} catch (err: any) {
|
|
300
|
-
if (err && err.name === 'HaltExecutionError') {
|
|
301
|
-
this.log.warn(`Halted execution of epoch ${epochNumber} prover job`, {
|
|
302
|
-
uuid: this.uuid,
|
|
303
|
-
epochNumber,
|
|
304
|
-
details: err.message,
|
|
305
|
-
});
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
this.log.error(`Error running epoch ${epochNumber} prover job`, err, { uuid: this.uuid, epochNumber });
|
|
309
|
-
if (this.state === 'processing' || this.state === 'awaiting-prover' || this.state === 'publishing-proof') {
|
|
310
|
-
this.state = 'failed';
|
|
311
|
-
}
|
|
312
|
-
} finally {
|
|
313
|
-
clearTimeout(this.deadlineTimeoutHandler);
|
|
314
|
-
await this.epochCheckPromise?.stop();
|
|
315
|
-
await this.prover.stop();
|
|
316
|
-
resolve();
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* Create a new db fork for tx processing, optionally inserting L1 to L2 messages.
|
|
322
|
-
* L1 to L2 messages should only be inserted for the first block in a checkpoint,
|
|
323
|
-
* as subsequent blocks' synced state already includes them.
|
|
324
|
-
* REFACTOR: The prover already spawns a db fork of its own for each block, so we may be able to do away with just one fork.
|
|
325
|
-
*/
|
|
326
|
-
private async createFork(blockNumber: BlockNumber, l1ToL2Messages: Fr[] | undefined) {
|
|
327
|
-
this.log.verbose(`Creating fork at ${blockNumber}`, { blockNumber });
|
|
328
|
-
const db = await this.dbProvider.fork(blockNumber);
|
|
329
|
-
|
|
330
|
-
if (l1ToL2Messages !== undefined) {
|
|
331
|
-
this.log.verbose(`Inserting ${l1ToL2Messages.length} L1 to L2 messages in fork`, {
|
|
332
|
-
blockNumber,
|
|
333
|
-
l1ToL2Messages: l1ToL2Messages.map(m => m.toString()),
|
|
334
|
-
});
|
|
335
|
-
const l1ToL2MessagesPadded = padArrayEnd<Fr, number>(
|
|
336
|
-
l1ToL2Messages,
|
|
337
|
-
Fr.ZERO,
|
|
338
|
-
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
339
|
-
'Too many L1 to L2 messages',
|
|
340
|
-
);
|
|
341
|
-
await db.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
return db;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
private progressState(state: EpochProvingJobState) {
|
|
348
|
-
this.checkState();
|
|
349
|
-
this.state = state;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
private checkState() {
|
|
353
|
-
if (this.state === 'timed-out' || this.state === 'stopped' || this.state === 'failed' || this.state === 'reorg') {
|
|
354
|
-
throw new HaltExecutionError(this.state);
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
public async stop(state: EpochProvingJobTerminalState = 'stopped') {
|
|
359
|
-
this.state = state;
|
|
360
|
-
this.prover.cancel();
|
|
361
|
-
if (this.runPromise) {
|
|
362
|
-
await this.runPromise;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
private scheduleDeadlineStop() {
|
|
367
|
-
const deadline = this.deadline;
|
|
368
|
-
if (deadline) {
|
|
369
|
-
const timeout = deadline.getTime() - Date.now();
|
|
370
|
-
if (timeout <= 0) {
|
|
371
|
-
throw new Error('Cannot start job with deadline in the past');
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
this.deadlineTimeoutHandler = setTimeout(() => {
|
|
375
|
-
if (EpochProvingJobTerminalState.includes(this.state)) {
|
|
376
|
-
return;
|
|
377
|
-
}
|
|
378
|
-
this.log.warn('Stopping job due to deadline hit', { uuid: this.uuid, epochNumber: this.epochNumber });
|
|
379
|
-
this.stop('timed-out').catch(err => {
|
|
380
|
-
this.log.error('Error stopping job', err, { uuid: this.uuid, epochNumber: this.epochNumber });
|
|
381
|
-
});
|
|
382
|
-
}, timeout);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* Kicks off a running promise that queries the archiver for the set of L2 blocks of the current epoch.
|
|
388
|
-
* If those change, stops the proving job with a `rerun` state, so the node re-enqueues it.
|
|
389
|
-
*/
|
|
390
|
-
private async scheduleEpochCheck() {
|
|
391
|
-
const l2BlockSource = this.l2BlockSource;
|
|
392
|
-
if (!l2BlockSource) {
|
|
393
|
-
this.log.warn(`No L2 block source available, skipping epoch check`);
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
const intervalMs = Math.ceil((await l2BlockSource.getL1Constants()).ethereumSlotDuration / 2) * 1000;
|
|
398
|
-
this.epochCheckPromise = new RunningPromise(
|
|
399
|
-
async () => {
|
|
400
|
-
const blockHeaders = await l2BlockSource.getCheckpointedBlockHeadersForEpoch(this.epochNumber);
|
|
401
|
-
const blockHashes = await Promise.all(blockHeaders.map(header => header.hash()));
|
|
402
|
-
const thisBlocks = this.checkpoints.flatMap(checkpoint => checkpoint.blocks);
|
|
403
|
-
const thisBlockHashes = await Promise.all(thisBlocks.map(block => block.hash()));
|
|
404
|
-
if (
|
|
405
|
-
blockHeaders.length !== thisBlocks.length ||
|
|
406
|
-
!blockHashes.every((block, i) => block.equals(thisBlockHashes[i]))
|
|
407
|
-
) {
|
|
408
|
-
this.log.warn('Epoch blocks changed underfoot', {
|
|
409
|
-
uuid: this.uuid,
|
|
410
|
-
epochNumber: this.epochNumber,
|
|
411
|
-
oldBlockHashes: thisBlockHashes,
|
|
412
|
-
newBlockHashes: blockHashes,
|
|
413
|
-
});
|
|
414
|
-
void this.stop('reorg');
|
|
415
|
-
}
|
|
416
|
-
},
|
|
417
|
-
this.log,
|
|
418
|
-
intervalMs,
|
|
419
|
-
).start();
|
|
420
|
-
this.log.verbose(`Scheduled epoch check for epoch ${this.epochNumber} every ${intervalMs}ms`);
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
/* Returns the last block header in the previous checkpoint for all checkpoints in the epoch */
|
|
424
|
-
private gatherPreviousBlockHeaders() {
|
|
425
|
-
const lastBlocks = this.checkpoints.map(checkpoint => checkpoint.blocks.at(-1)!);
|
|
426
|
-
return [this.data.previousBlockHeader, ...lastBlocks.map(block => block.header).slice(0, -1)];
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
private getTxs(block: L2Block): Tx[] {
|
|
430
|
-
return block.body.txEffects.map(txEffect => this.txs.get(txEffect.txHash.toString())!);
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
private getL1ToL2Messages(checkpoint: Checkpoint) {
|
|
434
|
-
return this.data.l1ToL2Messages[checkpoint.number];
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
private async processTxs(publicProcessor: PublicProcessor, txs: Tx[]): Promise<ProcessedTx[]> {
|
|
438
|
-
const { deadline } = this;
|
|
439
|
-
const [processedTxs, failedTxs] = await publicProcessor.process(txs, { deadline });
|
|
440
|
-
|
|
441
|
-
if (failedTxs.length) {
|
|
442
|
-
const failedTxHashes = await Promise.all(failedTxs.map(({ tx }) => tx.getTxHash()));
|
|
443
|
-
throw new Error(
|
|
444
|
-
`Txs failed processing: ${failedTxs
|
|
445
|
-
.map(({ error }, index) => `${failedTxHashes[index]} (${error})`)
|
|
446
|
-
.join(', ')}`,
|
|
447
|
-
);
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
if (processedTxs.length !== txs.length) {
|
|
451
|
-
throw new Error(`Failed to process all txs: processed ${processedTxs.length} out of ${txs.length}`);
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
return processedTxs;
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
class HaltExecutionError extends Error {
|
|
459
|
-
constructor(public readonly state: EpochProvingJobState) {
|
|
460
|
-
super(`Halted execution due to state ${state}`);
|
|
461
|
-
this.name = 'HaltExecutionError';
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
export { type EpochProvingJobState };
|