@aztec/prover-node 0.0.0-test.1 → 0.0.1-commit.b655e406
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 +18 -0
- package/dest/actions/download-epoch-proving-job.d.ts.map +1 -0
- package/dest/actions/download-epoch-proving-job.js +37 -0
- package/dest/actions/index.d.ts +3 -0
- package/dest/actions/index.d.ts.map +1 -0
- package/dest/actions/index.js +2 -0
- package/dest/actions/rerun-epoch-proving-job.d.ts +11 -0
- package/dest/actions/rerun-epoch-proving-job.d.ts.map +1 -0
- package/dest/actions/rerun-epoch-proving-job.js +40 -0
- package/dest/actions/upload-epoch-proof-failure.d.ts +15 -0
- package/dest/actions/upload-epoch-proof-failure.d.ts.map +1 -0
- package/dest/actions/upload-epoch-proof-failure.js +78 -0
- package/dest/bin/run-failed-epoch.d.ts +2 -0
- package/dest/bin/run-failed-epoch.d.ts.map +1 -0
- package/dest/bin/run-failed-epoch.js +67 -0
- package/dest/config.d.ts +12 -9
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +81 -14
- package/dest/factory.d.ts +12 -8
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +95 -31
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/job/epoch-proving-job-data.d.ts +16 -0
- package/dest/job/epoch-proving-job-data.d.ts.map +1 -0
- package/dest/job/epoch-proving-job-data.js +52 -0
- package/dest/job/epoch-proving-job.d.ts +30 -15
- package/dest/job/epoch-proving-job.d.ts.map +1 -1
- package/dest/job/epoch-proving-job.js +149 -50
- package/dest/metrics.d.ts +28 -4
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +141 -35
- package/dest/monitors/epoch-monitor.d.ts +3 -1
- package/dest/monitors/epoch-monitor.d.ts.map +1 -1
- package/dest/monitors/epoch-monitor.js +15 -2
- package/dest/prover-node-publisher.d.ts +7 -10
- package/dest/prover-node-publisher.d.ts.map +1 -1
- package/dest/prover-node-publisher.js +59 -60
- package/dest/prover-node.d.ts +43 -39
- package/dest/prover-node.d.ts.map +1 -1
- package/dest/prover-node.js +171 -100
- package/dest/prover-publisher-factory.d.ts +21 -0
- package/dest/prover-publisher-factory.d.ts.map +1 -0
- package/dest/prover-publisher-factory.js +26 -0
- package/dest/test/index.d.ts +4 -2
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +1 -3
- package/package.json +36 -31
- package/src/actions/download-epoch-proving-job.ts +44 -0
- package/src/actions/index.ts +2 -0
- package/src/actions/rerun-epoch-proving-job.ts +61 -0
- package/src/actions/upload-epoch-proof-failure.ts +88 -0
- package/src/bin/run-failed-epoch.ts +77 -0
- package/src/config.ts +108 -24
- package/src/factory.ts +161 -43
- package/src/index.ts +1 -1
- package/src/job/epoch-proving-job-data.ts +76 -0
- package/src/job/epoch-proving-job.ts +215 -50
- package/src/metrics.ts +135 -37
- package/src/monitors/epoch-monitor.ts +16 -5
- package/src/prover-node-publisher.ts +93 -86
- package/src/prover-node.ts +203 -126
- package/src/prover-publisher-factory.ts +37 -0
- package/src/test/index.ts +7 -4
- package/dest/http.d.ts +0 -8
- package/dest/http.d.ts.map +0 -1
- package/dest/http.js +0 -9
- package/dest/prover-coordination/config.d.ts +0 -7
- package/dest/prover-coordination/config.d.ts.map +0 -1
- package/dest/prover-coordination/config.js +0 -11
- package/dest/prover-coordination/factory.d.ts +0 -22
- package/dest/prover-coordination/factory.d.ts.map +0 -1
- package/dest/prover-coordination/factory.js +0 -42
- package/dest/prover-coordination/index.d.ts +0 -3
- package/dest/prover-coordination/index.d.ts.map +0 -1
- package/dest/prover-coordination/index.js +0 -2
- package/src/http.ts +0 -13
- package/src/prover-coordination/config.ts +0 -17
- package/src/prover-coordination/factory.ts +0 -72
- package/src/prover-coordination/index.ts +0 -2
package/dest/prover-node.js
CHANGED
|
@@ -4,134 +4,180 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
4
4
|
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
}
|
|
7
|
-
import { compact } from '@aztec/foundation/collection';
|
|
7
|
+
import { assertRequired, compact, pick, sum } from '@aztec/foundation/collection';
|
|
8
8
|
import { memoize } from '@aztec/foundation/decorators';
|
|
9
9
|
import { createLogger } from '@aztec/foundation/log';
|
|
10
|
-
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
11
10
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
12
11
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
13
|
-
import {
|
|
12
|
+
import { getProofSubmissionDeadlineTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
14
13
|
import { EpochProvingJobTerminalState, tryStop } from '@aztec/stdlib/interfaces/server';
|
|
15
14
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
15
|
+
import { uploadEpochProofFailure } from './actions/upload-epoch-proof-failure.js';
|
|
16
16
|
import { EpochProvingJob } from './job/epoch-proving-job.js';
|
|
17
|
-
import {
|
|
17
|
+
import { ProverNodeJobMetrics, ProverNodeRewardsMetrics } from './metrics.js';
|
|
18
18
|
/**
|
|
19
|
-
* An Aztec Prover Node is a standalone process that monitors the
|
|
20
|
-
*
|
|
21
|
-
* from a tx source in the p2p network or an external node, re-executes their public functions, creates a rollup
|
|
19
|
+
* An Aztec Prover Node is a standalone process that monitors the unfinalized chain on L1 for unproven epochs,
|
|
20
|
+
* fetches their txs from the p2p network or external nodes, re-executes their public functions, creates a rollup
|
|
22
21
|
* proof for the epoch, and submits it to L1.
|
|
23
22
|
*/ export class ProverNode {
|
|
24
23
|
prover;
|
|
25
|
-
|
|
24
|
+
publisherFactory;
|
|
26
25
|
l2BlockSource;
|
|
27
26
|
l1ToL2MessageSource;
|
|
28
27
|
contractDataSource;
|
|
29
28
|
worldState;
|
|
30
|
-
|
|
29
|
+
p2pClient;
|
|
31
30
|
epochsMonitor;
|
|
31
|
+
rollupContract;
|
|
32
|
+
l1Metrics;
|
|
32
33
|
telemetryClient;
|
|
33
34
|
log;
|
|
34
35
|
dateProvider;
|
|
35
|
-
latestEpochWeAreProving;
|
|
36
36
|
jobs;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
txFetcher;
|
|
41
|
-
lastBlockNumber;
|
|
37
|
+
config;
|
|
38
|
+
jobMetrics;
|
|
39
|
+
rewardsMetrics;
|
|
42
40
|
tracer;
|
|
43
|
-
|
|
41
|
+
publisher;
|
|
42
|
+
constructor(prover, publisherFactory, l2BlockSource, l1ToL2MessageSource, contractDataSource, worldState, p2pClient, epochsMonitor, rollupContract, l1Metrics, config = {}, telemetryClient = getTelemetryClient()){
|
|
44
43
|
this.prover = prover;
|
|
45
|
-
this.
|
|
44
|
+
this.publisherFactory = publisherFactory;
|
|
46
45
|
this.l2BlockSource = l2BlockSource;
|
|
47
46
|
this.l1ToL2MessageSource = l1ToL2MessageSource;
|
|
48
47
|
this.contractDataSource = contractDataSource;
|
|
49
48
|
this.worldState = worldState;
|
|
50
|
-
this.
|
|
49
|
+
this.p2pClient = p2pClient;
|
|
51
50
|
this.epochsMonitor = epochsMonitor;
|
|
51
|
+
this.rollupContract = rollupContract;
|
|
52
|
+
this.l1Metrics = l1Metrics;
|
|
52
53
|
this.telemetryClient = telemetryClient;
|
|
53
54
|
this.log = createLogger('prover-node');
|
|
54
55
|
this.dateProvider = new DateProvider();
|
|
55
56
|
this.jobs = new Map();
|
|
56
|
-
this.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
maxParallelBlocksPerEpoch: 32,
|
|
61
|
-
txGatheringTimeoutMs: 60_000,
|
|
57
|
+
this.config = {
|
|
58
|
+
proverNodePollingIntervalMs: 1_000,
|
|
59
|
+
proverNodeMaxPendingJobs: 100,
|
|
60
|
+
proverNodeMaxParallelBlocksPerEpoch: 32,
|
|
62
61
|
txGatheringIntervalMs: 1_000,
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
txGatheringBatchSize: 10,
|
|
63
|
+
txGatheringMaxParallelRequestsPerNode: 100,
|
|
64
|
+
txGatheringTimeoutMs: 120_000,
|
|
65
|
+
proverNodeFailedEpochStore: undefined,
|
|
66
|
+
proverNodeEpochProvingDelayMs: undefined,
|
|
67
|
+
...compact(config)
|
|
65
68
|
};
|
|
66
|
-
this.
|
|
69
|
+
this.validateConfig();
|
|
70
|
+
const meter = telemetryClient.getMeter('ProverNode');
|
|
67
71
|
this.tracer = telemetryClient.getTracer('ProverNode');
|
|
68
|
-
this.
|
|
72
|
+
this.jobMetrics = new ProverNodeJobMetrics(meter, telemetryClient.getTracer('EpochProvingJob'));
|
|
73
|
+
this.rewardsMetrics = new ProverNodeRewardsMetrics(meter, this.prover.getProverId(), rollupContract);
|
|
69
74
|
}
|
|
70
75
|
getProverId() {
|
|
71
76
|
return this.prover.getProverId();
|
|
72
77
|
}
|
|
73
78
|
getP2P() {
|
|
74
|
-
|
|
75
|
-
if (typeof asP2PClient.isP2PClient === 'function' && asP2PClient.isP2PClient()) {
|
|
76
|
-
return asP2PClient;
|
|
77
|
-
}
|
|
78
|
-
return undefined;
|
|
79
|
+
return this.p2pClient;
|
|
79
80
|
}
|
|
80
81
|
/**
|
|
81
82
|
* Handles an epoch being completed by starting a proof for it if there are no active jobs for it.
|
|
82
83
|
* @param epochNumber - The epoch number that was just completed.
|
|
84
|
+
* @returns false if there is an error, true otherwise
|
|
83
85
|
*/ async handleEpochReadyToProve(epochNumber) {
|
|
84
86
|
try {
|
|
85
|
-
this.log.debug(
|
|
87
|
+
this.log.debug(`Running jobs as ${epochNumber} is ready to prove`, {
|
|
88
|
+
jobs: Array.from(this.jobs.values()).map((job)=>`${job.getEpochNumber()}:${job.getId()}`)
|
|
89
|
+
});
|
|
86
90
|
const activeJobs = await this.getActiveJobsForEpoch(epochNumber);
|
|
87
91
|
if (activeJobs.length > 0) {
|
|
88
|
-
this.log.
|
|
89
|
-
|
|
92
|
+
this.log.warn(`Not starting proof for ${epochNumber} since there are active jobs for the epoch`, {
|
|
93
|
+
activeJobs: activeJobs.map((job)=>job.uuid)
|
|
94
|
+
});
|
|
95
|
+
return true;
|
|
90
96
|
}
|
|
91
|
-
// TODO: we probably want to skip starting a proof if we are too far into the current epoch
|
|
92
97
|
await this.startProof(epochNumber);
|
|
98
|
+
return true;
|
|
93
99
|
} catch (err) {
|
|
94
100
|
if (err instanceof EmptyEpochError) {
|
|
95
101
|
this.log.info(`Not starting proof for ${epochNumber} since no blocks were found`);
|
|
96
102
|
} else {
|
|
97
103
|
this.log.error(`Error handling epoch completed`, err);
|
|
98
104
|
}
|
|
105
|
+
return false;
|
|
99
106
|
}
|
|
100
107
|
}
|
|
101
108
|
/**
|
|
102
|
-
* Starts the prover node so it periodically checks for unproven epochs in the
|
|
109
|
+
* Starts the prover node so it periodically checks for unproven epochs in the unfinalized chain from L1 and
|
|
103
110
|
* starts proving jobs for them.
|
|
104
|
-
*/ start() {
|
|
105
|
-
this.txFetcher.start();
|
|
111
|
+
*/ async start() {
|
|
106
112
|
this.epochsMonitor.start(this);
|
|
107
|
-
this.
|
|
113
|
+
await this.publisherFactory.start();
|
|
114
|
+
this.publisher = await this.publisherFactory.create();
|
|
115
|
+
await this.rewardsMetrics.start();
|
|
116
|
+
this.l1Metrics.start();
|
|
117
|
+
this.log.info(`Started Prover Node with prover id ${this.prover.getProverId().toString()}`, this.config);
|
|
108
118
|
}
|
|
109
119
|
/**
|
|
110
120
|
* Stops the prover node and all its dependencies.
|
|
111
121
|
*/ async stop() {
|
|
112
122
|
this.log.info('Stopping ProverNode');
|
|
113
|
-
await this.txFetcher.stop();
|
|
114
123
|
await this.epochsMonitor.stop();
|
|
115
124
|
await this.prover.stop();
|
|
125
|
+
await tryStop(this.p2pClient);
|
|
116
126
|
await tryStop(this.l2BlockSource);
|
|
117
|
-
this.
|
|
127
|
+
await tryStop(this.publisherFactory);
|
|
128
|
+
this.publisher?.interrupt();
|
|
118
129
|
await Promise.all(Array.from(this.jobs.values()).map((job)=>job.stop()));
|
|
119
130
|
await this.worldState.stop();
|
|
120
|
-
|
|
131
|
+
this.rewardsMetrics.stop();
|
|
132
|
+
this.l1Metrics.stop();
|
|
121
133
|
await this.telemetryClient.stop();
|
|
122
134
|
this.log.info('Stopped ProverNode');
|
|
123
135
|
}
|
|
124
|
-
/**
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
136
|
+
/** Returns world state status. */ async getWorldStateSyncStatus() {
|
|
137
|
+
const { syncSummary } = await this.worldState.status();
|
|
138
|
+
return syncSummary;
|
|
139
|
+
}
|
|
140
|
+
/** Returns archiver status. */ getL2Tips() {
|
|
141
|
+
return this.l2BlockSource.getL2Tips();
|
|
129
142
|
}
|
|
130
143
|
/**
|
|
131
144
|
* Starts a proving process and returns immediately.
|
|
132
145
|
*/ async startProof(epochNumber) {
|
|
133
|
-
const job = await this.createProvingJob(BigInt(epochNumber)
|
|
134
|
-
|
|
146
|
+
const job = await this.createProvingJob(BigInt(epochNumber), {
|
|
147
|
+
skipEpochCheck: true
|
|
148
|
+
});
|
|
149
|
+
void this.runJob(job);
|
|
150
|
+
}
|
|
151
|
+
async runJob(job) {
|
|
152
|
+
const epochNumber = job.getEpochNumber();
|
|
153
|
+
const ctx = {
|
|
154
|
+
id: job.getId(),
|
|
155
|
+
epochNumber,
|
|
156
|
+
state: undefined
|
|
157
|
+
};
|
|
158
|
+
try {
|
|
159
|
+
await job.run();
|
|
160
|
+
const state = job.getState();
|
|
161
|
+
ctx.state = state;
|
|
162
|
+
if (state === 'reorg') {
|
|
163
|
+
this.log.warn(`Running new job for epoch ${epochNumber} due to reorg`, ctx);
|
|
164
|
+
await this.createProvingJob(epochNumber);
|
|
165
|
+
} else if (state === 'failed') {
|
|
166
|
+
this.log.error(`Job for ${epochNumber} exited with state ${state}`, ctx);
|
|
167
|
+
await this.tryUploadEpochFailure(job);
|
|
168
|
+
} else {
|
|
169
|
+
this.log.verbose(`Job for ${epochNumber} exited with state ${state}`, ctx);
|
|
170
|
+
}
|
|
171
|
+
} catch (err) {
|
|
172
|
+
this.log.error(`Error proving epoch ${epochNumber}`, err, ctx);
|
|
173
|
+
} finally{
|
|
174
|
+
this.jobs.delete(job.getId());
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
async tryUploadEpochFailure(job) {
|
|
178
|
+
if (this.config.proverNodeFailedEpochStore) {
|
|
179
|
+
return await uploadEpochProofFailure(this.config.proverNodeFailedEpochStore, job.getId(), job.getProvingData(), this.l2BlockSource, this.worldState, assertRequired(pick(this.config, 'l1ChainId', 'rollupVersion', 'dataDirectory')), this.log);
|
|
180
|
+
}
|
|
135
181
|
}
|
|
136
182
|
/**
|
|
137
183
|
* Returns the prover instance.
|
|
@@ -153,56 +199,51 @@ import { ProverNodeMetrics } from './metrics.js';
|
|
|
153
199
|
return jobs.filter((job)=>job.epochNumber === epochNumber && !EpochProvingJobTerminalState.includes(job.status));
|
|
154
200
|
}
|
|
155
201
|
checkMaximumPendingJobs() {
|
|
156
|
-
const { maxPendingJobs } = this.
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
async createProvingJob(epochNumber) {
|
|
160
|
-
if (!this.checkMaximumPendingJobs()) {
|
|
161
|
-
throw new Error(`Maximum pending proving jobs ${this.options.maxPendingJobs} reached. Cannot create new job.`);
|
|
202
|
+
const { proverNodeMaxPendingJobs: maxPendingJobs } = this.config;
|
|
203
|
+
if (maxPendingJobs > 0 && this.jobs.size >= maxPendingJobs) {
|
|
204
|
+
throw new Error(`Maximum pending proving jobs ${maxPendingJobs} reached. Cannot create new job.`);
|
|
162
205
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
206
|
+
}
|
|
207
|
+
async createProvingJob(epochNumber, opts = {}) {
|
|
208
|
+
this.checkMaximumPendingJobs();
|
|
209
|
+
this.publisher = await this.publisherFactory.create();
|
|
210
|
+
// Gather all data for this epoch
|
|
211
|
+
const epochData = await this.gatherEpochData(epochNumber);
|
|
212
|
+
const fromBlock = epochData.blocks[0].number;
|
|
213
|
+
const toBlock = epochData.blocks.at(-1).number;
|
|
169
214
|
this.log.verbose(`Creating proving job for epoch ${epochNumber} for block range ${fromBlock} to ${toBlock}`);
|
|
215
|
+
// Fast forward world state to right before the target block and get a fork
|
|
170
216
|
await this.worldState.syncImmediate(toBlock);
|
|
171
|
-
// Create a processor
|
|
217
|
+
// Create a processor factory
|
|
172
218
|
const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, this.dateProvider, this.telemetryClient);
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const [_, endTimestamp] = getTimestampRangeForEpoch(epochNumber + 1n, await this.getL1Constants());
|
|
178
|
-
const deadline = new Date(Number(endTimestamp) * 1000);
|
|
179
|
-
const job = this.doCreateEpochProvingJob(epochNumber, deadline, blocks, txs, publicProcessorFactory, cleanUp);
|
|
219
|
+
// Set deadline for this job to run. It will abort if it takes too long.
|
|
220
|
+
const deadlineTs = getProofSubmissionDeadlineTimestamp(epochNumber, await this.getL1Constants());
|
|
221
|
+
const deadline = new Date(Number(deadlineTs) * 1000);
|
|
222
|
+
const job = this.doCreateEpochProvingJob(epochData, deadline, publicProcessorFactory, this.publisher, opts);
|
|
180
223
|
this.jobs.set(job.getId(), job);
|
|
181
224
|
return job;
|
|
182
225
|
}
|
|
183
226
|
getL1Constants() {
|
|
184
227
|
return this.l2BlockSource.getL1Constants();
|
|
185
228
|
}
|
|
186
|
-
/** Monitors for new blocks and requests their txs from the p2p layer to ensure they are available for proving. */ async checkForTxs() {
|
|
187
|
-
const blockNumber = await this.l2BlockSource.getBlockNumber();
|
|
188
|
-
if (this.lastBlockNumber === undefined || blockNumber > this.lastBlockNumber) {
|
|
189
|
-
const block = await this.l2BlockSource.getBlock(blockNumber);
|
|
190
|
-
if (!block) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
const txHashes = block.body.txEffects.map((tx)=>tx.txHash);
|
|
194
|
-
this.log.verbose(`Fetching ${txHashes.length} tx hashes for block number ${blockNumber} from coordination`);
|
|
195
|
-
await this.coordination.getTxsByHash(txHashes); // This stores the txs in the tx pool, no need to persist them here
|
|
196
|
-
this.lastBlockNumber = blockNumber;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
229
|
async gatherEpochData(epochNumber) {
|
|
200
|
-
// Gather blocks for this epoch and their txs
|
|
201
230
|
const blocks = await this.gatherBlocks(epochNumber);
|
|
202
|
-
const
|
|
231
|
+
const txArray = await this.gatherTxs(epochNumber, blocks);
|
|
232
|
+
const txs = new Map(txArray.map((tx)=>[
|
|
233
|
+
tx.getTxHash().toString(),
|
|
234
|
+
tx
|
|
235
|
+
]));
|
|
236
|
+
const l1ToL2Messages = await this.gatherMessages(epochNumber, blocks);
|
|
237
|
+
const previousBlockHeader = await this.gatherPreviousBlockHeader(epochNumber, blocks[0]);
|
|
238
|
+
const [lastBlock] = await this.l2BlockSource.getPublishedBlocks(blocks.at(-1).number, 1);
|
|
239
|
+
const attestations = lastBlock?.attestations ?? [];
|
|
203
240
|
return {
|
|
204
241
|
blocks,
|
|
205
|
-
txs
|
|
242
|
+
txs,
|
|
243
|
+
l1ToL2Messages,
|
|
244
|
+
epochNumber,
|
|
245
|
+
previousBlockHeader,
|
|
246
|
+
attestations
|
|
206
247
|
};
|
|
207
248
|
}
|
|
208
249
|
async gatherBlocks(epochNumber) {
|
|
@@ -213,26 +254,59 @@ import { ProverNodeMetrics } from './metrics.js';
|
|
|
213
254
|
return blocks;
|
|
214
255
|
}
|
|
215
256
|
async gatherTxs(epochNumber, blocks) {
|
|
216
|
-
const
|
|
217
|
-
const
|
|
218
|
-
|
|
257
|
+
const deadline = new Date(this.dateProvider.now() + this.config.txGatheringTimeoutMs);
|
|
258
|
+
const txProvider = this.p2pClient.getTxProvider();
|
|
259
|
+
const txsByBlock = await Promise.all(blocks.map((block)=>txProvider.getTxsForBlock(block, {
|
|
260
|
+
deadline
|
|
261
|
+
})));
|
|
262
|
+
const txs = txsByBlock.map(({ txs })=>txs).flat();
|
|
263
|
+
const missingTxs = txsByBlock.map(({ missingTxs })=>missingTxs).flat();
|
|
264
|
+
if (missingTxs.length === 0) {
|
|
219
265
|
this.log.verbose(`Gathered all ${txs.length} txs for epoch ${epochNumber}`, {
|
|
220
266
|
epochNumber
|
|
221
267
|
});
|
|
222
268
|
return txs;
|
|
223
269
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
270
|
+
throw new Error(`Txs not found for epoch ${epochNumber}: ${missingTxs.map((hash)=>hash.toString()).join(', ')}`);
|
|
271
|
+
}
|
|
272
|
+
async gatherMessages(epochNumber, blocks) {
|
|
273
|
+
const messages = await Promise.all(blocks.map((b)=>this.l1ToL2MessageSource.getL1ToL2Messages(b.number)));
|
|
274
|
+
const messageCount = sum(messages.map((m)=>m.length));
|
|
275
|
+
this.log.verbose(`Gathered all ${messageCount} messages for epoch ${epochNumber}`, {
|
|
276
|
+
epochNumber
|
|
277
|
+
});
|
|
278
|
+
const messagesByBlock = {};
|
|
279
|
+
for(let i = 0; i < blocks.length; i++){
|
|
280
|
+
messagesByBlock[blocks[i].number] = messages[i];
|
|
281
|
+
}
|
|
282
|
+
return messagesByBlock;
|
|
283
|
+
}
|
|
284
|
+
async gatherPreviousBlockHeader(epochNumber, initialBlock) {
|
|
285
|
+
const previousBlockNumber = initialBlock.number - 1;
|
|
286
|
+
const header = await (previousBlockNumber === 0 ? this.worldState.getCommitted().getInitialHeader() : this.l2BlockSource.getBlockHeader(previousBlockNumber));
|
|
287
|
+
if (!header) {
|
|
288
|
+
throw new Error(`Previous block header ${initialBlock.number} not found for proving epoch ${epochNumber}`);
|
|
289
|
+
}
|
|
290
|
+
this.log.verbose(`Gathered previous block header ${header.getBlockNumber()} for epoch ${epochNumber}`);
|
|
291
|
+
return header;
|
|
227
292
|
}
|
|
228
|
-
/** Extracted for testing purposes. */ doCreateEpochProvingJob(
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
293
|
+
/** Extracted for testing purposes. */ doCreateEpochProvingJob(data, deadline, publicProcessorFactory, publisher, opts = {}) {
|
|
294
|
+
const { proverNodeMaxParallelBlocksPerEpoch: parallelBlockLimit, proverNodeDisableProofPublish } = this.config;
|
|
295
|
+
return new EpochProvingJob(data, this.worldState, this.prover.createEpochProver(), publicProcessorFactory, publisher, this.l2BlockSource, this.jobMetrics, deadline, {
|
|
296
|
+
parallelBlockLimit,
|
|
297
|
+
skipSubmitProof: proverNodeDisableProofPublish,
|
|
298
|
+
...opts
|
|
299
|
+
});
|
|
232
300
|
}
|
|
233
301
|
/** Extracted for testing purposes. */ async triggerMonitors() {
|
|
234
302
|
await this.epochsMonitor.work();
|
|
235
303
|
}
|
|
304
|
+
validateConfig() {
|
|
305
|
+
if (this.config.proverNodeFailedEpochStore && (!this.config.dataDirectory || !this.config.l1ChainId || !this.config.rollupVersion)) {
|
|
306
|
+
this.log.warn(`Invalid prover-node config (missing dataDirectory, l1ChainId, or rollupVersion)`, pick(this.config, 'proverNodeFailedEpochStore', 'dataDirectory', 'l1ChainId', 'rollupVersion'));
|
|
307
|
+
throw new Error('All of dataDirectory, l1ChainId, and rollupVersion are required if proverNodeFailedEpochStore is set.');
|
|
308
|
+
}
|
|
309
|
+
}
|
|
236
310
|
}
|
|
237
311
|
_ts_decorate([
|
|
238
312
|
trackSpan('ProverNode.createProvingJob', (epochNumber)=>({
|
|
@@ -242,9 +316,6 @@ _ts_decorate([
|
|
|
242
316
|
_ts_decorate([
|
|
243
317
|
memoize
|
|
244
318
|
], ProverNode.prototype, "getL1Constants", null);
|
|
245
|
-
_ts_decorate([
|
|
246
|
-
trackSpan('ProverNode.checkForTxs')
|
|
247
|
-
], ProverNode.prototype, "checkForTxs", null);
|
|
248
319
|
_ts_decorate([
|
|
249
320
|
trackSpan('ProverNode.gatherEpochData', (epochNumber)=>({
|
|
250
321
|
[Attributes.EPOCH_NUMBER]: Number(epochNumber)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { L1TxUtils, PublisherManager, RollupContract } from '@aztec/ethereum';
|
|
2
|
+
import type { PublisherConfig, TxSenderConfig } from '@aztec/sequencer-client';
|
|
3
|
+
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
4
|
+
import { ProverNodePublisher } from './prover-node-publisher.js';
|
|
5
|
+
export declare class ProverPublisherFactory {
|
|
6
|
+
private config;
|
|
7
|
+
private deps;
|
|
8
|
+
constructor(config: TxSenderConfig & PublisherConfig, deps: {
|
|
9
|
+
rollupContract: RollupContract;
|
|
10
|
+
publisherManager: PublisherManager<L1TxUtils>;
|
|
11
|
+
telemetry?: TelemetryClient;
|
|
12
|
+
});
|
|
13
|
+
start(): Promise<void>;
|
|
14
|
+
stop(): void;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new Prover Publisher instance.
|
|
17
|
+
* @returns A new ProverNodePublisher instance.
|
|
18
|
+
*/
|
|
19
|
+
create(): Promise<ProverNodePublisher>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=prover-publisher-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prover-publisher-factory.d.ts","sourceRoot":"","sources":["../src/prover-publisher-factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,qBAAa,sBAAsB;IAE/B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,IAAI;gBADJ,MAAM,EAAE,cAAc,GAAG,eAAe,EACxC,IAAI,EAAE;QACZ,cAAc,EAAE,cAAc,CAAC;QAC/B,gBAAgB,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;QAC9C,SAAS,CAAC,EAAE,eAAe,CAAC;KAC7B;IAGU,KAAK;IAIX,IAAI;IAIX;;;OAGG;IACU,MAAM,IAAI,OAAO,CAAC,mBAAmB,CAAC;CAQpD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ProverNodePublisher } from './prover-node-publisher.js';
|
|
2
|
+
export class ProverPublisherFactory {
|
|
3
|
+
config;
|
|
4
|
+
deps;
|
|
5
|
+
constructor(config, deps){
|
|
6
|
+
this.config = config;
|
|
7
|
+
this.deps = deps;
|
|
8
|
+
}
|
|
9
|
+
async start() {
|
|
10
|
+
await this.deps.publisherManager.loadState();
|
|
11
|
+
}
|
|
12
|
+
stop() {
|
|
13
|
+
this.deps.publisherManager.interrupt();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new Prover Publisher instance.
|
|
17
|
+
* @returns A new ProverNodePublisher instance.
|
|
18
|
+
*/ async create() {
|
|
19
|
+
const l1Publisher = await this.deps.publisherManager.getAvailablePublisher();
|
|
20
|
+
return new ProverNodePublisher(this.config, {
|
|
21
|
+
rollupContract: this.deps.rollupContract,
|
|
22
|
+
l1TxUtils: l1Publisher,
|
|
23
|
+
telemetry: this.deps.telemetry
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
package/dest/test/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { EpochProverManager } from '@aztec/stdlib/interfaces/server';
|
|
2
|
+
import type { EpochProvingJob } from '../job/epoch-proving-job.js';
|
|
2
3
|
import type { ProverNodePublisher } from '../prover-node-publisher.js';
|
|
3
4
|
import { ProverNode } from '../prover-node.js';
|
|
4
|
-
declare class
|
|
5
|
+
declare abstract class TestProverNodeClass extends ProverNode {
|
|
5
6
|
prover: EpochProverManager;
|
|
6
7
|
publisher: ProverNodePublisher;
|
|
8
|
+
abstract tryUploadEpochFailure(job: EpochProvingJob): Promise<string | undefined>;
|
|
7
9
|
}
|
|
8
|
-
export type TestProverNode =
|
|
10
|
+
export type TestProverNode = TestProverNodeClass;
|
|
9
11
|
export {};
|
|
10
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dest/test/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAE1E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAE1E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,uBAAe,mBAAoB,SAAQ,UAAU;IACpC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,SAAS,EAAE,mBAAmB,CAAC;aAErB,qBAAqB,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;CAClG;AAED,MAAM,MAAM,cAAc,GAAG,mBAAmB,CAAC"}
|
package/dest/test/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/prover-node",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1-commit.b655e406",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -14,10 +14,9 @@
|
|
|
14
14
|
"build": "yarn clean && tsc -b",
|
|
15
15
|
"build:dev": "tsc -b --watch",
|
|
16
16
|
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
17
|
-
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
|
|
18
|
-
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
|
|
19
17
|
"bb": "node --no-warnings ./dest/bb/index.js",
|
|
20
|
-
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
18
|
+
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}",
|
|
19
|
+
"run-failed-epoch": "node --no-warnings ./dest/bin/run-failed-epoch.js"
|
|
21
20
|
},
|
|
22
21
|
"jest": {
|
|
23
22
|
"moduleNameMapper": {
|
|
@@ -50,41 +49,47 @@
|
|
|
50
49
|
"testTimeout": 120000,
|
|
51
50
|
"setupFiles": [
|
|
52
51
|
"../../foundation/src/jest/setup.mjs"
|
|
52
|
+
],
|
|
53
|
+
"testEnvironment": "../../foundation/src/jest/env.mjs",
|
|
54
|
+
"setupFilesAfterEnv": [
|
|
55
|
+
"../../foundation/src/jest/setupAfterEnv.mjs"
|
|
53
56
|
]
|
|
54
57
|
},
|
|
55
58
|
"dependencies": {
|
|
56
|
-
"@aztec/archiver": "0.0.
|
|
57
|
-
"@aztec/bb-prover": "0.0.
|
|
58
|
-
"@aztec/blob-
|
|
59
|
-
"@aztec/
|
|
60
|
-
"@aztec/
|
|
61
|
-
"@aztec/
|
|
62
|
-
"@aztec/
|
|
63
|
-
"@aztec/
|
|
64
|
-
"@aztec/
|
|
65
|
-
"@aztec/
|
|
66
|
-
"@aztec/
|
|
67
|
-
"@aztec/
|
|
68
|
-
"@aztec/
|
|
69
|
-
"@aztec/
|
|
70
|
-
"@aztec/
|
|
71
|
-
"@aztec/
|
|
72
|
-
"@aztec/
|
|
73
|
-
"@aztec/
|
|
59
|
+
"@aztec/archiver": "0.0.1-commit.b655e406",
|
|
60
|
+
"@aztec/bb-prover": "0.0.1-commit.b655e406",
|
|
61
|
+
"@aztec/blob-lib": "0.0.1-commit.b655e406",
|
|
62
|
+
"@aztec/blob-sink": "0.0.1-commit.b655e406",
|
|
63
|
+
"@aztec/constants": "0.0.1-commit.b655e406",
|
|
64
|
+
"@aztec/epoch-cache": "0.0.1-commit.b655e406",
|
|
65
|
+
"@aztec/ethereum": "0.0.1-commit.b655e406",
|
|
66
|
+
"@aztec/foundation": "0.0.1-commit.b655e406",
|
|
67
|
+
"@aztec/kv-store": "0.0.1-commit.b655e406",
|
|
68
|
+
"@aztec/l1-artifacts": "0.0.1-commit.b655e406",
|
|
69
|
+
"@aztec/node-keystore": "0.0.1-commit.b655e406",
|
|
70
|
+
"@aztec/node-lib": "0.0.1-commit.b655e406",
|
|
71
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.b655e406",
|
|
72
|
+
"@aztec/p2p": "0.0.1-commit.b655e406",
|
|
73
|
+
"@aztec/protocol-contracts": "0.0.1-commit.b655e406",
|
|
74
|
+
"@aztec/prover-client": "0.0.1-commit.b655e406",
|
|
75
|
+
"@aztec/sequencer-client": "0.0.1-commit.b655e406",
|
|
76
|
+
"@aztec/simulator": "0.0.1-commit.b655e406",
|
|
77
|
+
"@aztec/stdlib": "0.0.1-commit.b655e406",
|
|
78
|
+
"@aztec/telemetry-client": "0.0.1-commit.b655e406",
|
|
79
|
+
"@aztec/world-state": "0.0.1-commit.b655e406",
|
|
74
80
|
"source-map-support": "^0.5.21",
|
|
75
81
|
"tslib": "^2.4.0",
|
|
76
|
-
"viem": "2.
|
|
82
|
+
"viem": "npm:@spalladino/viem@2.38.2-eip7594.0"
|
|
77
83
|
},
|
|
78
84
|
"devDependencies": {
|
|
79
|
-
"@jest/globals": "^
|
|
80
|
-
"@types/jest": "^
|
|
81
|
-
"@types/
|
|
82
|
-
"@types/node": "^18.7.23",
|
|
85
|
+
"@jest/globals": "^30.0.0",
|
|
86
|
+
"@types/jest": "^30.0.0",
|
|
87
|
+
"@types/node": "^22.15.17",
|
|
83
88
|
"@types/source-map-support": "^0.5.10",
|
|
84
|
-
"jest": "^
|
|
85
|
-
"jest-mock-extended": "^
|
|
89
|
+
"jest": "^30.0.0",
|
|
90
|
+
"jest-mock-extended": "^4.0.0",
|
|
86
91
|
"ts-node": "^10.9.1",
|
|
87
|
-
"typescript": "^5.
|
|
92
|
+
"typescript": "^5.3.3"
|
|
88
93
|
},
|
|
89
94
|
"files": [
|
|
90
95
|
"dest",
|
|
@@ -93,6 +98,6 @@
|
|
|
93
98
|
],
|
|
94
99
|
"types": "./dest/index.d.ts",
|
|
95
100
|
"engines": {
|
|
96
|
-
"node": ">=
|
|
101
|
+
"node": ">=20.10"
|
|
97
102
|
}
|
|
98
103
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsonParseWithSchema } from '@aztec/foundation/json-rpc';
|
|
2
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
3
|
+
import { urlJoin } from '@aztec/foundation/string';
|
|
4
|
+
import { snapshotSync } from '@aztec/node-lib/actions';
|
|
5
|
+
import { createReadOnlyFileStore } from '@aztec/stdlib/file-store';
|
|
6
|
+
import { UploadSnapshotMetadataSchema, makeSnapshotPaths } from '@aztec/stdlib/snapshots';
|
|
7
|
+
|
|
8
|
+
import { readFileSync } from 'fs';
|
|
9
|
+
|
|
10
|
+
import { deserializeEpochProvingJobData } from '../job/epoch-proving-job-data.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Given a location returned by `uploadEpochProofFailure`, downloads the world state and archiver snapshots
|
|
14
|
+
* and the proving job data, so we can re-run the job later using `rerunEpochProvingJob`. This is decoupled
|
|
15
|
+
* from actually proving so we can download once and run multiple times.
|
|
16
|
+
*/
|
|
17
|
+
export async function downloadEpochProvingJob(
|
|
18
|
+
location: string,
|
|
19
|
+
log: Logger,
|
|
20
|
+
config: {
|
|
21
|
+
dataDirectory: string;
|
|
22
|
+
jobDataDownloadPath: string;
|
|
23
|
+
},
|
|
24
|
+
) {
|
|
25
|
+
log.info(`Downloading epoch proving job data from ${location}`);
|
|
26
|
+
const fileStore = await createReadOnlyFileStore(location);
|
|
27
|
+
const metadataUrl = urlJoin(location, 'metadata.json');
|
|
28
|
+
const metadataRaw = await fileStore.read(metadataUrl);
|
|
29
|
+
const metadata = jsonParseWithSchema(metadataRaw.toString(), UploadSnapshotMetadataSchema);
|
|
30
|
+
|
|
31
|
+
const dataUrls = makeSnapshotPaths(location);
|
|
32
|
+
log.info(`Downloading state snapshot from ${location} to local data directory`, { metadata, dataUrls });
|
|
33
|
+
await snapshotSync({ dataUrls }, log, { ...config, ...metadata, snapshotsUrl: location });
|
|
34
|
+
|
|
35
|
+
const dataPath = urlJoin(location, 'data.bin');
|
|
36
|
+
const localPath = config.jobDataDownloadPath;
|
|
37
|
+
log.info(`Downloading epoch proving job data from ${dataPath} to ${localPath}`);
|
|
38
|
+
await fileStore.download(dataPath, localPath);
|
|
39
|
+
|
|
40
|
+
const jobData = deserializeEpochProvingJobData(readFileSync(localPath));
|
|
41
|
+
log.info(`Epoch proving job data for epoch ${jobData.epochNumber} downloaded successfully`);
|
|
42
|
+
|
|
43
|
+
return metadata;
|
|
44
|
+
}
|