@aztec/prover-node 0.0.1-commit.2448fdb → 0.0.1-commit.2606882
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/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 +8 -6
- package/dest/actions/upload-epoch-proof-failure.d.ts +2 -2
- package/dest/actions/upload-epoch-proof-failure.d.ts.map +1 -1
- package/dest/bin/run-failed-epoch.js +1 -3
- package/dest/config.d.ts +2 -2
- 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 +21 -2
- package/dest/job/epoch-proving-job.d.ts +6 -2
- package/dest/job/epoch-proving-job.d.ts.map +1 -1
- package/dest/job/epoch-proving-job.js +186 -36
- package/dest/metrics.d.ts +11 -1
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +22 -0
- package/dest/monitors/epoch-monitor.js +6 -2
- package/dest/prover-node-publisher.d.ts +20 -1
- package/dest/prover-node-publisher.d.ts.map +1 -1
- package/dest/prover-node-publisher.js +200 -5
- package/dest/prover-node.d.ts +7 -7
- package/dest/prover-node.d.ts.map +1 -1
- package/dest/prover-node.js +77 -32
- 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/package.json +23 -23
- package/src/actions/download-epoch-proving-job.ts +1 -1
- package/src/actions/rerun-epoch-proving-job.ts +17 -6
- package/src/actions/upload-epoch-proof-failure.ts +1 -1
- package/src/bin/run-failed-epoch.ts +1 -2
- package/src/config.ts +1 -1
- package/src/factory.ts +18 -2
- package/src/job/epoch-proving-job.ts +102 -36
- package/src/metrics.ts +37 -0
- package/src/monitors/epoch-monitor.ts +2 -2
- package/src/prover-node-publisher.ts +232 -9
- package/src/prover-node.ts +82 -45
- package/src/prover-publisher-factory.ts +3 -3
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
2
1
|
import { asyncPool } from '@aztec/foundation/async-pool';
|
|
3
2
|
import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
4
|
-
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
5
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
4
|
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
7
5
|
import { RunningPromise, promiseWithResolvers } from '@aztec/foundation/promise';
|
|
@@ -20,8 +18,8 @@ import {
|
|
|
20
18
|
EpochProvingJobTerminalState,
|
|
21
19
|
type ForkMerkleTreeOperations,
|
|
22
20
|
} from '@aztec/stdlib/interfaces/server';
|
|
21
|
+
import { appendL1ToL2MessagesToTree } from '@aztec/stdlib/messaging';
|
|
23
22
|
import { CheckpointConstantData } from '@aztec/stdlib/rollup';
|
|
24
|
-
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
25
23
|
import type { ProcessedTx, Tx } from '@aztec/stdlib/tx';
|
|
26
24
|
import { Attributes, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';
|
|
27
25
|
|
|
@@ -48,6 +46,7 @@ export class EpochProvingJob implements Traceable {
|
|
|
48
46
|
private uuid: string;
|
|
49
47
|
|
|
50
48
|
private runPromise: Promise<void> | undefined;
|
|
49
|
+
private abortController = new AbortController();
|
|
51
50
|
private epochCheckPromise: RunningPromise | undefined;
|
|
52
51
|
private deadlineTimeoutHandler: NodeJS.Timeout | undefined;
|
|
53
52
|
|
|
@@ -58,7 +57,7 @@ export class EpochProvingJob implements Traceable {
|
|
|
58
57
|
private dbProvider: Pick<ForkMerkleTreeOperations, 'fork'>,
|
|
59
58
|
private prover: EpochProver,
|
|
60
59
|
private publicProcessorFactory: PublicProcessorFactory,
|
|
61
|
-
private publisher: Pick<ProverNodePublisher, 'submitEpochProof'>,
|
|
60
|
+
private publisher: Pick<ProverNodePublisher, 'submitEpochProof' | 'analyzeEpochProofSubmission'>,
|
|
62
61
|
private l2BlockSource: L2BlockSource | undefined,
|
|
63
62
|
private metrics: ProverNodeJobMetrics,
|
|
64
63
|
private deadline: Date | undefined,
|
|
@@ -172,7 +171,7 @@ export class EpochProvingJob implements Traceable {
|
|
|
172
171
|
? AVM_MAX_CONCURRENT_SIMULATIONS
|
|
173
172
|
: this.checkpoints.length;
|
|
174
173
|
|
|
175
|
-
await
|
|
174
|
+
await this.processCheckpoints(parallelism, async checkpoint => {
|
|
176
175
|
this.checkState();
|
|
177
176
|
const checkpointTimer = new Timer();
|
|
178
177
|
|
|
@@ -191,11 +190,12 @@ export class EpochProvingJob implements Traceable {
|
|
|
191
190
|
const previousHeader = previousBlockHeaders[checkpointIndex];
|
|
192
191
|
const l1ToL2Messages = this.getL1ToL2Messages(checkpoint);
|
|
193
192
|
|
|
194
|
-
this.log.
|
|
193
|
+
this.log.debug(`Starting processing checkpoint ${checkpoint.number}`, {
|
|
195
194
|
number: checkpoint.number,
|
|
196
195
|
checkpointHash: checkpoint.hash().toString(),
|
|
197
|
-
|
|
198
|
-
|
|
196
|
+
headerHash: checkpoint.header.hash().toString(),
|
|
197
|
+
numL1ToL2Messages: l1ToL2Messages.length,
|
|
198
|
+
previousBlockNumber: previousHeader.globalVariables.blockNumber,
|
|
199
199
|
uuid: this.uuid,
|
|
200
200
|
});
|
|
201
201
|
|
|
@@ -229,22 +229,26 @@ export class EpochProvingJob implements Traceable {
|
|
|
229
229
|
|
|
230
230
|
// Process public fns. L1 to L2 messages are only inserted for the first block of a checkpoint,
|
|
231
231
|
// as the fork for subsequent blocks already includes them from the previous block's synced state.
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
232
|
+
{
|
|
233
|
+
await using db = await this.createFork(
|
|
234
|
+
BlockNumber(block.number - 1),
|
|
235
|
+
blockIndex === 0 ? l1ToL2Messages : undefined,
|
|
236
|
+
);
|
|
237
|
+
this.checkState();
|
|
238
|
+
const config = PublicSimulatorConfig.from({
|
|
239
|
+
proverId: this.prover.getProverId().toField(),
|
|
240
|
+
skipFeeEnforcement: false,
|
|
241
|
+
collectDebugLogs: false,
|
|
242
|
+
collectHints: true,
|
|
243
|
+
collectPublicInputs: true,
|
|
244
|
+
collectStatistics: false,
|
|
245
|
+
});
|
|
246
|
+
const publicProcessor = this.publicProcessorFactory.create(db, globalVariables, config);
|
|
247
|
+
const processed = await this.processTxs(publicProcessor, txs);
|
|
248
|
+
this.checkState();
|
|
249
|
+
await this.prover.addTxs(processed);
|
|
250
|
+
}
|
|
251
|
+
this.checkState();
|
|
248
252
|
this.log.verbose(`Processed all ${txs.length} txs for block ${block.number}`, {
|
|
249
253
|
blockNumber: block.number,
|
|
250
254
|
blockHash: (await block.hash()).toString(),
|
|
@@ -270,8 +274,21 @@ export class EpochProvingJob implements Traceable {
|
|
|
270
274
|
|
|
271
275
|
if (this.config.skipSubmitProof) {
|
|
272
276
|
this.log.info(
|
|
273
|
-
`Proof publishing is disabled.
|
|
277
|
+
`Proof publishing is disabled. Analyzing estimated L1 fees for epoch ${epochNumber} (checkpoints ${fromCheckpoint} to ${toCheckpoint})`,
|
|
274
278
|
);
|
|
279
|
+
try {
|
|
280
|
+
await this.publisher.analyzeEpochProofSubmission({
|
|
281
|
+
fromCheckpoint,
|
|
282
|
+
toCheckpoint,
|
|
283
|
+
epochNumber,
|
|
284
|
+
publicInputs,
|
|
285
|
+
proof,
|
|
286
|
+
batchedBlobInputs,
|
|
287
|
+
attestations,
|
|
288
|
+
});
|
|
289
|
+
} catch (err) {
|
|
290
|
+
this.log.warn(`Failed to analyze estimated L1 fees for epoch ${epochNumber}`, err);
|
|
291
|
+
}
|
|
275
292
|
this.state = 'completed';
|
|
276
293
|
this.metrics.recordProvingJob(executionTime, timer.ms(), epochSizeCheckpoints, epochSizeBlocks, epochSizeTxs);
|
|
277
294
|
return;
|
|
@@ -325,25 +342,56 @@ export class EpochProvingJob implements Traceable {
|
|
|
325
342
|
*/
|
|
326
343
|
private async createFork(blockNumber: BlockNumber, l1ToL2Messages: Fr[] | undefined) {
|
|
327
344
|
this.log.verbose(`Creating fork at ${blockNumber}`, { blockNumber });
|
|
328
|
-
|
|
345
|
+
// temporary stack to control fork lifetime
|
|
346
|
+
await using cleanup = new AsyncDisposableStack();
|
|
347
|
+
const db = cleanup.use(await this.dbProvider.fork(blockNumber));
|
|
329
348
|
|
|
330
349
|
if (l1ToL2Messages !== undefined) {
|
|
331
350
|
this.log.verbose(`Inserting ${l1ToL2Messages.length} L1 to L2 messages in fork`, {
|
|
332
351
|
blockNumber,
|
|
333
352
|
l1ToL2Messages: l1ToL2Messages.map(m => m.toString()),
|
|
334
353
|
});
|
|
335
|
-
|
|
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);
|
|
354
|
+
await appendL1ToL2MessagesToTree(db, l1ToL2Messages);
|
|
342
355
|
}
|
|
343
356
|
|
|
357
|
+
// everything run succesfully so we can release this stack and give control of the fork's lifetime to the caller
|
|
358
|
+
cleanup.move();
|
|
344
359
|
return db;
|
|
345
360
|
}
|
|
346
361
|
|
|
362
|
+
private async processCheckpoints(
|
|
363
|
+
parallelism: number,
|
|
364
|
+
processCheckpoint: (checkpoint: Checkpoint) => Promise<void>,
|
|
365
|
+
): Promise<void> {
|
|
366
|
+
let hasError = false;
|
|
367
|
+
let firstError: unknown;
|
|
368
|
+
|
|
369
|
+
await asyncPool(Math.max(parallelism, 1), this.checkpoints, async checkpoint => {
|
|
370
|
+
if (hasError || this.abortController.signal.aborted) {
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
try {
|
|
375
|
+
this.checkState();
|
|
376
|
+
await processCheckpoint(checkpoint);
|
|
377
|
+
} catch (err) {
|
|
378
|
+
if (!hasError) {
|
|
379
|
+
hasError = true;
|
|
380
|
+
firstError = err;
|
|
381
|
+
this.failProcessing();
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
if (hasError) {
|
|
387
|
+
throw firstError;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
if (this.abortController.signal.aborted) {
|
|
391
|
+
this.checkState();
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
347
395
|
private progressState(state: EpochProvingJobState) {
|
|
348
396
|
this.checkState();
|
|
349
397
|
this.state = state;
|
|
@@ -357,12 +405,24 @@ export class EpochProvingJob implements Traceable {
|
|
|
357
405
|
|
|
358
406
|
public async stop(state: EpochProvingJobTerminalState = 'stopped') {
|
|
359
407
|
this.state = state;
|
|
360
|
-
this.
|
|
408
|
+
this.interruptProcessing();
|
|
361
409
|
if (this.runPromise) {
|
|
362
410
|
await this.runPromise;
|
|
363
411
|
}
|
|
364
412
|
}
|
|
365
413
|
|
|
414
|
+
private failProcessing() {
|
|
415
|
+
if (!EpochProvingJobTerminalState.includes(this.state)) {
|
|
416
|
+
this.state = 'failed';
|
|
417
|
+
}
|
|
418
|
+
this.interruptProcessing();
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
private interruptProcessing() {
|
|
422
|
+
this.abortController.abort();
|
|
423
|
+
this.prover.cancel();
|
|
424
|
+
}
|
|
425
|
+
|
|
366
426
|
private scheduleDeadlineStop() {
|
|
367
427
|
const deadline = this.deadline;
|
|
368
428
|
if (deadline) {
|
|
@@ -397,7 +457,9 @@ export class EpochProvingJob implements Traceable {
|
|
|
397
457
|
const intervalMs = Math.ceil((await l2BlockSource.getL1Constants()).ethereumSlotDuration / 2) * 1000;
|
|
398
458
|
this.epochCheckPromise = new RunningPromise(
|
|
399
459
|
async () => {
|
|
400
|
-
const blockHeaders =
|
|
460
|
+
const blockHeaders = (
|
|
461
|
+
await l2BlockSource.getBlocksData({ epoch: this.epochNumber, onlyCheckpointed: true })
|
|
462
|
+
).map(d => d.header);
|
|
401
463
|
const blockHashes = await Promise.all(blockHeaders.map(header => header.hash()));
|
|
402
464
|
const thisBlocks = this.checkpoints.flatMap(checkpoint => checkpoint.blocks);
|
|
403
465
|
const thisBlockHashes = await Promise.all(thisBlocks.map(block => block.hash()));
|
|
@@ -436,7 +498,11 @@ export class EpochProvingJob implements Traceable {
|
|
|
436
498
|
|
|
437
499
|
private async processTxs(publicProcessor: PublicProcessor, txs: Tx[]): Promise<ProcessedTx[]> {
|
|
438
500
|
const { deadline } = this;
|
|
439
|
-
const [processedTxs, failedTxs] = await publicProcessor.process(txs, {
|
|
501
|
+
const [processedTxs, failedTxs] = await publicProcessor.process(txs, {
|
|
502
|
+
deadline,
|
|
503
|
+
signal: this.abortController.signal,
|
|
504
|
+
});
|
|
505
|
+
this.checkState();
|
|
440
506
|
|
|
441
507
|
if (failedTxs.length) {
|
|
442
508
|
const failedTxHashes = await Promise.all(failedTxs.map(({ tx }) => tx.getTxHash()));
|
package/src/metrics.ts
CHANGED
|
@@ -140,6 +140,13 @@ export class ProverNodeRewardsMetrics {
|
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
export type EstimatedSubmitProofStats = {
|
|
144
|
+
gasLimit: bigint;
|
|
145
|
+
baseFeePerGas: bigint;
|
|
146
|
+
maxPriorityFeePerGas: bigint;
|
|
147
|
+
estimatedTotalFee: bigint;
|
|
148
|
+
};
|
|
149
|
+
|
|
143
150
|
export class ProverNodePublisherMetrics {
|
|
144
151
|
gasPrice: Histogram;
|
|
145
152
|
txCount: UpDownCounter;
|
|
@@ -151,6 +158,10 @@ export class ProverNodePublisherMetrics {
|
|
|
151
158
|
txBlobDataGasCost: Histogram;
|
|
152
159
|
txTotalFee: Histogram;
|
|
153
160
|
|
|
161
|
+
private txGasEstimated: Histogram;
|
|
162
|
+
private gasPriceEstimated: Histogram;
|
|
163
|
+
private txTotalFeeEstimated: Histogram;
|
|
164
|
+
|
|
154
165
|
private senderBalance: Gauge;
|
|
155
166
|
private meter: Meter;
|
|
156
167
|
|
|
@@ -182,6 +193,12 @@ export class ProverNodePublisherMetrics {
|
|
|
182
193
|
|
|
183
194
|
this.txTotalFee = this.meter.createHistogram(Metrics.L1_PUBLISHER_TX_TOTAL_FEE);
|
|
184
195
|
|
|
196
|
+
this.txGasEstimated = this.meter.createHistogram(Metrics.PROVER_NODE_ESTIMATED_SUBMISSION_GAS);
|
|
197
|
+
|
|
198
|
+
this.gasPriceEstimated = this.meter.createHistogram(Metrics.PROVER_NODE_ESTIMATED_SUBMISSION_GAS_PRICE);
|
|
199
|
+
|
|
200
|
+
this.txTotalFeeEstimated = this.meter.createHistogram(Metrics.PROVER_NODE_ESTIMATED_SUBMISSION_TOTAL_FEE);
|
|
201
|
+
|
|
185
202
|
this.senderBalance = this.meter.createGauge(Metrics.L1_PUBLISHER_BALANCE);
|
|
186
203
|
}
|
|
187
204
|
|
|
@@ -196,6 +213,26 @@ export class ProverNodePublisherMetrics {
|
|
|
196
213
|
this.recordTx(durationMs, stats);
|
|
197
214
|
}
|
|
198
215
|
|
|
216
|
+
public recordEstimatedSubmitProof(stats: EstimatedSubmitProofStats) {
|
|
217
|
+
const attributes = { [Attributes.L1_TX_TYPE]: 'submitProof' } as const;
|
|
218
|
+
|
|
219
|
+
this.txGasEstimated.record(Number(stats.gasLimit), attributes);
|
|
220
|
+
|
|
221
|
+
try {
|
|
222
|
+
this.gasPriceEstimated.record(
|
|
223
|
+
parseInt(formatEther(stats.baseFeePerGas + stats.maxPriorityFeePerGas, 'gwei'), 10),
|
|
224
|
+
);
|
|
225
|
+
} catch {
|
|
226
|
+
// ignore
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
try {
|
|
230
|
+
this.txTotalFeeEstimated.record(parseFloat(formatEther(stats.estimatedTotalFee)));
|
|
231
|
+
} catch {
|
|
232
|
+
// ignore
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
199
236
|
public recordSenderBalance(wei: bigint, senderAddress: string) {
|
|
200
237
|
const eth = parseFloat(formatEther(wei, 'wei'));
|
|
201
238
|
this.senderBalance.record(eth, {
|
|
@@ -96,9 +96,9 @@ export class EpochMonitor implements Traceable {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
private async getEpochNumberToProve() {
|
|
99
|
-
const lastBlockProven = await this.l2BlockSource.
|
|
99
|
+
const lastBlockProven = (await this.l2BlockSource.getBlockNumber({ tag: 'proven' })) ?? BlockNumber.ZERO;
|
|
100
100
|
const firstBlockToProve = BlockNumber(lastBlockProven + 1);
|
|
101
|
-
const firstBlockHeaderToProve = await this.l2BlockSource.
|
|
101
|
+
const firstBlockHeaderToProve = (await this.l2BlockSource.getBlockData({ number: firstBlockToProve }))?.header;
|
|
102
102
|
if (!firstBlockHeaderToProve) {
|
|
103
103
|
return { epochToProve: undefined, blockNumber: firstBlockToProve };
|
|
104
104
|
}
|
|
@@ -8,20 +8,22 @@ import { areArraysEqual } from '@aztec/foundation/collection';
|
|
|
8
8
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
9
9
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
10
10
|
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
11
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
11
12
|
import type { Tuple } from '@aztec/foundation/serialize';
|
|
12
13
|
import { Timer } from '@aztec/foundation/timer';
|
|
13
14
|
import { RollupAbi } from '@aztec/l1-artifacts';
|
|
14
15
|
import type { PublisherConfig, TxSenderConfig } from '@aztec/sequencer-client';
|
|
15
16
|
import { CommitteeAttestation, CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
17
|
+
import { getProofSubmissionDeadlineTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
16
18
|
import type { Proof } from '@aztec/stdlib/proofs';
|
|
17
19
|
import type { FeeRecipient, RootRollupPublicInputs } from '@aztec/stdlib/rollup';
|
|
18
20
|
import type { L1PublishProofStats } from '@aztec/stdlib/stats';
|
|
19
21
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
20
22
|
|
|
21
23
|
import { inspect } from 'util';
|
|
22
|
-
import { type Hex, type TransactionReceipt, encodeFunctionData } from 'viem';
|
|
24
|
+
import { type Hex, type TransactionReceipt, encodeFunctionData, formatEther, formatGwei } from 'viem';
|
|
23
25
|
|
|
24
|
-
import { ProverNodePublisherMetrics } from './metrics.js';
|
|
26
|
+
import { type EstimatedSubmitProofStats, ProverNodePublisherMetrics } from './metrics.js';
|
|
25
27
|
|
|
26
28
|
/** Arguments to the submitEpochProof method of the rollup contract */
|
|
27
29
|
export type L1SubmitEpochProofArgs = {
|
|
@@ -101,6 +103,11 @@ export class ProverNodePublisher {
|
|
|
101
103
|
const ctx = { epochNumber, fromCheckpoint, toCheckpoint };
|
|
102
104
|
|
|
103
105
|
if (!this.interrupted) {
|
|
106
|
+
if (!(await this.waitUntilStartBuildsOnProven(args))) {
|
|
107
|
+
this.log.verbose('Checkpoint data syncing interrupted', ctx);
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
|
|
104
111
|
const timer = new Timer();
|
|
105
112
|
// Validate epoch proof range and hashes are correct before submitting
|
|
106
113
|
await this.validateEpochProofSubmission(args);
|
|
@@ -147,6 +154,53 @@ export class ProverNodePublisher {
|
|
|
147
154
|
return false;
|
|
148
155
|
}
|
|
149
156
|
|
|
157
|
+
private async waitUntilStartBuildsOnProven(args: { epochNumber: EpochNumber; fromCheckpoint: CheckpointNumber }) {
|
|
158
|
+
const { epochNumber, fromCheckpoint } = args;
|
|
159
|
+
const provenCheckpoint = await this.getProvenCheckpoint();
|
|
160
|
+
if (this.isStartBuildingOnProven(fromCheckpoint, provenCheckpoint)) {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const timeout = await this.getSecondsUntilProofSubmissionWindowEnd(epochNumber);
|
|
165
|
+
this.log.info(`Waiting for proven checkpoint to reach proof start`, {
|
|
166
|
+
epochNumber,
|
|
167
|
+
fromCheckpoint,
|
|
168
|
+
provenCheckpoint,
|
|
169
|
+
timeout,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
await retryUntil(
|
|
173
|
+
async () => {
|
|
174
|
+
if (this.interrupted) {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const proven = await this.getProvenCheckpoint();
|
|
179
|
+
this.log.verbose(`Proven checkpoint is at ${proven} (waiting for ${fromCheckpoint - 1})`, { epochNumber });
|
|
180
|
+
return this.isStartBuildingOnProven(fromCheckpoint, proven) ? true : undefined;
|
|
181
|
+
},
|
|
182
|
+
`proven checkpoint to reach ${fromCheckpoint - 1}`,
|
|
183
|
+
timeout,
|
|
184
|
+
4,
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
return !this.interrupted;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
private async getProvenCheckpoint() {
|
|
191
|
+
return (await this.rollupContract.getTips()).proven;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
private isStartBuildingOnProven(fromCheckpoint: CheckpointNumber, provenCheckpoint: CheckpointNumber) {
|
|
195
|
+
return fromCheckpoint - 1 <= provenCheckpoint;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
private async getSecondsUntilProofSubmissionWindowEnd(epochNumber: EpochNumber) {
|
|
199
|
+
const deadline = getProofSubmissionDeadlineTimestamp(epochNumber, await this.rollupContract.getRollupConstants());
|
|
200
|
+
const now = BigInt(Math.floor(Date.now() / 1000));
|
|
201
|
+
return Math.max(Number(deadline - now), 0.001);
|
|
202
|
+
}
|
|
203
|
+
|
|
150
204
|
private async validateEpochProofSubmission(args: {
|
|
151
205
|
fromCheckpoint: CheckpointNumber;
|
|
152
206
|
toCheckpoint: CheckpointNumber;
|
|
@@ -168,7 +222,7 @@ export class ProverNodePublisher {
|
|
|
168
222
|
// toCheckpoint can't be greater than pending
|
|
169
223
|
if (toCheckpoint > pending) {
|
|
170
224
|
throw new Error(
|
|
171
|
-
`Cannot submit epoch proof for ${fromCheckpoint}-${toCheckpoint} as
|
|
225
|
+
`Cannot submit epoch proof for ${fromCheckpoint}-${toCheckpoint} as proposed checkpoint is ${pending}`,
|
|
172
226
|
);
|
|
173
227
|
}
|
|
174
228
|
|
|
@@ -203,13 +257,85 @@ export class ProverNodePublisher {
|
|
|
203
257
|
const argsPublicInputs = [...publicInputs.toFields()];
|
|
204
258
|
|
|
205
259
|
if (!areArraysEqual(rollupPublicInputs, argsPublicInputs, (a, b) => a.equals(b))) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
260
|
+
throw await reportPublicInputsMismatch({
|
|
261
|
+
rollupPublicInputs,
|
|
262
|
+
argsPublicInputs,
|
|
263
|
+
fromCheckpoint,
|
|
264
|
+
toCheckpoint,
|
|
265
|
+
rollupContract: this.rollupContract,
|
|
266
|
+
log: this.log,
|
|
267
|
+
});
|
|
210
268
|
}
|
|
211
269
|
}
|
|
212
270
|
|
|
271
|
+
/**
|
|
272
|
+
* Estimates what submitting the epoch proof would have cost on L1 without actually sending it.
|
|
273
|
+
* Runs the same validation as `submitEpochProof`, encodes the calldata, estimates gas, and records metrics.
|
|
274
|
+
* Used when proof publishing is disabled (e.g. PROVER_NODE_DISABLE_PROOF_PUBLISH=true on mainnet).
|
|
275
|
+
*/
|
|
276
|
+
public async analyzeEpochProofSubmission(args: {
|
|
277
|
+
epochNumber: EpochNumber;
|
|
278
|
+
fromCheckpoint: CheckpointNumber;
|
|
279
|
+
toCheckpoint: CheckpointNumber;
|
|
280
|
+
publicInputs: RootRollupPublicInputs;
|
|
281
|
+
proof: Proof;
|
|
282
|
+
batchedBlobInputs: BatchedBlob;
|
|
283
|
+
attestations: ViemCommitteeAttestation[];
|
|
284
|
+
}): Promise<void> {
|
|
285
|
+
const { epochNumber, fromCheckpoint, toCheckpoint } = args;
|
|
286
|
+
|
|
287
|
+
await this.validateEpochProofSubmission(args);
|
|
288
|
+
|
|
289
|
+
const data = this.encodeSubmitEpochProofCalldata(args);
|
|
290
|
+
const senderAddress = this.l1TxUtils.getSenderAddress();
|
|
291
|
+
|
|
292
|
+
const [gasLimit, gasPrice, latestBlock] = await Promise.all([
|
|
293
|
+
this.l1TxUtils.estimateGas(senderAddress.toString() as `0x${string}`, { to: this.rollupContract.address, data }),
|
|
294
|
+
this.l1TxUtils.getGasPrice(),
|
|
295
|
+
this.l1TxUtils.client.getBlock({ blockTag: 'latest' }),
|
|
296
|
+
]);
|
|
297
|
+
|
|
298
|
+
const baseFeePerGas = latestBlock.baseFeePerGas ?? 0n;
|
|
299
|
+
const { maxPriorityFeePerGas } = gasPrice;
|
|
300
|
+
|
|
301
|
+
const effectiveFeePerGas = baseFeePerGas + maxPriorityFeePerGas;
|
|
302
|
+
const estimatedTotalFee = gasLimit * effectiveFeePerGas;
|
|
303
|
+
|
|
304
|
+
const stats: EstimatedSubmitProofStats = {
|
|
305
|
+
gasLimit,
|
|
306
|
+
baseFeePerGas,
|
|
307
|
+
maxPriorityFeePerGas,
|
|
308
|
+
estimatedTotalFee,
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
this.log.info(`Estimated epoch proof submission cost (not submitted)`, {
|
|
312
|
+
epochNumber,
|
|
313
|
+
fromCheckpoint,
|
|
314
|
+
toCheckpoint,
|
|
315
|
+
gasLimit: gasLimit.toString(),
|
|
316
|
+
baseFeePerGas: formatGwei(baseFeePerGas),
|
|
317
|
+
maxPriorityFeePerGas: formatGwei(maxPriorityFeePerGas),
|
|
318
|
+
estimatedTotalFeeEth: formatEther(estimatedTotalFee),
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
this.metrics.recordEstimatedSubmitProof(stats);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
private encodeSubmitEpochProofCalldata(args: {
|
|
325
|
+
fromCheckpoint: CheckpointNumber;
|
|
326
|
+
toCheckpoint: CheckpointNumber;
|
|
327
|
+
publicInputs: RootRollupPublicInputs;
|
|
328
|
+
proof: Proof;
|
|
329
|
+
batchedBlobInputs: BatchedBlob;
|
|
330
|
+
attestations: ViemCommitteeAttestation[];
|
|
331
|
+
}): Hex {
|
|
332
|
+
return encodeFunctionData({
|
|
333
|
+
abi: RollupAbi,
|
|
334
|
+
functionName: 'submitEpochRootProof',
|
|
335
|
+
args: [this.getSubmitEpochProofArgs(args)],
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
|
|
213
339
|
private async sendSubmitEpochProofTx(args: {
|
|
214
340
|
fromCheckpoint: CheckpointNumber;
|
|
215
341
|
toCheckpoint: CheckpointNumber;
|
|
@@ -296,11 +422,108 @@ export class ProverNodePublisher {
|
|
|
296
422
|
end: argsArray[1],
|
|
297
423
|
args: argsArray[2],
|
|
298
424
|
fees: argsArray[3],
|
|
299
|
-
attestations:
|
|
425
|
+
attestations: CommitteeAttestationsAndSigners.packAttestations(
|
|
300
426
|
args.attestations.map(a => CommitteeAttestation.fromViem(a)),
|
|
301
|
-
)
|
|
427
|
+
),
|
|
302
428
|
blobInputs: argsArray[4],
|
|
303
429
|
proof: proofHex,
|
|
304
430
|
};
|
|
305
431
|
}
|
|
306
432
|
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Decodes a `Root rollup public inputs mismatch`, fetches the on-chain CheckpointLog for any
|
|
436
|
+
* mismatching `checkpointHeaderHashes[i]`, emits a structured error log, and returns a thrown-ready
|
|
437
|
+
* Error with a human-readable summary.
|
|
438
|
+
*
|
|
439
|
+
* Layout of `RootRollupPublicInputs.toFields()`:
|
|
440
|
+
* [0] previousArchiveRoot
|
|
441
|
+
* [1] endArchiveRoot
|
|
442
|
+
* [2] outHash
|
|
443
|
+
* [3 .. 3+N-1] checkpointHeaderHashes[i] for i in 0..N-1 (N = MAX_CHECKPOINTS_PER_EPOCH)
|
|
444
|
+
* [3+N .. 3+3N-1] fees[i] = (recipient, value) for i in 0..N-1
|
|
445
|
+
* [3+3N .. 3+3N+4] EpochConstantData (chainId, version, vkTreeRoot, protocolContractsHash, proverId)
|
|
446
|
+
* [3+3N+5 ..] blobPublicInputs (FinalBlobAccumulator)
|
|
447
|
+
*/
|
|
448
|
+
async function reportPublicInputsMismatch(input: {
|
|
449
|
+
rollupPublicInputs: readonly Fr[];
|
|
450
|
+
argsPublicInputs: readonly Fr[];
|
|
451
|
+
fromCheckpoint: CheckpointNumber;
|
|
452
|
+
toCheckpoint: CheckpointNumber;
|
|
453
|
+
rollupContract: RollupContract;
|
|
454
|
+
log: Logger;
|
|
455
|
+
}): Promise<Error> {
|
|
456
|
+
const { rollupPublicInputs, argsPublicInputs, fromCheckpoint, toCheckpoint, rollupContract, log } = input;
|
|
457
|
+
const N = MAX_CHECKPOINTS_PER_EPOCH;
|
|
458
|
+
const constantsStart = 3 + 3 * N;
|
|
459
|
+
const blobStart = constantsStart + 5;
|
|
460
|
+
const constantLabels = ['chainId', 'version', 'vkTreeRoot', 'protocolContractsHash', 'proverId'];
|
|
461
|
+
|
|
462
|
+
const diffs: { index: number; label: string; rollup: Fr; computed: Fr; checkpointIndex?: number }[] = [];
|
|
463
|
+
const len = Math.max(rollupPublicInputs.length, argsPublicInputs.length);
|
|
464
|
+
for (let i = 0; i < len; i++) {
|
|
465
|
+
const a = rollupPublicInputs[i] ?? Fr.ZERO;
|
|
466
|
+
const b = argsPublicInputs[i] ?? Fr.ZERO;
|
|
467
|
+
if (a.equals(b)) {
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
let label: string;
|
|
471
|
+
let checkpointIndex: number | undefined;
|
|
472
|
+
if (i === 0) {
|
|
473
|
+
label = 'previousArchiveRoot';
|
|
474
|
+
} else if (i === 1) {
|
|
475
|
+
label = 'endArchiveRoot';
|
|
476
|
+
} else if (i === 2) {
|
|
477
|
+
label = 'outHash';
|
|
478
|
+
} else if (i < 3 + N) {
|
|
479
|
+
checkpointIndex = i - 3;
|
|
480
|
+
label = `checkpointHeaderHashes[${checkpointIndex}]`;
|
|
481
|
+
} else if (i < 3 + 3 * N) {
|
|
482
|
+
const feePairIndex = i - (3 + N);
|
|
483
|
+
const feeIndex = Math.floor(feePairIndex / 2);
|
|
484
|
+
const sub = feePairIndex % 2 === 0 ? 'recipient' : 'value';
|
|
485
|
+
label = `fees[${feeIndex}].${sub}`;
|
|
486
|
+
} else if (i < blobStart) {
|
|
487
|
+
label = `constants.${constantLabels[i - constantsStart]}`;
|
|
488
|
+
} else {
|
|
489
|
+
label = `blobPublicInputs[${i - blobStart}]`;
|
|
490
|
+
}
|
|
491
|
+
diffs.push({ index: i, label, rollup: a, computed: b, checkpointIndex });
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// For each mismatching checkpointHeaderHash, fetch the L1 CheckpointLog so the operator can
|
|
495
|
+
// see what was published on-chain alongside the prover's recomputed hash.
|
|
496
|
+
const onChainCheckpoints = await Promise.all(
|
|
497
|
+
diffs
|
|
498
|
+
.filter(d => d.checkpointIndex !== undefined)
|
|
499
|
+
.map(async d => {
|
|
500
|
+
const checkpointNumber = CheckpointNumber(fromCheckpoint + d.checkpointIndex!);
|
|
501
|
+
try {
|
|
502
|
+
const cp = await rollupContract.getCheckpoint(checkpointNumber);
|
|
503
|
+
return { checkpointIndex: d.checkpointIndex!, checkpointNumber, headerHash: cp.headerHash.toString() };
|
|
504
|
+
} catch (err) {
|
|
505
|
+
return { checkpointIndex: d.checkpointIndex!, checkpointNumber, error: (err as Error).message };
|
|
506
|
+
}
|
|
507
|
+
}),
|
|
508
|
+
);
|
|
509
|
+
|
|
510
|
+
log.error(`Root rollup public inputs mismatch`, undefined, {
|
|
511
|
+
fromCheckpoint,
|
|
512
|
+
toCheckpoint,
|
|
513
|
+
numDiffs: diffs.length,
|
|
514
|
+
diffs: diffs.map(d => ({
|
|
515
|
+
index: d.index,
|
|
516
|
+
label: d.label,
|
|
517
|
+
rollup: d.rollup.toString(),
|
|
518
|
+
computed: d.computed.toString(),
|
|
519
|
+
})),
|
|
520
|
+
onChainCheckpoints,
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
const fmt = (inputs: readonly Fr[]) => inputs.map(x => x.toString()).join(', ');
|
|
524
|
+
const summary = diffs.map(d => `[${d.index} ${d.label}] L1=${d.rollup} prover=${d.computed}`).join('\n');
|
|
525
|
+
return new Error(
|
|
526
|
+
`Root rollup public inputs mismatch (${diffs.length} fields differ):\n${summary}\n` +
|
|
527
|
+
`Rollup: ${fmt(rollupPublicInputs)}\nComputed:${fmt(argsPublicInputs)}`,
|
|
528
|
+
);
|
|
529
|
+
}
|