@aztec/prover-client 0.0.1-commit.9b94fc1 → 0.0.1-commit.9badcec54
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 +13 -3
- 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 +148 -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 +40 -18
- 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 +25 -8
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +568 -158
- 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 +6 -6
- 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 +18 -31
- 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 +22 -5
- 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 +60 -18
- 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 +6 -2
- package/dest/proving_broker/rpc.d.ts.map +1 -1
- package/dest/proving_broker/rpc.js +24 -15
- 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 +14 -3
- package/src/light/index.ts +1 -0
- package/src/light/lightweight_checkpoint_builder.ts +215 -45
- package/src/mocks/fixtures.ts +6 -5
- package/src/mocks/test_context.ts +36 -19
- 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 +173 -147
- 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 +33 -24
- package/src/prover-client/server-epoch-prover.ts +4 -4
- package/src/proving_broker/broker_prover_facade.ts +26 -36
- package/src/proving_broker/config.ts +25 -3
- 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 +59 -13
- 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 +26 -3
- 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,25 @@ 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
|
+
import { SerialQueue } from '@aztec/foundation/queue';
|
|
15
16
|
import { assertLength } from '@aztec/foundation/serialize';
|
|
17
|
+
import { sleep } from '@aztec/foundation/sleep';
|
|
16
18
|
import { pushTestData } from '@aztec/foundation/testing';
|
|
17
19
|
import { elapsed } from '@aztec/foundation/timer';
|
|
18
20
|
import type { TreeNodeLocation } from '@aztec/foundation/trees';
|
|
19
|
-
import { readAvmMinimalPublicTxInputsFromFile } from '@aztec/simulator/public/fixtures';
|
|
20
21
|
import { EthAddress } from '@aztec/stdlib/block';
|
|
21
22
|
import type {
|
|
22
23
|
EpochProver,
|
|
23
24
|
ForkMerkleTreeOperations,
|
|
24
25
|
MerkleTreeWriteOperations,
|
|
25
26
|
PublicInputsAndRecursiveProof,
|
|
27
|
+
ReadonlyWorldStateAccess,
|
|
26
28
|
ServerCircuitProver,
|
|
27
29
|
} from '@aztec/stdlib/interfaces/server';
|
|
28
30
|
import type { Proof } from '@aztec/stdlib/proofs';
|
|
@@ -71,8 +73,6 @@ import { EpochProvingState, type ProvingResult, type TreeSnapshots } from './epo
|
|
|
71
73
|
import { ProvingOrchestratorMetrics } from './orchestrator_metrics.js';
|
|
72
74
|
import { TxProvingState } from './tx-proving-state.js';
|
|
73
75
|
|
|
74
|
-
const logger = createLogger('prover-client:orchestrator');
|
|
75
|
-
|
|
76
76
|
/**
|
|
77
77
|
* Implements an event driven proving scheduler to build the recursive proof tree. The idea being:
|
|
78
78
|
* 1. Transactions are provided to the scheduler post simulation.
|
|
@@ -93,15 +93,23 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
93
93
|
|
|
94
94
|
private provingPromise: Promise<ProvingResult> | undefined = undefined;
|
|
95
95
|
private metrics: ProvingOrchestratorMetrics;
|
|
96
|
-
|
|
96
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
97
|
+
private dbs: Map<BlockNumber, MerkleTreeWriteOperations> = new Map();
|
|
98
|
+
private logger: Logger;
|
|
99
|
+
private deferredJobQueue = new SerialQueue();
|
|
97
100
|
|
|
98
101
|
constructor(
|
|
99
|
-
private dbProvider: ForkMerkleTreeOperations,
|
|
102
|
+
private dbProvider: ReadonlyWorldStateAccess & ForkMerkleTreeOperations,
|
|
100
103
|
private prover: ServerCircuitProver,
|
|
101
104
|
private readonly proverId: EthAddress,
|
|
105
|
+
private readonly cancelJobsOnStop: boolean = false,
|
|
106
|
+
private readonly enqueueConcurrency: number,
|
|
102
107
|
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
108
|
+
bindings?: LoggerBindings,
|
|
103
109
|
) {
|
|
110
|
+
this.logger = createLogger('prover-client:orchestrator', bindings);
|
|
104
111
|
this.metrics = new ProvingOrchestratorMetrics(telemetryClient, 'ProvingOrchestrator');
|
|
112
|
+
this.deferredJobQueue.start(this.enqueueConcurrency);
|
|
105
113
|
}
|
|
106
114
|
|
|
107
115
|
get tracer(): Tracer {
|
|
@@ -112,9 +120,15 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
112
120
|
return this.proverId;
|
|
113
121
|
}
|
|
114
122
|
|
|
115
|
-
public
|
|
123
|
+
public getNumActiveForks() {
|
|
124
|
+
return this.dbs.size;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
public async stop(): Promise<void> {
|
|
128
|
+
// Grab the old queue before cancel() replaces it, so we can await its draining.
|
|
129
|
+
const oldQueue = this.deferredJobQueue;
|
|
116
130
|
this.cancel();
|
|
117
|
-
|
|
131
|
+
await oldQueue.cancel();
|
|
118
132
|
}
|
|
119
133
|
|
|
120
134
|
public startNewEpoch(
|
|
@@ -130,7 +144,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
130
144
|
|
|
131
145
|
const { promise: _promise, resolve, reject } = promiseWithResolvers<ProvingResult>();
|
|
132
146
|
const promise = _promise.catch((reason): ProvingResult => ({ status: 'failure', reason }));
|
|
133
|
-
logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
|
|
147
|
+
this.logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
|
|
134
148
|
this.provingState = new EpochProvingState(
|
|
135
149
|
epochNumber,
|
|
136
150
|
totalNumCheckpoints,
|
|
@@ -142,6 +156,14 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
142
156
|
this.provingPromise = promise;
|
|
143
157
|
}
|
|
144
158
|
|
|
159
|
+
/**
|
|
160
|
+
* Starts a new checkpoint.
|
|
161
|
+
* @param checkpointIndex - The index of the checkpoint in the epoch.
|
|
162
|
+
* @param constants - The constants for this checkpoint.
|
|
163
|
+
* @param l1ToL2Messages - The set of L1 to L2 messages to be inserted at the beginning of this checkpoint.
|
|
164
|
+
* @param totalNumBlocks - The total number of blocks expected in the checkpoint (must be at least one).
|
|
165
|
+
* @param headerOfLastBlockInPreviousCheckpoint - The header of the last block in the previous checkpoint.
|
|
166
|
+
*/
|
|
145
167
|
public async startNewCheckpoint(
|
|
146
168
|
checkpointIndex: number,
|
|
147
169
|
constants: CheckpointConstantData,
|
|
@@ -161,7 +183,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
161
183
|
const lastBlockNumber = headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber;
|
|
162
184
|
const db = await this.dbProvider.fork(lastBlockNumber);
|
|
163
185
|
|
|
164
|
-
const firstBlockNumber = lastBlockNumber + 1;
|
|
186
|
+
const firstBlockNumber = BlockNumber(lastBlockNumber + 1);
|
|
165
187
|
this.dbs.set(firstBlockNumber, db);
|
|
166
188
|
|
|
167
189
|
// Get archive sibling path before any block in this checkpoint lands.
|
|
@@ -199,7 +221,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
199
221
|
@trackSpan('ProvingOrchestrator.startNewBlock', blockNumber => ({
|
|
200
222
|
[Attributes.BLOCK_NUMBER]: blockNumber,
|
|
201
223
|
}))
|
|
202
|
-
public async startNewBlock(blockNumber:
|
|
224
|
+
public async startNewBlock(blockNumber: BlockNumber, timestamp: UInt64, totalNumTxs: number) {
|
|
203
225
|
if (!this.provingState) {
|
|
204
226
|
throw new Error('Empty epoch proving state. Call startNewEpoch before starting a block.');
|
|
205
227
|
}
|
|
@@ -214,15 +236,15 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
214
236
|
}
|
|
215
237
|
|
|
216
238
|
const constants = checkpointProvingState.constants;
|
|
217
|
-
logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
|
|
239
|
+
this.logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
|
|
218
240
|
|
|
219
241
|
// Fork the db only when it's not already set. The db for the first block is set in `startNewCheckpoint`.
|
|
220
242
|
if (!this.dbs.has(blockNumber)) {
|
|
221
243
|
// Fork world state at the end of the immediately previous block
|
|
222
|
-
const db = await this.dbProvider.fork(blockNumber - 1);
|
|
244
|
+
const db = await this.dbProvider.fork(BlockNumber(blockNumber - 1));
|
|
223
245
|
this.dbs.set(blockNumber, db);
|
|
224
246
|
}
|
|
225
|
-
const db = this.
|
|
247
|
+
const db = this.getDbForBlock(blockNumber);
|
|
226
248
|
|
|
227
249
|
// Get archive snapshot and sibling path before any txs in this block lands.
|
|
228
250
|
const lastArchiveTreeSnapshot = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
@@ -254,7 +276,8 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
254
276
|
await endSpongeBlob.absorb(blockEndBlobFields);
|
|
255
277
|
blockProvingState.setEndSpongeBlob(endSpongeBlob);
|
|
256
278
|
|
|
257
|
-
//
|
|
279
|
+
// Try to accumulate the out hashes and blobs as far as we can:
|
|
280
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
258
281
|
await this.provingState.setBlobAccumulators();
|
|
259
282
|
}
|
|
260
283
|
}
|
|
@@ -274,11 +297,11 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
274
297
|
if (!txs.length) {
|
|
275
298
|
// To avoid an ugly throw below. If we require an empty block, we can just call setBlockCompleted
|
|
276
299
|
// 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.`);
|
|
300
|
+
this.logger.warn(`Provided no txs to orchestrator addTxs.`);
|
|
278
301
|
return;
|
|
279
302
|
}
|
|
280
303
|
|
|
281
|
-
const blockNumber = txs[0].globalVariables.blockNumber;
|
|
304
|
+
const blockNumber = BlockNumber(txs[0].globalVariables.blockNumber);
|
|
282
305
|
const provingState = this.provingState.getBlockProvingStateByBlockNumber(blockNumber!);
|
|
283
306
|
if (!provingState) {
|
|
284
307
|
throw new Error(`Proving state for block ${blockNumber} not found. Call startNewBlock first.`);
|
|
@@ -294,9 +317,9 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
294
317
|
throw new Error(`Block ${blockNumber} has been initialized with transactions.`);
|
|
295
318
|
}
|
|
296
319
|
|
|
297
|
-
logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
320
|
+
this.logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
298
321
|
|
|
299
|
-
const db = this.
|
|
322
|
+
const db = this.getDbForBlock(blockNumber);
|
|
300
323
|
const lastArchive = provingState.lastArchiveTreeSnapshot;
|
|
301
324
|
const newL1ToL2MessageTreeSnapshot = provingState.newL1ToL2MessageTreeSnapshot;
|
|
302
325
|
const spongeBlobState = provingState.getStartSpongeBlob().clone();
|
|
@@ -309,7 +332,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
309
332
|
|
|
310
333
|
validateTx(tx);
|
|
311
334
|
|
|
312
|
-
logger.
|
|
335
|
+
this.logger.debug(`Received transaction: ${tx.hash}`);
|
|
313
336
|
|
|
314
337
|
const startSpongeBlob = spongeBlobState.clone();
|
|
315
338
|
const [hints, treeSnapshots] = await this.prepareBaseRollupInputs(
|
|
@@ -330,10 +353,10 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
330
353
|
const txIndex = provingState.addNewTx(txProvingState);
|
|
331
354
|
if (txProvingState.requireAvmProof) {
|
|
332
355
|
this.getOrEnqueueChonkVerifier(provingState, txIndex);
|
|
333
|
-
logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
356
|
+
this.logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
334
357
|
this.enqueueVM(provingState, txIndex);
|
|
335
358
|
} else {
|
|
336
|
-
logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
359
|
+
this.logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
337
360
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
338
361
|
}
|
|
339
362
|
} catch (err: any) {
|
|
@@ -351,7 +374,8 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
351
374
|
|
|
352
375
|
provingState.setEndSpongeBlob(spongeBlobState);
|
|
353
376
|
|
|
354
|
-
// Txs have been added to the block. Now try to accumulate the blobs as far as we can:
|
|
377
|
+
// Txs have been added to the block. Now try to accumulate the out hashes and blobs as far as we can:
|
|
378
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
355
379
|
await this.provingState.setBlobAccumulators();
|
|
356
380
|
}
|
|
357
381
|
|
|
@@ -375,7 +399,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
375
399
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
376
400
|
>
|
|
377
401
|
>();
|
|
378
|
-
logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
|
|
402
|
+
this.logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
|
|
379
403
|
this.doEnqueueChonkVerifier(txHash, privateInputs, proof => {
|
|
380
404
|
tubeProof.resolve(proof);
|
|
381
405
|
});
|
|
@@ -388,10 +412,10 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
388
412
|
* Marks the block as completed.
|
|
389
413
|
* Computes the block header and updates the archive tree.
|
|
390
414
|
*/
|
|
391
|
-
@trackSpan('ProvingOrchestrator.setBlockCompleted', (blockNumber:
|
|
415
|
+
@trackSpan('ProvingOrchestrator.setBlockCompleted', (blockNumber: BlockNumber) => ({
|
|
392
416
|
[Attributes.BLOCK_NUMBER]: blockNumber,
|
|
393
417
|
}))
|
|
394
|
-
public async setBlockCompleted(blockNumber:
|
|
418
|
+
public async setBlockCompleted(blockNumber: BlockNumber, expectedHeader?: BlockHeader): Promise<BlockHeader> {
|
|
395
419
|
const provingState = this.provingState?.getBlockProvingStateByBlockNumber(blockNumber);
|
|
396
420
|
if (!provingState) {
|
|
397
421
|
throw new Error(`Block proving state for ${blockNumber} not found`);
|
|
@@ -415,22 +439,28 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
415
439
|
}
|
|
416
440
|
|
|
417
441
|
// Given we've applied every change from this block, now assemble the block header:
|
|
418
|
-
logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
|
|
442
|
+
this.logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
|
|
419
443
|
const header = await provingState.buildBlockHeader();
|
|
420
444
|
|
|
421
445
|
if (expectedHeader && !header.equals(expectedHeader)) {
|
|
422
|
-
logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
446
|
+
this.logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
423
447
|
throw new Error('Block header mismatch');
|
|
424
448
|
}
|
|
425
449
|
|
|
426
|
-
// Get db for this block
|
|
427
|
-
const db = this.
|
|
450
|
+
// Get db for this block and remove from map — no other code should use it after this point.
|
|
451
|
+
const db = this.getDbForBlock(provingState.blockNumber);
|
|
452
|
+
this.dbs.delete(provingState.blockNumber);
|
|
428
453
|
|
|
429
|
-
// Update the archive tree,
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
454
|
+
// Update the archive tree, capture the snapshot, and close the fork deterministically.
|
|
455
|
+
try {
|
|
456
|
+
this.logger.verbose(
|
|
457
|
+
`Updating archive tree with block ${provingState.blockNumber} header ${(await header.hash()).toString()}`,
|
|
458
|
+
);
|
|
459
|
+
await db.updateArchive(header);
|
|
460
|
+
provingState.setBuiltArchive(await getTreeSnapshot(MerkleTreeId.ARCHIVE, db));
|
|
461
|
+
} finally {
|
|
462
|
+
await db.close();
|
|
463
|
+
}
|
|
434
464
|
|
|
435
465
|
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
436
466
|
|
|
@@ -441,31 +471,34 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
441
471
|
protected async verifyBuiltBlockAgainstSyncedState(provingState: BlockProvingState) {
|
|
442
472
|
const builtBlockHeader = provingState.getBuiltBlockHeader();
|
|
443
473
|
if (!builtBlockHeader) {
|
|
444
|
-
logger.debug('Block header not built yet, skipping header check.');
|
|
474
|
+
this.logger.debug('Block header not built yet, skipping header check.');
|
|
445
475
|
return;
|
|
446
476
|
}
|
|
447
477
|
|
|
448
478
|
const output = provingState.getBlockRootRollupOutput();
|
|
449
479
|
if (!output) {
|
|
450
|
-
logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
480
|
+
this.logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
const newArchive = provingState.getBuiltArchive();
|
|
485
|
+
if (!newArchive) {
|
|
486
|
+
this.logger.debug('Archive snapshot not yet captured, skipping header check.');
|
|
451
487
|
return;
|
|
452
488
|
}
|
|
489
|
+
|
|
453
490
|
const header = await buildHeaderFromCircuitOutputs(output);
|
|
454
491
|
|
|
455
492
|
if (!(await header.hash()).equals(await builtBlockHeader.hash())) {
|
|
456
|
-
logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
493
|
+
this.logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
457
494
|
provingState.reject(`Block header hash mismatch.`);
|
|
458
495
|
return;
|
|
459
496
|
}
|
|
460
497
|
|
|
461
|
-
// Get db for this block
|
|
462
498
|
const blockNumber = provingState.blockNumber;
|
|
463
|
-
const db = this.dbs.get(blockNumber)!;
|
|
464
|
-
|
|
465
|
-
const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
466
499
|
const syncedArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.dbProvider.getSnapshot(blockNumber));
|
|
467
500
|
if (!syncedArchive.equals(newArchive)) {
|
|
468
|
-
logger.error(
|
|
501
|
+
this.logger.error(
|
|
469
502
|
`Archive tree mismatch for block ${blockNumber}: world state synced to ${inspect(
|
|
470
503
|
syncedArchive,
|
|
471
504
|
)} but built ${inspect(newArchive)}`,
|
|
@@ -476,32 +509,43 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
476
509
|
|
|
477
510
|
const circuitArchive = output.newArchive;
|
|
478
511
|
if (!newArchive.equals(circuitArchive)) {
|
|
479
|
-
logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
512
|
+
this.logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
480
513
|
provingState.reject(`New archive mismatch.`);
|
|
481
514
|
return;
|
|
482
515
|
}
|
|
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
516
|
}
|
|
495
517
|
|
|
496
518
|
/**
|
|
497
|
-
* Cancel any further proving
|
|
519
|
+
* Cancel any further proving.
|
|
520
|
+
* If cancelJobsOnStop is true, aborts all pending jobs with the broker (which marks them as 'Aborted').
|
|
521
|
+
* If cancelJobsOnStop is false (default), jobs remain in the broker queue and can be reused on restart/reorg.
|
|
498
522
|
*/
|
|
499
523
|
public cancel() {
|
|
500
|
-
|
|
501
|
-
|
|
524
|
+
void this.deferredJobQueue.cancel();
|
|
525
|
+
// Recreate the queue so it can accept jobs for subsequent epochs.
|
|
526
|
+
this.deferredJobQueue = new SerialQueue();
|
|
527
|
+
this.deferredJobQueue.start(this.enqueueConcurrency);
|
|
528
|
+
|
|
529
|
+
if (this.cancelJobsOnStop) {
|
|
530
|
+
for (const controller of this.pendingProvingJobs) {
|
|
531
|
+
controller.abort();
|
|
532
|
+
}
|
|
502
533
|
}
|
|
503
534
|
|
|
504
535
|
this.provingState?.cancel();
|
|
536
|
+
|
|
537
|
+
for (const [blockNumber, db] of this.dbs.entries()) {
|
|
538
|
+
void db.close().catch(err => this.logger.error(`Error closing db for block ${blockNumber}`, err));
|
|
539
|
+
}
|
|
540
|
+
this.dbs.clear();
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
private getDbForBlock(blockNumber: BlockNumber): MerkleTreeWriteOperations {
|
|
544
|
+
const db = this.dbs.get(blockNumber);
|
|
545
|
+
if (!db) {
|
|
546
|
+
throw new Error(`World state fork for block ${blockNumber} not found.`);
|
|
547
|
+
}
|
|
548
|
+
return db;
|
|
505
549
|
}
|
|
506
550
|
|
|
507
551
|
/**
|
|
@@ -545,7 +589,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
545
589
|
callback: (result: T) => void | Promise<void>,
|
|
546
590
|
) {
|
|
547
591
|
if (!provingState.verifyState()) {
|
|
548
|
-
logger.debug(`Not enqueuing job, state no longer valid`);
|
|
592
|
+
this.logger.debug(`Not enqueuing job, state no longer valid`);
|
|
549
593
|
return;
|
|
550
594
|
}
|
|
551
595
|
|
|
@@ -563,7 +607,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
563
607
|
|
|
564
608
|
const result = await request(controller.signal);
|
|
565
609
|
if (!provingState.verifyState()) {
|
|
566
|
-
logger.debug(`State no longer valid, discarding result`);
|
|
610
|
+
this.logger.debug(`State no longer valid, discarding result`);
|
|
567
611
|
return;
|
|
568
612
|
}
|
|
569
613
|
|
|
@@ -581,7 +625,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
581
625
|
return;
|
|
582
626
|
}
|
|
583
627
|
|
|
584
|
-
logger.error(`Error thrown when proving job`, err);
|
|
628
|
+
this.logger.error(`Error thrown when proving job`, err);
|
|
585
629
|
provingState!.reject(`${err}`);
|
|
586
630
|
} finally {
|
|
587
631
|
const index = this.pendingProvingJobs.indexOf(controller);
|
|
@@ -591,8 +635,11 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
591
635
|
}
|
|
592
636
|
};
|
|
593
637
|
|
|
594
|
-
|
|
595
|
-
|
|
638
|
+
void this.deferredJobQueue.put(async () => {
|
|
639
|
+
void safeJob();
|
|
640
|
+
// we yield here to the macro task queue such to give Nodejs a chance to run other operatoins in between enqueues
|
|
641
|
+
await sleep(0);
|
|
642
|
+
});
|
|
596
643
|
}
|
|
597
644
|
|
|
598
645
|
private async updateL1ToL2MessageTree(l1ToL2Messages: Fr[], db: MerkleTreeWriteOperations) {
|
|
@@ -666,12 +713,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
666
713
|
// Executes the next level of merge if all inputs are available
|
|
667
714
|
private enqueueBaseRollup(provingState: BlockProvingState, txIndex: number) {
|
|
668
715
|
if (!provingState.verifyState()) {
|
|
669
|
-
logger.debug('Not running base rollup, state invalid');
|
|
716
|
+
this.logger.debug('Not running base rollup, state invalid');
|
|
670
717
|
return;
|
|
671
718
|
}
|
|
672
719
|
|
|
673
720
|
if (!provingState.tryStartProvingBase(txIndex)) {
|
|
674
|
-
logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
721
|
+
this.logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
675
722
|
return;
|
|
676
723
|
}
|
|
677
724
|
|
|
@@ -679,7 +726,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
679
726
|
const { processedTx } = txProvingState;
|
|
680
727
|
const { rollupType, inputs } = txProvingState.getBaseRollupTypeAndInputs();
|
|
681
728
|
|
|
682
|
-
logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
729
|
+
this.logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
683
730
|
|
|
684
731
|
this.deferredProving(
|
|
685
732
|
provingState,
|
|
@@ -703,7 +750,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
703
750
|
},
|
|
704
751
|
),
|
|
705
752
|
result => {
|
|
706
|
-
logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
753
|
+
this.logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
707
754
|
validatePartialState(result.inputs.endTreeSnapshots, txProvingState.treeSnapshots);
|
|
708
755
|
const leafLocation = provingState.setBaseRollupProof(txIndex, result);
|
|
709
756
|
if (provingState.totalNumTxs === 1) {
|
|
@@ -719,7 +766,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
719
766
|
// Once completed, will enqueue the the public tx base rollup.
|
|
720
767
|
private getOrEnqueueChonkVerifier(provingState: BlockProvingState, txIndex: number) {
|
|
721
768
|
if (!provingState.verifyState()) {
|
|
722
|
-
logger.debug('Not running chonk verifier circuit, state invalid');
|
|
769
|
+
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
723
770
|
return;
|
|
724
771
|
}
|
|
725
772
|
|
|
@@ -732,19 +779,19 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
732
779
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
733
780
|
>,
|
|
734
781
|
) => {
|
|
735
|
-
logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, { txHash });
|
|
782
|
+
this.logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, { txHash });
|
|
736
783
|
txProvingState.setPublicChonkVerifierProof(result);
|
|
737
784
|
this.provingState?.cachedChonkVerifierProofs.delete(txHash);
|
|
738
785
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
739
786
|
};
|
|
740
787
|
|
|
741
788
|
if (this.provingState?.cachedChonkVerifierProofs.has(txHash)) {
|
|
742
|
-
logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, { txHash });
|
|
789
|
+
this.logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, { txHash });
|
|
743
790
|
void this.provingState!.cachedChonkVerifierProofs.get(txHash)!.then(handleResult);
|
|
744
791
|
return;
|
|
745
792
|
}
|
|
746
793
|
|
|
747
|
-
logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
|
|
794
|
+
this.logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
|
|
748
795
|
this.doEnqueueChonkVerifier(txHash, txProvingState.getPublicChonkVerifierPrivateInputs(), handleResult);
|
|
749
796
|
}
|
|
750
797
|
|
|
@@ -760,7 +807,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
760
807
|
provingState: EpochProvingState | BlockProvingState = this.provingState!,
|
|
761
808
|
) {
|
|
762
809
|
if (!provingState.verifyState()) {
|
|
763
|
-
logger.debug('Not running chonk verifier circuit, state invalid');
|
|
810
|
+
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
764
811
|
return;
|
|
765
812
|
}
|
|
766
813
|
|
|
@@ -783,12 +830,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
783
830
|
// Enqueues the next level of merge if all inputs are available
|
|
784
831
|
private enqueueMergeRollup(provingState: BlockProvingState, location: TreeNodeLocation) {
|
|
785
832
|
if (!provingState.verifyState()) {
|
|
786
|
-
logger.debug('Not running merge rollup. State no longer valid.');
|
|
833
|
+
this.logger.debug('Not running merge rollup. State no longer valid.');
|
|
787
834
|
return;
|
|
788
835
|
}
|
|
789
836
|
|
|
790
837
|
if (!provingState.tryStartProvingMerge(location)) {
|
|
791
|
-
logger.debug('Merge rollup already started.');
|
|
838
|
+
this.logger.debug('Merge rollup already started.');
|
|
792
839
|
return;
|
|
793
840
|
}
|
|
794
841
|
|
|
@@ -814,18 +861,18 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
814
861
|
// Executes the block root rollup circuit
|
|
815
862
|
private enqueueBlockRootRollup(provingState: BlockProvingState) {
|
|
816
863
|
if (!provingState.verifyState()) {
|
|
817
|
-
logger.debug('Not running block root rollup, state no longer valid');
|
|
864
|
+
this.logger.debug('Not running block root rollup, state no longer valid');
|
|
818
865
|
return;
|
|
819
866
|
}
|
|
820
867
|
|
|
821
868
|
if (!provingState.tryStartProvingBlockRoot()) {
|
|
822
|
-
logger.debug('Block root rollup already started.');
|
|
869
|
+
this.logger.debug('Block root rollup already started.');
|
|
823
870
|
return;
|
|
824
871
|
}
|
|
825
872
|
|
|
826
873
|
const { rollupType, inputs } = provingState.getBlockRootRollupTypeAndInputs();
|
|
827
874
|
|
|
828
|
-
logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
875
|
+
this.logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
829
876
|
|
|
830
877
|
this.deferredProving(
|
|
831
878
|
provingState,
|
|
@@ -850,18 +897,19 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
850
897
|
},
|
|
851
898
|
),
|
|
852
899
|
async result => {
|
|
853
|
-
|
|
854
|
-
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
855
|
-
|
|
856
|
-
logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`);
|
|
900
|
+
this.logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`);
|
|
857
901
|
|
|
858
902
|
const leafLocation = provingState.setBlockRootRollupProof(result);
|
|
859
903
|
const checkpointProvingState = provingState.parentCheckpoint;
|
|
860
904
|
|
|
905
|
+
// Verification is called from both here and setBlockCompleted. Whichever runs last
|
|
906
|
+
// will be the first to see all three pieces (header, proof output, archive) and run the checks.
|
|
907
|
+
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
908
|
+
|
|
861
909
|
if (checkpointProvingState.totalNumBlocks === 1) {
|
|
862
|
-
this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
910
|
+
await this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
863
911
|
} else {
|
|
864
|
-
this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
912
|
+
await this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
865
913
|
}
|
|
866
914
|
},
|
|
867
915
|
);
|
|
@@ -875,12 +923,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
875
923
|
baseParityIndex: number,
|
|
876
924
|
) {
|
|
877
925
|
if (!provingState.verifyState()) {
|
|
878
|
-
logger.debug('Not running base parity. State no longer valid.');
|
|
926
|
+
this.logger.debug('Not running base parity. State no longer valid.');
|
|
879
927
|
return;
|
|
880
928
|
}
|
|
881
929
|
|
|
882
930
|
if (!provingState.tryStartProvingBaseParity(baseParityIndex)) {
|
|
883
|
-
logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
931
|
+
this.logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
884
932
|
return;
|
|
885
933
|
}
|
|
886
934
|
|
|
@@ -915,12 +963,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
915
963
|
// Enqueues the root rollup proof if all inputs are available
|
|
916
964
|
private enqueueRootParityCircuit(provingState: BlockProvingState) {
|
|
917
965
|
if (!provingState.verifyState()) {
|
|
918
|
-
logger.debug('Not running root parity. State no longer valid.');
|
|
966
|
+
this.logger.debug('Not running root parity. State no longer valid.');
|
|
919
967
|
return;
|
|
920
968
|
}
|
|
921
969
|
|
|
922
970
|
if (!provingState.tryStartProvingRootParity()) {
|
|
923
|
-
logger.debug('Root parity already started.');
|
|
971
|
+
this.logger.debug('Root parity already started.');
|
|
924
972
|
return;
|
|
925
973
|
}
|
|
926
974
|
|
|
@@ -947,12 +995,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
947
995
|
// Enqueues the next level of merge if all inputs are available
|
|
948
996
|
private enqueueBlockMergeRollup(provingState: CheckpointProvingState, location: TreeNodeLocation) {
|
|
949
997
|
if (!provingState.verifyState()) {
|
|
950
|
-
logger.debug('Not running block merge rollup. State no longer valid.');
|
|
998
|
+
this.logger.debug('Not running block merge rollup. State no longer valid.');
|
|
951
999
|
return;
|
|
952
1000
|
}
|
|
953
1001
|
|
|
954
1002
|
if (!provingState.tryStartProvingBlockMerge(location)) {
|
|
955
|
-
logger.debug('Block merge rollup already started.');
|
|
1003
|
+
this.logger.debug('Block merge rollup already started.');
|
|
956
1004
|
return;
|
|
957
1005
|
}
|
|
958
1006
|
|
|
@@ -967,29 +1015,29 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
967
1015
|
},
|
|
968
1016
|
signal => this.prover.getBlockMergeRollupProof(inputs, signal, provingState.epochNumber),
|
|
969
1017
|
),
|
|
970
|
-
result => {
|
|
1018
|
+
async result => {
|
|
971
1019
|
provingState.setBlockMergeRollupProof(location, result);
|
|
972
|
-
this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
1020
|
+
await this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
973
1021
|
},
|
|
974
1022
|
);
|
|
975
1023
|
}
|
|
976
1024
|
|
|
977
|
-
private enqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
1025
|
+
private async enqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
978
1026
|
if (!provingState.verifyState()) {
|
|
979
|
-
logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
1027
|
+
this.logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
980
1028
|
return;
|
|
981
1029
|
}
|
|
982
1030
|
|
|
983
1031
|
if (!provingState.tryStartProvingCheckpointRoot()) {
|
|
984
|
-
logger.debug('Checkpoint root rollup already started.');
|
|
1032
|
+
this.logger.debug('Checkpoint root rollup already started.');
|
|
985
1033
|
return;
|
|
986
1034
|
}
|
|
987
1035
|
|
|
988
1036
|
const rollupType = provingState.getCheckpointRootRollupType();
|
|
989
1037
|
|
|
990
|
-
logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
1038
|
+
this.logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
991
1039
|
|
|
992
|
-
const inputs = provingState.getCheckpointRootRollupInputs();
|
|
1040
|
+
const inputs = await provingState.getCheckpointRootRollupInputs();
|
|
993
1041
|
|
|
994
1042
|
this.deferredProving(
|
|
995
1043
|
provingState,
|
|
@@ -1011,7 +1059,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1011
1059
|
const computedEndBlobAccumulatorState = provingState.getEndBlobAccumulator()!.toBlobAccumulator();
|
|
1012
1060
|
const circuitEndBlobAccumulatorState = result.inputs.endBlobAccumulator;
|
|
1013
1061
|
if (!circuitEndBlobAccumulatorState.equals(computedEndBlobAccumulatorState)) {
|
|
1014
|
-
logger.error(
|
|
1062
|
+
this.logger.error(
|
|
1015
1063
|
`Blob accumulator state mismatch.\nCircuit: ${inspect(circuitEndBlobAccumulatorState)}\nComputed: ${inspect(
|
|
1016
1064
|
computedEndBlobAccumulatorState,
|
|
1017
1065
|
)}`,
|
|
@@ -1020,7 +1068,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1020
1068
|
return;
|
|
1021
1069
|
}
|
|
1022
1070
|
|
|
1023
|
-
logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}.`);
|
|
1071
|
+
this.logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}.`);
|
|
1024
1072
|
|
|
1025
1073
|
const leafLocation = provingState.setCheckpointRootRollupProof(result);
|
|
1026
1074
|
const epochProvingState = provingState.parentEpoch;
|
|
@@ -1036,12 +1084,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1036
1084
|
|
|
1037
1085
|
private enqueueCheckpointMergeRollup(provingState: EpochProvingState, location: TreeNodeLocation) {
|
|
1038
1086
|
if (!provingState.verifyState()) {
|
|
1039
|
-
logger.debug('Not running checkpoint merge rollup. State no longer valid.');
|
|
1087
|
+
this.logger.debug('Not running checkpoint merge rollup. State no longer valid.');
|
|
1040
1088
|
return;
|
|
1041
1089
|
}
|
|
1042
1090
|
|
|
1043
1091
|
if (!provingState.tryStartProvingCheckpointMerge(location)) {
|
|
1044
|
-
logger.debug('Checkpoint merge rollup already started.');
|
|
1092
|
+
this.logger.debug('Checkpoint merge rollup already started.');
|
|
1045
1093
|
return;
|
|
1046
1094
|
}
|
|
1047
1095
|
|
|
@@ -1058,7 +1106,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1058
1106
|
signal => this.prover.getCheckpointMergeRollupProof(inputs, signal, provingState.epochNumber),
|
|
1059
1107
|
),
|
|
1060
1108
|
result => {
|
|
1061
|
-
logger.debug('Completed proof for checkpoint merge rollup.');
|
|
1109
|
+
this.logger.debug('Completed proof for checkpoint merge rollup.');
|
|
1062
1110
|
provingState.setCheckpointMergeRollupProof(location, result);
|
|
1063
1111
|
this.checkAndEnqueueNextCheckpointMergeRollup(provingState, location);
|
|
1064
1112
|
},
|
|
@@ -1067,16 +1115,16 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1067
1115
|
|
|
1068
1116
|
private enqueueEpochPadding(provingState: EpochProvingState) {
|
|
1069
1117
|
if (!provingState.verifyState()) {
|
|
1070
|
-
logger.debug('Not running epoch padding. State no longer valid.');
|
|
1118
|
+
this.logger.debug('Not running epoch padding. State no longer valid.');
|
|
1071
1119
|
return;
|
|
1072
1120
|
}
|
|
1073
1121
|
|
|
1074
1122
|
if (!provingState.tryStartProvingPaddingCheckpoint()) {
|
|
1075
|
-
logger.debug('Padding checkpoint already started.');
|
|
1123
|
+
this.logger.debug('Padding checkpoint already started.');
|
|
1076
1124
|
return;
|
|
1077
1125
|
}
|
|
1078
1126
|
|
|
1079
|
-
logger.debug('Padding epoch proof with a padding block root proof.');
|
|
1127
|
+
this.logger.debug('Padding epoch proof with a padding block root proof.');
|
|
1080
1128
|
|
|
1081
1129
|
const inputs = provingState.getPaddingCheckpointInputs();
|
|
1082
1130
|
|
|
@@ -1091,7 +1139,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1091
1139
|
signal => this.prover.getCheckpointPaddingRollupProof(inputs, signal, provingState.epochNumber),
|
|
1092
1140
|
),
|
|
1093
1141
|
result => {
|
|
1094
|
-
logger.debug('Completed proof for padding checkpoint.');
|
|
1142
|
+
this.logger.debug('Completed proof for padding checkpoint.');
|
|
1095
1143
|
provingState.setCheckpointPaddingProof(result);
|
|
1096
1144
|
this.checkAndEnqueueRootRollup(provingState);
|
|
1097
1145
|
},
|
|
@@ -1101,11 +1149,11 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1101
1149
|
// Executes the root rollup circuit
|
|
1102
1150
|
private enqueueRootRollup(provingState: EpochProvingState) {
|
|
1103
1151
|
if (!provingState.verifyState()) {
|
|
1104
|
-
logger.debug('Not running root rollup, state no longer valid');
|
|
1152
|
+
this.logger.debug('Not running root rollup, state no longer valid');
|
|
1105
1153
|
return;
|
|
1106
1154
|
}
|
|
1107
1155
|
|
|
1108
|
-
logger.debug(`Preparing root rollup`);
|
|
1156
|
+
this.logger.debug(`Preparing root rollup`);
|
|
1109
1157
|
|
|
1110
1158
|
const inputs = provingState.getRootRollupInputs();
|
|
1111
1159
|
|
|
@@ -1120,7 +1168,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1120
1168
|
signal => this.prover.getRootRollupProof(inputs, signal, provingState.epochNumber),
|
|
1121
1169
|
),
|
|
1122
1170
|
result => {
|
|
1123
|
-
logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
|
|
1171
|
+
this.logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
|
|
1124
1172
|
provingState.setRootRollupProof(result);
|
|
1125
1173
|
provingState.resolve({ status: 'success' });
|
|
1126
1174
|
},
|
|
@@ -1142,32 +1190,35 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1142
1190
|
|
|
1143
1191
|
private checkAndEnqueueBlockRootRollup(provingState: BlockProvingState) {
|
|
1144
1192
|
if (!provingState.isReadyForBlockRootRollup()) {
|
|
1145
|
-
logger.debug('Not ready for block root rollup');
|
|
1193
|
+
this.logger.debug('Not ready for block root rollup');
|
|
1146
1194
|
return;
|
|
1147
1195
|
}
|
|
1148
1196
|
|
|
1149
1197
|
this.enqueueBlockRootRollup(provingState);
|
|
1150
1198
|
}
|
|
1151
1199
|
|
|
1152
|
-
private checkAndEnqueueNextBlockMergeRollup(
|
|
1200
|
+
private async checkAndEnqueueNextBlockMergeRollup(
|
|
1201
|
+
provingState: CheckpointProvingState,
|
|
1202
|
+
currentLocation: TreeNodeLocation,
|
|
1203
|
+
) {
|
|
1153
1204
|
if (!provingState.isReadyForBlockMerge(currentLocation)) {
|
|
1154
1205
|
return;
|
|
1155
1206
|
}
|
|
1156
1207
|
|
|
1157
1208
|
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
1158
1209
|
if (parentLocation.level === 0) {
|
|
1159
|
-
this.checkAndEnqueueCheckpointRootRollup(provingState);
|
|
1210
|
+
await this.checkAndEnqueueCheckpointRootRollup(provingState);
|
|
1160
1211
|
} else {
|
|
1161
1212
|
this.enqueueBlockMergeRollup(provingState, parentLocation);
|
|
1162
1213
|
}
|
|
1163
1214
|
}
|
|
1164
1215
|
|
|
1165
|
-
private checkAndEnqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
1216
|
+
private async checkAndEnqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
1166
1217
|
if (!provingState.isReadyForCheckpointRoot()) {
|
|
1167
1218
|
return;
|
|
1168
1219
|
}
|
|
1169
1220
|
|
|
1170
|
-
this.enqueueCheckpointRootRollup(provingState);
|
|
1221
|
+
await this.enqueueCheckpointRootRollup(provingState);
|
|
1171
1222
|
}
|
|
1172
1223
|
|
|
1173
1224
|
private checkAndEnqueueNextCheckpointMergeRollup(provingState: EpochProvingState, currentLocation: TreeNodeLocation) {
|
|
@@ -1185,7 +1236,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1185
1236
|
|
|
1186
1237
|
private checkAndEnqueueRootRollup(provingState: EpochProvingState) {
|
|
1187
1238
|
if (!provingState.isReadyForRootRollup()) {
|
|
1188
|
-
logger.debug('Not ready for root rollup');
|
|
1239
|
+
this.logger.debug('Not ready for root rollup');
|
|
1189
1240
|
return;
|
|
1190
1241
|
}
|
|
1191
1242
|
|
|
@@ -1200,14 +1251,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1200
1251
|
*/
|
|
1201
1252
|
private enqueueVM(provingState: BlockProvingState, txIndex: number) {
|
|
1202
1253
|
if (!provingState.verifyState()) {
|
|
1203
|
-
logger.debug(`Not running VM circuit as state is no longer valid`);
|
|
1254
|
+
this.logger.debug(`Not running VM circuit as state is no longer valid`);
|
|
1204
1255
|
return;
|
|
1205
1256
|
}
|
|
1206
1257
|
|
|
1207
1258
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
1208
1259
|
|
|
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
1260
|
const doAvmProving = wrapCallbackInSpan(
|
|
1212
1261
|
this.tracer,
|
|
1213
1262
|
'ProvingOrchestrator.prover.getAvmProof',
|
|
@@ -1216,36 +1265,13 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1216
1265
|
},
|
|
1217
1266
|
async (signal: AbortSignal) => {
|
|
1218
1267
|
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
|
-
}
|
|
1268
|
+
return await this.prover.getAvmProof(inputs, signal, provingState.epochNumber);
|
|
1243
1269
|
},
|
|
1244
1270
|
);
|
|
1245
1271
|
|
|
1246
|
-
this.deferredProving(provingState, doAvmProving,
|
|
1247
|
-
logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1248
|
-
txProvingState.setAvmProof(
|
|
1272
|
+
this.deferredProving(provingState, doAvmProving, proof => {
|
|
1273
|
+
this.logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1274
|
+
txProvingState.setAvmProof(proof);
|
|
1249
1275
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
1250
1276
|
});
|
|
1251
1277
|
}
|
|
@@ -1257,7 +1283,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1257
1283
|
}
|
|
1258
1284
|
|
|
1259
1285
|
// 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`);
|
|
1286
|
+
this.logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1261
1287
|
|
|
1262
1288
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
1263
1289
|
}
|