@aztec/prover-node 0.0.1-commit.c31f2472 → 0.0.1-commit.c52d6e7
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/README.md +572 -0
- package/dest/actions/download-epoch-proving-job.js +1 -1
- package/dest/actions/rerun-epoch-proving-job.d.ts +14 -4
- package/dest/actions/rerun-epoch-proving-job.d.ts.map +1 -1
- package/dest/actions/rerun-epoch-proving-job.js +244 -24
- package/dest/actions/upload-epoch-proof-failure.d.ts +2 -2
- package/dest/actions/upload-epoch-proof-failure.d.ts.map +1 -1
- package/dest/bin/run-failed-epoch.js +6 -5
- package/dest/checkpoint-store.d.ts +95 -0
- package/dest/checkpoint-store.d.ts.map +1 -0
- package/dest/checkpoint-store.js +178 -0
- package/dest/config.d.ts +7 -8
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +24 -20
- package/dest/factory.d.ts +22 -13
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +41 -65
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/job/checkpoint-prover.d.ts +165 -0
- package/dest/job/checkpoint-prover.d.ts.map +1 -0
- package/dest/job/checkpoint-prover.js +405 -0
- package/dest/job/epoch-session.d.ts +160 -0
- package/dest/job/epoch-session.d.ts.map +1 -0
- package/dest/job/{epoch-proving-job.js → epoch-session.js} +301 -298
- package/dest/job/top-tree-job.d.ts +82 -0
- package/dest/job/top-tree-job.d.ts.map +1 -0
- package/dest/job/top-tree-job.js +152 -0
- package/dest/metrics.d.ts +40 -3
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +101 -4
- package/dest/monitors/epoch-monitor.d.ts +1 -1
- package/dest/monitors/epoch-monitor.d.ts.map +1 -1
- package/dest/monitors/epoch-monitor.js +11 -9
- package/dest/proof-publishing-service.d.ts +161 -0
- package/dest/proof-publishing-service.d.ts.map +1 -0
- package/dest/proof-publishing-service.js +335 -0
- package/dest/prover-node-publisher.d.ts +25 -15
- package/dest/prover-node-publisher.d.ts.map +1 -1
- package/dest/prover-node-publisher.js +202 -63
- package/dest/prover-node.d.ts +146 -69
- package/dest/prover-node.d.ts.map +1 -1
- package/dest/prover-node.js +545 -221
- package/dest/prover-publisher-factory.d.ts +6 -4
- package/dest/prover-publisher-factory.d.ts.map +1 -1
- package/dest/prover-publisher-factory.js +4 -3
- package/dest/session-manager.d.ts +158 -0
- package/dest/session-manager.d.ts.map +1 -0
- package/dest/session-manager.js +492 -0
- package/dest/test/index.d.ts +7 -6
- package/dest/test/index.d.ts.map +1 -1
- package/package.json +24 -22
- package/src/actions/download-epoch-proving-job.ts +1 -1
- package/src/actions/rerun-epoch-proving-job.ts +190 -31
- package/src/actions/upload-epoch-proof-failure.ts +1 -1
- package/src/bin/run-failed-epoch.ts +5 -3
- package/src/checkpoint-store.ts +212 -0
- package/src/config.ts +35 -32
- package/src/factory.ts +73 -111
- package/src/index.ts +1 -0
- package/src/job/checkpoint-prover.ts +538 -0
- package/src/job/epoch-session.ts +462 -0
- package/src/job/top-tree-job.ts +227 -0
- package/src/metrics.ts +123 -10
- package/src/monitors/epoch-monitor.ts +5 -6
- package/src/proof-publishing-service.ts +427 -0
- package/src/prover-node-publisher.ts +237 -79
- package/src/prover-node.ts +631 -248
- package/src/prover-publisher-factory.ts +8 -5
- package/src/session-manager.ts +592 -0
- package/src/test/index.ts +6 -6
- package/dest/job/epoch-proving-job.d.ts +0 -63
- package/dest/job/epoch-proving-job.d.ts.map +0 -1
- package/src/job/epoch-proving-job.ts +0 -435
|
@@ -1,63 +1,222 @@
|
|
|
1
|
-
import { createArchiverStore } from '@aztec/archiver';
|
|
1
|
+
import { createArchiverStore, createContractDataSource } from '@aztec/archiver';
|
|
2
2
|
import type { L1ContractsConfig } from '@aztec/ethereum/config';
|
|
3
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
4
|
import type { Logger } from '@aztec/foundation/log';
|
|
4
|
-
import
|
|
5
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
5
6
|
import { type ProverClientConfig, createProverClient } from '@aztec/prover-client';
|
|
6
7
|
import { ProverBrokerConfig, createAndStartProvingBroker } from '@aztec/prover-client/broker';
|
|
7
|
-
import {
|
|
8
|
+
import { getLastSiblingPath } from '@aztec/prover-client/helpers';
|
|
9
|
+
import { ChonkCache } from '@aztec/prover-client/orchestrator';
|
|
10
|
+
import { AvmSimulatorPool, PublicProcessorFactory } from '@aztec/simulator/server';
|
|
11
|
+
import type { L2Block } from '@aztec/stdlib/block';
|
|
12
|
+
import { getEpochAtSlot, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
13
|
+
import type { ITxProvider } from '@aztec/stdlib/interfaces/server';
|
|
14
|
+
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
15
|
+
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
16
|
+
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
17
|
+
import type { GenesisData } from '@aztec/stdlib/world-state';
|
|
8
18
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
9
19
|
import { createWorldState } from '@aztec/world-state';
|
|
10
20
|
|
|
11
21
|
import { readFileSync } from 'fs';
|
|
12
22
|
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
23
|
+
import { CheckpointProver } from '../job/checkpoint-prover.js';
|
|
24
|
+
import { type EpochProvingJobData, deserializeEpochProvingJobData } from '../job/epoch-proving-job-data.js';
|
|
25
|
+
import { EpochSession, type SessionSpec } from '../job/epoch-session.js';
|
|
15
26
|
import { ProverNodeJobMetrics } from '../metrics.js';
|
|
16
27
|
|
|
28
|
+
type RerunConfig = DataStoreConfig &
|
|
29
|
+
ProverBrokerConfig &
|
|
30
|
+
ProverClientConfig &
|
|
31
|
+
Pick<L1ContractsConfig, 'aztecEpochDuration'>;
|
|
32
|
+
|
|
17
33
|
/**
|
|
18
34
|
* Given a local folder where `downloadEpochProvingJob` was called, creates a new archiver and world state
|
|
19
|
-
* using the state snapshots, and creates a new epoch proving
|
|
35
|
+
* using the state snapshots, and creates a new epoch proving session to prove the downloaded proving job.
|
|
20
36
|
* Proving is done with a local proving broker and agents as specified by the config.
|
|
21
37
|
*/
|
|
22
|
-
export async function rerunEpochProvingJob(
|
|
38
|
+
export async function rerunEpochProvingJob(localPath: string, log: Logger, config: RerunConfig, genesis?: GenesisData) {
|
|
39
|
+
await using ctx = await createRerunContext(localPath, log, config, genesis);
|
|
40
|
+
const { jobData, prover, metrics } = ctx;
|
|
41
|
+
|
|
42
|
+
log.info(`Rerunning epoch proving for epoch ${jobData.epochNumber}`);
|
|
43
|
+
|
|
44
|
+
const provers: CheckpointProver[] = [];
|
|
45
|
+
for (let i = 0; i < jobData.checkpoints.length; i++) {
|
|
46
|
+
provers.push(await buildCheckpointProver(ctx, i, log));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Local rerun never publishes — stub the service so submit() always resolves 'published'
|
|
50
|
+
// and withdraw is a no-op.
|
|
51
|
+
const publishingService = {
|
|
52
|
+
submit: () => Promise.resolve('published' as const),
|
|
53
|
+
withdraw: () => {},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const l1Constants = { epochDuration: config.aztecEpochDuration };
|
|
57
|
+
const [fromSlot, toSlot] = getSlotRangeForEpoch(jobData.epochNumber, l1Constants);
|
|
58
|
+
const spec: SessionSpec = { kind: 'full', epochNumber: jobData.epochNumber, fromSlot, toSlot };
|
|
59
|
+
|
|
60
|
+
const session = new EpochSession(spec, provers, {
|
|
61
|
+
proverFactory: prover,
|
|
62
|
+
proverId: prover.getProverId(),
|
|
63
|
+
publishingService,
|
|
64
|
+
metrics,
|
|
65
|
+
dateProvider: new DateProvider(),
|
|
66
|
+
deadline: undefined,
|
|
67
|
+
config: {},
|
|
68
|
+
bindings: log.getBindings(),
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const finalState = await session.start();
|
|
72
|
+
log.info(`Completed proving for epoch ${jobData.epochNumber} with status ${finalState}`, {
|
|
73
|
+
derivedEpoch: getEpochAtSlot(provers[0].slotNumber, l1Constants),
|
|
74
|
+
});
|
|
75
|
+
return finalState;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Re-proves a single downloaded checkpoint proving job (as uploaded by a `CheckpointProver` failure).
|
|
80
|
+
* Reconstructs just that checkpoint's sub-tree prover from the snapshot and awaits its block proofs — no
|
|
81
|
+
* epoch top-tree, no L1 submission — so a checkpoint-level failure can be reproduced offline in isolation.
|
|
82
|
+
* Returns the block-rollup proof outputs on success; throws if the checkpoint fails to prove again.
|
|
83
|
+
*/
|
|
84
|
+
export async function rerunCheckpointProvingJob(
|
|
23
85
|
localPath: string,
|
|
24
86
|
log: Logger,
|
|
25
|
-
config:
|
|
87
|
+
config: RerunConfig,
|
|
88
|
+
genesis?: GenesisData,
|
|
26
89
|
) {
|
|
90
|
+
await using ctx = await createRerunContext(localPath, log, config, genesis);
|
|
91
|
+
const { jobData } = ctx;
|
|
92
|
+
const checkpointNumber = jobData.checkpoints[0].number;
|
|
93
|
+
|
|
94
|
+
log.info(`Rerunning checkpoint proving for checkpoint ${checkpointNumber} (epoch ${jobData.epochNumber})`);
|
|
95
|
+
|
|
96
|
+
const prover = await buildCheckpointProver(ctx, 0, log);
|
|
97
|
+
try {
|
|
98
|
+
const blockProofs = await prover.whenBlockProofsReady();
|
|
99
|
+
log.info(`Completed proving for checkpoint ${checkpointNumber} with ${blockProofs.length} block proof(s)`);
|
|
100
|
+
return blockProofs;
|
|
101
|
+
} finally {
|
|
102
|
+
prover.cancel({ routine: true });
|
|
103
|
+
await prover.whenDone();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Everything a rerun needs, reconstructed from the downloaded snapshot + job data. */
|
|
108
|
+
type RerunContext = {
|
|
109
|
+
jobData: EpochProvingJobData;
|
|
110
|
+
metrics: ProverNodeJobMetrics;
|
|
111
|
+
worldState: Awaited<ReturnType<typeof createWorldState>>;
|
|
112
|
+
publicProcessorFactory: PublicProcessorFactory;
|
|
113
|
+
prover: Awaited<ReturnType<typeof createProverClient>>;
|
|
114
|
+
chonkCache: ChonkCache;
|
|
115
|
+
txProvider: ITxProvider;
|
|
116
|
+
} & AsyncDisposable;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Rebuilds the offline proving environment from a downloaded job: world state + archiver from the
|
|
120
|
+
* snapshots, a local proving broker + client, a chonk cache, and a tx provider that replays the job's txs.
|
|
121
|
+
*/
|
|
122
|
+
async function createRerunContext(
|
|
123
|
+
localPath: string,
|
|
124
|
+
log: Logger,
|
|
125
|
+
config: RerunConfig,
|
|
126
|
+
genesis?: GenesisData,
|
|
127
|
+
): Promise<RerunContext> {
|
|
27
128
|
const jobData = deserializeEpochProvingJobData(readFileSync(localPath));
|
|
28
129
|
log.info(`Loaded proving job data for epoch ${jobData.epochNumber}`);
|
|
29
130
|
|
|
30
131
|
const telemetry = getTelemetryClient();
|
|
31
132
|
const metrics = new ProverNodeJobMetrics(telemetry.getMeter('prover-job'), telemetry.getTracer('prover-job'));
|
|
32
|
-
const worldState = await createWorldState(config);
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
133
|
+
const worldState = await createWorldState(config, genesis);
|
|
134
|
+
const initialBlockHash = await worldState.getInitialHeader().hash();
|
|
135
|
+
const archiver = await createArchiverStore(config, initialBlockHash);
|
|
136
|
+
const avmSimulator = await AvmSimulatorPool.spawn({ wsdbIpcPath: worldState.getIpcPath() });
|
|
137
|
+
const publicProcessorFactory = new PublicProcessorFactory(
|
|
138
|
+
createContractDataSource(archiver),
|
|
139
|
+
avmSimulator,
|
|
140
|
+
undefined,
|
|
141
|
+
undefined,
|
|
142
|
+
log.getBindings(),
|
|
143
|
+
);
|
|
43
144
|
const broker = await createAndStartProvingBroker(config, telemetry);
|
|
44
145
|
const prover = await createProverClient(config, worldState, broker, telemetry);
|
|
146
|
+
const chonkCache = new ChonkCache(log.getBindings());
|
|
147
|
+
const txProvider = makeReplayingTxProvider(jobData.txs);
|
|
45
148
|
|
|
46
|
-
|
|
149
|
+
return {
|
|
47
150
|
jobData,
|
|
151
|
+
metrics,
|
|
48
152
|
worldState,
|
|
49
|
-
prover.createEpochProver(),
|
|
50
153
|
publicProcessorFactory,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
154
|
+
prover,
|
|
155
|
+
chonkCache,
|
|
156
|
+
txProvider,
|
|
157
|
+
async [Symbol.asyncDispose]() {
|
|
158
|
+
await avmSimulator[Symbol.asyncDispose]();
|
|
159
|
+
await worldState[Symbol.asyncDispose]();
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Reconstructs the `CheckpointProver` for the checkpoint at `index` in the job, ready to prove. */
|
|
165
|
+
async function buildCheckpointProver(ctx: RerunContext, index: number, log: Logger): Promise<CheckpointProver> {
|
|
166
|
+
const { jobData, worldState, prover, chonkCache, publicProcessorFactory, txProvider, metrics } = ctx;
|
|
167
|
+
const checkpoint = jobData.checkpoints[index];
|
|
168
|
+
const previousBlockHeader =
|
|
169
|
+
index === 0 ? jobData.previousBlockHeader : jobData.checkpoints[index - 1].blocks.at(-1)!.header;
|
|
170
|
+
const l1ToL2Messages = jobData.l1ToL2Messages[checkpoint.number] ?? [];
|
|
171
|
+
const previousArchiveSiblingPath = await getLastSiblingPath(
|
|
172
|
+
MerkleTreeId.ARCHIVE,
|
|
173
|
+
worldState.getSnapshot(BlockNumber(checkpoint.blocks[0].number - 1)),
|
|
57
174
|
);
|
|
175
|
+
const attestations = checkpoint.number === jobData.checkpoints.at(-1)!.number ? jobData.attestations : [];
|
|
176
|
+
return new CheckpointProver(
|
|
177
|
+
{
|
|
178
|
+
checkpoint,
|
|
179
|
+
epochNumber: jobData.epochNumber,
|
|
180
|
+
attestations,
|
|
181
|
+
previousBlockHeader,
|
|
182
|
+
l1ToL2Messages,
|
|
183
|
+
previousArchiveSiblingPath,
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
proverFactory: prover,
|
|
187
|
+
chonkCache,
|
|
188
|
+
publicProcessorFactory,
|
|
189
|
+
dbProvider: worldState,
|
|
190
|
+
txProvider,
|
|
191
|
+
dateProvider: new DateProvider(),
|
|
192
|
+
proverId: prover.getProverId(),
|
|
193
|
+
metrics,
|
|
194
|
+
txGatheringTimeoutMs: 120_000,
|
|
195
|
+
deadline: undefined,
|
|
196
|
+
log,
|
|
197
|
+
},
|
|
198
|
+
);
|
|
199
|
+
}
|
|
58
200
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
201
|
+
/** Build a synthetic ITxProvider that returns the supplied txs map by lookup. */
|
|
202
|
+
function makeReplayingTxProvider(txs: Map<string, Tx>): ITxProvider {
|
|
203
|
+
const lookup = (hashes: TxHash[]) => {
|
|
204
|
+
const found: Tx[] = [];
|
|
205
|
+
const missing: TxHash[] = [];
|
|
206
|
+
for (const hash of hashes) {
|
|
207
|
+
const tx = txs.get(hash.toString());
|
|
208
|
+
if (tx) {
|
|
209
|
+
found.push(tx);
|
|
210
|
+
} else {
|
|
211
|
+
missing.push(hash);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return { txs: found, missingTxs: missing };
|
|
215
|
+
};
|
|
216
|
+
return {
|
|
217
|
+
getAvailableTxs: hashes => Promise.resolve(lookup(hashes)),
|
|
218
|
+
hasTxs: hashes => Promise.resolve(hashes.map(h => txs.has(h.toString()))),
|
|
219
|
+
getTxsForBlockProposal: () => Promise.resolve({ txs: [], missingTxs: [] }),
|
|
220
|
+
getTxsForBlock: (block: L2Block) => Promise.resolve(lookup(block.body.txEffects.map(e => e.txHash))),
|
|
221
|
+
};
|
|
63
222
|
}
|
|
@@ -3,11 +3,11 @@ import { tryRmDir } from '@aztec/foundation/fs';
|
|
|
3
3
|
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
4
4
|
import type { Logger } from '@aztec/foundation/log';
|
|
5
5
|
import { isoDate } from '@aztec/foundation/string';
|
|
6
|
-
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
7
6
|
import { buildSnapshotMetadata, createBackups } from '@aztec/node-lib/actions';
|
|
8
7
|
import type { ChainConfig } from '@aztec/stdlib/config';
|
|
9
8
|
import { type FileStore, createFileStore } from '@aztec/stdlib/file-store';
|
|
10
9
|
import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
10
|
+
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
11
11
|
import { type UploadSnapshotMetadata, getBasePath, uploadSnapshotData } from '@aztec/stdlib/snapshots';
|
|
12
12
|
import { WORLD_STATE_DB_VERSION } from '@aztec/world-state';
|
|
13
13
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
|
-
import
|
|
2
|
+
import { getL1ContractsConfigEnvVars } from '@aztec/ethereum/config';
|
|
3
3
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
4
|
import { jsonParseWithSchema, jsonStringify } from '@aztec/foundation/json-rpc';
|
|
5
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
@@ -22,8 +22,10 @@ async function rerunFailedEpoch(provingJobUrl: string, baseLocalDir: string) {
|
|
|
22
22
|
const dataDir = join(localDir, 'state');
|
|
23
23
|
|
|
24
24
|
const env = getProverNodeConfigFromEnv();
|
|
25
|
+
const l1Config = getL1ContractsConfigEnvVars();
|
|
25
26
|
const config = {
|
|
26
|
-
...
|
|
27
|
+
...env,
|
|
28
|
+
...l1Config,
|
|
27
29
|
dataDirectory: dataDir,
|
|
28
30
|
dataStoreMapSizeKb: env.dataStoreMapSizeKb ?? 1024 * 1024,
|
|
29
31
|
proverId: env.proverId ?? EthAddress.random(),
|
|
@@ -47,7 +49,7 @@ async function rerunFailedEpoch(provingJobUrl: string, baseLocalDir: string) {
|
|
|
47
49
|
logger.info(`Rerunning proving job from ${jobPath} with state from ${dataDir}`, metadata);
|
|
48
50
|
const result = await rerunEpochProvingJob(jobPath, logger, {
|
|
49
51
|
...config,
|
|
50
|
-
|
|
52
|
+
rollupAddress: metadata.rollupAddress,
|
|
51
53
|
rollupVersion: metadata.rollupVersion,
|
|
52
54
|
});
|
|
53
55
|
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import type { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
4
|
+
import type { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
5
|
+
import { type L1RollupConstants, getEpochAtSlot, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
CheckpointProver,
|
|
9
|
+
type CheckpointProverArgs,
|
|
10
|
+
type CheckpointProverDeps,
|
|
11
|
+
type CheckpointProverTestHooks,
|
|
12
|
+
} from './job/checkpoint-prover.js';
|
|
13
|
+
|
|
14
|
+
/** Register-time data needed to construct a `CheckpointProver` (everything except the checkpoint + epoch). */
|
|
15
|
+
export type RegisterCheckpointData = Omit<CheckpointProverArgs, 'checkpoint' | 'epochNumber'>;
|
|
16
|
+
|
|
17
|
+
/** Factory used by the store to construct new provers. Tests can inject a stub. */
|
|
18
|
+
export type CheckpointProverFactory = (args: CheckpointProverArgs, deps: CheckpointProverDeps) => CheckpointProver;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Prover-node-wide registry of `CheckpointProver` instances, content-addressed by
|
|
22
|
+
* `(checkpoint number, slot, checkpoint archive root)`.
|
|
23
|
+
*
|
|
24
|
+
* The store survives every epoch / session boundary. A prover lives from its first
|
|
25
|
+
* `addOrUpdate` call until either:
|
|
26
|
+
* - its checkpoint is pruned by an L1 reorg (`cancelAndRemoveAboveBlock`), or
|
|
27
|
+
* - its epoch's proof-submission window has closed (`reapExpired`), so the proof could no
|
|
28
|
+
* longer be accepted on L1 even if produced.
|
|
29
|
+
*
|
|
30
|
+
* A prover's sub-tree work forks world-state per block and does not survive a prune of a base
|
|
31
|
+
* block, so there is nothing to preserve across a reorg: a pruned prover is cancelled and
|
|
32
|
+
* dropped, and a re-add (even of identical content) constructs a fresh prover.
|
|
33
|
+
*/
|
|
34
|
+
export class CheckpointStore {
|
|
35
|
+
private readonly provers = new Map<string, CheckpointProver>();
|
|
36
|
+
/**
|
|
37
|
+
* Teardowns of provers already removed from `provers` (by prune or reap), awaited on `stop()`.
|
|
38
|
+
* Keyed by a monotonic id rather than the prover's content id: a prune-then-re-add can leave two
|
|
39
|
+
* teardowns for the same content id in flight at once, which a content-id key would clobber.
|
|
40
|
+
*/
|
|
41
|
+
private readonly pendingTeardowns = new Map<number, Promise<void>>();
|
|
42
|
+
private nextTeardownId = 0;
|
|
43
|
+
/** Test-only hooks injected into every prover this store constructs. */
|
|
44
|
+
private testHooks: CheckpointProverTestHooks = {};
|
|
45
|
+
private readonly log: Logger;
|
|
46
|
+
|
|
47
|
+
constructor(
|
|
48
|
+
private readonly l2BlockSource: Pick<L2BlockSource, 'getL1Constants'>,
|
|
49
|
+
private readonly proverDeps: Omit<CheckpointProverDeps, 'log'>,
|
|
50
|
+
bindings?: LoggerBindings,
|
|
51
|
+
private readonly proverFactoryFn: CheckpointProverFactory = (args, deps) => new CheckpointProver(args, deps),
|
|
52
|
+
) {
|
|
53
|
+
this.log = createLogger('prover-node:checkpoint-store', bindings);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public start(): Promise<void> {
|
|
57
|
+
return Promise.resolve();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public async stop(): Promise<void> {
|
|
61
|
+
// Cancel every live prover, then await both their teardown and any still in flight for provers
|
|
62
|
+
// already removed by a prune or reap.
|
|
63
|
+
const provers = Array.from(this.provers.values());
|
|
64
|
+
this.provers.clear();
|
|
65
|
+
for (const prover of provers) {
|
|
66
|
+
prover.cancel();
|
|
67
|
+
}
|
|
68
|
+
await Promise.allSettled([...provers.map(p => p.whenDone()), ...this.pendingTeardowns.values()]);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Tracks the teardown of a prover just removed from the store so `stop()` can await it. The entry
|
|
73
|
+
* removes itself once teardown settles, so the map stays bounded by the number in flight.
|
|
74
|
+
*/
|
|
75
|
+
private trackTeardown(prover: CheckpointProver): void {
|
|
76
|
+
const id = this.nextTeardownId++;
|
|
77
|
+
const done = prover.whenDone();
|
|
78
|
+
this.pendingTeardowns.set(id, done);
|
|
79
|
+
void done.finally(() => this.pendingTeardowns.delete(id));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Registers a checkpoint with the store. If a prover already exists for the
|
|
84
|
+
* `(number, slot, archive root)` content key it is reused (an at-least-once re-registration of
|
|
85
|
+
* still-canonical content); otherwise a new prover is constructed.
|
|
86
|
+
*/
|
|
87
|
+
public async addOrUpdate(checkpoint: Checkpoint, data: RegisterCheckpointData): Promise<CheckpointProver> {
|
|
88
|
+
const l1Constants = await this.l2BlockSource.getL1Constants();
|
|
89
|
+
const epochNumber = getEpochAtSlot(checkpoint.header.slotNumber, l1Constants);
|
|
90
|
+
const id = CheckpointProver.idFor(checkpoint);
|
|
91
|
+
|
|
92
|
+
const existing = this.provers.get(id);
|
|
93
|
+
if (existing) {
|
|
94
|
+
return existing;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// At most one canonical checkpoint per slot. A different checkpoint at the same slot means the
|
|
98
|
+
// caller forgot to prune the old chain before adding the replacement — surface it rather than
|
|
99
|
+
// silently creating a parallel canonical chain. A pruned checkpoint has already been removed,
|
|
100
|
+
// so every prover still in the store is canonical.
|
|
101
|
+
for (const prover of this.provers.values()) {
|
|
102
|
+
if (prover.slotNumber === checkpoint.header.slotNumber) {
|
|
103
|
+
throw new Error(
|
|
104
|
+
`Cannot add checkpoint ${checkpoint.number} (archive ${checkpoint.archive.root}) at slot ${checkpoint.header.slotNumber}: ` +
|
|
105
|
+
`a different checkpoint already occupies this slot. Prune it first.`,
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const prover = this.proverFactoryFn(
|
|
111
|
+
{ ...data, checkpoint, epochNumber },
|
|
112
|
+
{ ...this.proverDeps, checkpointProveOverride: this.testHooks.checkpointProveOverride, log: this.log },
|
|
113
|
+
);
|
|
114
|
+
this.provers.set(id, prover);
|
|
115
|
+
return prover;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Installs test-only hooks applied to every prover constructed from now on. Used by the e2e harness to
|
|
120
|
+
* force a checkpoint sub-tree failure without monkey-patching the prover factory.
|
|
121
|
+
*/
|
|
122
|
+
public setTestHooks(hooks: CheckpointProverTestHooks): void {
|
|
123
|
+
this.testHooks = hooks;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Cancels and removes every prover that holds a block above the prune target. A checkpoint is orphaned by a prune to
|
|
128
|
+
* block `targetBlockNumber` iff its last block sits above the target — including a checkpoint whose range straddles
|
|
129
|
+
* the target (partially orphaned), which block-range marking catches without boundary ambiguity. Keying off the
|
|
130
|
+
* surviving block number (rather than a checkpoint number) is correct even when the source has already
|
|
131
|
+
* re-checkpointed past the divergence: the prune event reports the highest surviving block, which by construction
|
|
132
|
+
* survives on the source, whereas the source's current checkpointed tip can sit above the prune target.
|
|
133
|
+
*
|
|
134
|
+
* The prover's in-flight sub-tree work forks world-state per block and faults once its base block is pruned, so it
|
|
135
|
+
* cannot be reused; it is cancelled (aborting the fork reads) and dropped. A subsequent re-add constructs a fresh
|
|
136
|
+
* prover. Returns the removed provers.
|
|
137
|
+
*/
|
|
138
|
+
public cancelAndRemoveAboveBlock(targetBlockNumber: BlockNumber): CheckpointProver[] {
|
|
139
|
+
const affected: CheckpointProver[] = [];
|
|
140
|
+
for (const [id, prover] of Array.from(this.provers.entries())) {
|
|
141
|
+
const lastBlockNumber = prover.checkpoint.blocks.at(-1)!.number;
|
|
142
|
+
if (lastBlockNumber > targetBlockNumber) {
|
|
143
|
+
prover.cancel();
|
|
144
|
+
this.trackTeardown(prover);
|
|
145
|
+
this.provers.delete(id);
|
|
146
|
+
affected.push(prover);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return affected;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Drops provers whose epoch is at or below the supplied expired epoch. Once an epoch's
|
|
154
|
+
* proof-submission window has closed, its proof can no longer be accepted on L1, so the
|
|
155
|
+
* prover is no longer needed.
|
|
156
|
+
*/
|
|
157
|
+
public reapExpired(expiredEpoch: EpochNumber): void {
|
|
158
|
+
const reaped: { id: string; checkpointNumber: CheckpointNumber; epochNumber: EpochNumber }[] = [];
|
|
159
|
+
for (const [id, prover] of Array.from(this.provers.entries())) {
|
|
160
|
+
if (prover.epochNumber <= expiredEpoch) {
|
|
161
|
+
reaped.push({ id, checkpointNumber: prover.checkpoint.number, epochNumber: prover.epochNumber });
|
|
162
|
+
prover.cancel({ routine: true });
|
|
163
|
+
this.trackTeardown(prover);
|
|
164
|
+
this.provers.delete(id);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (reaped.length > 0) {
|
|
168
|
+
this.log.info(`Reaped ${reaped.length} expired CheckpointProver(s) for expiredEpoch ${expiredEpoch}`, {
|
|
169
|
+
expiredEpoch,
|
|
170
|
+
reapedCount: reaped.length,
|
|
171
|
+
reaped,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Returns the prover with the supplied id, or undefined. */
|
|
177
|
+
public get(id: string): CheckpointProver | undefined {
|
|
178
|
+
return this.provers.get(id);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Returns the prover for the supplied checkpoint (by its content-addressed id), or undefined. */
|
|
182
|
+
public getByCheckpoint(checkpoint: Checkpoint): CheckpointProver | undefined {
|
|
183
|
+
return this.provers.get(CheckpointProver.idFor(checkpoint));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Every prover currently in the store, in insertion order. */
|
|
187
|
+
public listAll(): CheckpointProver[] {
|
|
188
|
+
return Array.from(this.provers.values());
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Provers in the store, sorted by checkpoint number. */
|
|
192
|
+
public list(): CheckpointProver[] {
|
|
193
|
+
return Array.from(this.provers.values()).sort((a, b) => a.checkpoint.number - b.checkpoint.number);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Provers whose slot is in the supplied epoch's slot range, sorted by checkpoint number.
|
|
198
|
+
*/
|
|
199
|
+
public async listForEpoch(epoch: EpochNumber): Promise<CheckpointProver[]> {
|
|
200
|
+
const l1Constants = await this.l2BlockSource.getL1Constants();
|
|
201
|
+
const [fromSlot, toSlot] = getSlotRangeForEpoch(epoch, l1Constants);
|
|
202
|
+
return this.listInSlotRange(fromSlot, toSlot);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Provers whose slot falls within `[fromSlot, toSlot]`, sorted by checkpoint number. */
|
|
206
|
+
public listInSlotRange(fromSlot: SlotNumber, toSlot: SlotNumber): CheckpointProver[] {
|
|
207
|
+
return this.list().filter(p => p.slotNumber >= fromSlot && p.slotNumber <= toSlot);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Sub-set of `L1RollupConstants` actually consumed by the store's slot helpers. */
|
|
212
|
+
export type CheckpointStoreL1Constants = Pick<L1RollupConstants, 'epochDuration'>;
|
package/src/config.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import { type ArchiverConfig, archiverConfigMappings } from '@aztec/archiver/config';
|
|
2
1
|
import type { ACVMConfig, BBConfig } from '@aztec/bb-prover/config';
|
|
3
|
-
import { type GenesisStateConfig, genesisStateConfigMappings } from '@aztec/ethereum/config';
|
|
4
2
|
import {
|
|
5
3
|
type ConfigMappingsType,
|
|
6
4
|
booleanConfigHelper,
|
|
7
5
|
getConfigFromMappings,
|
|
8
6
|
numberConfigHelper,
|
|
7
|
+
pickConfigMappings,
|
|
9
8
|
} from '@aztec/foundation/config';
|
|
10
|
-
import {
|
|
9
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
11
10
|
import { type KeyStoreConfig, keyStoreConfigMappings } from '@aztec/node-keystore/config';
|
|
12
11
|
import { ethPrivateKeySchema } from '@aztec/node-keystore/schemas';
|
|
13
12
|
import type { KeyStore } from '@aztec/node-keystore/types';
|
|
14
13
|
import { type SharedNodeConfig, sharedNodeConfigMappings } from '@aztec/node-lib/config';
|
|
15
|
-
import { type P2PConfig, p2pConfigMappings } from '@aztec/p2p/config';
|
|
16
14
|
import {
|
|
17
15
|
type ProverAgentConfig,
|
|
18
16
|
type ProverBrokerConfig,
|
|
@@ -21,24 +19,20 @@ import {
|
|
|
21
19
|
} from '@aztec/prover-client/broker/config';
|
|
22
20
|
import { type ProverClientUserConfig, bbConfigMappings, proverClientConfigMappings } from '@aztec/prover-client/config';
|
|
23
21
|
import {
|
|
24
|
-
type
|
|
25
|
-
type
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
type ProverPublisherConfig,
|
|
23
|
+
type ProverTxSenderConfig,
|
|
24
|
+
proverPublisherConfigMappings,
|
|
25
|
+
proverTxSenderConfigMappings,
|
|
28
26
|
} from '@aztec/sequencer-client/config';
|
|
29
|
-
import { type
|
|
30
|
-
|
|
31
|
-
export type ProverNodeConfig =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
WorldStateConfig &
|
|
35
|
-
PublisherConfig &
|
|
36
|
-
TxSenderConfig &
|
|
27
|
+
import { type DataStoreConfig, dataConfigMappings } from '@aztec/stdlib/kv-store';
|
|
28
|
+
|
|
29
|
+
export type ProverNodeConfig = ProverClientUserConfig &
|
|
30
|
+
ProverPublisherConfig &
|
|
31
|
+
ProverTxSenderConfig &
|
|
37
32
|
DataStoreConfig &
|
|
38
33
|
KeyStoreConfig &
|
|
39
|
-
SharedNodeConfig &
|
|
40
34
|
SpecificProverNodeConfig &
|
|
41
|
-
|
|
35
|
+
Pick<SharedNodeConfig, 'web3SignerUrl'>;
|
|
42
36
|
|
|
43
37
|
export type SpecificProverNodeConfig = {
|
|
44
38
|
proverNodeMaxPendingJobs: number;
|
|
@@ -51,9 +45,10 @@ export type SpecificProverNodeConfig = {
|
|
|
51
45
|
txGatheringIntervalMs: number;
|
|
52
46
|
txGatheringBatchSize: number;
|
|
53
47
|
txGatheringMaxParallelRequestsPerNode: number;
|
|
48
|
+
proofSubmissionTargetAddress?: EthAddress;
|
|
54
49
|
};
|
|
55
50
|
|
|
56
|
-
const specificProverNodeConfigMappings: ConfigMappingsType<SpecificProverNodeConfig> = {
|
|
51
|
+
export const specificProverNodeConfigMappings: ConfigMappingsType<SpecificProverNodeConfig> = {
|
|
57
52
|
proverNodeMaxPendingJobs: {
|
|
58
53
|
env: 'PROVER_NODE_MAX_PENDING_JOBS',
|
|
59
54
|
description: 'The maximum number of pending jobs for the prover node',
|
|
@@ -67,7 +62,7 @@ const specificProverNodeConfigMappings: ConfigMappingsType<SpecificProverNodeCon
|
|
|
67
62
|
proverNodeMaxParallelBlocksPerEpoch: {
|
|
68
63
|
env: 'PROVER_NODE_MAX_PARALLEL_BLOCKS_PER_EPOCH',
|
|
69
64
|
description: 'The Maximum number of blocks to process in parallel while proving an epoch',
|
|
70
|
-
...numberConfigHelper(
|
|
65
|
+
...numberConfigHelper(0),
|
|
71
66
|
},
|
|
72
67
|
proverNodeFailedEpochStore: {
|
|
73
68
|
env: 'PROVER_NODE_FAILED_EPOCH_STORE',
|
|
@@ -75,7 +70,8 @@ const specificProverNodeConfigMappings: ConfigMappingsType<SpecificProverNodeCon
|
|
|
75
70
|
defaultValue: undefined,
|
|
76
71
|
},
|
|
77
72
|
proverNodeEpochProvingDelayMs: {
|
|
78
|
-
description:
|
|
73
|
+
description:
|
|
74
|
+
'Optional delay in milliseconds to wait for late-arriving events (e.g. reorgs) to settle before starting top-tree proving for an epoch',
|
|
79
75
|
defaultValue: undefined,
|
|
80
76
|
},
|
|
81
77
|
txGatheringIntervalMs: {
|
|
@@ -103,20 +99,24 @@ const specificProverNodeConfigMappings: ConfigMappingsType<SpecificProverNodeCon
|
|
|
103
99
|
description: 'Whether the prover node skips publishing proofs to L1',
|
|
104
100
|
...booleanConfigHelper(false),
|
|
105
101
|
},
|
|
102
|
+
proofSubmissionTargetAddress: {
|
|
103
|
+
env: 'PROVER_NODE_PROOF_SUBMISSION_TARGET_ADDRESS',
|
|
104
|
+
description:
|
|
105
|
+
'Optional L1 address the submitEpochRootProof tx is sent to. Must expose the identical submitEpochRootProof ABI ' +
|
|
106
|
+
'and forward to the rollup. Defaults to the rollup address.',
|
|
107
|
+
parseEnv: (val: string) => EthAddress.fromString(val),
|
|
108
|
+
defaultValue: undefined,
|
|
109
|
+
},
|
|
106
110
|
};
|
|
107
111
|
|
|
108
112
|
export const proverNodeConfigMappings: ConfigMappingsType<ProverNodeConfig> = {
|
|
109
113
|
...dataConfigMappings,
|
|
110
114
|
...keyStoreConfigMappings,
|
|
111
|
-
...archiverConfigMappings,
|
|
112
115
|
...proverClientConfigMappings,
|
|
113
|
-
...
|
|
114
|
-
...
|
|
115
|
-
...getPublisherConfigMappings('PROVER'),
|
|
116
|
-
...getTxSenderConfigMappings('PROVER'),
|
|
116
|
+
...proverPublisherConfigMappings,
|
|
117
|
+
...proverTxSenderConfigMappings,
|
|
117
118
|
...specificProverNodeConfigMappings,
|
|
118
|
-
...
|
|
119
|
-
...sharedNodeConfigMappings,
|
|
119
|
+
...pickConfigMappings(sharedNodeConfigMappings, ['web3SignerUrl']),
|
|
120
120
|
};
|
|
121
121
|
|
|
122
122
|
export function getProverNodeConfigFromEnv(): ProverNodeConfig {
|
|
@@ -143,7 +143,7 @@ function createKeyStoreFromWeb3Signer(config: ProverNodeConfig): KeyStore | unde
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
// Also, we need at least one publisher address.
|
|
146
|
-
const publishers = config.
|
|
146
|
+
const publishers = config.proverPublisherAddresses ?? [];
|
|
147
147
|
|
|
148
148
|
if (publishers.length === 0) {
|
|
149
149
|
return undefined;
|
|
@@ -164,8 +164,8 @@ function createKeyStoreFromWeb3Signer(config: ProverNodeConfig): KeyStore | unde
|
|
|
164
164
|
|
|
165
165
|
function createKeyStoreFromPublisherKeys(config: ProverNodeConfig): KeyStore | undefined {
|
|
166
166
|
// Extract the publisher keys from the provided config.
|
|
167
|
-
const publisherKeys = config.
|
|
168
|
-
? config.
|
|
167
|
+
const publisherKeys = config.proverPublisherPrivateKeys
|
|
168
|
+
? config.proverPublisherPrivateKeys.map((k: { getValue: () => string }) => ethPrivateKeySchema.parse(k.getValue()))
|
|
169
169
|
: [];
|
|
170
170
|
|
|
171
171
|
// There must be at least 1.
|
|
@@ -194,7 +194,10 @@ function createKeyStoreFromPublisherKeys(config: ProverNodeConfig): KeyStore | u
|
|
|
194
194
|
|
|
195
195
|
export function createKeyStoreForProver(config: ProverNodeConfig): KeyStore | undefined {
|
|
196
196
|
if (config.web3SignerUrl !== undefined && config.web3SignerUrl.length > 0) {
|
|
197
|
-
|
|
197
|
+
const keyStore = createKeyStoreFromWeb3Signer(config);
|
|
198
|
+
if (keyStore) {
|
|
199
|
+
return keyStore;
|
|
200
|
+
}
|
|
198
201
|
}
|
|
199
202
|
|
|
200
203
|
return createKeyStoreFromPublisherKeys(config);
|