@aztec/prover-client 0.0.1-commit.fce3e4f → 0.0.1-commit.ffe5b04ea
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/config.d.ts +2 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +1 -1
- package/dest/light/index.d.ts +2 -0
- package/dest/light/index.d.ts.map +1 -0
- package/dest/light/index.js +1 -0
- package/dest/light/lightweight_checkpoint_builder.d.ts +38 -14
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
- package/dest/light/lightweight_checkpoint_builder.js +144 -32
- package/dest/mocks/fixtures.d.ts +1 -1
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +6 -5
- package/dest/mocks/test_context.d.ts +5 -3
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +28 -11
- package/dest/orchestrator/block-building-helpers.d.ts +6 -6
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +7 -6
- package/dest/orchestrator/block-proving-state.d.ts +8 -4
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +8 -1
- package/dest/orchestrator/checkpoint-proving-state.d.ts +22 -8
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/checkpoint-proving-state.js +43 -8
- package/dest/orchestrator/epoch-proving-state.d.ts +10 -9
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +38 -2
- package/dest/orchestrator/orchestrator.d.ts +23 -8
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +548 -154
- package/dest/orchestrator/orchestrator_metrics.d.ts +1 -3
- package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator_metrics.js +2 -15
- package/dest/orchestrator/tx-proving-state.d.ts +6 -5
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +8 -8
- package/dest/prover-client/factory.d.ts +3 -3
- package/dest/prover-client/factory.d.ts.map +1 -1
- package/dest/prover-client/prover-client.d.ts +5 -5
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +15 -10
- package/dest/prover-client/server-epoch-prover.d.ts +5 -5
- package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.d.ts +7 -5
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +6 -13
- package/dest/proving_broker/config.d.ts +15 -3
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +21 -4
- package/dest/proving_broker/fixtures.js +1 -1
- package/dest/proving_broker/proof_store/factory.d.ts +2 -5
- package/dest/proving_broker/proof_store/factory.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/factory.js +7 -30
- package/dest/proving_broker/proof_store/file_store_proof_store.d.ts +18 -0
- package/dest/proving_broker/proof_store/file_store_proof_store.d.ts.map +1 -0
- package/dest/proving_broker/proof_store/file_store_proof_store.js +60 -0
- package/dest/proving_broker/proof_store/index.d.ts +2 -2
- package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/index.js +1 -1
- package/dest/proving_broker/proving_agent.d.ts +5 -9
- package/dest/proving_broker/proving_agent.d.ts.map +1 -1
- package/dest/proving_broker/proving_agent.js +4 -19
- package/dest/proving_broker/proving_broker.d.ts +7 -4
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +40 -14
- package/dest/proving_broker/proving_broker_database/persisted.d.ts +3 -2
- package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.js +389 -1
- package/dest/proving_broker/proving_broker_instrumentation.d.ts +3 -1
- package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.js +22 -35
- package/dest/proving_broker/proving_job_controller.d.ts +4 -3
- package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
- package/dest/proving_broker/proving_job_controller.js +8 -6
- package/dest/proving_broker/rpc.d.ts +4 -2
- package/dest/proving_broker/rpc.d.ts.map +1 -1
- package/dest/proving_broker/rpc.js +8 -0
- package/dest/test/mock_proof_store.d.ts +3 -3
- package/dest/test/mock_proof_store.d.ts.map +1 -1
- package/dest/test/mock_prover.d.ts +5 -5
- package/dest/test/mock_prover.d.ts.map +1 -1
- package/dest/test/mock_prover.js +4 -4
- package/package.json +22 -22
- package/src/config.ts +1 -1
- package/src/light/index.ts +1 -0
- package/src/light/lightweight_checkpoint_builder.ts +208 -45
- package/src/mocks/fixtures.ts +6 -5
- package/src/mocks/test_context.ts +26 -11
- package/src/orchestrator/block-building-helpers.ts +7 -6
- package/src/orchestrator/block-proving-state.ts +12 -2
- package/src/orchestrator/checkpoint-proving-state.ts +60 -12
- package/src/orchestrator/epoch-proving-state.ts +66 -13
- package/src/orchestrator/orchestrator.ts +154 -143
- package/src/orchestrator/orchestrator_metrics.ts +2 -25
- package/src/orchestrator/tx-proving-state.ts +10 -14
- package/src/prover-client/factory.ts +6 -2
- package/src/prover-client/prover-client.ts +31 -23
- package/src/prover-client/server-epoch-prover.ts +4 -4
- package/src/proving_broker/broker_prover_facade.ts +10 -17
- package/src/proving_broker/config.ts +24 -2
- package/src/proving_broker/fixtures.ts +1 -1
- package/src/proving_broker/proof_store/factory.ts +10 -32
- package/src/proving_broker/proof_store/file_store_proof_store.ts +78 -0
- package/src/proving_broker/proof_store/index.ts +1 -1
- package/src/proving_broker/proving_agent.ts +6 -19
- package/src/proving_broker/proving_broker.ts +41 -11
- package/src/proving_broker/proving_broker_database/persisted.ts +15 -1
- package/src/proving_broker/proving_broker_instrumentation.ts +23 -35
- package/src/proving_broker/proving_job_controller.ts +11 -6
- package/src/proving_broker/rpc.ts +14 -0
- package/src/test/mock_prover.ts +2 -14
- package/dest/block-factory/index.d.ts +0 -2
- package/dest/block-factory/index.d.ts.map +0 -1
- package/dest/block-factory/index.js +0 -1
- package/dest/block-factory/light.d.ts +0 -38
- package/dest/block-factory/light.d.ts.map +0 -1
- package/dest/block-factory/light.js +0 -108
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +0 -14
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +0 -1
- package/dest/proving_broker/proof_store/gcs_proof_store.js +0 -52
- package/dest/proving_broker/proving_agent_instrumentation.d.ts +0 -8
- package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +0 -1
- package/dest/proving_broker/proving_agent_instrumentation.js +0 -16
- package/src/block-factory/index.ts +0 -1
- package/src/block-factory/light.ts +0 -137
- package/src/proving_broker/proof_store/gcs_proof_store.ts +0 -76
- package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
|
@@ -6,23 +6,23 @@ import {
|
|
|
6
6
|
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
7
7
|
NUM_BASE_PARITY_PER_ROOT_PARITY,
|
|
8
8
|
} from '@aztec/constants';
|
|
9
|
-
import { EpochNumber } from '@aztec/foundation/branded-types';
|
|
9
|
+
import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
10
10
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
11
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
11
12
|
import { AbortError } from '@aztec/foundation/error';
|
|
12
|
-
import {
|
|
13
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
13
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
14
14
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
15
15
|
import { assertLength } from '@aztec/foundation/serialize';
|
|
16
16
|
import { pushTestData } from '@aztec/foundation/testing';
|
|
17
17
|
import { elapsed } from '@aztec/foundation/timer';
|
|
18
18
|
import type { TreeNodeLocation } from '@aztec/foundation/trees';
|
|
19
|
-
import { readAvmMinimalPublicTxInputsFromFile } from '@aztec/simulator/public/fixtures';
|
|
20
19
|
import { EthAddress } from '@aztec/stdlib/block';
|
|
21
20
|
import type {
|
|
22
21
|
EpochProver,
|
|
23
22
|
ForkMerkleTreeOperations,
|
|
24
23
|
MerkleTreeWriteOperations,
|
|
25
24
|
PublicInputsAndRecursiveProof,
|
|
25
|
+
ReadonlyWorldStateAccess,
|
|
26
26
|
ServerCircuitProver,
|
|
27
27
|
} from '@aztec/stdlib/interfaces/server';
|
|
28
28
|
import type { Proof } from '@aztec/stdlib/proofs';
|
|
@@ -71,8 +71,6 @@ import { EpochProvingState, type ProvingResult, type TreeSnapshots } from './epo
|
|
|
71
71
|
import { ProvingOrchestratorMetrics } from './orchestrator_metrics.js';
|
|
72
72
|
import { TxProvingState } from './tx-proving-state.js';
|
|
73
73
|
|
|
74
|
-
const logger = createLogger('prover-client:orchestrator');
|
|
75
|
-
|
|
76
74
|
/**
|
|
77
75
|
* Implements an event driven proving scheduler to build the recursive proof tree. The idea being:
|
|
78
76
|
* 1. Transactions are provided to the scheduler post simulation.
|
|
@@ -93,14 +91,19 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
93
91
|
|
|
94
92
|
private provingPromise: Promise<ProvingResult> | undefined = undefined;
|
|
95
93
|
private metrics: ProvingOrchestratorMetrics;
|
|
96
|
-
|
|
94
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
95
|
+
private dbs: Map<BlockNumber, MerkleTreeWriteOperations> = new Map();
|
|
96
|
+
private logger: Logger;
|
|
97
97
|
|
|
98
98
|
constructor(
|
|
99
|
-
private dbProvider: ForkMerkleTreeOperations,
|
|
99
|
+
private dbProvider: ReadonlyWorldStateAccess & ForkMerkleTreeOperations,
|
|
100
100
|
private prover: ServerCircuitProver,
|
|
101
101
|
private readonly proverId: EthAddress,
|
|
102
|
+
private readonly cancelJobsOnStop: boolean = false,
|
|
102
103
|
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
104
|
+
bindings?: LoggerBindings,
|
|
103
105
|
) {
|
|
106
|
+
this.logger = createLogger('prover-client:orchestrator', bindings);
|
|
104
107
|
this.metrics = new ProvingOrchestratorMetrics(telemetryClient, 'ProvingOrchestrator');
|
|
105
108
|
}
|
|
106
109
|
|
|
@@ -112,6 +115,10 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
112
115
|
return this.proverId;
|
|
113
116
|
}
|
|
114
117
|
|
|
118
|
+
public getNumActiveForks() {
|
|
119
|
+
return this.dbs.size;
|
|
120
|
+
}
|
|
121
|
+
|
|
115
122
|
public stop(): Promise<void> {
|
|
116
123
|
this.cancel();
|
|
117
124
|
return Promise.resolve();
|
|
@@ -130,7 +137,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
130
137
|
|
|
131
138
|
const { promise: _promise, resolve, reject } = promiseWithResolvers<ProvingResult>();
|
|
132
139
|
const promise = _promise.catch((reason): ProvingResult => ({ status: 'failure', reason }));
|
|
133
|
-
logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
|
|
140
|
+
this.logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
|
|
134
141
|
this.provingState = new EpochProvingState(
|
|
135
142
|
epochNumber,
|
|
136
143
|
totalNumCheckpoints,
|
|
@@ -142,6 +149,14 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
142
149
|
this.provingPromise = promise;
|
|
143
150
|
}
|
|
144
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Starts a new checkpoint.
|
|
154
|
+
* @param checkpointIndex - The index of the checkpoint in the epoch.
|
|
155
|
+
* @param constants - The constants for this checkpoint.
|
|
156
|
+
* @param l1ToL2Messages - The set of L1 to L2 messages to be inserted at the beginning of this checkpoint.
|
|
157
|
+
* @param totalNumBlocks - The total number of blocks expected in the checkpoint (must be at least one).
|
|
158
|
+
* @param headerOfLastBlockInPreviousCheckpoint - The header of the last block in the previous checkpoint.
|
|
159
|
+
*/
|
|
145
160
|
public async startNewCheckpoint(
|
|
146
161
|
checkpointIndex: number,
|
|
147
162
|
constants: CheckpointConstantData,
|
|
@@ -161,7 +176,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
161
176
|
const lastBlockNumber = headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber;
|
|
162
177
|
const db = await this.dbProvider.fork(lastBlockNumber);
|
|
163
178
|
|
|
164
|
-
const firstBlockNumber = lastBlockNumber + 1;
|
|
179
|
+
const firstBlockNumber = BlockNumber(lastBlockNumber + 1);
|
|
165
180
|
this.dbs.set(firstBlockNumber, db);
|
|
166
181
|
|
|
167
182
|
// Get archive sibling path before any block in this checkpoint lands.
|
|
@@ -199,7 +214,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
199
214
|
@trackSpan('ProvingOrchestrator.startNewBlock', blockNumber => ({
|
|
200
215
|
[Attributes.BLOCK_NUMBER]: blockNumber,
|
|
201
216
|
}))
|
|
202
|
-
public async startNewBlock(blockNumber:
|
|
217
|
+
public async startNewBlock(blockNumber: BlockNumber, timestamp: UInt64, totalNumTxs: number) {
|
|
203
218
|
if (!this.provingState) {
|
|
204
219
|
throw new Error('Empty epoch proving state. Call startNewEpoch before starting a block.');
|
|
205
220
|
}
|
|
@@ -214,15 +229,15 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
214
229
|
}
|
|
215
230
|
|
|
216
231
|
const constants = checkpointProvingState.constants;
|
|
217
|
-
logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
|
|
232
|
+
this.logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
|
|
218
233
|
|
|
219
234
|
// Fork the db only when it's not already set. The db for the first block is set in `startNewCheckpoint`.
|
|
220
235
|
if (!this.dbs.has(blockNumber)) {
|
|
221
236
|
// Fork world state at the end of the immediately previous block
|
|
222
|
-
const db = await this.dbProvider.fork(blockNumber - 1);
|
|
237
|
+
const db = await this.dbProvider.fork(BlockNumber(blockNumber - 1));
|
|
223
238
|
this.dbs.set(blockNumber, db);
|
|
224
239
|
}
|
|
225
|
-
const db = this.
|
|
240
|
+
const db = this.getDbForBlock(blockNumber);
|
|
226
241
|
|
|
227
242
|
// Get archive snapshot and sibling path before any txs in this block lands.
|
|
228
243
|
const lastArchiveTreeSnapshot = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
@@ -254,7 +269,8 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
254
269
|
await endSpongeBlob.absorb(blockEndBlobFields);
|
|
255
270
|
blockProvingState.setEndSpongeBlob(endSpongeBlob);
|
|
256
271
|
|
|
257
|
-
//
|
|
272
|
+
// Try to accumulate the out hashes and blobs as far as we can:
|
|
273
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
258
274
|
await this.provingState.setBlobAccumulators();
|
|
259
275
|
}
|
|
260
276
|
}
|
|
@@ -274,11 +290,11 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
274
290
|
if (!txs.length) {
|
|
275
291
|
// To avoid an ugly throw below. If we require an empty block, we can just call setBlockCompleted
|
|
276
292
|
// on a block with no txs. We cannot do that here because we cannot find the blockNumber without any txs.
|
|
277
|
-
logger.warn(`Provided no txs to orchestrator addTxs.`);
|
|
293
|
+
this.logger.warn(`Provided no txs to orchestrator addTxs.`);
|
|
278
294
|
return;
|
|
279
295
|
}
|
|
280
296
|
|
|
281
|
-
const blockNumber = txs[0].globalVariables.blockNumber;
|
|
297
|
+
const blockNumber = BlockNumber(txs[0].globalVariables.blockNumber);
|
|
282
298
|
const provingState = this.provingState.getBlockProvingStateByBlockNumber(blockNumber!);
|
|
283
299
|
if (!provingState) {
|
|
284
300
|
throw new Error(`Proving state for block ${blockNumber} not found. Call startNewBlock first.`);
|
|
@@ -294,9 +310,9 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
294
310
|
throw new Error(`Block ${blockNumber} has been initialized with transactions.`);
|
|
295
311
|
}
|
|
296
312
|
|
|
297
|
-
logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
313
|
+
this.logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
298
314
|
|
|
299
|
-
const db = this.
|
|
315
|
+
const db = this.getDbForBlock(blockNumber);
|
|
300
316
|
const lastArchive = provingState.lastArchiveTreeSnapshot;
|
|
301
317
|
const newL1ToL2MessageTreeSnapshot = provingState.newL1ToL2MessageTreeSnapshot;
|
|
302
318
|
const spongeBlobState = provingState.getStartSpongeBlob().clone();
|
|
@@ -309,7 +325,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
309
325
|
|
|
310
326
|
validateTx(tx);
|
|
311
327
|
|
|
312
|
-
logger.
|
|
328
|
+
this.logger.debug(`Received transaction: ${tx.hash}`);
|
|
313
329
|
|
|
314
330
|
const startSpongeBlob = spongeBlobState.clone();
|
|
315
331
|
const [hints, treeSnapshots] = await this.prepareBaseRollupInputs(
|
|
@@ -330,10 +346,10 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
330
346
|
const txIndex = provingState.addNewTx(txProvingState);
|
|
331
347
|
if (txProvingState.requireAvmProof) {
|
|
332
348
|
this.getOrEnqueueChonkVerifier(provingState, txIndex);
|
|
333
|
-
logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
349
|
+
this.logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
334
350
|
this.enqueueVM(provingState, txIndex);
|
|
335
351
|
} else {
|
|
336
|
-
logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
352
|
+
this.logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
337
353
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
338
354
|
}
|
|
339
355
|
} catch (err: any) {
|
|
@@ -351,7 +367,8 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
351
367
|
|
|
352
368
|
provingState.setEndSpongeBlob(spongeBlobState);
|
|
353
369
|
|
|
354
|
-
// Txs have been added to the block. Now try to accumulate the blobs as far as we can:
|
|
370
|
+
// Txs have been added to the block. Now try to accumulate the out hashes and blobs as far as we can:
|
|
371
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
355
372
|
await this.provingState.setBlobAccumulators();
|
|
356
373
|
}
|
|
357
374
|
|
|
@@ -375,7 +392,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
375
392
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
376
393
|
>
|
|
377
394
|
>();
|
|
378
|
-
logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
|
|
395
|
+
this.logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
|
|
379
396
|
this.doEnqueueChonkVerifier(txHash, privateInputs, proof => {
|
|
380
397
|
tubeProof.resolve(proof);
|
|
381
398
|
});
|
|
@@ -388,10 +405,10 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
388
405
|
* Marks the block as completed.
|
|
389
406
|
* Computes the block header and updates the archive tree.
|
|
390
407
|
*/
|
|
391
|
-
@trackSpan('ProvingOrchestrator.setBlockCompleted', (blockNumber:
|
|
408
|
+
@trackSpan('ProvingOrchestrator.setBlockCompleted', (blockNumber: BlockNumber) => ({
|
|
392
409
|
[Attributes.BLOCK_NUMBER]: blockNumber,
|
|
393
410
|
}))
|
|
394
|
-
public async setBlockCompleted(blockNumber:
|
|
411
|
+
public async setBlockCompleted(blockNumber: BlockNumber, expectedHeader?: BlockHeader): Promise<BlockHeader> {
|
|
395
412
|
const provingState = this.provingState?.getBlockProvingStateByBlockNumber(blockNumber);
|
|
396
413
|
if (!provingState) {
|
|
397
414
|
throw new Error(`Block proving state for ${blockNumber} not found`);
|
|
@@ -415,22 +432,28 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
415
432
|
}
|
|
416
433
|
|
|
417
434
|
// Given we've applied every change from this block, now assemble the block header:
|
|
418
|
-
logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
|
|
435
|
+
this.logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
|
|
419
436
|
const header = await provingState.buildBlockHeader();
|
|
420
437
|
|
|
421
438
|
if (expectedHeader && !header.equals(expectedHeader)) {
|
|
422
|
-
logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
439
|
+
this.logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
423
440
|
throw new Error('Block header mismatch');
|
|
424
441
|
}
|
|
425
442
|
|
|
426
|
-
// Get db for this block
|
|
427
|
-
const db = this.
|
|
443
|
+
// Get db for this block and remove from map — no other code should use it after this point.
|
|
444
|
+
const db = this.getDbForBlock(provingState.blockNumber);
|
|
445
|
+
this.dbs.delete(provingState.blockNumber);
|
|
428
446
|
|
|
429
|
-
// Update the archive tree,
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
447
|
+
// Update the archive tree, capture the snapshot, and close the fork deterministically.
|
|
448
|
+
try {
|
|
449
|
+
this.logger.verbose(
|
|
450
|
+
`Updating archive tree with block ${provingState.blockNumber} header ${(await header.hash()).toString()}`,
|
|
451
|
+
);
|
|
452
|
+
await db.updateArchive(header);
|
|
453
|
+
provingState.setBuiltArchive(await getTreeSnapshot(MerkleTreeId.ARCHIVE, db));
|
|
454
|
+
} finally {
|
|
455
|
+
await db.close();
|
|
456
|
+
}
|
|
434
457
|
|
|
435
458
|
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
436
459
|
|
|
@@ -441,31 +464,34 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
441
464
|
protected async verifyBuiltBlockAgainstSyncedState(provingState: BlockProvingState) {
|
|
442
465
|
const builtBlockHeader = provingState.getBuiltBlockHeader();
|
|
443
466
|
if (!builtBlockHeader) {
|
|
444
|
-
logger.debug('Block header not built yet, skipping header check.');
|
|
467
|
+
this.logger.debug('Block header not built yet, skipping header check.');
|
|
445
468
|
return;
|
|
446
469
|
}
|
|
447
470
|
|
|
448
471
|
const output = provingState.getBlockRootRollupOutput();
|
|
449
472
|
if (!output) {
|
|
450
|
-
logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
473
|
+
this.logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
451
474
|
return;
|
|
452
475
|
}
|
|
476
|
+
|
|
477
|
+
const newArchive = provingState.getBuiltArchive();
|
|
478
|
+
if (!newArchive) {
|
|
479
|
+
this.logger.debug('Archive snapshot not yet captured, skipping header check.');
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
|
|
453
483
|
const header = await buildHeaderFromCircuitOutputs(output);
|
|
454
484
|
|
|
455
485
|
if (!(await header.hash()).equals(await builtBlockHeader.hash())) {
|
|
456
|
-
logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
486
|
+
this.logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
457
487
|
provingState.reject(`Block header hash mismatch.`);
|
|
458
488
|
return;
|
|
459
489
|
}
|
|
460
490
|
|
|
461
|
-
// Get db for this block
|
|
462
491
|
const blockNumber = provingState.blockNumber;
|
|
463
|
-
const db = this.dbs.get(blockNumber)!;
|
|
464
|
-
|
|
465
|
-
const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
466
492
|
const syncedArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.dbProvider.getSnapshot(blockNumber));
|
|
467
493
|
if (!syncedArchive.equals(newArchive)) {
|
|
468
|
-
logger.error(
|
|
494
|
+
this.logger.error(
|
|
469
495
|
`Archive tree mismatch for block ${blockNumber}: world state synced to ${inspect(
|
|
470
496
|
syncedArchive,
|
|
471
497
|
)} but built ${inspect(newArchive)}`,
|
|
@@ -476,32 +502,38 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
476
502
|
|
|
477
503
|
const circuitArchive = output.newArchive;
|
|
478
504
|
if (!newArchive.equals(circuitArchive)) {
|
|
479
|
-
logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
505
|
+
this.logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
480
506
|
provingState.reject(`New archive mismatch.`);
|
|
481
507
|
return;
|
|
482
508
|
}
|
|
483
|
-
|
|
484
|
-
// TODO(palla/prover): This closes the fork only on the happy path. If this epoch orchestrator
|
|
485
|
-
// is aborted and never reaches this point, it will leak the fork. We need to add a global cleanup,
|
|
486
|
-
// but have to make sure it only runs once all operations are completed, otherwise some function here
|
|
487
|
-
// will attempt to access the fork after it was closed.
|
|
488
|
-
logger.debug(`Cleaning up world state fork for ${blockNumber}`);
|
|
489
|
-
void this.dbs
|
|
490
|
-
.get(blockNumber)
|
|
491
|
-
?.close()
|
|
492
|
-
.then(() => this.dbs.delete(blockNumber))
|
|
493
|
-
.catch(err => logger.error(`Error closing db for block ${blockNumber}`, err));
|
|
494
509
|
}
|
|
495
510
|
|
|
496
511
|
/**
|
|
497
|
-
* Cancel any further proving
|
|
512
|
+
* Cancel any further proving.
|
|
513
|
+
* If cancelJobsOnStop is true, aborts all pending jobs with the broker (which marks them as 'Aborted').
|
|
514
|
+
* If cancelJobsOnStop is false (default), jobs remain in the broker queue and can be reused on restart/reorg.
|
|
498
515
|
*/
|
|
499
516
|
public cancel() {
|
|
500
|
-
|
|
501
|
-
controller.
|
|
517
|
+
if (this.cancelJobsOnStop) {
|
|
518
|
+
for (const controller of this.pendingProvingJobs) {
|
|
519
|
+
controller.abort();
|
|
520
|
+
}
|
|
502
521
|
}
|
|
503
522
|
|
|
504
523
|
this.provingState?.cancel();
|
|
524
|
+
|
|
525
|
+
for (const [blockNumber, db] of this.dbs.entries()) {
|
|
526
|
+
void db.close().catch(err => this.logger.error(`Error closing db for block ${blockNumber}`, err));
|
|
527
|
+
}
|
|
528
|
+
this.dbs.clear();
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
private getDbForBlock(blockNumber: BlockNumber): MerkleTreeWriteOperations {
|
|
532
|
+
const db = this.dbs.get(blockNumber);
|
|
533
|
+
if (!db) {
|
|
534
|
+
throw new Error(`World state fork for block ${blockNumber} not found.`);
|
|
535
|
+
}
|
|
536
|
+
return db;
|
|
505
537
|
}
|
|
506
538
|
|
|
507
539
|
/**
|
|
@@ -545,7 +577,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
545
577
|
callback: (result: T) => void | Promise<void>,
|
|
546
578
|
) {
|
|
547
579
|
if (!provingState.verifyState()) {
|
|
548
|
-
logger.debug(`Not enqueuing job, state no longer valid`);
|
|
580
|
+
this.logger.debug(`Not enqueuing job, state no longer valid`);
|
|
549
581
|
return;
|
|
550
582
|
}
|
|
551
583
|
|
|
@@ -563,7 +595,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
563
595
|
|
|
564
596
|
const result = await request(controller.signal);
|
|
565
597
|
if (!provingState.verifyState()) {
|
|
566
|
-
logger.debug(`State no longer valid, discarding result`);
|
|
598
|
+
this.logger.debug(`State no longer valid, discarding result`);
|
|
567
599
|
return;
|
|
568
600
|
}
|
|
569
601
|
|
|
@@ -581,7 +613,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
581
613
|
return;
|
|
582
614
|
}
|
|
583
615
|
|
|
584
|
-
logger.error(`Error thrown when proving job`, err);
|
|
616
|
+
this.logger.error(`Error thrown when proving job`, err);
|
|
585
617
|
provingState!.reject(`${err}`);
|
|
586
618
|
} finally {
|
|
587
619
|
const index = this.pendingProvingJobs.indexOf(controller);
|
|
@@ -666,12 +698,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
666
698
|
// Executes the next level of merge if all inputs are available
|
|
667
699
|
private enqueueBaseRollup(provingState: BlockProvingState, txIndex: number) {
|
|
668
700
|
if (!provingState.verifyState()) {
|
|
669
|
-
logger.debug('Not running base rollup, state invalid');
|
|
701
|
+
this.logger.debug('Not running base rollup, state invalid');
|
|
670
702
|
return;
|
|
671
703
|
}
|
|
672
704
|
|
|
673
705
|
if (!provingState.tryStartProvingBase(txIndex)) {
|
|
674
|
-
logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
706
|
+
this.logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
675
707
|
return;
|
|
676
708
|
}
|
|
677
709
|
|
|
@@ -679,7 +711,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
679
711
|
const { processedTx } = txProvingState;
|
|
680
712
|
const { rollupType, inputs } = txProvingState.getBaseRollupTypeAndInputs();
|
|
681
713
|
|
|
682
|
-
logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
714
|
+
this.logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
683
715
|
|
|
684
716
|
this.deferredProving(
|
|
685
717
|
provingState,
|
|
@@ -703,7 +735,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
703
735
|
},
|
|
704
736
|
),
|
|
705
737
|
result => {
|
|
706
|
-
logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
738
|
+
this.logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
707
739
|
validatePartialState(result.inputs.endTreeSnapshots, txProvingState.treeSnapshots);
|
|
708
740
|
const leafLocation = provingState.setBaseRollupProof(txIndex, result);
|
|
709
741
|
if (provingState.totalNumTxs === 1) {
|
|
@@ -719,7 +751,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
719
751
|
// Once completed, will enqueue the the public tx base rollup.
|
|
720
752
|
private getOrEnqueueChonkVerifier(provingState: BlockProvingState, txIndex: number) {
|
|
721
753
|
if (!provingState.verifyState()) {
|
|
722
|
-
logger.debug('Not running chonk verifier circuit, state invalid');
|
|
754
|
+
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
723
755
|
return;
|
|
724
756
|
}
|
|
725
757
|
|
|
@@ -732,19 +764,19 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
732
764
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
733
765
|
>,
|
|
734
766
|
) => {
|
|
735
|
-
logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, { txHash });
|
|
767
|
+
this.logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, { txHash });
|
|
736
768
|
txProvingState.setPublicChonkVerifierProof(result);
|
|
737
769
|
this.provingState?.cachedChonkVerifierProofs.delete(txHash);
|
|
738
770
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
739
771
|
};
|
|
740
772
|
|
|
741
773
|
if (this.provingState?.cachedChonkVerifierProofs.has(txHash)) {
|
|
742
|
-
logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, { txHash });
|
|
774
|
+
this.logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, { txHash });
|
|
743
775
|
void this.provingState!.cachedChonkVerifierProofs.get(txHash)!.then(handleResult);
|
|
744
776
|
return;
|
|
745
777
|
}
|
|
746
778
|
|
|
747
|
-
logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
|
|
779
|
+
this.logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
|
|
748
780
|
this.doEnqueueChonkVerifier(txHash, txProvingState.getPublicChonkVerifierPrivateInputs(), handleResult);
|
|
749
781
|
}
|
|
750
782
|
|
|
@@ -760,7 +792,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
760
792
|
provingState: EpochProvingState | BlockProvingState = this.provingState!,
|
|
761
793
|
) {
|
|
762
794
|
if (!provingState.verifyState()) {
|
|
763
|
-
logger.debug('Not running chonk verifier circuit, state invalid');
|
|
795
|
+
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
764
796
|
return;
|
|
765
797
|
}
|
|
766
798
|
|
|
@@ -783,12 +815,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
783
815
|
// Enqueues the next level of merge if all inputs are available
|
|
784
816
|
private enqueueMergeRollup(provingState: BlockProvingState, location: TreeNodeLocation) {
|
|
785
817
|
if (!provingState.verifyState()) {
|
|
786
|
-
logger.debug('Not running merge rollup. State no longer valid.');
|
|
818
|
+
this.logger.debug('Not running merge rollup. State no longer valid.');
|
|
787
819
|
return;
|
|
788
820
|
}
|
|
789
821
|
|
|
790
822
|
if (!provingState.tryStartProvingMerge(location)) {
|
|
791
|
-
logger.debug('Merge rollup already started.');
|
|
823
|
+
this.logger.debug('Merge rollup already started.');
|
|
792
824
|
return;
|
|
793
825
|
}
|
|
794
826
|
|
|
@@ -814,18 +846,18 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
814
846
|
// Executes the block root rollup circuit
|
|
815
847
|
private enqueueBlockRootRollup(provingState: BlockProvingState) {
|
|
816
848
|
if (!provingState.verifyState()) {
|
|
817
|
-
logger.debug('Not running block root rollup, state no longer valid');
|
|
849
|
+
this.logger.debug('Not running block root rollup, state no longer valid');
|
|
818
850
|
return;
|
|
819
851
|
}
|
|
820
852
|
|
|
821
853
|
if (!provingState.tryStartProvingBlockRoot()) {
|
|
822
|
-
logger.debug('Block root rollup already started.');
|
|
854
|
+
this.logger.debug('Block root rollup already started.');
|
|
823
855
|
return;
|
|
824
856
|
}
|
|
825
857
|
|
|
826
858
|
const { rollupType, inputs } = provingState.getBlockRootRollupTypeAndInputs();
|
|
827
859
|
|
|
828
|
-
logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
860
|
+
this.logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
829
861
|
|
|
830
862
|
this.deferredProving(
|
|
831
863
|
provingState,
|
|
@@ -850,18 +882,19 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
850
882
|
},
|
|
851
883
|
),
|
|
852
884
|
async result => {
|
|
853
|
-
|
|
854
|
-
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
855
|
-
|
|
856
|
-
logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`);
|
|
885
|
+
this.logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`);
|
|
857
886
|
|
|
858
887
|
const leafLocation = provingState.setBlockRootRollupProof(result);
|
|
859
888
|
const checkpointProvingState = provingState.parentCheckpoint;
|
|
860
889
|
|
|
890
|
+
// Verification is called from both here and setBlockCompleted. Whichever runs last
|
|
891
|
+
// will be the first to see all three pieces (header, proof output, archive) and run the checks.
|
|
892
|
+
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
893
|
+
|
|
861
894
|
if (checkpointProvingState.totalNumBlocks === 1) {
|
|
862
|
-
this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
895
|
+
await this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
863
896
|
} else {
|
|
864
|
-
this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
897
|
+
await this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
865
898
|
}
|
|
866
899
|
},
|
|
867
900
|
);
|
|
@@ -875,12 +908,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
875
908
|
baseParityIndex: number,
|
|
876
909
|
) {
|
|
877
910
|
if (!provingState.verifyState()) {
|
|
878
|
-
logger.debug('Not running base parity. State no longer valid.');
|
|
911
|
+
this.logger.debug('Not running base parity. State no longer valid.');
|
|
879
912
|
return;
|
|
880
913
|
}
|
|
881
914
|
|
|
882
915
|
if (!provingState.tryStartProvingBaseParity(baseParityIndex)) {
|
|
883
|
-
logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
916
|
+
this.logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
884
917
|
return;
|
|
885
918
|
}
|
|
886
919
|
|
|
@@ -915,12 +948,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
915
948
|
// Enqueues the root rollup proof if all inputs are available
|
|
916
949
|
private enqueueRootParityCircuit(provingState: BlockProvingState) {
|
|
917
950
|
if (!provingState.verifyState()) {
|
|
918
|
-
logger.debug('Not running root parity. State no longer valid.');
|
|
951
|
+
this.logger.debug('Not running root parity. State no longer valid.');
|
|
919
952
|
return;
|
|
920
953
|
}
|
|
921
954
|
|
|
922
955
|
if (!provingState.tryStartProvingRootParity()) {
|
|
923
|
-
logger.debug('Root parity already started.');
|
|
956
|
+
this.logger.debug('Root parity already started.');
|
|
924
957
|
return;
|
|
925
958
|
}
|
|
926
959
|
|
|
@@ -947,12 +980,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
947
980
|
// Enqueues the next level of merge if all inputs are available
|
|
948
981
|
private enqueueBlockMergeRollup(provingState: CheckpointProvingState, location: TreeNodeLocation) {
|
|
949
982
|
if (!provingState.verifyState()) {
|
|
950
|
-
logger.debug('Not running block merge rollup. State no longer valid.');
|
|
983
|
+
this.logger.debug('Not running block merge rollup. State no longer valid.');
|
|
951
984
|
return;
|
|
952
985
|
}
|
|
953
986
|
|
|
954
987
|
if (!provingState.tryStartProvingBlockMerge(location)) {
|
|
955
|
-
logger.debug('Block merge rollup already started.');
|
|
988
|
+
this.logger.debug('Block merge rollup already started.');
|
|
956
989
|
return;
|
|
957
990
|
}
|
|
958
991
|
|
|
@@ -967,29 +1000,29 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
967
1000
|
},
|
|
968
1001
|
signal => this.prover.getBlockMergeRollupProof(inputs, signal, provingState.epochNumber),
|
|
969
1002
|
),
|
|
970
|
-
result => {
|
|
1003
|
+
async result => {
|
|
971
1004
|
provingState.setBlockMergeRollupProof(location, result);
|
|
972
|
-
this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
1005
|
+
await this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
973
1006
|
},
|
|
974
1007
|
);
|
|
975
1008
|
}
|
|
976
1009
|
|
|
977
|
-
private enqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
1010
|
+
private async enqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
978
1011
|
if (!provingState.verifyState()) {
|
|
979
|
-
logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
1012
|
+
this.logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
980
1013
|
return;
|
|
981
1014
|
}
|
|
982
1015
|
|
|
983
1016
|
if (!provingState.tryStartProvingCheckpointRoot()) {
|
|
984
|
-
logger.debug('Checkpoint root rollup already started.');
|
|
1017
|
+
this.logger.debug('Checkpoint root rollup already started.');
|
|
985
1018
|
return;
|
|
986
1019
|
}
|
|
987
1020
|
|
|
988
1021
|
const rollupType = provingState.getCheckpointRootRollupType();
|
|
989
1022
|
|
|
990
|
-
logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
1023
|
+
this.logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
991
1024
|
|
|
992
|
-
const inputs = provingState.getCheckpointRootRollupInputs();
|
|
1025
|
+
const inputs = await provingState.getCheckpointRootRollupInputs();
|
|
993
1026
|
|
|
994
1027
|
this.deferredProving(
|
|
995
1028
|
provingState,
|
|
@@ -1011,7 +1044,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1011
1044
|
const computedEndBlobAccumulatorState = provingState.getEndBlobAccumulator()!.toBlobAccumulator();
|
|
1012
1045
|
const circuitEndBlobAccumulatorState = result.inputs.endBlobAccumulator;
|
|
1013
1046
|
if (!circuitEndBlobAccumulatorState.equals(computedEndBlobAccumulatorState)) {
|
|
1014
|
-
logger.error(
|
|
1047
|
+
this.logger.error(
|
|
1015
1048
|
`Blob accumulator state mismatch.\nCircuit: ${inspect(circuitEndBlobAccumulatorState)}\nComputed: ${inspect(
|
|
1016
1049
|
computedEndBlobAccumulatorState,
|
|
1017
1050
|
)}`,
|
|
@@ -1020,7 +1053,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1020
1053
|
return;
|
|
1021
1054
|
}
|
|
1022
1055
|
|
|
1023
|
-
logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}.`);
|
|
1056
|
+
this.logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}.`);
|
|
1024
1057
|
|
|
1025
1058
|
const leafLocation = provingState.setCheckpointRootRollupProof(result);
|
|
1026
1059
|
const epochProvingState = provingState.parentEpoch;
|
|
@@ -1036,12 +1069,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1036
1069
|
|
|
1037
1070
|
private enqueueCheckpointMergeRollup(provingState: EpochProvingState, location: TreeNodeLocation) {
|
|
1038
1071
|
if (!provingState.verifyState()) {
|
|
1039
|
-
logger.debug('Not running checkpoint merge rollup. State no longer valid.');
|
|
1072
|
+
this.logger.debug('Not running checkpoint merge rollup. State no longer valid.');
|
|
1040
1073
|
return;
|
|
1041
1074
|
}
|
|
1042
1075
|
|
|
1043
1076
|
if (!provingState.tryStartProvingCheckpointMerge(location)) {
|
|
1044
|
-
logger.debug('Checkpoint merge rollup already started.');
|
|
1077
|
+
this.logger.debug('Checkpoint merge rollup already started.');
|
|
1045
1078
|
return;
|
|
1046
1079
|
}
|
|
1047
1080
|
|
|
@@ -1058,7 +1091,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1058
1091
|
signal => this.prover.getCheckpointMergeRollupProof(inputs, signal, provingState.epochNumber),
|
|
1059
1092
|
),
|
|
1060
1093
|
result => {
|
|
1061
|
-
logger.debug('Completed proof for checkpoint merge rollup.');
|
|
1094
|
+
this.logger.debug('Completed proof for checkpoint merge rollup.');
|
|
1062
1095
|
provingState.setCheckpointMergeRollupProof(location, result);
|
|
1063
1096
|
this.checkAndEnqueueNextCheckpointMergeRollup(provingState, location);
|
|
1064
1097
|
},
|
|
@@ -1067,16 +1100,16 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1067
1100
|
|
|
1068
1101
|
private enqueueEpochPadding(provingState: EpochProvingState) {
|
|
1069
1102
|
if (!provingState.verifyState()) {
|
|
1070
|
-
logger.debug('Not running epoch padding. State no longer valid.');
|
|
1103
|
+
this.logger.debug('Not running epoch padding. State no longer valid.');
|
|
1071
1104
|
return;
|
|
1072
1105
|
}
|
|
1073
1106
|
|
|
1074
1107
|
if (!provingState.tryStartProvingPaddingCheckpoint()) {
|
|
1075
|
-
logger.debug('Padding checkpoint already started.');
|
|
1108
|
+
this.logger.debug('Padding checkpoint already started.');
|
|
1076
1109
|
return;
|
|
1077
1110
|
}
|
|
1078
1111
|
|
|
1079
|
-
logger.debug('Padding epoch proof with a padding block root proof.');
|
|
1112
|
+
this.logger.debug('Padding epoch proof with a padding block root proof.');
|
|
1080
1113
|
|
|
1081
1114
|
const inputs = provingState.getPaddingCheckpointInputs();
|
|
1082
1115
|
|
|
@@ -1091,7 +1124,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1091
1124
|
signal => this.prover.getCheckpointPaddingRollupProof(inputs, signal, provingState.epochNumber),
|
|
1092
1125
|
),
|
|
1093
1126
|
result => {
|
|
1094
|
-
logger.debug('Completed proof for padding checkpoint.');
|
|
1127
|
+
this.logger.debug('Completed proof for padding checkpoint.');
|
|
1095
1128
|
provingState.setCheckpointPaddingProof(result);
|
|
1096
1129
|
this.checkAndEnqueueRootRollup(provingState);
|
|
1097
1130
|
},
|
|
@@ -1101,11 +1134,11 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1101
1134
|
// Executes the root rollup circuit
|
|
1102
1135
|
private enqueueRootRollup(provingState: EpochProvingState) {
|
|
1103
1136
|
if (!provingState.verifyState()) {
|
|
1104
|
-
logger.debug('Not running root rollup, state no longer valid');
|
|
1137
|
+
this.logger.debug('Not running root rollup, state no longer valid');
|
|
1105
1138
|
return;
|
|
1106
1139
|
}
|
|
1107
1140
|
|
|
1108
|
-
logger.debug(`Preparing root rollup`);
|
|
1141
|
+
this.logger.debug(`Preparing root rollup`);
|
|
1109
1142
|
|
|
1110
1143
|
const inputs = provingState.getRootRollupInputs();
|
|
1111
1144
|
|
|
@@ -1120,7 +1153,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1120
1153
|
signal => this.prover.getRootRollupProof(inputs, signal, provingState.epochNumber),
|
|
1121
1154
|
),
|
|
1122
1155
|
result => {
|
|
1123
|
-
logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
|
|
1156
|
+
this.logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
|
|
1124
1157
|
provingState.setRootRollupProof(result);
|
|
1125
1158
|
provingState.resolve({ status: 'success' });
|
|
1126
1159
|
},
|
|
@@ -1142,32 +1175,35 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1142
1175
|
|
|
1143
1176
|
private checkAndEnqueueBlockRootRollup(provingState: BlockProvingState) {
|
|
1144
1177
|
if (!provingState.isReadyForBlockRootRollup()) {
|
|
1145
|
-
logger.debug('Not ready for block root rollup');
|
|
1178
|
+
this.logger.debug('Not ready for block root rollup');
|
|
1146
1179
|
return;
|
|
1147
1180
|
}
|
|
1148
1181
|
|
|
1149
1182
|
this.enqueueBlockRootRollup(provingState);
|
|
1150
1183
|
}
|
|
1151
1184
|
|
|
1152
|
-
private checkAndEnqueueNextBlockMergeRollup(
|
|
1185
|
+
private async checkAndEnqueueNextBlockMergeRollup(
|
|
1186
|
+
provingState: CheckpointProvingState,
|
|
1187
|
+
currentLocation: TreeNodeLocation,
|
|
1188
|
+
) {
|
|
1153
1189
|
if (!provingState.isReadyForBlockMerge(currentLocation)) {
|
|
1154
1190
|
return;
|
|
1155
1191
|
}
|
|
1156
1192
|
|
|
1157
1193
|
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
1158
1194
|
if (parentLocation.level === 0) {
|
|
1159
|
-
this.checkAndEnqueueCheckpointRootRollup(provingState);
|
|
1195
|
+
await this.checkAndEnqueueCheckpointRootRollup(provingState);
|
|
1160
1196
|
} else {
|
|
1161
1197
|
this.enqueueBlockMergeRollup(provingState, parentLocation);
|
|
1162
1198
|
}
|
|
1163
1199
|
}
|
|
1164
1200
|
|
|
1165
|
-
private checkAndEnqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
1201
|
+
private async checkAndEnqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
1166
1202
|
if (!provingState.isReadyForCheckpointRoot()) {
|
|
1167
1203
|
return;
|
|
1168
1204
|
}
|
|
1169
1205
|
|
|
1170
|
-
this.enqueueCheckpointRootRollup(provingState);
|
|
1206
|
+
await this.enqueueCheckpointRootRollup(provingState);
|
|
1171
1207
|
}
|
|
1172
1208
|
|
|
1173
1209
|
private checkAndEnqueueNextCheckpointMergeRollup(provingState: EpochProvingState, currentLocation: TreeNodeLocation) {
|
|
@@ -1185,7 +1221,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1185
1221
|
|
|
1186
1222
|
private checkAndEnqueueRootRollup(provingState: EpochProvingState) {
|
|
1187
1223
|
if (!provingState.isReadyForRootRollup()) {
|
|
1188
|
-
logger.debug('Not ready for root rollup');
|
|
1224
|
+
this.logger.debug('Not ready for root rollup');
|
|
1189
1225
|
return;
|
|
1190
1226
|
}
|
|
1191
1227
|
|
|
@@ -1200,14 +1236,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1200
1236
|
*/
|
|
1201
1237
|
private enqueueVM(provingState: BlockProvingState, txIndex: number) {
|
|
1202
1238
|
if (!provingState.verifyState()) {
|
|
1203
|
-
logger.debug(`Not running VM circuit as state is no longer valid`);
|
|
1239
|
+
this.logger.debug(`Not running VM circuit as state is no longer valid`);
|
|
1204
1240
|
return;
|
|
1205
1241
|
}
|
|
1206
1242
|
|
|
1207
1243
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
1208
1244
|
|
|
1209
|
-
// This function tries to do AVM proving. If there is a failure, it fakes the proof unless AVM_PROVING_STRICT is defined.
|
|
1210
|
-
// Nothing downstream depends on the AVM proof yet. So having this mode lets us incrementally build the AVM circuit.
|
|
1211
1245
|
const doAvmProving = wrapCallbackInSpan(
|
|
1212
1246
|
this.tracer,
|
|
1213
1247
|
'ProvingOrchestrator.prover.getAvmProof',
|
|
@@ -1216,36 +1250,13 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1216
1250
|
},
|
|
1217
1251
|
async (signal: AbortSignal) => {
|
|
1218
1252
|
const inputs = txProvingState.getAvmInputs();
|
|
1219
|
-
|
|
1220
|
-
// TODO(#14234)[Unconditional PIs validation]: Remove the whole try-catch logic and
|
|
1221
|
-
// just keep the next line but removing the second argument (false).
|
|
1222
|
-
return await this.prover.getAvmProof(inputs, false, signal, provingState.epochNumber);
|
|
1223
|
-
} catch (err) {
|
|
1224
|
-
if (process.env.AVM_PROVING_STRICT) {
|
|
1225
|
-
logger.error(`Error thrown when proving AVM circuit with AVM_PROVING_STRICT on`, err);
|
|
1226
|
-
throw err;
|
|
1227
|
-
} else {
|
|
1228
|
-
logger.warn(
|
|
1229
|
-
`Error thrown when proving AVM circuit but AVM_PROVING_STRICT is off. Use snapshotted
|
|
1230
|
-
AVM inputs and carrying on. ${inspect(err)}.`,
|
|
1231
|
-
);
|
|
1232
|
-
|
|
1233
|
-
try {
|
|
1234
|
-
this.metrics.incAvmFallback();
|
|
1235
|
-
const snapshotAvmPrivateInputs = readAvmMinimalPublicTxInputsFromFile();
|
|
1236
|
-
return await this.prover.getAvmProof(snapshotAvmPrivateInputs, true, signal, provingState.epochNumber);
|
|
1237
|
-
} catch (err) {
|
|
1238
|
-
logger.error(`Error thrown when proving snapshotted AVM inputs.`, err);
|
|
1239
|
-
throw err;
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
}
|
|
1253
|
+
return await this.prover.getAvmProof(inputs, signal, provingState.epochNumber);
|
|
1243
1254
|
},
|
|
1244
1255
|
);
|
|
1245
1256
|
|
|
1246
|
-
this.deferredProving(provingState, doAvmProving,
|
|
1247
|
-
logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1248
|
-
txProvingState.setAvmProof(
|
|
1257
|
+
this.deferredProving(provingState, doAvmProving, proof => {
|
|
1258
|
+
this.logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1259
|
+
txProvingState.setAvmProof(proof);
|
|
1249
1260
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
1250
1261
|
});
|
|
1251
1262
|
}
|
|
@@ -1257,7 +1268,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1257
1268
|
}
|
|
1258
1269
|
|
|
1259
1270
|
// We must have completed all proving (chonk verifier proof and (if required) vm proof are generated), we now move to the base rollup.
|
|
1260
|
-
logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1271
|
+
this.logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1261
1272
|
|
|
1262
1273
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
1263
1274
|
}
|