@aztec/prover-node 0.0.1-commit.b655e406 → 0.0.1-commit.d3ec352c
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 +2 -2
- 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 +1 -1
- package/dest/factory.d.ts +1 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +1 -1
- package/dest/index.d.ts +1 -1
- package/dest/job/epoch-proving-job-data.d.ts +7 -5
- package/dest/job/epoch-proving-job-data.d.ts.map +1 -1
- package/dest/job/epoch-proving-job-data.js +24 -17
- 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 +91 -82
- package/dest/metrics.d.ts +3 -2
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +8 -2
- 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 +2 -1
- package/dest/monitors/index.d.ts +1 -1
- package/dest/prover-node-publisher.d.ts +6 -5
- package/dest/prover-node-publisher.d.ts.map +1 -1
- package/dest/prover-node-publisher.js +28 -26
- package/dest/prover-node.d.ts +7 -6
- package/dest/prover-node.d.ts.map +1 -1
- package/dest/prover-node.js +34 -31
- package/dest/prover-publisher-factory.d.ts +1 -1
- 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/factory.ts +3 -1
- package/src/job/epoch-proving-job-data.ts +30 -24
- package/src/job/epoch-proving-job.ts +105 -99
- package/src/metrics.ts +14 -2
- package/src/monitors/epoch-monitor.ts +4 -3
- package/src/prover-node-publisher.ts +42 -37
- package/src/prover-node.ts +46 -40
|
@@ -1,49 +1,55 @@
|
|
|
1
|
+
import { CheckpointNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
3
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
3
|
-
import { CommitteeAttestation
|
|
4
|
+
import { CommitteeAttestation } from '@aztec/stdlib/block';
|
|
5
|
+
import { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
4
6
|
import { BlockHeader, Tx } from '@aztec/stdlib/tx';
|
|
5
7
|
|
|
6
8
|
/** All data from an epoch used in proving. */
|
|
7
9
|
export type EpochProvingJobData = {
|
|
8
|
-
epochNumber:
|
|
9
|
-
|
|
10
|
+
epochNumber: EpochNumber;
|
|
11
|
+
checkpoints: Checkpoint[];
|
|
10
12
|
txs: Map<string, Tx>;
|
|
11
|
-
l1ToL2Messages: Record<
|
|
13
|
+
l1ToL2Messages: Record<CheckpointNumber, Fr[]>;
|
|
12
14
|
previousBlockHeader: BlockHeader;
|
|
13
15
|
attestations: CommitteeAttestation[];
|
|
14
16
|
};
|
|
15
17
|
|
|
16
18
|
export function validateEpochProvingJobData(data: EpochProvingJobData) {
|
|
17
|
-
if (data.
|
|
19
|
+
if (data.checkpoints.length === 0) {
|
|
20
|
+
throw new Error('No checkpoints to prove');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const firstBlockNumber = data.checkpoints[0].blocks[0].number;
|
|
24
|
+
const previousBlockNumber = data.previousBlockHeader.getBlockNumber();
|
|
25
|
+
if (previousBlockNumber + 1 !== firstBlockNumber) {
|
|
18
26
|
throw new Error(
|
|
19
|
-
`Initial block number ${
|
|
20
|
-
data.blocks[0].number
|
|
21
|
-
} does not match previous block header ${data.previousBlockHeader.getBlockNumber()}`,
|
|
27
|
+
`Initial block number ${firstBlockNumber} does not match previous block header ${previousBlockNumber}`,
|
|
22
28
|
);
|
|
23
29
|
}
|
|
24
30
|
|
|
25
|
-
for (const
|
|
26
|
-
if (!(
|
|
27
|
-
throw new Error(`Missing L1 to L2 messages for
|
|
31
|
+
for (const checkpoint of data.checkpoints) {
|
|
32
|
+
if (!(checkpoint.number in data.l1ToL2Messages)) {
|
|
33
|
+
throw new Error(`Missing L1 to L2 messages for checkpoint number ${checkpoint.number}`);
|
|
28
34
|
}
|
|
29
35
|
}
|
|
30
36
|
}
|
|
31
37
|
|
|
32
38
|
export function serializeEpochProvingJobData(data: EpochProvingJobData): Buffer {
|
|
33
|
-
const
|
|
39
|
+
const checkpoints = data.checkpoints.map(checkpoint => checkpoint.toBuffer());
|
|
34
40
|
const txs = Array.from(data.txs.values()).map(tx => tx.toBuffer());
|
|
35
|
-
const l1ToL2Messages = Object.entries(data.l1ToL2Messages).map(([
|
|
36
|
-
Number(
|
|
41
|
+
const l1ToL2Messages = Object.entries(data.l1ToL2Messages).map(([checkpointNumber, messages]) => [
|
|
42
|
+
Number(checkpointNumber),
|
|
37
43
|
messages.length,
|
|
38
44
|
...messages,
|
|
39
45
|
]);
|
|
40
46
|
const attestations = data.attestations.map(attestation => attestation.toBuffer());
|
|
41
47
|
|
|
42
48
|
return serializeToBuffer(
|
|
43
|
-
|
|
49
|
+
data.epochNumber,
|
|
44
50
|
data.previousBlockHeader,
|
|
45
|
-
|
|
46
|
-
...
|
|
51
|
+
checkpoints.length,
|
|
52
|
+
...checkpoints,
|
|
47
53
|
txs.length,
|
|
48
54
|
...txs,
|
|
49
55
|
l1ToL2Messages.length,
|
|
@@ -55,22 +61,22 @@ export function serializeEpochProvingJobData(data: EpochProvingJobData): Buffer
|
|
|
55
61
|
|
|
56
62
|
export function deserializeEpochProvingJobData(buf: Buffer): EpochProvingJobData {
|
|
57
63
|
const reader = BufferReader.asReader(buf);
|
|
58
|
-
const epochNumber =
|
|
64
|
+
const epochNumber = EpochNumber(reader.readNumber());
|
|
59
65
|
const previousBlockHeader = reader.readObject(BlockHeader);
|
|
60
|
-
const
|
|
66
|
+
const checkpoints = reader.readVector(Checkpoint);
|
|
61
67
|
const txArray = reader.readVector(Tx);
|
|
62
68
|
|
|
63
|
-
const
|
|
69
|
+
const l1ToL2MessageCheckpointCount = reader.readNumber();
|
|
64
70
|
const l1ToL2Messages: Record<number, Fr[]> = {};
|
|
65
|
-
for (let i = 0; i <
|
|
66
|
-
const
|
|
71
|
+
for (let i = 0; i < l1ToL2MessageCheckpointCount; i++) {
|
|
72
|
+
const checkpointNumber = CheckpointNumber(reader.readNumber());
|
|
67
73
|
const messages = reader.readVector(Fr);
|
|
68
|
-
l1ToL2Messages[
|
|
74
|
+
l1ToL2Messages[checkpointNumber] = messages;
|
|
69
75
|
}
|
|
70
76
|
|
|
71
77
|
const attestations = reader.readVector(CommitteeAttestation);
|
|
72
78
|
|
|
73
79
|
const txs = new Map<string, Tx>(txArray.map(tx => [tx.getTxHash().toString(), tx]));
|
|
74
80
|
|
|
75
|
-
return { epochNumber, previousBlockHeader,
|
|
81
|
+
return { epochNumber, previousBlockHeader, checkpoints, txs, l1ToL2Messages, attestations };
|
|
76
82
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
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
5
|
import { Fr } from '@aztec/foundation/fields';
|
|
5
6
|
import { createLogger } from '@aztec/foundation/log';
|
|
@@ -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';
|
|
12
|
-
import
|
|
13
|
+
import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
14
|
+
import type { L2BlockNew, 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,92 @@ 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
|
+
collectStatistics: false,
|
|
217
|
+
});
|
|
218
|
+
const publicProcessor = this.publicProcessorFactory.create(db, globalVariables, config);
|
|
219
|
+
const processed = await this.processTxs(publicProcessor, txs);
|
|
220
|
+
await this.prover.addTxs(processed);
|
|
221
|
+
await db.close();
|
|
222
|
+
this.log.verbose(`Processed all ${txs.length} txs for block ${block.number}`, {
|
|
223
|
+
blockNumber: block.number,
|
|
224
|
+
blockHash: (await block.hash()).toString(),
|
|
225
|
+
uuid: this.uuid,
|
|
226
|
+
});
|
|
208
227
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
228
|
+
// Mark block as completed to pad it
|
|
229
|
+
const expectedBlockHeader = block.header;
|
|
230
|
+
await this.prover.setBlockCompleted(block.number, expectedBlockHeader);
|
|
231
|
+
}
|
|
212
232
|
});
|
|
213
233
|
|
|
214
234
|
const executionTime = timer.ms();
|
|
@@ -221,16 +241,16 @@ export class EpochProvingJob implements Traceable {
|
|
|
221
241
|
|
|
222
242
|
if (this.config.skipSubmitProof) {
|
|
223
243
|
this.log.info(
|
|
224
|
-
`Proof publishing is disabled. Dropping valid proof for epoch ${epochNumber} (
|
|
244
|
+
`Proof publishing is disabled. Dropping valid proof for epoch ${epochNumber} (checkpoints ${fromCheckpoint} to ${toCheckpoint})`,
|
|
225
245
|
);
|
|
226
246
|
this.state = 'completed';
|
|
227
|
-
this.metrics.recordProvingJob(executionTime, timer.ms(), epochSizeBlocks, epochSizeTxs);
|
|
247
|
+
this.metrics.recordProvingJob(executionTime, timer.ms(), epochSizeCheckpoints, epochSizeBlocks, epochSizeTxs);
|
|
228
248
|
return;
|
|
229
249
|
}
|
|
230
250
|
|
|
231
251
|
const success = await this.publisher.submitEpochProof({
|
|
232
|
-
|
|
233
|
-
|
|
252
|
+
fromCheckpoint,
|
|
253
|
+
toCheckpoint,
|
|
234
254
|
epochNumber,
|
|
235
255
|
publicInputs,
|
|
236
256
|
proof,
|
|
@@ -241,12 +261,12 @@ export class EpochProvingJob implements Traceable {
|
|
|
241
261
|
throw new Error('Failed to submit epoch proof to L1');
|
|
242
262
|
}
|
|
243
263
|
|
|
244
|
-
this.log.info(`Submitted proof for epoch ${epochNumber} (
|
|
264
|
+
this.log.info(`Submitted proof for epoch ${epochNumber} (checkpoints ${fromCheckpoint} to ${toCheckpoint})`, {
|
|
245
265
|
epochNumber,
|
|
246
266
|
uuid: this.uuid,
|
|
247
267
|
});
|
|
248
268
|
this.state = 'completed';
|
|
249
|
-
this.metrics.recordProvingJob(executionTime, timer.ms(), epochSizeBlocks, epochSizeTxs);
|
|
269
|
+
this.metrics.recordProvingJob(executionTime, timer.ms(), epochSizeCheckpoints, epochSizeBlocks, epochSizeTxs);
|
|
250
270
|
} catch (err: any) {
|
|
251
271
|
if (err && err.name === 'HaltExecutionError') {
|
|
252
272
|
this.log.warn(`Halted execution of epoch ${epochNumber} prover job`, {
|
|
@@ -272,7 +292,7 @@ export class EpochProvingJob implements Traceable {
|
|
|
272
292
|
* Create a new db fork for tx processing, inserting all L1 to L2.
|
|
273
293
|
* 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
294
|
*/
|
|
275
|
-
private async createFork(blockNumber:
|
|
295
|
+
private async createFork(blockNumber: BlockNumber, l1ToL2Messages: Fr[]) {
|
|
276
296
|
const db = await this.dbProvider.fork(blockNumber);
|
|
277
297
|
const l1ToL2MessagesPadded = padArrayEnd<Fr, number>(
|
|
278
298
|
l1ToL2Messages,
|
|
@@ -282,7 +302,7 @@ export class EpochProvingJob implements Traceable {
|
|
|
282
302
|
);
|
|
283
303
|
this.log.verbose(`Creating fork at ${blockNumber} with ${l1ToL2Messages.length} L1 to L2 messages`, {
|
|
284
304
|
blockNumber,
|
|
285
|
-
l1ToL2Messages:
|
|
305
|
+
l1ToL2Messages: l1ToL2Messages.map(m => m.toString()),
|
|
286
306
|
});
|
|
287
307
|
await db.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
|
|
288
308
|
return db;
|
|
@@ -343,11 +363,9 @@ export class EpochProvingJob implements Traceable {
|
|
|
343
363
|
async () => {
|
|
344
364
|
const blocks = await l2BlockSource.getBlockHeadersForEpoch(this.epochNumber);
|
|
345
365
|
const blockHashes = await Promise.all(blocks.map(block => block.hash()));
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
!blockHashes.every((block, i) => block.equals(thisBlockHashes[i]))
|
|
350
|
-
) {
|
|
366
|
+
const thisBlocks = this.checkpoints.flatMap(checkpoint => checkpoint.blocks);
|
|
367
|
+
const thisBlockHashes = await Promise.all(thisBlocks.map(block => block.hash()));
|
|
368
|
+
if (blocks.length !== thisBlocks.length || !blockHashes.every((block, i) => block.equals(thisBlockHashes[i]))) {
|
|
351
369
|
this.log.warn('Epoch blocks changed underfoot', {
|
|
352
370
|
uuid: this.uuid,
|
|
353
371
|
epochNumber: this.epochNumber,
|
|
@@ -363,30 +381,18 @@ export class EpochProvingJob implements Traceable {
|
|
|
363
381
|
this.log.verbose(`Scheduled epoch check for epoch ${this.epochNumber} every ${intervalMs}ms`);
|
|
364
382
|
}
|
|
365
383
|
|
|
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
|
-
);
|
|
384
|
+
/* Returns the last block header in the previous checkpoint for all checkpoints in the epoch */
|
|
385
|
+
private gatherPreviousBlockHeaders() {
|
|
386
|
+
const lastBlocks = this.checkpoints.map(checkpoint => checkpoint.blocks.at(-1)!);
|
|
387
|
+
return [this.data.previousBlockHeader, ...lastBlocks.map(block => block.header).slice(0, -1)];
|
|
382
388
|
}
|
|
383
389
|
|
|
384
|
-
private getTxs(block:
|
|
390
|
+
private getTxs(block: L2BlockNew): Tx[] {
|
|
385
391
|
return block.body.txEffects.map(txEffect => this.txs.get(txEffect.txHash.toString())!);
|
|
386
392
|
}
|
|
387
393
|
|
|
388
|
-
private getL1ToL2Messages(
|
|
389
|
-
return this.data.l1ToL2Messages[
|
|
394
|
+
private getL1ToL2Messages(checkpoint: Checkpoint) {
|
|
395
|
+
return this.data.l1ToL2Messages[checkpoint.number];
|
|
390
396
|
}
|
|
391
397
|
|
|
392
398
|
private async processTxs(publicProcessor: PublicProcessor, txs: Tx[]): Promise<ProcessedTx[]> {
|
package/src/metrics.ts
CHANGED
|
@@ -21,6 +21,7 @@ import { formatEther, formatUnits } from 'viem';
|
|
|
21
21
|
export class ProverNodeJobMetrics {
|
|
22
22
|
proverEpochExecutionDuration: Histogram;
|
|
23
23
|
provingJobDuration: Histogram;
|
|
24
|
+
provingJobCheckpoints: Gauge;
|
|
24
25
|
provingJobBlocks: Gauge;
|
|
25
26
|
provingJobTransactions: Gauge;
|
|
26
27
|
|
|
@@ -39,6 +40,10 @@ export class ProverNodeJobMetrics {
|
|
|
39
40
|
unit: 's',
|
|
40
41
|
valueType: ValueType.DOUBLE,
|
|
41
42
|
});
|
|
43
|
+
this.provingJobCheckpoints = this.meter.createGauge(Metrics.PROVER_NODE_JOB_CHECKPOINTS, {
|
|
44
|
+
description: 'Number of checkpoints in a proven epoch',
|
|
45
|
+
valueType: ValueType.INT,
|
|
46
|
+
});
|
|
42
47
|
this.provingJobBlocks = this.meter.createGauge(Metrics.PROVER_NODE_JOB_BLOCKS, {
|
|
43
48
|
description: 'Number of blocks in a proven epoch',
|
|
44
49
|
valueType: ValueType.INT,
|
|
@@ -49,9 +54,16 @@ export class ProverNodeJobMetrics {
|
|
|
49
54
|
});
|
|
50
55
|
}
|
|
51
56
|
|
|
52
|
-
public recordProvingJob(
|
|
57
|
+
public recordProvingJob(
|
|
58
|
+
executionTimeMs: number,
|
|
59
|
+
totalTimeMs: number,
|
|
60
|
+
numCheckpoints: number,
|
|
61
|
+
numBlocks: number,
|
|
62
|
+
numTxs: number,
|
|
63
|
+
) {
|
|
53
64
|
this.proverEpochExecutionDuration.record(Math.ceil(executionTimeMs));
|
|
54
65
|
this.provingJobDuration.record(totalTimeMs / 1000);
|
|
66
|
+
this.provingJobCheckpoints.record(Math.floor(numCheckpoints));
|
|
55
67
|
this.provingJobBlocks.record(Math.floor(numBlocks));
|
|
56
68
|
this.provingJobTransactions.record(Math.floor(numTxs));
|
|
57
69
|
}
|
|
@@ -97,7 +109,7 @@ export class ProverNodeRewardsMetrics {
|
|
|
97
109
|
// look at the prev epoch so that we get an accurate value, after proof submission window has closed
|
|
98
110
|
// For example, if proof submission window is 1 epoch, and we are in epoch 2, we should be looking at epoch 0.
|
|
99
111
|
// 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;
|
|
112
|
+
const closedEpoch = BigInt(epoch) - BigInt(this.proofSubmissionEpochs) - 1n;
|
|
101
113
|
const rewards = await this.rollup.getSpecificProverRewardsForEpoch(closedEpoch, this.coinbase);
|
|
102
114
|
|
|
103
115
|
const fmt = parseFloat(formatUnits(rewards, 18));
|
|
@@ -1,3 +1,4 @@
|
|
|
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';
|
|
@@ -12,7 +13,7 @@ import {
|
|
|
12
13
|
} from '@aztec/telemetry-client';
|
|
13
14
|
|
|
14
15
|
export interface EpochMonitorHandler {
|
|
15
|
-
handleEpochReadyToProve(epochNumber:
|
|
16
|
+
handleEpochReadyToProve(epochNumber: EpochNumber): Promise<boolean>;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
/**
|
|
@@ -32,7 +33,7 @@ export class EpochMonitor implements Traceable {
|
|
|
32
33
|
public readonly tracer: Tracer;
|
|
33
34
|
|
|
34
35
|
private handler: EpochMonitorHandler | undefined;
|
|
35
|
-
private latestEpochNumber:
|
|
36
|
+
private latestEpochNumber: EpochNumber | undefined;
|
|
36
37
|
|
|
37
38
|
constructor(
|
|
38
39
|
private readonly l2BlockSource: L2BlockSource,
|
|
@@ -104,7 +105,7 @@ export class EpochMonitor implements Traceable {
|
|
|
104
105
|
|
|
105
106
|
private async getEpochNumberToProve() {
|
|
106
107
|
const lastBlockProven = await this.l2BlockSource.getProvenBlockNumber();
|
|
107
|
-
const firstBlockToProve = lastBlockProven + 1;
|
|
108
|
+
const firstBlockToProve = BlockNumber(lastBlockProven + 1);
|
|
108
109
|
const firstBlockHeaderToProve = await this.l2BlockSource.getBlockHeader(firstBlockToProve);
|
|
109
110
|
if (!firstBlockHeaderToProve) {
|
|
110
111
|
return { epochToProve: undefined, blockNumber: firstBlockToProve };
|