@aztec/prover-node 0.0.1-commit.2ed92850 → 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 +7 -2
- package/dest/job/epoch-proving-job.d.ts.map +1 -1
- package/dest/job/epoch-proving-job.js +212 -38
- package/dest/metrics.d.ts +21 -1
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +58 -3
- 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 +28 -5
- package/dest/prover-node-publisher.d.ts.map +1 -1
- package/dest/prover-node-publisher.js +209 -11
- package/dest/prover-node.d.ts +24 -14
- package/dest/prover-node.d.ts.map +1 -1
- package/dest/prover-node.js +93 -43
- package/dest/prover-publisher-factory.d.ts +9 -5
- package/dest/prover-publisher-factory.d.ts.map +1 -1
- package/dest/prover-publisher-factory.js +8 -5
- package/package.json +23 -22
- package/src/actions/download-epoch-proving-job.ts +1 -1
- package/src/actions/rerun-epoch-proving-job.ts +18 -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 +145 -44
- package/src/metrics.ts +77 -2
- package/src/monitors/epoch-monitor.ts +5 -6
- package/src/prover-node-publisher.ts +245 -16
- package/src/prover-node.ts +100 -55
- package/src/prover-publisher-factory.ts +19 -10
package/src/metrics.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
type TelemetryClient,
|
|
14
14
|
type Tracer,
|
|
15
15
|
type UpDownCounter,
|
|
16
|
+
createUpDownCounterWithDefault,
|
|
16
17
|
} from '@aztec/telemetry-client';
|
|
17
18
|
|
|
18
19
|
import { formatEther, formatUnits } from 'viem';
|
|
@@ -24,6 +25,12 @@ export class ProverNodeJobMetrics {
|
|
|
24
25
|
provingJobBlocks: Gauge;
|
|
25
26
|
provingJobTransactions: Gauge;
|
|
26
27
|
|
|
28
|
+
private blobProcessingDuration: Gauge;
|
|
29
|
+
private chonkVerifierDuration: Gauge;
|
|
30
|
+
private blockProcessingDuration: Histogram;
|
|
31
|
+
private checkpointProcessingDuration: Histogram;
|
|
32
|
+
private allCheckpointsProcessingDuration: Gauge;
|
|
33
|
+
|
|
27
34
|
constructor(
|
|
28
35
|
private meter: Meter,
|
|
29
36
|
public readonly tracer: Tracer,
|
|
@@ -34,6 +41,14 @@ export class ProverNodeJobMetrics {
|
|
|
34
41
|
this.provingJobCheckpoints = this.meter.createGauge(Metrics.PROVER_NODE_JOB_CHECKPOINTS);
|
|
35
42
|
this.provingJobBlocks = this.meter.createGauge(Metrics.PROVER_NODE_JOB_BLOCKS);
|
|
36
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
|
+
);
|
|
37
52
|
}
|
|
38
53
|
|
|
39
54
|
public recordProvingJob(
|
|
@@ -49,6 +64,26 @@ export class ProverNodeJobMetrics {
|
|
|
49
64
|
this.provingJobBlocks.record(Math.floor(numBlocks));
|
|
50
65
|
this.provingJobTransactions.record(Math.floor(numTxs));
|
|
51
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
|
+
}
|
|
52
87
|
}
|
|
53
88
|
|
|
54
89
|
export class ProverNodeRewardsMetrics {
|
|
@@ -65,7 +100,7 @@ export class ProverNodeRewardsMetrics {
|
|
|
65
100
|
) {
|
|
66
101
|
this.rewards = this.meter.createObservableGauge(Metrics.PROVER_NODE_REWARDS_PER_EPOCH);
|
|
67
102
|
|
|
68
|
-
this.accumulatedRewards = this.meter
|
|
103
|
+
this.accumulatedRewards = createUpDownCounterWithDefault(this.meter, Metrics.PROVER_NODE_REWARDS_TOTAL);
|
|
69
104
|
}
|
|
70
105
|
|
|
71
106
|
public async start() {
|
|
@@ -105,6 +140,13 @@ export class ProverNodeRewardsMetrics {
|
|
|
105
140
|
};
|
|
106
141
|
}
|
|
107
142
|
|
|
143
|
+
export type EstimatedSubmitProofStats = {
|
|
144
|
+
gasLimit: bigint;
|
|
145
|
+
baseFeePerGas: bigint;
|
|
146
|
+
maxPriorityFeePerGas: bigint;
|
|
147
|
+
estimatedTotalFee: bigint;
|
|
148
|
+
};
|
|
149
|
+
|
|
108
150
|
export class ProverNodePublisherMetrics {
|
|
109
151
|
gasPrice: Histogram;
|
|
110
152
|
txCount: UpDownCounter;
|
|
@@ -116,6 +158,10 @@ export class ProverNodePublisherMetrics {
|
|
|
116
158
|
txBlobDataGasCost: Histogram;
|
|
117
159
|
txTotalFee: Histogram;
|
|
118
160
|
|
|
161
|
+
private txGasEstimated: Histogram;
|
|
162
|
+
private gasPriceEstimated: Histogram;
|
|
163
|
+
private txTotalFeeEstimated: Histogram;
|
|
164
|
+
|
|
119
165
|
private senderBalance: Gauge;
|
|
120
166
|
private meter: Meter;
|
|
121
167
|
|
|
@@ -128,7 +174,10 @@ export class ProverNodePublisherMetrics {
|
|
|
128
174
|
|
|
129
175
|
this.gasPrice = this.meter.createHistogram(Metrics.L1_PUBLISHER_GAS_PRICE);
|
|
130
176
|
|
|
131
|
-
this.txCount = this.meter
|
|
177
|
+
this.txCount = createUpDownCounterWithDefault(this.meter, Metrics.L1_PUBLISHER_TX_COUNT, {
|
|
178
|
+
[Attributes.L1_TX_TYPE]: ['submitProof'],
|
|
179
|
+
[Attributes.OK]: [true, false],
|
|
180
|
+
});
|
|
132
181
|
|
|
133
182
|
this.txDuration = this.meter.createHistogram(Metrics.L1_PUBLISHER_TX_DURATION);
|
|
134
183
|
|
|
@@ -144,6 +193,12 @@ export class ProverNodePublisherMetrics {
|
|
|
144
193
|
|
|
145
194
|
this.txTotalFee = this.meter.createHistogram(Metrics.L1_PUBLISHER_TX_TOTAL_FEE);
|
|
146
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
|
+
|
|
147
202
|
this.senderBalance = this.meter.createGauge(Metrics.L1_PUBLISHER_BALANCE);
|
|
148
203
|
}
|
|
149
204
|
|
|
@@ -158,6 +213,26 @@ export class ProverNodePublisherMetrics {
|
|
|
158
213
|
this.recordTx(durationMs, stats);
|
|
159
214
|
}
|
|
160
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
|
+
|
|
161
236
|
public recordSenderBalance(wei: bigint, senderAddress: string) {
|
|
162
237
|
const eth = parseFloat(formatEther(wei, 'wei'));
|
|
163
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';
|
|
@@ -7,21 +7,23 @@ import { CheckpointNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
|
7
7
|
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
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
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
|
|
|
@@ -39,10 +41,12 @@ export class ProverNodePublisher {
|
|
|
39
41
|
private interrupted = false;
|
|
40
42
|
private metrics: ProverNodePublisherMetrics;
|
|
41
43
|
|
|
42
|
-
protected log
|
|
44
|
+
protected log: Logger;
|
|
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,14 +54,18 @@ export class ProverNodePublisher {
|
|
|
50
54
|
deps: {
|
|
51
55
|
rollupContract: RollupContract;
|
|
52
56
|
l1TxUtils: L1TxUtils;
|
|
57
|
+
proofSubmissionTarget?: EthAddress;
|
|
53
58
|
telemetry?: TelemetryClient;
|
|
54
59
|
},
|
|
60
|
+
bindings?: LoggerBindings,
|
|
55
61
|
) {
|
|
56
62
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
57
63
|
|
|
58
64
|
this.metrics = new ProverNodePublisherMetrics(telemetry, 'ProverNode');
|
|
65
|
+
this.log = createLogger('prover-node:l1-tx-publisher', bindings);
|
|
59
66
|
|
|
60
67
|
this.rollupContract = deps.rollupContract;
|
|
68
|
+
this.proofSubmissionTarget = deps.proofSubmissionTarget?.toString() ?? deps.rollupContract.address;
|
|
61
69
|
this.l1TxUtils = deps.l1TxUtils;
|
|
62
70
|
}
|
|
63
71
|
|
|
@@ -99,6 +107,11 @@ export class ProverNodePublisher {
|
|
|
99
107
|
const ctx = { epochNumber, fromCheckpoint, toCheckpoint };
|
|
100
108
|
|
|
101
109
|
if (!this.interrupted) {
|
|
110
|
+
if (!(await this.waitUntilStartBuildsOnProven(args))) {
|
|
111
|
+
this.log.verbose('Checkpoint data syncing interrupted', ctx);
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
|
|
102
115
|
const timer = new Timer();
|
|
103
116
|
// Validate epoch proof range and hashes are correct before submitting
|
|
104
117
|
await this.validateEpochProofSubmission(args);
|
|
@@ -145,6 +158,53 @@ export class ProverNodePublisher {
|
|
|
145
158
|
return false;
|
|
146
159
|
}
|
|
147
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
|
+
|
|
148
208
|
private async validateEpochProofSubmission(args: {
|
|
149
209
|
fromCheckpoint: CheckpointNumber;
|
|
150
210
|
toCheckpoint: CheckpointNumber;
|
|
@@ -166,7 +226,7 @@ export class ProverNodePublisher {
|
|
|
166
226
|
// toCheckpoint can't be greater than pending
|
|
167
227
|
if (toCheckpoint > pending) {
|
|
168
228
|
throw new Error(
|
|
169
|
-
`Cannot submit epoch proof for ${fromCheckpoint}-${toCheckpoint} as
|
|
229
|
+
`Cannot submit epoch proof for ${fromCheckpoint}-${toCheckpoint} as proposed checkpoint is ${pending}`,
|
|
170
230
|
);
|
|
171
231
|
}
|
|
172
232
|
|
|
@@ -201,13 +261,85 @@ export class ProverNodePublisher {
|
|
|
201
261
|
const argsPublicInputs = [...publicInputs.toFields()];
|
|
202
262
|
|
|
203
263
|
if (!areArraysEqual(rollupPublicInputs, argsPublicInputs, (a, b) => a.equals(b))) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
264
|
+
throw await reportPublicInputsMismatch({
|
|
265
|
+
rollupPublicInputs,
|
|
266
|
+
argsPublicInputs,
|
|
267
|
+
fromCheckpoint,
|
|
268
|
+
toCheckpoint,
|
|
269
|
+
rollupContract: this.rollupContract,
|
|
270
|
+
log: this.log,
|
|
271
|
+
});
|
|
208
272
|
}
|
|
209
273
|
}
|
|
210
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
|
+
|
|
211
343
|
private async sendSubmitEpochProofTx(args: {
|
|
212
344
|
fromCheckpoint: CheckpointNumber;
|
|
213
345
|
toCheckpoint: CheckpointNumber;
|
|
@@ -229,7 +361,7 @@ export class ProverNodePublisher {
|
|
|
229
361
|
args: txArgs,
|
|
230
362
|
});
|
|
231
363
|
try {
|
|
232
|
-
const { receipt } = await this.l1TxUtils.sendAndMonitorTransaction({ to: this.
|
|
364
|
+
const { receipt } = await this.l1TxUtils.sendAndMonitorTransaction({ to: this.proofSubmissionTarget, data });
|
|
233
365
|
if (receipt.status !== 'success') {
|
|
234
366
|
const errorMsg = await this.l1TxUtils.tryGetErrorFromRevertedTx(
|
|
235
367
|
data,
|
|
@@ -237,7 +369,7 @@ export class ProverNodePublisher {
|
|
|
237
369
|
args: [...txArgs],
|
|
238
370
|
functionName: 'submitEpochRootProof',
|
|
239
371
|
abi: RollupAbi,
|
|
240
|
-
address: this.
|
|
372
|
+
address: this.proofSubmissionTarget,
|
|
241
373
|
},
|
|
242
374
|
/*blobInputs*/ undefined,
|
|
243
375
|
/*stateOverride*/ [],
|
|
@@ -269,7 +401,7 @@ export class ProverNodePublisher {
|
|
|
269
401
|
outHash: args.publicInputs.outHash.toString(),
|
|
270
402
|
proverId: EthAddress.fromField(args.publicInputs.constants.proverId).toString(),
|
|
271
403
|
} /*_args*/,
|
|
272
|
-
makeTuple(
|
|
404
|
+
makeTuple(MAX_CHECKPOINTS_PER_EPOCH * 2, i =>
|
|
273
405
|
i % 2 === 0
|
|
274
406
|
? args.publicInputs.fees[i / 2].recipient.toField().toString()
|
|
275
407
|
: args.publicInputs.fees[(i - 1) / 2].value.toString(),
|
|
@@ -294,11 +426,108 @@ export class ProverNodePublisher {
|
|
|
294
426
|
end: argsArray[1],
|
|
295
427
|
args: argsArray[2],
|
|
296
428
|
fees: argsArray[3],
|
|
297
|
-
attestations:
|
|
429
|
+
attestations: CommitteeAttestationsAndSigners.packAttestations(
|
|
298
430
|
args.attestations.map(a => CommitteeAttestation.fromViem(a)),
|
|
299
|
-
)
|
|
431
|
+
),
|
|
300
432
|
blobInputs: argsArray[4],
|
|
301
433
|
proof: proofHex,
|
|
302
434
|
};
|
|
303
435
|
}
|
|
304
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
|
+
}
|