@aztec/prover-node 0.0.1-commit.2eb6648a → 0.0.1-commit.2f68f620
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 +105 -27
- 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 +6 -5
- package/dest/config.d.ts +7 -8
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +23 -19
- package/dest/factory.d.ts +19 -13
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +41 -60
- 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 +206 -35
- package/dest/metrics.d.ts +21 -1
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +47 -0
- package/dest/monitors/epoch-monitor.d.ts +1 -1
- package/dest/monitors/epoch-monitor.d.ts.map +1 -1
- package/dest/monitors/epoch-monitor.js +11 -9
- package/dest/prover-node-publisher.d.ts +25 -3
- package/dest/prover-node-publisher.d.ts.map +1 -1
- package/dest/prover-node-publisher.js +206 -9
- package/dest/prover-node.d.ts +24 -14
- package/dest/prover-node.d.ts.map +1 -1
- package/dest/prover-node.js +91 -41
- package/dest/prover-publisher-factory.d.ts +6 -4
- package/dest/prover-publisher-factory.d.ts.map +1 -1
- package/dest/prover-publisher-factory.js +4 -3
- package/package.json +23 -22
- 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 +5 -3
- package/src/config.ts +33 -31
- package/src/factory.ts +69 -103
- package/src/job/epoch-proving-job.ts +137 -41
- package/src/metrics.ts +71 -0
- package/src/monitors/epoch-monitor.ts +5 -6
- package/src/prover-node-publisher.ts +241 -14
- package/src/prover-node.ts +98 -55
- package/src/prover-publisher-factory.ts +8 -5
package/src/metrics.ts
CHANGED
|
@@ -25,6 +25,12 @@ export class ProverNodeJobMetrics {
|
|
|
25
25
|
provingJobBlocks: Gauge;
|
|
26
26
|
provingJobTransactions: Gauge;
|
|
27
27
|
|
|
28
|
+
private blobProcessingDuration: Gauge;
|
|
29
|
+
private chonkVerifierDuration: Gauge;
|
|
30
|
+
private blockProcessingDuration: Histogram;
|
|
31
|
+
private checkpointProcessingDuration: Histogram;
|
|
32
|
+
private allCheckpointsProcessingDuration: Gauge;
|
|
33
|
+
|
|
28
34
|
constructor(
|
|
29
35
|
private meter: Meter,
|
|
30
36
|
public readonly tracer: Tracer,
|
|
@@ -35,6 +41,14 @@ export class ProverNodeJobMetrics {
|
|
|
35
41
|
this.provingJobCheckpoints = this.meter.createGauge(Metrics.PROVER_NODE_JOB_CHECKPOINTS);
|
|
36
42
|
this.provingJobBlocks = this.meter.createGauge(Metrics.PROVER_NODE_JOB_BLOCKS);
|
|
37
43
|
this.provingJobTransactions = this.meter.createGauge(Metrics.PROVER_NODE_JOB_TRANSACTIONS);
|
|
44
|
+
|
|
45
|
+
this.blobProcessingDuration = this.meter.createGauge(Metrics.PROVER_NODE_BLOB_PROCESSING_LAST_DURATION);
|
|
46
|
+
this.chonkVerifierDuration = this.meter.createGauge(Metrics.PROVER_NODE_CHONK_VERIFIER_LAST_DURATION);
|
|
47
|
+
this.blockProcessingDuration = this.meter.createHistogram(Metrics.PROVER_NODE_BLOCK_PROCESSING_DURATION);
|
|
48
|
+
this.checkpointProcessingDuration = this.meter.createHistogram(Metrics.PROVER_NODE_CHECKPOINT_PROCESSING_DURATION);
|
|
49
|
+
this.allCheckpointsProcessingDuration = this.meter.createGauge(
|
|
50
|
+
Metrics.PROVER_NODE_ALL_CHECKPOINTS_PROCESSING_LAST_DURATION,
|
|
51
|
+
);
|
|
38
52
|
}
|
|
39
53
|
|
|
40
54
|
public recordProvingJob(
|
|
@@ -50,6 +64,26 @@ export class ProverNodeJobMetrics {
|
|
|
50
64
|
this.provingJobBlocks.record(Math.floor(numBlocks));
|
|
51
65
|
this.provingJobTransactions.record(Math.floor(numTxs));
|
|
52
66
|
}
|
|
67
|
+
|
|
68
|
+
public recordBlobProcessing(durationMs: number) {
|
|
69
|
+
this.blobProcessingDuration.record(Math.ceil(durationMs));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public recordChonkVerifier(durationMs: number) {
|
|
73
|
+
this.chonkVerifierDuration.record(Math.ceil(durationMs));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public recordBlockProcessing(durationMs: number) {
|
|
77
|
+
this.blockProcessingDuration.record(Math.ceil(durationMs));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public recordCheckpointProcessing(durationMs: number) {
|
|
81
|
+
this.checkpointProcessingDuration.record(Math.ceil(durationMs));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public recordAllCheckpointsProcessing(durationMs: number) {
|
|
85
|
+
this.allCheckpointsProcessingDuration.record(Math.ceil(durationMs));
|
|
86
|
+
}
|
|
53
87
|
}
|
|
54
88
|
|
|
55
89
|
export class ProverNodeRewardsMetrics {
|
|
@@ -106,6 +140,13 @@ export class ProverNodeRewardsMetrics {
|
|
|
106
140
|
};
|
|
107
141
|
}
|
|
108
142
|
|
|
143
|
+
export type EstimatedSubmitProofStats = {
|
|
144
|
+
gasLimit: bigint;
|
|
145
|
+
baseFeePerGas: bigint;
|
|
146
|
+
maxPriorityFeePerGas: bigint;
|
|
147
|
+
estimatedTotalFee: bigint;
|
|
148
|
+
};
|
|
149
|
+
|
|
109
150
|
export class ProverNodePublisherMetrics {
|
|
110
151
|
gasPrice: Histogram;
|
|
111
152
|
txCount: UpDownCounter;
|
|
@@ -117,6 +158,10 @@ export class ProverNodePublisherMetrics {
|
|
|
117
158
|
txBlobDataGasCost: Histogram;
|
|
118
159
|
txTotalFee: Histogram;
|
|
119
160
|
|
|
161
|
+
private txGasEstimated: Histogram;
|
|
162
|
+
private gasPriceEstimated: Histogram;
|
|
163
|
+
private txTotalFeeEstimated: Histogram;
|
|
164
|
+
|
|
120
165
|
private senderBalance: Gauge;
|
|
121
166
|
private meter: Meter;
|
|
122
167
|
|
|
@@ -148,6 +193,12 @@ export class ProverNodePublisherMetrics {
|
|
|
148
193
|
|
|
149
194
|
this.txTotalFee = this.meter.createHistogram(Metrics.L1_PUBLISHER_TX_TOTAL_FEE);
|
|
150
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
|
+
|
|
151
202
|
this.senderBalance = this.meter.createGauge(Metrics.L1_PUBLISHER_BALANCE);
|
|
152
203
|
}
|
|
153
204
|
|
|
@@ -162,6 +213,26 @@ export class ProverNodePublisherMetrics {
|
|
|
162
213
|
this.recordTx(durationMs, stats);
|
|
163
214
|
}
|
|
164
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
|
+
|
|
165
236
|
public recordSenderBalance(wei: bigint, senderAddress: string) {
|
|
166
237
|
const eth = parseFloat(formatEther(wei, 'wei'));
|
|
167
238
|
this.senderBalance.record(eth, {
|
|
@@ -69,9 +69,8 @@ export class EpochMonitor implements Traceable {
|
|
|
69
69
|
|
|
70
70
|
public async work() {
|
|
71
71
|
const { epochToProve, blockNumber, slotNumber } = await this.getEpochNumberToProve();
|
|
72
|
-
this.log.debug(`Epoch to prove: ${epochToProve}`, { blockNumber, slotNumber });
|
|
73
72
|
if (epochToProve === undefined) {
|
|
74
|
-
this.log.trace(`Next block to prove ${blockNumber} not yet mined`, { blockNumber });
|
|
73
|
+
this.log.trace(`Next block to prove ${blockNumber} not yet mined`, { epochToProve, blockNumber, slotNumber });
|
|
75
74
|
return;
|
|
76
75
|
}
|
|
77
76
|
if (this.latestEpochNumber !== undefined && epochToProve <= this.latestEpochNumber) {
|
|
@@ -86,20 +85,20 @@ export class EpochMonitor implements Traceable {
|
|
|
86
85
|
}
|
|
87
86
|
|
|
88
87
|
if (this.options.provingDelayMs) {
|
|
89
|
-
this.log.
|
|
88
|
+
this.log.warn(`Waiting ${this.options.provingDelayMs}ms before proving epoch ${epochToProve}`);
|
|
90
89
|
await sleep(this.options.provingDelayMs);
|
|
91
90
|
}
|
|
92
91
|
|
|
93
|
-
this.log.
|
|
92
|
+
this.log.verbose(`Epoch ${epochToProve} is ready to be proven`);
|
|
94
93
|
if (await this.handler?.handleEpochReadyToProve(epochToProve)) {
|
|
95
94
|
this.latestEpochNumber = epochToProve;
|
|
96
95
|
}
|
|
97
96
|
}
|
|
98
97
|
|
|
99
98
|
private async getEpochNumberToProve() {
|
|
100
|
-
const lastBlockProven = await this.l2BlockSource.
|
|
99
|
+
const lastBlockProven = (await this.l2BlockSource.getBlockNumber({ tag: 'proven' })) ?? BlockNumber.ZERO;
|
|
101
100
|
const firstBlockToProve = BlockNumber(lastBlockProven + 1);
|
|
102
|
-
const firstBlockHeaderToProve = await this.l2BlockSource.
|
|
101
|
+
const firstBlockHeaderToProve = (await this.l2BlockSource.getBlockData({ number: firstBlockToProve }))?.header;
|
|
103
102
|
if (!firstBlockHeaderToProve) {
|
|
104
103
|
return { epochToProve: undefined, blockNumber: firstBlockToProve };
|
|
105
104
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BatchedBlob, getEthBlobEvaluationInputs } from '@aztec/blob-lib';
|
|
2
|
-
import {
|
|
2
|
+
import { MAX_CHECKPOINTS_PER_EPOCH } from '@aztec/constants';
|
|
3
3
|
import type { RollupContract, ViemCommitteeAttestation } from '@aztec/ethereum/contracts';
|
|
4
4
|
import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
|
|
5
5
|
import { makeTuple } from '@aztec/foundation/array';
|
|
@@ -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 = {
|
|
@@ -31,7 +33,7 @@ export type L1SubmitEpochProofArgs = {
|
|
|
31
33
|
endTimestamp: Fr;
|
|
32
34
|
outHash: Fr;
|
|
33
35
|
proverId: Fr;
|
|
34
|
-
fees: Tuple<FeeRecipient, typeof
|
|
36
|
+
fees: Tuple<FeeRecipient, typeof MAX_CHECKPOINTS_PER_EPOCH>;
|
|
35
37
|
proof: Proof;
|
|
36
38
|
};
|
|
37
39
|
|
|
@@ -43,6 +45,8 @@ export class ProverNodePublisher {
|
|
|
43
45
|
|
|
44
46
|
protected rollupContract: RollupContract;
|
|
45
47
|
|
|
48
|
+
protected proofSubmissionTarget: Hex;
|
|
49
|
+
|
|
46
50
|
public readonly l1TxUtils: L1TxUtils;
|
|
47
51
|
|
|
48
52
|
constructor(
|
|
@@ -50,6 +54,7 @@ export class ProverNodePublisher {
|
|
|
50
54
|
deps: {
|
|
51
55
|
rollupContract: RollupContract;
|
|
52
56
|
l1TxUtils: L1TxUtils;
|
|
57
|
+
proofSubmissionTarget?: EthAddress;
|
|
53
58
|
telemetry?: TelemetryClient;
|
|
54
59
|
},
|
|
55
60
|
bindings?: LoggerBindings,
|
|
@@ -60,6 +65,7 @@ export class ProverNodePublisher {
|
|
|
60
65
|
this.log = createLogger('prover-node:l1-tx-publisher', bindings);
|
|
61
66
|
|
|
62
67
|
this.rollupContract = deps.rollupContract;
|
|
68
|
+
this.proofSubmissionTarget = deps.proofSubmissionTarget?.toString() ?? deps.rollupContract.address;
|
|
63
69
|
this.l1TxUtils = deps.l1TxUtils;
|
|
64
70
|
}
|
|
65
71
|
|
|
@@ -101,6 +107,11 @@ export class ProverNodePublisher {
|
|
|
101
107
|
const ctx = { epochNumber, fromCheckpoint, toCheckpoint };
|
|
102
108
|
|
|
103
109
|
if (!this.interrupted) {
|
|
110
|
+
if (!(await this.waitUntilStartBuildsOnProven(args))) {
|
|
111
|
+
this.log.verbose('Checkpoint data syncing interrupted', ctx);
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
|
|
104
115
|
const timer = new Timer();
|
|
105
116
|
// Validate epoch proof range and hashes are correct before submitting
|
|
106
117
|
await this.validateEpochProofSubmission(args);
|
|
@@ -147,6 +158,53 @@ export class ProverNodePublisher {
|
|
|
147
158
|
return false;
|
|
148
159
|
}
|
|
149
160
|
|
|
161
|
+
private async waitUntilStartBuildsOnProven(args: { epochNumber: EpochNumber; fromCheckpoint: CheckpointNumber }) {
|
|
162
|
+
const { epochNumber, fromCheckpoint } = args;
|
|
163
|
+
const provenCheckpoint = await this.getProvenCheckpoint();
|
|
164
|
+
if (this.isStartBuildingOnProven(fromCheckpoint, provenCheckpoint)) {
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const timeout = await this.getSecondsUntilProofSubmissionWindowEnd(epochNumber);
|
|
169
|
+
this.log.info(`Waiting for proven checkpoint to reach proof start`, {
|
|
170
|
+
epochNumber,
|
|
171
|
+
fromCheckpoint,
|
|
172
|
+
provenCheckpoint,
|
|
173
|
+
timeout,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
await retryUntil(
|
|
177
|
+
async () => {
|
|
178
|
+
if (this.interrupted) {
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const proven = await this.getProvenCheckpoint();
|
|
183
|
+
this.log.verbose(`Proven checkpoint is at ${proven} (waiting for ${fromCheckpoint - 1})`, { epochNumber });
|
|
184
|
+
return this.isStartBuildingOnProven(fromCheckpoint, proven) ? true : undefined;
|
|
185
|
+
},
|
|
186
|
+
`proven checkpoint to reach ${fromCheckpoint - 1}`,
|
|
187
|
+
timeout,
|
|
188
|
+
4,
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
return !this.interrupted;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
private async getProvenCheckpoint() {
|
|
195
|
+
return (await this.rollupContract.getTips()).proven;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
private isStartBuildingOnProven(fromCheckpoint: CheckpointNumber, provenCheckpoint: CheckpointNumber) {
|
|
199
|
+
return fromCheckpoint - 1 <= provenCheckpoint;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private async getSecondsUntilProofSubmissionWindowEnd(epochNumber: EpochNumber) {
|
|
203
|
+
const deadline = getProofSubmissionDeadlineTimestamp(epochNumber, await this.rollupContract.getRollupConstants());
|
|
204
|
+
const now = BigInt(Math.floor(Date.now() / 1000));
|
|
205
|
+
return Math.max(Number(deadline - now), 0.001);
|
|
206
|
+
}
|
|
207
|
+
|
|
150
208
|
private async validateEpochProofSubmission(args: {
|
|
151
209
|
fromCheckpoint: CheckpointNumber;
|
|
152
210
|
toCheckpoint: CheckpointNumber;
|
|
@@ -168,7 +226,7 @@ export class ProverNodePublisher {
|
|
|
168
226
|
// toCheckpoint can't be greater than pending
|
|
169
227
|
if (toCheckpoint > pending) {
|
|
170
228
|
throw new Error(
|
|
171
|
-
`Cannot submit epoch proof for ${fromCheckpoint}-${toCheckpoint} as
|
|
229
|
+
`Cannot submit epoch proof for ${fromCheckpoint}-${toCheckpoint} as proposed checkpoint is ${pending}`,
|
|
172
230
|
);
|
|
173
231
|
}
|
|
174
232
|
|
|
@@ -203,13 +261,85 @@ export class ProverNodePublisher {
|
|
|
203
261
|
const argsPublicInputs = [...publicInputs.toFields()];
|
|
204
262
|
|
|
205
263
|
if (!areArraysEqual(rollupPublicInputs, argsPublicInputs, (a, b) => a.equals(b))) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
264
|
+
throw await reportPublicInputsMismatch({
|
|
265
|
+
rollupPublicInputs,
|
|
266
|
+
argsPublicInputs,
|
|
267
|
+
fromCheckpoint,
|
|
268
|
+
toCheckpoint,
|
|
269
|
+
rollupContract: this.rollupContract,
|
|
270
|
+
log: this.log,
|
|
271
|
+
});
|
|
210
272
|
}
|
|
211
273
|
}
|
|
212
274
|
|
|
275
|
+
/**
|
|
276
|
+
* Estimates what submitting the epoch proof would have cost on L1 without actually sending it.
|
|
277
|
+
* Runs the same validation as `submitEpochProof`, encodes the calldata, estimates gas, and records metrics.
|
|
278
|
+
* Used when proof publishing is disabled (e.g. PROVER_NODE_DISABLE_PROOF_PUBLISH=true on mainnet).
|
|
279
|
+
*/
|
|
280
|
+
public async analyzeEpochProofSubmission(args: {
|
|
281
|
+
epochNumber: EpochNumber;
|
|
282
|
+
fromCheckpoint: CheckpointNumber;
|
|
283
|
+
toCheckpoint: CheckpointNumber;
|
|
284
|
+
publicInputs: RootRollupPublicInputs;
|
|
285
|
+
proof: Proof;
|
|
286
|
+
batchedBlobInputs: BatchedBlob;
|
|
287
|
+
attestations: ViemCommitteeAttestation[];
|
|
288
|
+
}): Promise<void> {
|
|
289
|
+
const { epochNumber, fromCheckpoint, toCheckpoint } = args;
|
|
290
|
+
|
|
291
|
+
await this.validateEpochProofSubmission(args);
|
|
292
|
+
|
|
293
|
+
const data = this.encodeSubmitEpochProofCalldata(args);
|
|
294
|
+
const senderAddress = this.l1TxUtils.getSenderAddress();
|
|
295
|
+
|
|
296
|
+
const [gasLimit, gasPrice, latestBlock] = await Promise.all([
|
|
297
|
+
this.l1TxUtils.estimateGas(senderAddress.toString() as `0x${string}`, { to: this.proofSubmissionTarget, data }),
|
|
298
|
+
this.l1TxUtils.getGasPrice(),
|
|
299
|
+
this.l1TxUtils.client.getBlock({ blockTag: 'latest' }),
|
|
300
|
+
]);
|
|
301
|
+
|
|
302
|
+
const baseFeePerGas = latestBlock.baseFeePerGas ?? 0n;
|
|
303
|
+
const { maxPriorityFeePerGas } = gasPrice;
|
|
304
|
+
|
|
305
|
+
const effectiveFeePerGas = baseFeePerGas + maxPriorityFeePerGas;
|
|
306
|
+
const estimatedTotalFee = gasLimit * effectiveFeePerGas;
|
|
307
|
+
|
|
308
|
+
const stats: EstimatedSubmitProofStats = {
|
|
309
|
+
gasLimit,
|
|
310
|
+
baseFeePerGas,
|
|
311
|
+
maxPriorityFeePerGas,
|
|
312
|
+
estimatedTotalFee,
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
this.log.info(`Estimated epoch proof submission cost (not submitted)`, {
|
|
316
|
+
epochNumber,
|
|
317
|
+
fromCheckpoint,
|
|
318
|
+
toCheckpoint,
|
|
319
|
+
gasLimit: gasLimit.toString(),
|
|
320
|
+
baseFeePerGas: formatGwei(baseFeePerGas),
|
|
321
|
+
maxPriorityFeePerGas: formatGwei(maxPriorityFeePerGas),
|
|
322
|
+
estimatedTotalFeeEth: formatEther(estimatedTotalFee),
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
this.metrics.recordEstimatedSubmitProof(stats);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
private encodeSubmitEpochProofCalldata(args: {
|
|
329
|
+
fromCheckpoint: CheckpointNumber;
|
|
330
|
+
toCheckpoint: CheckpointNumber;
|
|
331
|
+
publicInputs: RootRollupPublicInputs;
|
|
332
|
+
proof: Proof;
|
|
333
|
+
batchedBlobInputs: BatchedBlob;
|
|
334
|
+
attestations: ViemCommitteeAttestation[];
|
|
335
|
+
}): Hex {
|
|
336
|
+
return encodeFunctionData({
|
|
337
|
+
abi: RollupAbi,
|
|
338
|
+
functionName: 'submitEpochRootProof',
|
|
339
|
+
args: [this.getSubmitEpochProofArgs(args)],
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
|
|
213
343
|
private async sendSubmitEpochProofTx(args: {
|
|
214
344
|
fromCheckpoint: CheckpointNumber;
|
|
215
345
|
toCheckpoint: CheckpointNumber;
|
|
@@ -231,7 +361,7 @@ export class ProverNodePublisher {
|
|
|
231
361
|
args: txArgs,
|
|
232
362
|
});
|
|
233
363
|
try {
|
|
234
|
-
const { receipt } = await this.l1TxUtils.sendAndMonitorTransaction({ to: this.
|
|
364
|
+
const { receipt } = await this.l1TxUtils.sendAndMonitorTransaction({ to: this.proofSubmissionTarget, data });
|
|
235
365
|
if (receipt.status !== 'success') {
|
|
236
366
|
const errorMsg = await this.l1TxUtils.tryGetErrorFromRevertedTx(
|
|
237
367
|
data,
|
|
@@ -239,7 +369,7 @@ export class ProverNodePublisher {
|
|
|
239
369
|
args: [...txArgs],
|
|
240
370
|
functionName: 'submitEpochRootProof',
|
|
241
371
|
abi: RollupAbi,
|
|
242
|
-
address: this.
|
|
372
|
+
address: this.proofSubmissionTarget,
|
|
243
373
|
},
|
|
244
374
|
/*blobInputs*/ undefined,
|
|
245
375
|
/*stateOverride*/ [],
|
|
@@ -271,7 +401,7 @@ export class ProverNodePublisher {
|
|
|
271
401
|
outHash: args.publicInputs.outHash.toString(),
|
|
272
402
|
proverId: EthAddress.fromField(args.publicInputs.constants.proverId).toString(),
|
|
273
403
|
} /*_args*/,
|
|
274
|
-
makeTuple(
|
|
404
|
+
makeTuple(MAX_CHECKPOINTS_PER_EPOCH * 2, i =>
|
|
275
405
|
i % 2 === 0
|
|
276
406
|
? args.publicInputs.fees[i / 2].recipient.toField().toString()
|
|
277
407
|
: args.publicInputs.fees[(i - 1) / 2].value.toString(),
|
|
@@ -296,11 +426,108 @@ export class ProverNodePublisher {
|
|
|
296
426
|
end: argsArray[1],
|
|
297
427
|
args: argsArray[2],
|
|
298
428
|
fees: argsArray[3],
|
|
299
|
-
attestations:
|
|
429
|
+
attestations: CommitteeAttestationsAndSigners.packAttestations(
|
|
300
430
|
args.attestations.map(a => CommitteeAttestation.fromViem(a)),
|
|
301
|
-
)
|
|
431
|
+
),
|
|
302
432
|
blobInputs: argsArray[4],
|
|
303
433
|
proof: proofHex,
|
|
304
434
|
};
|
|
305
435
|
}
|
|
306
436
|
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Decodes a `Root rollup public inputs mismatch`, fetches the on-chain CheckpointLog for any
|
|
440
|
+
* mismatching `checkpointHeaderHashes[i]`, emits a structured error log, and returns a thrown-ready
|
|
441
|
+
* Error with a human-readable summary.
|
|
442
|
+
*
|
|
443
|
+
* Layout of `RootRollupPublicInputs.toFields()`:
|
|
444
|
+
* [0] previousArchiveRoot
|
|
445
|
+
* [1] endArchiveRoot
|
|
446
|
+
* [2] outHash
|
|
447
|
+
* [3 .. 3+N-1] checkpointHeaderHashes[i] for i in 0..N-1 (N = MAX_CHECKPOINTS_PER_EPOCH)
|
|
448
|
+
* [3+N .. 3+3N-1] fees[i] = (recipient, value) for i in 0..N-1
|
|
449
|
+
* [3+3N .. 3+3N+4] EpochConstantData (chainId, version, vkTreeRoot, protocolContractsHash, proverId)
|
|
450
|
+
* [3+3N+5 ..] blobPublicInputs (FinalBlobAccumulator)
|
|
451
|
+
*/
|
|
452
|
+
async function reportPublicInputsMismatch(input: {
|
|
453
|
+
rollupPublicInputs: readonly Fr[];
|
|
454
|
+
argsPublicInputs: readonly Fr[];
|
|
455
|
+
fromCheckpoint: CheckpointNumber;
|
|
456
|
+
toCheckpoint: CheckpointNumber;
|
|
457
|
+
rollupContract: RollupContract;
|
|
458
|
+
log: Logger;
|
|
459
|
+
}): Promise<Error> {
|
|
460
|
+
const { rollupPublicInputs, argsPublicInputs, fromCheckpoint, toCheckpoint, rollupContract, log } = input;
|
|
461
|
+
const N = MAX_CHECKPOINTS_PER_EPOCH;
|
|
462
|
+
const constantsStart = 3 + 3 * N;
|
|
463
|
+
const blobStart = constantsStart + 5;
|
|
464
|
+
const constantLabels = ['chainId', 'version', 'vkTreeRoot', 'protocolContractsHash', 'proverId'];
|
|
465
|
+
|
|
466
|
+
const diffs: { index: number; label: string; rollup: Fr; computed: Fr; checkpointIndex?: number }[] = [];
|
|
467
|
+
const len = Math.max(rollupPublicInputs.length, argsPublicInputs.length);
|
|
468
|
+
for (let i = 0; i < len; i++) {
|
|
469
|
+
const a = rollupPublicInputs[i] ?? Fr.ZERO;
|
|
470
|
+
const b = argsPublicInputs[i] ?? Fr.ZERO;
|
|
471
|
+
if (a.equals(b)) {
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
let label: string;
|
|
475
|
+
let checkpointIndex: number | undefined;
|
|
476
|
+
if (i === 0) {
|
|
477
|
+
label = 'previousArchiveRoot';
|
|
478
|
+
} else if (i === 1) {
|
|
479
|
+
label = 'endArchiveRoot';
|
|
480
|
+
} else if (i === 2) {
|
|
481
|
+
label = 'outHash';
|
|
482
|
+
} else if (i < 3 + N) {
|
|
483
|
+
checkpointIndex = i - 3;
|
|
484
|
+
label = `checkpointHeaderHashes[${checkpointIndex}]`;
|
|
485
|
+
} else if (i < 3 + 3 * N) {
|
|
486
|
+
const feePairIndex = i - (3 + N);
|
|
487
|
+
const feeIndex = Math.floor(feePairIndex / 2);
|
|
488
|
+
const sub = feePairIndex % 2 === 0 ? 'recipient' : 'value';
|
|
489
|
+
label = `fees[${feeIndex}].${sub}`;
|
|
490
|
+
} else if (i < blobStart) {
|
|
491
|
+
label = `constants.${constantLabels[i - constantsStart]}`;
|
|
492
|
+
} else {
|
|
493
|
+
label = `blobPublicInputs[${i - blobStart}]`;
|
|
494
|
+
}
|
|
495
|
+
diffs.push({ index: i, label, rollup: a, computed: b, checkpointIndex });
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// For each mismatching checkpointHeaderHash, fetch the L1 CheckpointLog so the operator can
|
|
499
|
+
// see what was published on-chain alongside the prover's recomputed hash.
|
|
500
|
+
const onChainCheckpoints = await Promise.all(
|
|
501
|
+
diffs
|
|
502
|
+
.filter(d => d.checkpointIndex !== undefined)
|
|
503
|
+
.map(async d => {
|
|
504
|
+
const checkpointNumber = CheckpointNumber(fromCheckpoint + d.checkpointIndex!);
|
|
505
|
+
try {
|
|
506
|
+
const cp = await rollupContract.getCheckpoint(checkpointNumber);
|
|
507
|
+
return { checkpointIndex: d.checkpointIndex!, checkpointNumber, headerHash: cp.headerHash.toString() };
|
|
508
|
+
} catch (err) {
|
|
509
|
+
return { checkpointIndex: d.checkpointIndex!, checkpointNumber, error: (err as Error).message };
|
|
510
|
+
}
|
|
511
|
+
}),
|
|
512
|
+
);
|
|
513
|
+
|
|
514
|
+
log.error(`Root rollup public inputs mismatch`, undefined, {
|
|
515
|
+
fromCheckpoint,
|
|
516
|
+
toCheckpoint,
|
|
517
|
+
numDiffs: diffs.length,
|
|
518
|
+
diffs: diffs.map(d => ({
|
|
519
|
+
index: d.index,
|
|
520
|
+
label: d.label,
|
|
521
|
+
rollup: d.rollup.toString(),
|
|
522
|
+
computed: d.computed.toString(),
|
|
523
|
+
})),
|
|
524
|
+
onChainCheckpoints,
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
const fmt = (inputs: readonly Fr[]) => inputs.map(x => x.toString()).join(', ');
|
|
528
|
+
const summary = diffs.map(d => `[${d.index} ${d.label}] L1=${d.rollup} prover=${d.computed}`).join('\n');
|
|
529
|
+
return new Error(
|
|
530
|
+
`Root rollup public inputs mismatch (${diffs.length} fields differ):\n${summary}\n` +
|
|
531
|
+
`Rollup: ${fmt(rollupPublicInputs)}\nComputed:${fmt(argsPublicInputs)}`,
|
|
532
|
+
);
|
|
533
|
+
}
|