@aztec/prover-node 0.0.1-commit.b655e406 → 0.0.1-commit.d1f2d6c
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.d.ts +4 -4
- package/dest/actions/index.d.ts +1 -1
- package/dest/actions/rerun-epoch-proving-job.d.ts +3 -2
- package/dest/actions/rerun-epoch-proving-job.d.ts.map +1 -1
- package/dest/actions/rerun-epoch-proving-job.js +3 -1
- package/dest/actions/upload-epoch-proof-failure.d.ts +1 -1
- package/dest/bin/run-failed-epoch.d.ts +1 -1
- package/dest/config.d.ts +5 -4
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +4 -3
- package/dest/factory.d.ts +2 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +20 -15
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/job/epoch-proving-job-data.d.ts +8 -6
- package/dest/job/epoch-proving-job-data.d.ts.map +1 -1
- package/dest/job/epoch-proving-job-data.js +25 -18
- package/dest/job/epoch-proving-job.d.ts +5 -12
- package/dest/job/epoch-proving-job.d.ts.map +1 -1
- package/dest/job/epoch-proving-job.js +481 -97
- package/dest/metrics.d.ts +4 -3
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +22 -98
- package/dest/monitors/epoch-monitor.d.ts +3 -2
- package/dest/monitors/epoch-monitor.d.ts.map +1 -1
- package/dest/monitors/epoch-monitor.js +3 -11
- package/dest/monitors/index.d.ts +1 -1
- package/dest/prover-node-publisher.d.ts +9 -7
- package/dest/prover-node-publisher.d.ts.map +1 -1
- package/dest/prover-node-publisher.js +44 -38
- package/dest/prover-node.d.ts +9 -8
- package/dest/prover-node.d.ts.map +1 -1
- package/dest/prover-node.js +430 -49
- package/dest/prover-publisher-factory.d.ts +4 -2
- package/dest/prover-publisher-factory.d.ts.map +1 -1
- package/dest/test/index.d.ts +1 -1
- package/dest/test/index.d.ts.map +1 -1
- package/package.json +26 -25
- package/src/actions/rerun-epoch-proving-job.ts +3 -2
- package/src/bin/run-failed-epoch.ts +1 -1
- package/src/config.ts +6 -4
- package/src/factory.ts +30 -17
- package/src/index.ts +1 -0
- package/src/job/epoch-proving-job-data.ts +31 -25
- package/src/job/epoch-proving-job.ts +107 -97
- package/src/metrics.ts +28 -83
- package/src/monitors/epoch-monitor.ts +5 -11
- package/src/prover-node-publisher.ts +64 -53
- package/src/prover-node.ts +47 -43
- package/src/prover-publisher-factory.ts +3 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
2
2
|
import { asyncPool } from '@aztec/foundation/async-pool';
|
|
3
|
+
import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
3
4
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
4
|
-
import { Fr } from '@aztec/foundation/
|
|
5
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
6
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
7
|
import { RunningPromise, promiseWithResolvers } from '@aztec/foundation/promise';
|
|
7
8
|
import { Timer } from '@aztec/foundation/timer';
|
|
@@ -9,7 +10,9 @@ import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
|
9
10
|
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
10
11
|
import { buildFinalBlobChallenges } from '@aztec/prover-client/helpers';
|
|
11
12
|
import type { PublicProcessor, PublicProcessorFactory } from '@aztec/simulator/server';
|
|
13
|
+
import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
12
14
|
import type { L2Block, L2BlockSource } from '@aztec/stdlib/block';
|
|
15
|
+
import type { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
13
16
|
import {
|
|
14
17
|
type EpochProver,
|
|
15
18
|
type EpochProvingJobState,
|
|
@@ -73,7 +76,7 @@ export class EpochProvingJob implements Traceable {
|
|
|
73
76
|
return this.state;
|
|
74
77
|
}
|
|
75
78
|
|
|
76
|
-
public getEpochNumber():
|
|
79
|
+
public getEpochNumber(): EpochNumber {
|
|
77
80
|
return this.data.epochNumber;
|
|
78
81
|
}
|
|
79
82
|
|
|
@@ -89,8 +92,8 @@ export class EpochProvingJob implements Traceable {
|
|
|
89
92
|
return this.data.epochNumber;
|
|
90
93
|
}
|
|
91
94
|
|
|
92
|
-
private get
|
|
93
|
-
return this.data.
|
|
95
|
+
private get checkpoints() {
|
|
96
|
+
return this.data.checkpoints;
|
|
94
97
|
}
|
|
95
98
|
|
|
96
99
|
private get txs() {
|
|
@@ -105,7 +108,7 @@ export class EpochProvingJob implements Traceable {
|
|
|
105
108
|
* Proves the given epoch and submits the proof to L1.
|
|
106
109
|
*/
|
|
107
110
|
@trackSpan('EpochProvingJob.run', function () {
|
|
108
|
-
return { [Attributes.EPOCH_NUMBER]:
|
|
111
|
+
return { [Attributes.EPOCH_NUMBER]: this.data.epochNumber };
|
|
109
112
|
})
|
|
110
113
|
public async run() {
|
|
111
114
|
this.scheduleDeadlineStop();
|
|
@@ -114,14 +117,22 @@ export class EpochProvingJob implements Traceable {
|
|
|
114
117
|
}
|
|
115
118
|
|
|
116
119
|
const attestations = this.attestations.map(attestation => attestation.toViem());
|
|
117
|
-
const epochNumber =
|
|
118
|
-
const
|
|
119
|
-
const
|
|
120
|
-
const
|
|
121
|
-
|
|
120
|
+
const epochNumber = this.epochNumber;
|
|
121
|
+
const epochSizeCheckpoints = this.checkpoints.length;
|
|
122
|
+
const epochSizeBlocks = this.checkpoints.reduce((accum, checkpoint) => accum + checkpoint.blocks.length, 0);
|
|
123
|
+
const epochSizeTxs = this.checkpoints.reduce(
|
|
124
|
+
(accum, checkpoint) =>
|
|
125
|
+
accum + checkpoint.blocks.reduce((accumC, block) => accumC + block.body.txEffects.length, 0),
|
|
126
|
+
0,
|
|
127
|
+
);
|
|
128
|
+
const fromCheckpoint = this.checkpoints[0].number;
|
|
129
|
+
const toCheckpoint = this.checkpoints.at(-1)!.number;
|
|
130
|
+
const fromBlock = this.checkpoints[0].blocks[0].number;
|
|
131
|
+
const toBlock = this.checkpoints.at(-1)!.blocks.at(-1)!.number;
|
|
132
|
+
this.log.info(`Starting epoch ${epochNumber} proving job with checkpoints ${fromCheckpoint} to ${toCheckpoint}`, {
|
|
122
133
|
fromBlock,
|
|
123
134
|
toBlock,
|
|
124
|
-
|
|
135
|
+
epochSizeTxs,
|
|
125
136
|
epochNumber,
|
|
126
137
|
uuid: this.uuid,
|
|
127
138
|
});
|
|
@@ -132,83 +143,93 @@ export class EpochProvingJob implements Traceable {
|
|
|
132
143
|
this.runPromise = promise;
|
|
133
144
|
|
|
134
145
|
try {
|
|
135
|
-
const blobFieldsPerCheckpoint = this.
|
|
146
|
+
const blobFieldsPerCheckpoint = this.checkpoints.map(checkpoint => checkpoint.toBlobFields());
|
|
136
147
|
const finalBlobBatchingChallenges = await buildFinalBlobChallenges(blobFieldsPerCheckpoint);
|
|
137
148
|
|
|
138
|
-
|
|
139
|
-
// Total number of checkpoints equals number of blocks because we currently build a checkpoint with only one block.
|
|
140
|
-
const totalNumCheckpoints = epochSizeBlocks;
|
|
141
|
-
|
|
142
|
-
this.prover.startNewEpoch(epochNumber, totalNumCheckpoints, finalBlobBatchingChallenges);
|
|
149
|
+
this.prover.startNewEpoch(epochNumber, epochSizeCheckpoints, finalBlobBatchingChallenges);
|
|
143
150
|
await this.prover.startChonkVerifierCircuits(Array.from(this.txs.values()));
|
|
144
151
|
|
|
145
|
-
|
|
146
|
-
|
|
152
|
+
// Everything in the epoch should have the same chainId and version.
|
|
153
|
+
const { chainId, version } = this.checkpoints[0].blocks[0].header.globalVariables;
|
|
147
154
|
|
|
148
|
-
|
|
149
|
-
const txs = this.getTxs(block);
|
|
150
|
-
const l1ToL2Messages = this.getL1ToL2Messages(block);
|
|
151
|
-
const previousHeader = this.getBlockHeader(block.number - 1)!;
|
|
152
|
-
|
|
153
|
-
this.log.verbose(`Starting processing block ${block.number}`, {
|
|
154
|
-
number: block.number,
|
|
155
|
-
blockHash: (await block.hash()).toString(),
|
|
156
|
-
lastArchive: block.header.lastArchive.root,
|
|
157
|
-
noteHashTreeRoot: block.header.state.partial.noteHashTree.root,
|
|
158
|
-
nullifierTreeRoot: block.header.state.partial.nullifierTree.root,
|
|
159
|
-
publicDataTreeRoot: block.header.state.partial.publicDataTree.root,
|
|
160
|
-
previousHeader: previousHeader.hash(),
|
|
161
|
-
uuid: this.uuid,
|
|
162
|
-
...globalVariables,
|
|
163
|
-
});
|
|
155
|
+
const previousBlockHeaders = this.gatherPreviousBlockHeaders();
|
|
164
156
|
|
|
157
|
+
await asyncPool(this.config.parallelBlockLimit ?? 32, this.checkpoints, async checkpoint => {
|
|
158
|
+
this.checkState();
|
|
159
|
+
|
|
160
|
+
const checkpointIndex = checkpoint.number - fromCheckpoint;
|
|
165
161
|
const checkpointConstants = CheckpointConstantData.from({
|
|
166
|
-
chainId
|
|
167
|
-
version
|
|
162
|
+
chainId,
|
|
163
|
+
version,
|
|
168
164
|
vkTreeRoot: getVKTreeRoot(),
|
|
169
165
|
protocolContractsHash: protocolContractsHash,
|
|
170
166
|
proverId: this.prover.getProverId().toField(),
|
|
171
|
-
slotNumber:
|
|
172
|
-
coinbase:
|
|
173
|
-
feeRecipient:
|
|
174
|
-
gasFees:
|
|
167
|
+
slotNumber: checkpoint.header.slotNumber,
|
|
168
|
+
coinbase: checkpoint.header.coinbase,
|
|
169
|
+
feeRecipient: checkpoint.header.feeRecipient,
|
|
170
|
+
gasFees: checkpoint.header.gasFees,
|
|
171
|
+
});
|
|
172
|
+
const previousHeader = previousBlockHeaders[checkpointIndex];
|
|
173
|
+
const l1ToL2Messages = this.getL1ToL2Messages(checkpoint);
|
|
174
|
+
|
|
175
|
+
this.log.verbose(`Starting processing checkpoint ${checkpoint.number}`, {
|
|
176
|
+
number: checkpoint.number,
|
|
177
|
+
checkpointHash: checkpoint.hash().toString(),
|
|
178
|
+
lastArchive: checkpoint.header.lastArchiveRoot,
|
|
179
|
+
previousHeader: previousHeader.hash(),
|
|
180
|
+
uuid: this.uuid,
|
|
175
181
|
});
|
|
176
182
|
|
|
177
|
-
// TODO(#17027): Enable multiple blocks per checkpoint.
|
|
178
|
-
// Each checkpoint has only one block.
|
|
179
|
-
const totalNumBlocks = 1;
|
|
180
|
-
const checkpointIndex = block.number - fromBlock;
|
|
181
183
|
await this.prover.startNewCheckpoint(
|
|
182
184
|
checkpointIndex,
|
|
183
185
|
checkpointConstants,
|
|
184
186
|
l1ToL2Messages,
|
|
185
|
-
|
|
186
|
-
blobFieldsPerCheckpoint[checkpointIndex].length,
|
|
187
|
+
checkpoint.blocks.length,
|
|
187
188
|
previousHeader,
|
|
188
189
|
);
|
|
189
190
|
|
|
190
|
-
|
|
191
|
-
|
|
191
|
+
for (const block of checkpoint.blocks) {
|
|
192
|
+
const globalVariables = block.header.globalVariables;
|
|
193
|
+
const txs = this.getTxs(block);
|
|
194
|
+
|
|
195
|
+
this.log.verbose(`Starting processing block ${block.number}`, {
|
|
196
|
+
number: block.number,
|
|
197
|
+
blockHash: (await block.hash()).toString(),
|
|
198
|
+
lastArchive: block.header.lastArchive.root,
|
|
199
|
+
noteHashTreeRoot: block.header.state.partial.noteHashTree.root,
|
|
200
|
+
nullifierTreeRoot: block.header.state.partial.nullifierTree.root,
|
|
201
|
+
publicDataTreeRoot: block.header.state.partial.publicDataTree.root,
|
|
202
|
+
...globalVariables,
|
|
203
|
+
numTxs: txs.length,
|
|
204
|
+
});
|
|
192
205
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
206
|
+
// Start block proving
|
|
207
|
+
await this.prover.startNewBlock(block.number, globalVariables.timestamp, txs.length);
|
|
208
|
+
|
|
209
|
+
// Process public fns
|
|
210
|
+
const db = await this.createFork(BlockNumber(block.number - 1), l1ToL2Messages);
|
|
211
|
+
const config = PublicSimulatorConfig.from({
|
|
212
|
+
proverId: this.prover.getProverId().toField(),
|
|
213
|
+
skipFeeEnforcement: false,
|
|
214
|
+
collectDebugLogs: false,
|
|
215
|
+
collectHints: true,
|
|
216
|
+
collectPublicInputs: true,
|
|
217
|
+
collectStatistics: false,
|
|
218
|
+
});
|
|
219
|
+
const publicProcessor = this.publicProcessorFactory.create(db, globalVariables, config);
|
|
220
|
+
const processed = await this.processTxs(publicProcessor, txs);
|
|
221
|
+
await this.prover.addTxs(processed);
|
|
222
|
+
await db.close();
|
|
223
|
+
this.log.verbose(`Processed all ${txs.length} txs for block ${block.number}`, {
|
|
224
|
+
blockNumber: block.number,
|
|
225
|
+
blockHash: (await block.hash()).toString(),
|
|
226
|
+
uuid: this.uuid,
|
|
227
|
+
});
|
|
208
228
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
229
|
+
// Mark block as completed to pad it
|
|
230
|
+
const expectedBlockHeader = block.header;
|
|
231
|
+
await this.prover.setBlockCompleted(block.number, expectedBlockHeader);
|
|
232
|
+
}
|
|
212
233
|
});
|
|
213
234
|
|
|
214
235
|
const executionTime = timer.ms();
|
|
@@ -221,16 +242,16 @@ export class EpochProvingJob implements Traceable {
|
|
|
221
242
|
|
|
222
243
|
if (this.config.skipSubmitProof) {
|
|
223
244
|
this.log.info(
|
|
224
|
-
`Proof publishing is disabled. Dropping valid proof for epoch ${epochNumber} (
|
|
245
|
+
`Proof publishing is disabled. Dropping valid proof for epoch ${epochNumber} (checkpoints ${fromCheckpoint} to ${toCheckpoint})`,
|
|
225
246
|
);
|
|
226
247
|
this.state = 'completed';
|
|
227
|
-
this.metrics.recordProvingJob(executionTime, timer.ms(), epochSizeBlocks, epochSizeTxs);
|
|
248
|
+
this.metrics.recordProvingJob(executionTime, timer.ms(), epochSizeCheckpoints, epochSizeBlocks, epochSizeTxs);
|
|
228
249
|
return;
|
|
229
250
|
}
|
|
230
251
|
|
|
231
252
|
const success = await this.publisher.submitEpochProof({
|
|
232
|
-
|
|
233
|
-
|
|
253
|
+
fromCheckpoint,
|
|
254
|
+
toCheckpoint,
|
|
234
255
|
epochNumber,
|
|
235
256
|
publicInputs,
|
|
236
257
|
proof,
|
|
@@ -241,12 +262,12 @@ export class EpochProvingJob implements Traceable {
|
|
|
241
262
|
throw new Error('Failed to submit epoch proof to L1');
|
|
242
263
|
}
|
|
243
264
|
|
|
244
|
-
this.log.info(`Submitted proof for epoch ${epochNumber} (
|
|
265
|
+
this.log.info(`Submitted proof for epoch ${epochNumber} (checkpoints ${fromCheckpoint} to ${toCheckpoint})`, {
|
|
245
266
|
epochNumber,
|
|
246
267
|
uuid: this.uuid,
|
|
247
268
|
});
|
|
248
269
|
this.state = 'completed';
|
|
249
|
-
this.metrics.recordProvingJob(executionTime, timer.ms(), epochSizeBlocks, epochSizeTxs);
|
|
270
|
+
this.metrics.recordProvingJob(executionTime, timer.ms(), epochSizeCheckpoints, epochSizeBlocks, epochSizeTxs);
|
|
250
271
|
} catch (err: any) {
|
|
251
272
|
if (err && err.name === 'HaltExecutionError') {
|
|
252
273
|
this.log.warn(`Halted execution of epoch ${epochNumber} prover job`, {
|
|
@@ -272,7 +293,7 @@ export class EpochProvingJob implements Traceable {
|
|
|
272
293
|
* Create a new db fork for tx processing, inserting all L1 to L2.
|
|
273
294
|
* 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.
|
|
274
295
|
*/
|
|
275
|
-
private async createFork(blockNumber:
|
|
296
|
+
private async createFork(blockNumber: BlockNumber, l1ToL2Messages: Fr[]) {
|
|
276
297
|
const db = await this.dbProvider.fork(blockNumber);
|
|
277
298
|
const l1ToL2MessagesPadded = padArrayEnd<Fr, number>(
|
|
278
299
|
l1ToL2Messages,
|
|
@@ -282,7 +303,7 @@ export class EpochProvingJob implements Traceable {
|
|
|
282
303
|
);
|
|
283
304
|
this.log.verbose(`Creating fork at ${blockNumber} with ${l1ToL2Messages.length} L1 to L2 messages`, {
|
|
284
305
|
blockNumber,
|
|
285
|
-
l1ToL2Messages:
|
|
306
|
+
l1ToL2Messages: l1ToL2Messages.map(m => m.toString()),
|
|
286
307
|
});
|
|
287
308
|
await db.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
|
|
288
309
|
return db;
|
|
@@ -341,11 +362,12 @@ export class EpochProvingJob implements Traceable {
|
|
|
341
362
|
const intervalMs = Math.ceil((await l2BlockSource.getL1Constants()).ethereumSlotDuration / 2) * 1000;
|
|
342
363
|
this.epochCheckPromise = new RunningPromise(
|
|
343
364
|
async () => {
|
|
344
|
-
const
|
|
345
|
-
const blockHashes = await Promise.all(
|
|
346
|
-
const
|
|
365
|
+
const blockHeaders = await l2BlockSource.getCheckpointedBlockHeadersForEpoch(this.epochNumber);
|
|
366
|
+
const blockHashes = await Promise.all(blockHeaders.map(header => header.hash()));
|
|
367
|
+
const thisBlocks = this.checkpoints.flatMap(checkpoint => checkpoint.blocks);
|
|
368
|
+
const thisBlockHashes = await Promise.all(thisBlocks.map(block => block.hash()));
|
|
347
369
|
if (
|
|
348
|
-
|
|
370
|
+
blockHeaders.length !== thisBlocks.length ||
|
|
349
371
|
!blockHashes.every((block, i) => block.equals(thisBlockHashes[i]))
|
|
350
372
|
) {
|
|
351
373
|
this.log.warn('Epoch blocks changed underfoot', {
|
|
@@ -363,30 +385,18 @@ export class EpochProvingJob implements Traceable {
|
|
|
363
385
|
this.log.verbose(`Scheduled epoch check for epoch ${this.epochNumber} every ${intervalMs}ms`);
|
|
364
386
|
}
|
|
365
387
|
|
|
366
|
-
/* Returns the header
|
|
367
|
-
private
|
|
368
|
-
const
|
|
369
|
-
|
|
370
|
-
return block.getBlockHeader();
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
if (blockNumber === Number(this.data.previousBlockHeader.getBlockNumber())) {
|
|
374
|
-
return this.data.previousBlockHeader;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
throw new Error(
|
|
378
|
-
`Block header not found for block number ${blockNumber} (got ${this.blocks
|
|
379
|
-
.map(b => b.number)
|
|
380
|
-
.join(', ')} and previous header ${this.data.previousBlockHeader.getBlockNumber()})`,
|
|
381
|
-
);
|
|
388
|
+
/* Returns the last block header in the previous checkpoint for all checkpoints in the epoch */
|
|
389
|
+
private gatherPreviousBlockHeaders() {
|
|
390
|
+
const lastBlocks = this.checkpoints.map(checkpoint => checkpoint.blocks.at(-1)!);
|
|
391
|
+
return [this.data.previousBlockHeader, ...lastBlocks.map(block => block.header).slice(0, -1)];
|
|
382
392
|
}
|
|
383
393
|
|
|
384
394
|
private getTxs(block: L2Block): Tx[] {
|
|
385
395
|
return block.body.txEffects.map(txEffect => this.txs.get(txEffect.txHash.toString())!);
|
|
386
396
|
}
|
|
387
397
|
|
|
388
|
-
private getL1ToL2Messages(
|
|
389
|
-
return this.data.l1ToL2Messages[
|
|
398
|
+
private getL1ToL2Messages(checkpoint: Checkpoint) {
|
|
399
|
+
return this.data.l1ToL2Messages[checkpoint.number];
|
|
390
400
|
}
|
|
391
401
|
|
|
392
402
|
private async processTxs(publicProcessor: PublicProcessor, txs: Tx[]): Promise<ProcessedTx[]> {
|
package/src/metrics.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RollupContract } from '@aztec/ethereum';
|
|
1
|
+
import type { RollupContract } from '@aztec/ethereum/contracts';
|
|
2
2
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import type { L1PublishProofStats, L1PublishStats } from '@aztec/stdlib/stats';
|
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
type TelemetryClient,
|
|
14
14
|
type Tracer,
|
|
15
15
|
type UpDownCounter,
|
|
16
|
-
ValueType,
|
|
17
16
|
} from '@aztec/telemetry-client';
|
|
18
17
|
|
|
19
18
|
import { formatEther, formatUnits } from 'viem';
|
|
@@ -21,6 +20,7 @@ import { formatEther, formatUnits } from 'viem';
|
|
|
21
20
|
export class ProverNodeJobMetrics {
|
|
22
21
|
proverEpochExecutionDuration: Histogram;
|
|
23
22
|
provingJobDuration: Histogram;
|
|
23
|
+
provingJobCheckpoints: Gauge;
|
|
24
24
|
provingJobBlocks: Gauge;
|
|
25
25
|
provingJobTransactions: Gauge;
|
|
26
26
|
|
|
@@ -29,29 +29,23 @@ export class ProverNodeJobMetrics {
|
|
|
29
29
|
public readonly tracer: Tracer,
|
|
30
30
|
private logger = createLogger('prover-node:publisher:metrics'),
|
|
31
31
|
) {
|
|
32
|
-
this.proverEpochExecutionDuration = this.meter.createHistogram(Metrics.PROVER_NODE_EXECUTION_DURATION
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
this.provingJobDuration = this.meter.createHistogram(Metrics.PROVER_NODE_JOB_DURATION, {
|
|
38
|
-
description: 'Duration of proving job',
|
|
39
|
-
unit: 's',
|
|
40
|
-
valueType: ValueType.DOUBLE,
|
|
41
|
-
});
|
|
42
|
-
this.provingJobBlocks = this.meter.createGauge(Metrics.PROVER_NODE_JOB_BLOCKS, {
|
|
43
|
-
description: 'Number of blocks in a proven epoch',
|
|
44
|
-
valueType: ValueType.INT,
|
|
45
|
-
});
|
|
46
|
-
this.provingJobTransactions = this.meter.createGauge(Metrics.PROVER_NODE_JOB_TRANSACTIONS, {
|
|
47
|
-
description: 'Number of transactions in a proven epoch',
|
|
48
|
-
valueType: ValueType.INT,
|
|
49
|
-
});
|
|
32
|
+
this.proverEpochExecutionDuration = this.meter.createHistogram(Metrics.PROVER_NODE_EXECUTION_DURATION);
|
|
33
|
+
this.provingJobDuration = this.meter.createHistogram(Metrics.PROVER_NODE_JOB_DURATION);
|
|
34
|
+
this.provingJobCheckpoints = this.meter.createGauge(Metrics.PROVER_NODE_JOB_CHECKPOINTS);
|
|
35
|
+
this.provingJobBlocks = this.meter.createGauge(Metrics.PROVER_NODE_JOB_BLOCKS);
|
|
36
|
+
this.provingJobTransactions = this.meter.createGauge(Metrics.PROVER_NODE_JOB_TRANSACTIONS);
|
|
50
37
|
}
|
|
51
38
|
|
|
52
|
-
public recordProvingJob(
|
|
39
|
+
public recordProvingJob(
|
|
40
|
+
executionTimeMs: number,
|
|
41
|
+
totalTimeMs: number,
|
|
42
|
+
numCheckpoints: number,
|
|
43
|
+
numBlocks: number,
|
|
44
|
+
numTxs: number,
|
|
45
|
+
) {
|
|
53
46
|
this.proverEpochExecutionDuration.record(Math.ceil(executionTimeMs));
|
|
54
47
|
this.provingJobDuration.record(totalTimeMs / 1000);
|
|
48
|
+
this.provingJobCheckpoints.record(Math.floor(numCheckpoints));
|
|
55
49
|
this.provingJobBlocks.record(Math.floor(numBlocks));
|
|
56
50
|
this.provingJobTransactions.record(Math.floor(numTxs));
|
|
57
51
|
}
|
|
@@ -69,15 +63,9 @@ export class ProverNodeRewardsMetrics {
|
|
|
69
63
|
private rollup: RollupContract,
|
|
70
64
|
private logger = createLogger('prover-node:publisher:metrics'),
|
|
71
65
|
) {
|
|
72
|
-
this.rewards = this.meter.createObservableGauge(Metrics.PROVER_NODE_REWARDS_PER_EPOCH
|
|
73
|
-
valueType: ValueType.DOUBLE,
|
|
74
|
-
description: 'The rewards earned',
|
|
75
|
-
});
|
|
66
|
+
this.rewards = this.meter.createObservableGauge(Metrics.PROVER_NODE_REWARDS_PER_EPOCH);
|
|
76
67
|
|
|
77
|
-
this.accumulatedRewards = this.meter.createUpDownCounter(Metrics.PROVER_NODE_REWARDS_TOTAL
|
|
78
|
-
valueType: ValueType.DOUBLE,
|
|
79
|
-
description: 'The rewards earned (total)',
|
|
80
|
-
});
|
|
68
|
+
this.accumulatedRewards = this.meter.createUpDownCounter(Metrics.PROVER_NODE_REWARDS_TOTAL);
|
|
81
69
|
}
|
|
82
70
|
|
|
83
71
|
public async start() {
|
|
@@ -97,7 +85,7 @@ export class ProverNodeRewardsMetrics {
|
|
|
97
85
|
// look at the prev epoch so that we get an accurate value, after proof submission window has closed
|
|
98
86
|
// For example, if proof submission window is 1 epoch, and we are in epoch 2, we should be looking at epoch 0.
|
|
99
87
|
// Similarly, if the proof submission window is 0, and we are in epoch 1, we should be looking at epoch 0.
|
|
100
|
-
const closedEpoch = epoch - BigInt(this.proofSubmissionEpochs) - 1n;
|
|
88
|
+
const closedEpoch = BigInt(epoch) - BigInt(this.proofSubmissionEpochs) - 1n;
|
|
101
89
|
const rewards = await this.rollup.getSpecificProverRewardsForEpoch(closedEpoch, this.coinbase);
|
|
102
90
|
|
|
103
91
|
const fmt = parseFloat(formatUnits(rewards, 18));
|
|
@@ -138,68 +126,25 @@ export class ProverNodePublisherMetrics {
|
|
|
138
126
|
) {
|
|
139
127
|
this.meter = client.getMeter(name);
|
|
140
128
|
|
|
141
|
-
this.gasPrice = this.meter.createHistogram(Metrics.L1_PUBLISHER_GAS_PRICE
|
|
142
|
-
description: 'The gas price used for transactions',
|
|
143
|
-
unit: 'gwei',
|
|
144
|
-
valueType: ValueType.DOUBLE,
|
|
145
|
-
});
|
|
129
|
+
this.gasPrice = this.meter.createHistogram(Metrics.L1_PUBLISHER_GAS_PRICE);
|
|
146
130
|
|
|
147
|
-
this.txCount = this.meter.createUpDownCounter(Metrics.L1_PUBLISHER_TX_COUNT
|
|
148
|
-
description: 'The number of transactions processed',
|
|
149
|
-
});
|
|
131
|
+
this.txCount = this.meter.createUpDownCounter(Metrics.L1_PUBLISHER_TX_COUNT);
|
|
150
132
|
|
|
151
|
-
this.txDuration = this.meter.createHistogram(Metrics.L1_PUBLISHER_TX_DURATION
|
|
152
|
-
description: 'The duration of transaction processing',
|
|
153
|
-
unit: 'ms',
|
|
154
|
-
valueType: ValueType.INT,
|
|
155
|
-
});
|
|
133
|
+
this.txDuration = this.meter.createHistogram(Metrics.L1_PUBLISHER_TX_DURATION);
|
|
156
134
|
|
|
157
|
-
this.txGas = this.meter.createHistogram(Metrics.L1_PUBLISHER_TX_GAS
|
|
158
|
-
description: 'The gas consumed by transactions',
|
|
159
|
-
unit: 'gas',
|
|
160
|
-
valueType: ValueType.INT,
|
|
161
|
-
});
|
|
135
|
+
this.txGas = this.meter.createHistogram(Metrics.L1_PUBLISHER_TX_GAS);
|
|
162
136
|
|
|
163
|
-
this.txCalldataSize = this.meter.createHistogram(Metrics.L1_PUBLISHER_TX_CALLDATA_SIZE
|
|
164
|
-
description: 'The size of the calldata in transactions',
|
|
165
|
-
unit: 'By',
|
|
166
|
-
valueType: ValueType.INT,
|
|
167
|
-
});
|
|
137
|
+
this.txCalldataSize = this.meter.createHistogram(Metrics.L1_PUBLISHER_TX_CALLDATA_SIZE);
|
|
168
138
|
|
|
169
|
-
this.txCalldataGas = this.meter.createHistogram(Metrics.L1_PUBLISHER_TX_CALLDATA_GAS
|
|
170
|
-
description: 'The gas consumed by the calldata in transactions',
|
|
171
|
-
unit: 'gas',
|
|
172
|
-
valueType: ValueType.INT,
|
|
173
|
-
});
|
|
139
|
+
this.txCalldataGas = this.meter.createHistogram(Metrics.L1_PUBLISHER_TX_CALLDATA_GAS);
|
|
174
140
|
|
|
175
|
-
this.txBlobDataGasUsed = this.meter.createHistogram(Metrics.L1_PUBLISHER_TX_BLOBDATA_GAS_USED
|
|
176
|
-
description: 'The amount of blob gas used in transactions',
|
|
177
|
-
unit: 'gas',
|
|
178
|
-
valueType: ValueType.INT,
|
|
179
|
-
});
|
|
141
|
+
this.txBlobDataGasUsed = this.meter.createHistogram(Metrics.L1_PUBLISHER_TX_BLOBDATA_GAS_USED);
|
|
180
142
|
|
|
181
|
-
this.txBlobDataGasCost = this.meter.createHistogram(Metrics.L1_PUBLISHER_TX_BLOBDATA_GAS_COST
|
|
182
|
-
description: 'The gas cost of blobs in transactions',
|
|
183
|
-
unit: 'gwei',
|
|
184
|
-
valueType: ValueType.INT,
|
|
185
|
-
});
|
|
143
|
+
this.txBlobDataGasCost = this.meter.createHistogram(Metrics.L1_PUBLISHER_TX_BLOBDATA_GAS_COST);
|
|
186
144
|
|
|
187
|
-
this.txTotalFee = this.meter.createHistogram(Metrics.L1_PUBLISHER_TX_TOTAL_FEE
|
|
188
|
-
description: 'How much L1 tx costs',
|
|
189
|
-
unit: 'gwei',
|
|
190
|
-
valueType: ValueType.DOUBLE,
|
|
191
|
-
advice: {
|
|
192
|
-
explicitBucketBoundaries: [
|
|
193
|
-
0.001, 0.002, 0.004, 0.008, 0.01, 0.02, 0.04, 0.08, 0.1, 0.2, 0.4, 0.8, 1, 1.2, 1.4, 1.8, 2,
|
|
194
|
-
],
|
|
195
|
-
},
|
|
196
|
-
});
|
|
145
|
+
this.txTotalFee = this.meter.createHistogram(Metrics.L1_PUBLISHER_TX_TOTAL_FEE);
|
|
197
146
|
|
|
198
|
-
this.senderBalance = this.meter.createGauge(Metrics.L1_PUBLISHER_BALANCE
|
|
199
|
-
unit: 'eth',
|
|
200
|
-
description: 'The balance of the sender address',
|
|
201
|
-
valueType: ValueType.DOUBLE,
|
|
202
|
-
});
|
|
147
|
+
this.senderBalance = this.meter.createGauge(Metrics.L1_PUBLISHER_BALANCE);
|
|
203
148
|
}
|
|
204
149
|
|
|
205
150
|
recordFailedTx() {
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
+
import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
3
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
3
4
|
import { sleep } from '@aztec/foundation/sleep';
|
|
4
5
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
5
6
|
import { type L1RollupConstants, getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
6
|
-
import {
|
|
7
|
-
type TelemetryClient,
|
|
8
|
-
type Traceable,
|
|
9
|
-
type Tracer,
|
|
10
|
-
getTelemetryClient,
|
|
11
|
-
trackSpan,
|
|
12
|
-
} from '@aztec/telemetry-client';
|
|
7
|
+
import { type TelemetryClient, type Traceable, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
13
8
|
|
|
14
9
|
export interface EpochMonitorHandler {
|
|
15
|
-
handleEpochReadyToProve(epochNumber:
|
|
10
|
+
handleEpochReadyToProve(epochNumber: EpochNumber): Promise<boolean>;
|
|
16
11
|
}
|
|
17
12
|
|
|
18
13
|
/**
|
|
@@ -32,7 +27,7 @@ export class EpochMonitor implements Traceable {
|
|
|
32
27
|
public readonly tracer: Tracer;
|
|
33
28
|
|
|
34
29
|
private handler: EpochMonitorHandler | undefined;
|
|
35
|
-
private latestEpochNumber:
|
|
30
|
+
private latestEpochNumber: EpochNumber | undefined;
|
|
36
31
|
|
|
37
32
|
constructor(
|
|
38
33
|
private readonly l2BlockSource: L2BlockSource,
|
|
@@ -72,7 +67,6 @@ export class EpochMonitor implements Traceable {
|
|
|
72
67
|
this.log.info('Stopped EpochMonitor');
|
|
73
68
|
}
|
|
74
69
|
|
|
75
|
-
@trackSpan('EpochMonitor.work')
|
|
76
70
|
public async work() {
|
|
77
71
|
const { epochToProve, blockNumber, slotNumber } = await this.getEpochNumberToProve();
|
|
78
72
|
this.log.debug(`Epoch to prove: ${epochToProve}`, { blockNumber, slotNumber });
|
|
@@ -104,7 +98,7 @@ export class EpochMonitor implements Traceable {
|
|
|
104
98
|
|
|
105
99
|
private async getEpochNumberToProve() {
|
|
106
100
|
const lastBlockProven = await this.l2BlockSource.getProvenBlockNumber();
|
|
107
|
-
const firstBlockToProve = lastBlockProven + 1;
|
|
101
|
+
const firstBlockToProve = BlockNumber(lastBlockProven + 1);
|
|
108
102
|
const firstBlockHeaderToProve = await this.l2BlockSource.getBlockHeader(firstBlockToProve);
|
|
109
103
|
if (!firstBlockHeaderToProve) {
|
|
110
104
|
return { epochToProve: undefined, blockNumber: firstBlockToProve };
|