@aztec/prover-node 0.0.1-commit.e6bd8901 → 0.0.1-commit.ec7ac5448
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 +5 -7
- 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 +5 -2
- package/dest/config.d.ts +5 -8
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +16 -19
- package/dest/factory.d.ts +19 -13
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +39 -59
- package/dest/job/epoch-proving-job.d.ts +3 -2
- package/dest/job/epoch-proving-job.d.ts.map +1 -1
- package/dest/job/epoch-proving-job.js +37 -13
- package/dest/metrics.d.ts +11 -1
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +36 -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 +5 -7
- 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 +6 -5
- package/dest/prover-node.d.ts +19 -9
- package/dest/prover-node.d.ts.map +1 -1
- package/dest/prover-node.js +16 -11
- package/dest/prover-publisher-factory.d.ts +7 -5
- package/dest/prover-publisher-factory.d.ts.map +1 -1
- package/dest/prover-publisher-factory.js +7 -5
- package/package.json +23 -22
- package/src/actions/download-epoch-proving-job.ts +1 -1
- package/src/actions/rerun-epoch-proving-job.ts +7 -4
- package/src/actions/upload-epoch-proof-failure.ts +1 -1
- package/src/bin/run-failed-epoch.ts +4 -1
- package/src/config.ts +23 -31
- package/src/factory.ts +67 -102
- package/src/job/epoch-proving-job.ts +54 -19
- package/src/metrics.ts +40 -2
- package/src/monitors/epoch-monitor.ts +3 -4
- package/src/prover-node-publisher.ts +8 -6
- package/src/prover-node.ts +19 -11
- package/src/prover-publisher-factory.ts +16 -10
|
@@ -3,9 +3,10 @@ import { asyncPool } from '@aztec/foundation/async-pool';
|
|
|
3
3
|
import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
4
4
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
5
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
7
7
|
import { RunningPromise, promiseWithResolvers } from '@aztec/foundation/promise';
|
|
8
8
|
import { Timer } from '@aztec/foundation/timer';
|
|
9
|
+
import { AVM_MAX_CONCURRENT_SIMULATIONS } from '@aztec/native';
|
|
9
10
|
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
10
11
|
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
11
12
|
import { buildFinalBlobChallenges } from '@aztec/prover-client/helpers';
|
|
@@ -43,7 +44,7 @@ export type EpochProvingJobOptions = {
|
|
|
43
44
|
*/
|
|
44
45
|
export class EpochProvingJob implements Traceable {
|
|
45
46
|
private state: EpochProvingJobState = 'initialized';
|
|
46
|
-
private log
|
|
47
|
+
private log: Logger;
|
|
47
48
|
private uuid: string;
|
|
48
49
|
|
|
49
50
|
private runPromise: Promise<void> | undefined;
|
|
@@ -62,9 +63,14 @@ export class EpochProvingJob implements Traceable {
|
|
|
62
63
|
private metrics: ProverNodeJobMetrics,
|
|
63
64
|
private deadline: Date | undefined,
|
|
64
65
|
private config: EpochProvingJobOptions,
|
|
66
|
+
bindings?: LoggerBindings,
|
|
65
67
|
) {
|
|
66
68
|
validateEpochProvingJobData(data);
|
|
67
69
|
this.uuid = crypto.randomUUID();
|
|
70
|
+
this.log = createLogger('prover-node:epoch-proving-job', {
|
|
71
|
+
...bindings,
|
|
72
|
+
instanceId: `epoch-${data.epochNumber}`,
|
|
73
|
+
});
|
|
68
74
|
this.tracer = metrics.tracer;
|
|
69
75
|
}
|
|
70
76
|
|
|
@@ -143,19 +149,32 @@ export class EpochProvingJob implements Traceable {
|
|
|
143
149
|
this.runPromise = promise;
|
|
144
150
|
|
|
145
151
|
try {
|
|
152
|
+
const blobTimer = new Timer();
|
|
146
153
|
const blobFieldsPerCheckpoint = this.checkpoints.map(checkpoint => checkpoint.toBlobFields());
|
|
147
154
|
const finalBlobBatchingChallenges = await buildFinalBlobChallenges(blobFieldsPerCheckpoint);
|
|
155
|
+
this.metrics.recordBlobProcessing(blobTimer.ms());
|
|
148
156
|
|
|
149
157
|
this.prover.startNewEpoch(epochNumber, epochSizeCheckpoints, finalBlobBatchingChallenges);
|
|
158
|
+
const chonkTimer = new Timer();
|
|
150
159
|
await this.prover.startChonkVerifierCircuits(Array.from(this.txs.values()));
|
|
160
|
+
this.metrics.recordChonkVerifier(chonkTimer.ms());
|
|
151
161
|
|
|
152
162
|
// Everything in the epoch should have the same chainId and version.
|
|
153
163
|
const { chainId, version } = this.checkpoints[0].blocks[0].header.globalVariables;
|
|
154
164
|
|
|
155
165
|
const previousBlockHeaders = this.gatherPreviousBlockHeaders();
|
|
156
166
|
|
|
157
|
-
|
|
167
|
+
const allCheckpointsTimer = new Timer();
|
|
168
|
+
|
|
169
|
+
const parallelism = this.config.parallelBlockLimit
|
|
170
|
+
? this.config.parallelBlockLimit
|
|
171
|
+
: AVM_MAX_CONCURRENT_SIMULATIONS > 0
|
|
172
|
+
? AVM_MAX_CONCURRENT_SIMULATIONS
|
|
173
|
+
: this.checkpoints.length;
|
|
174
|
+
|
|
175
|
+
await asyncPool(parallelism, this.checkpoints, async checkpoint => {
|
|
158
176
|
this.checkState();
|
|
177
|
+
const checkpointTimer = new Timer();
|
|
159
178
|
|
|
160
179
|
const checkpointIndex = checkpoint.number - fromCheckpoint;
|
|
161
180
|
const checkpointConstants = CheckpointConstantData.from({
|
|
@@ -188,7 +207,9 @@ export class EpochProvingJob implements Traceable {
|
|
|
188
207
|
previousHeader,
|
|
189
208
|
);
|
|
190
209
|
|
|
191
|
-
for (
|
|
210
|
+
for (let blockIndex = 0; blockIndex < checkpoint.blocks.length; blockIndex++) {
|
|
211
|
+
const blockTimer = new Timer();
|
|
212
|
+
const block = checkpoint.blocks[blockIndex];
|
|
192
213
|
const globalVariables = block.header.globalVariables;
|
|
193
214
|
const txs = this.getTxs(block);
|
|
194
215
|
|
|
@@ -206,8 +227,12 @@ export class EpochProvingJob implements Traceable {
|
|
|
206
227
|
// Start block proving
|
|
207
228
|
await this.prover.startNewBlock(block.number, globalVariables.timestamp, txs.length);
|
|
208
229
|
|
|
209
|
-
// Process public fns
|
|
210
|
-
|
|
230
|
+
// Process public fns. L1 to L2 messages are only inserted for the first block of a checkpoint,
|
|
231
|
+
// as the fork for subsequent blocks already includes them from the previous block's synced state.
|
|
232
|
+
const db = await this.createFork(
|
|
233
|
+
BlockNumber(block.number - 1),
|
|
234
|
+
blockIndex === 0 ? l1ToL2Messages : undefined,
|
|
235
|
+
);
|
|
211
236
|
const config = PublicSimulatorConfig.from({
|
|
212
237
|
proverId: this.prover.getProverId().toField(),
|
|
213
238
|
skipFeeEnforcement: false,
|
|
@@ -229,8 +254,11 @@ export class EpochProvingJob implements Traceable {
|
|
|
229
254
|
// Mark block as completed to pad it
|
|
230
255
|
const expectedBlockHeader = block.header;
|
|
231
256
|
await this.prover.setBlockCompleted(block.number, expectedBlockHeader);
|
|
257
|
+
this.metrics.recordBlockProcessing(blockTimer.ms());
|
|
232
258
|
}
|
|
259
|
+
this.metrics.recordCheckpointProcessing(checkpointTimer.ms());
|
|
233
260
|
});
|
|
261
|
+
this.metrics.recordAllCheckpointsProcessing(allCheckpointsTimer.ms());
|
|
234
262
|
|
|
235
263
|
const executionTime = timer.ms();
|
|
236
264
|
|
|
@@ -290,22 +318,29 @@ export class EpochProvingJob implements Traceable {
|
|
|
290
318
|
}
|
|
291
319
|
|
|
292
320
|
/**
|
|
293
|
-
* Create a new db fork for tx processing, inserting
|
|
321
|
+
* Create a new db fork for tx processing, optionally inserting L1 to L2 messages.
|
|
322
|
+
* L1 to L2 messages should only be inserted for the first block in a checkpoint,
|
|
323
|
+
* as subsequent blocks' synced state already includes them.
|
|
294
324
|
* 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.
|
|
295
325
|
*/
|
|
296
|
-
private async createFork(blockNumber: BlockNumber, l1ToL2Messages: Fr[]) {
|
|
326
|
+
private async createFork(blockNumber: BlockNumber, l1ToL2Messages: Fr[] | undefined) {
|
|
327
|
+
this.log.verbose(`Creating fork at ${blockNumber}`, { blockNumber });
|
|
297
328
|
const db = await this.dbProvider.fork(blockNumber);
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
329
|
+
|
|
330
|
+
if (l1ToL2Messages !== undefined) {
|
|
331
|
+
this.log.verbose(`Inserting ${l1ToL2Messages.length} L1 to L2 messages in fork`, {
|
|
332
|
+
blockNumber,
|
|
333
|
+
l1ToL2Messages: l1ToL2Messages.map(m => m.toString()),
|
|
334
|
+
});
|
|
335
|
+
const l1ToL2MessagesPadded = padArrayEnd<Fr, number>(
|
|
336
|
+
l1ToL2Messages,
|
|
337
|
+
Fr.ZERO,
|
|
338
|
+
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
339
|
+
'Too many L1 to L2 messages',
|
|
340
|
+
);
|
|
341
|
+
await db.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
|
|
342
|
+
}
|
|
343
|
+
|
|
309
344
|
return db;
|
|
310
345
|
}
|
|
311
346
|
|
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() {
|
|
@@ -128,7 +163,10 @@ export class ProverNodePublisherMetrics {
|
|
|
128
163
|
|
|
129
164
|
this.gasPrice = this.meter.createHistogram(Metrics.L1_PUBLISHER_GAS_PRICE);
|
|
130
165
|
|
|
131
|
-
this.txCount = this.meter
|
|
166
|
+
this.txCount = createUpDownCounterWithDefault(this.meter, Metrics.L1_PUBLISHER_TX_COUNT, {
|
|
167
|
+
[Attributes.L1_TX_TYPE]: ['submitProof'],
|
|
168
|
+
[Attributes.OK]: [true, false],
|
|
169
|
+
});
|
|
132
170
|
|
|
133
171
|
this.txDuration = this.meter.createHistogram(Metrics.L1_PUBLISHER_TX_DURATION);
|
|
134
172
|
|
|
@@ -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,11 +85,11 @@ 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
|
}
|
|
@@ -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,7 +7,7 @@ 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
11
|
import type { Tuple } from '@aztec/foundation/serialize';
|
|
12
12
|
import { Timer } from '@aztec/foundation/timer';
|
|
13
13
|
import { RollupAbi } from '@aztec/l1-artifacts';
|
|
@@ -31,7 +31,7 @@ export type L1SubmitEpochProofArgs = {
|
|
|
31
31
|
endTimestamp: Fr;
|
|
32
32
|
outHash: Fr;
|
|
33
33
|
proverId: Fr;
|
|
34
|
-
fees: Tuple<FeeRecipient, typeof
|
|
34
|
+
fees: Tuple<FeeRecipient, typeof MAX_CHECKPOINTS_PER_EPOCH>;
|
|
35
35
|
proof: Proof;
|
|
36
36
|
};
|
|
37
37
|
|
|
@@ -39,7 +39,7 @@ export class ProverNodePublisher {
|
|
|
39
39
|
private interrupted = false;
|
|
40
40
|
private metrics: ProverNodePublisherMetrics;
|
|
41
41
|
|
|
42
|
-
protected log
|
|
42
|
+
protected log: Logger;
|
|
43
43
|
|
|
44
44
|
protected rollupContract: RollupContract;
|
|
45
45
|
|
|
@@ -52,10 +52,12 @@ export class ProverNodePublisher {
|
|
|
52
52
|
l1TxUtils: L1TxUtils;
|
|
53
53
|
telemetry?: TelemetryClient;
|
|
54
54
|
},
|
|
55
|
+
bindings?: LoggerBindings,
|
|
55
56
|
) {
|
|
56
57
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
57
58
|
|
|
58
59
|
this.metrics = new ProverNodePublisherMetrics(telemetry, 'ProverNode');
|
|
60
|
+
this.log = createLogger('prover-node:l1-tx-publisher', bindings);
|
|
59
61
|
|
|
60
62
|
this.rollupContract = deps.rollupContract;
|
|
61
63
|
this.l1TxUtils = deps.l1TxUtils;
|
|
@@ -166,7 +168,7 @@ export class ProverNodePublisher {
|
|
|
166
168
|
// toCheckpoint can't be greater than pending
|
|
167
169
|
if (toCheckpoint > pending) {
|
|
168
170
|
throw new Error(
|
|
169
|
-
`Cannot submit epoch proof for ${fromCheckpoint}-${toCheckpoint} as
|
|
171
|
+
`Cannot submit epoch proof for ${fromCheckpoint}-${toCheckpoint} as proposed checkpoint is ${pending}`,
|
|
170
172
|
);
|
|
171
173
|
}
|
|
172
174
|
|
|
@@ -269,7 +271,7 @@ export class ProverNodePublisher {
|
|
|
269
271
|
outHash: args.publicInputs.outHash.toString(),
|
|
270
272
|
proverId: EthAddress.fromField(args.publicInputs.constants.proverId).toString(),
|
|
271
273
|
} /*_args*/,
|
|
272
|
-
makeTuple(
|
|
274
|
+
makeTuple(MAX_CHECKPOINTS_PER_EPOCH * 2, i =>
|
|
273
275
|
i % 2 === 0
|
|
274
276
|
? args.publicInputs.fees[i / 2].recipient.toField().toString()
|
|
275
277
|
: args.publicInputs.fees[(i - 1) / 2].value.toString(),
|
package/src/prover-node.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import type { Archiver } from '@aztec/archiver';
|
|
2
2
|
import type { RollupContract } from '@aztec/ethereum/contracts';
|
|
3
|
+
import type { Delayer } from '@aztec/ethereum/l1-tx-utils';
|
|
3
4
|
import { BlockNumber, CheckpointNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
4
5
|
import { assertRequired, compact, pick, sum } from '@aztec/foundation/collection';
|
|
5
6
|
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
7
|
import { memoize } from '@aztec/foundation/decorators';
|
|
7
8
|
import { createLogger } from '@aztec/foundation/log';
|
|
8
9
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
9
|
-
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
10
|
-
import type { P2PClient } from '@aztec/p2p';
|
|
11
10
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
12
11
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
13
12
|
import type { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
@@ -17,14 +16,15 @@ import { getProofSubmissionDeadlineTimestamp } from '@aztec/stdlib/epoch-helpers
|
|
|
17
16
|
import {
|
|
18
17
|
type EpochProverManager,
|
|
19
18
|
EpochProvingJobTerminalState,
|
|
19
|
+
type ITxProvider,
|
|
20
20
|
type ProverNodeApi,
|
|
21
21
|
type Service,
|
|
22
22
|
type WorldStateSyncStatus,
|
|
23
23
|
type WorldStateSynchronizer,
|
|
24
24
|
tryStop,
|
|
25
25
|
} from '@aztec/stdlib/interfaces/server';
|
|
26
|
+
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
26
27
|
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
27
|
-
import type { P2PClientType } from '@aztec/stdlib/p2p';
|
|
28
28
|
import type { Tx } from '@aztec/stdlib/tx';
|
|
29
29
|
import {
|
|
30
30
|
Attributes,
|
|
@@ -55,7 +55,6 @@ type DataStoreOptions = Pick<DataStoreConfig, 'dataDirectory'> & Pick<ChainConfi
|
|
|
55
55
|
*/
|
|
56
56
|
export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable {
|
|
57
57
|
private log = createLogger('prover-node');
|
|
58
|
-
private dateProvider = new DateProvider();
|
|
59
58
|
|
|
60
59
|
private jobs: Map<string, EpochProvingJob> = new Map();
|
|
61
60
|
private config: ProverNodeOptions;
|
|
@@ -73,17 +72,19 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
|
|
|
73
72
|
protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
|
|
74
73
|
protected readonly contractDataSource: ContractDataSource,
|
|
75
74
|
protected readonly worldState: WorldStateSynchronizer,
|
|
76
|
-
protected readonly p2pClient:
|
|
75
|
+
protected readonly p2pClient: { getTxProvider(): ITxProvider } & Partial<Service>,
|
|
77
76
|
protected readonly epochsMonitor: EpochMonitor,
|
|
78
77
|
protected readonly rollupContract: RollupContract,
|
|
79
78
|
protected readonly l1Metrics: L1Metrics,
|
|
80
79
|
config: Partial<ProverNodeOptions> = {},
|
|
81
80
|
protected readonly telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
81
|
+
private delayer?: Delayer,
|
|
82
|
+
private readonly dateProvider: DateProvider = new DateProvider(),
|
|
82
83
|
) {
|
|
83
84
|
this.config = {
|
|
84
85
|
proverNodePollingIntervalMs: 1_000,
|
|
85
86
|
proverNodeMaxPendingJobs: 100,
|
|
86
|
-
proverNodeMaxParallelBlocksPerEpoch:
|
|
87
|
+
proverNodeMaxParallelBlocksPerEpoch: 0,
|
|
87
88
|
txGatheringIntervalMs: 1_000,
|
|
88
89
|
txGatheringBatchSize: 10,
|
|
89
90
|
txGatheringMaxParallelRequestsPerNode: 100,
|
|
@@ -111,6 +112,11 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
|
|
|
111
112
|
return this.p2pClient;
|
|
112
113
|
}
|
|
113
114
|
|
|
115
|
+
/** Returns the shared tx delayer for prover L1 txs, if enabled. Test-only. */
|
|
116
|
+
public getDelayer(): Delayer | undefined {
|
|
117
|
+
return this.delayer;
|
|
118
|
+
}
|
|
119
|
+
|
|
114
120
|
/**
|
|
115
121
|
* Handles an epoch being completed by starting a proof for it if there are no active jobs for it.
|
|
116
122
|
* @param epochNumber - The epoch number that was just completed.
|
|
@@ -155,17 +161,15 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
|
|
|
155
161
|
|
|
156
162
|
/**
|
|
157
163
|
* Stops the prover node and all its dependencies.
|
|
164
|
+
* Resources not owned by this node (shared with the parent aztec-node) are skipped.
|
|
158
165
|
*/
|
|
159
166
|
async stop() {
|
|
160
167
|
this.log.info('Stopping ProverNode');
|
|
161
168
|
await this.epochsMonitor.stop();
|
|
162
169
|
await this.prover.stop();
|
|
163
|
-
await tryStop(this.p2pClient);
|
|
164
|
-
await tryStop(this.l2BlockSource);
|
|
165
170
|
await tryStop(this.publisherFactory);
|
|
166
171
|
this.publisher?.interrupt();
|
|
167
172
|
await Promise.all(Array.from(this.jobs.values()).map(job => job.stop()));
|
|
168
|
-
await this.worldState.stop();
|
|
169
173
|
this.rewardsMetrics.stop();
|
|
170
174
|
this.l1Metrics.stop();
|
|
171
175
|
await this.telemetryClient.stop();
|
|
@@ -275,19 +279,22 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
|
|
|
275
279
|
const fromCheckpoint = epochData.checkpoints[0].number;
|
|
276
280
|
const toCheckpoint = epochData.checkpoints.at(-1)!.number;
|
|
277
281
|
const fromBlock = epochData.checkpoints[0].blocks[0].number;
|
|
278
|
-
const
|
|
282
|
+
const lastBlock = epochData.checkpoints.at(-1)!.blocks.at(-1)!;
|
|
283
|
+
const toBlock = lastBlock.number;
|
|
279
284
|
this.log.verbose(
|
|
280
285
|
`Creating proving job for epoch ${epochNumber} for checkpoint range ${fromCheckpoint} to ${toCheckpoint} and block range ${fromBlock} to ${toBlock}`,
|
|
281
286
|
);
|
|
282
287
|
|
|
283
288
|
// Fast forward world state to right before the target block and get a fork
|
|
284
|
-
await
|
|
289
|
+
const lastBlockHash = await lastBlock.header.hash();
|
|
290
|
+
await this.worldState.syncImmediate(toBlock, lastBlockHash);
|
|
285
291
|
|
|
286
292
|
// Create a processor factory
|
|
287
293
|
const publicProcessorFactory = new PublicProcessorFactory(
|
|
288
294
|
this.contractDataSource,
|
|
289
295
|
this.dateProvider,
|
|
290
296
|
this.telemetryClient,
|
|
297
|
+
this.log.getBindings(),
|
|
291
298
|
);
|
|
292
299
|
|
|
293
300
|
// Set deadline for this job to run. It will abort if it takes too long.
|
|
@@ -384,6 +391,7 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
|
|
|
384
391
|
this.jobMetrics,
|
|
385
392
|
deadline,
|
|
386
393
|
{ parallelBlockLimit, skipSubmitProof: proverNodeDisableProofPublish, ...opts },
|
|
394
|
+
this.log.getBindings(),
|
|
387
395
|
);
|
|
388
396
|
}
|
|
389
397
|
|
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
import type { RollupContract } from '@aztec/ethereum/contracts';
|
|
2
2
|
import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
|
|
3
3
|
import type { PublisherManager } from '@aztec/ethereum/publisher-manager';
|
|
4
|
-
import type {
|
|
4
|
+
import type { LoggerBindings } from '@aztec/foundation/log';
|
|
5
|
+
import type { ProverPublisherConfig, ProverTxSenderConfig } from '@aztec/sequencer-client';
|
|
5
6
|
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
6
7
|
|
|
7
8
|
import { ProverNodePublisher } from './prover-node-publisher.js';
|
|
8
9
|
|
|
9
10
|
export class ProverPublisherFactory {
|
|
10
11
|
constructor(
|
|
11
|
-
private config:
|
|
12
|
+
private config: ProverTxSenderConfig & ProverPublisherConfig,
|
|
12
13
|
private deps: {
|
|
13
14
|
rollupContract: RollupContract;
|
|
14
15
|
publisherManager: PublisherManager<L1TxUtils>;
|
|
15
16
|
telemetry?: TelemetryClient;
|
|
16
17
|
},
|
|
18
|
+
private bindings?: LoggerBindings,
|
|
17
19
|
) {}
|
|
18
20
|
|
|
19
21
|
public async start() {
|
|
20
|
-
await this.deps.publisherManager.
|
|
22
|
+
await this.deps.publisherManager.start();
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
public stop() {
|
|
24
|
-
this.deps.publisherManager.
|
|
25
|
+
public async stop() {
|
|
26
|
+
await this.deps.publisherManager.stop();
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
/**
|
|
@@ -30,10 +32,14 @@ export class ProverPublisherFactory {
|
|
|
30
32
|
*/
|
|
31
33
|
public async create(): Promise<ProverNodePublisher> {
|
|
32
34
|
const l1Publisher = await this.deps.publisherManager.getAvailablePublisher();
|
|
33
|
-
return new ProverNodePublisher(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
return new ProverNodePublisher(
|
|
36
|
+
this.config,
|
|
37
|
+
{
|
|
38
|
+
rollupContract: this.deps.rollupContract,
|
|
39
|
+
l1TxUtils: l1Publisher,
|
|
40
|
+
telemetry: this.deps.telemetry,
|
|
41
|
+
},
|
|
42
|
+
this.bindings,
|
|
43
|
+
);
|
|
38
44
|
}
|
|
39
45
|
}
|