@aztec/prover-client 0.0.1-commit.d431d1c → 0.0.1-commit.d58ff9d0
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 +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +16 -2
- package/dest/light/lightweight_checkpoint_builder.d.ts +14 -6
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
- package/dest/light/lightweight_checkpoint_builder.js +66 -27
- package/dest/mocks/fixtures.d.ts +1 -1
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +2 -1
- package/dest/mocks/test_context.d.ts +11 -11
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +31 -30
- package/dest/orchestrator/block-building-helpers.d.ts +4 -4
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +3 -3
- package/dest/orchestrator/block-proving-state.d.ts +4 -1
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +7 -0
- package/dest/orchestrator/checkpoint-proving-state.d.ts +20 -36
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/checkpoint-proving-state.js +22 -120
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts +161 -0
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts.map +1 -0
- package/dest/orchestrator/{orchestrator.js → checkpoint-sub-tree-orchestrator.js} +311 -472
- package/dest/orchestrator/chonk-cache.d.ts +39 -0
- package/dest/orchestrator/chonk-cache.d.ts.map +1 -0
- package/dest/orchestrator/chonk-cache.js +80 -0
- package/dest/orchestrator/index.d.ts +4 -2
- package/dest/orchestrator/index.d.ts.map +1 -1
- package/dest/orchestrator/index.js +3 -1
- package/dest/orchestrator/proving-scheduler.d.ts +81 -0
- package/dest/orchestrator/proving-scheduler.d.ts.map +1 -0
- package/dest/orchestrator/proving-scheduler.js +120 -0
- package/dest/orchestrator/top-tree-orchestrator.d.ts +88 -0
- package/dest/orchestrator/top-tree-orchestrator.d.ts.map +1 -0
- package/dest/orchestrator/top-tree-orchestrator.js +232 -0
- package/dest/orchestrator/top-tree-proving-state.d.ts +61 -0
- package/dest/orchestrator/top-tree-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/top-tree-proving-state.js +185 -0
- package/dest/orchestrator/tx-proving-state.d.ts +3 -3
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/prover-client/prover-client.d.ts +64 -7
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +66 -14
- package/dest/proving_broker/broker_prover_facade.d.ts +6 -5
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +16 -22
- package/dest/proving_broker/config.d.ts +12 -64
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +22 -5
- package/dest/proving_broker/index.d.ts +2 -1
- package/dest/proving_broker/index.d.ts.map +1 -1
- package/dest/proving_broker/index.js +1 -0
- 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 +4 -3
- package/dest/proving_broker/proving_agent.d.ts.map +1 -1
- package/dest/proving_broker/proving_agent.js +4 -4
- package/dest/proving_broker/proving_broker.d.ts +8 -5
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +68 -11
- package/dest/proving_broker/proving_broker_database/persisted.js +2 -2
- 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 +18 -7
- 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 +6 -3
- 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 +87 -23
- package/dest/test/epoch_settlement.d.ts +36 -0
- package/dest/test/epoch_settlement.d.ts.map +1 -0
- package/dest/test/epoch_settlement.js +52 -0
- package/dest/test/index.d.ts +2 -0
- package/dest/test/index.d.ts.map +1 -0
- package/dest/test/index.js +1 -0
- package/dest/test/mock_prover.d.ts +4 -4
- package/dest/test/mock_prover.js +2 -2
- package/package.json +20 -20
- package/src/config.ts +18 -2
- package/src/light/lightweight_checkpoint_builder.ts +79 -31
- package/src/mocks/fixtures.ts +2 -1
- package/src/mocks/test_context.ts +27 -43
- package/src/orchestrator/block-building-helpers.ts +3 -3
- package/src/orchestrator/block-proving-state.ts +9 -0
- package/src/orchestrator/checkpoint-proving-state.ts +21 -162
- package/src/orchestrator/checkpoint-sub-tree-orchestrator.ts +1044 -0
- package/src/orchestrator/chonk-cache.ts +99 -0
- package/src/orchestrator/index.ts +8 -1
- package/src/orchestrator/proving-scheduler.ts +160 -0
- package/src/orchestrator/top-tree-orchestrator.ts +384 -0
- package/src/orchestrator/top-tree-proving-state.ts +219 -0
- package/src/orchestrator/tx-proving-state.ts +3 -3
- package/src/prover-client/prover-client.ts +146 -20
- package/src/proving_broker/broker_prover_facade.ts +25 -25
- package/src/proving_broker/config.ts +25 -2
- package/src/proving_broker/index.ts +1 -0
- 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 +5 -2
- package/src/proving_broker/proving_broker.ts +64 -8
- package/src/proving_broker/proving_broker_database/persisted.ts +2 -2
- package/src/proving_broker/proving_broker_instrumentation.ts +19 -6
- package/src/proving_broker/proving_job_controller.ts +9 -3
- package/src/proving_broker/rpc.ts +46 -20
- package/src/test/epoch_settlement.ts +82 -0
- package/src/test/index.ts +1 -0
- package/src/test/mock_prover.ts +2 -2
- package/dest/orchestrator/epoch-proving-state.d.ts +0 -75
- package/dest/orchestrator/epoch-proving-state.d.ts.map +0 -1
- package/dest/orchestrator/epoch-proving-state.js +0 -267
- package/dest/orchestrator/orchestrator.d.ts +0 -123
- package/dest/orchestrator/orchestrator.d.ts.map +0 -1
- package/dest/prover-client/server-epoch-prover.d.ts +0 -32
- package/dest/prover-client/server-epoch-prover.d.ts.map +0 -1
- package/dest/prover-client/server-epoch-prover.js +0 -40
- 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/src/orchestrator/epoch-proving-state.ts +0 -378
- package/src/orchestrator/orchestrator.ts +0 -1267
- package/src/prover-client/server-epoch-prover.ts +0 -69
- package/src/proving_broker/proof_store/gcs_proof_store.ts +0 -76
|
@@ -370,50 +370,49 @@ function applyDecs2203RFactory() {
|
|
|
370
370
|
function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
371
371
|
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
372
372
|
}
|
|
373
|
-
var _dec, _dec1, _dec2, _dec3,
|
|
374
|
-
import { L1_TO_L2_MSG_SUBTREE_HEIGHT, L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
|
|
373
|
+
var _dec, _dec1, _dec2, _dec3, _initProto;
|
|
374
|
+
import { L1_TO_L2_MSG_SUBTREE_HEIGHT, L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH, NUM_BASE_PARITY_PER_ROOT_PARITY } from '@aztec/constants';
|
|
375
375
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
376
|
-
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
377
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
378
376
|
import { AbortError } from '@aztec/foundation/error';
|
|
379
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
380
377
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
381
378
|
import { assertLength } from '@aztec/foundation/serialize';
|
|
382
|
-
import {
|
|
383
|
-
import {
|
|
384
|
-
import { BlockRootEmptyTxFirstRollupPrivateInputs, BlockRootFirstRollupPrivateInputs, BlockRootSingleTxFirstRollupPrivateInputs, BlockRootSingleTxRollupPrivateInputs, CheckpointRootSingleBlockRollupPrivateInputs, PrivateTxBaseRollupPrivateInputs } from '@aztec/stdlib/rollup';
|
|
379
|
+
import { appendL1ToL2MessagesToTree } from '@aztec/stdlib/messaging';
|
|
380
|
+
import { BlockRootEmptyTxFirstRollupPrivateInputs, BlockRootFirstRollupPrivateInputs, BlockRootSingleTxFirstRollupPrivateInputs, BlockRootSingleTxRollupPrivateInputs, PrivateTxBaseRollupPrivateInputs } from '@aztec/stdlib/rollup';
|
|
385
381
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
386
382
|
import { Attributes, getTelemetryClient, trackSpan, wrapCallbackInSpan } from '@aztec/telemetry-client';
|
|
387
383
|
import { inspect } from 'util';
|
|
388
384
|
import { buildHeaderFromCircuitOutputs, getLastSiblingPath, getPublicChonkVerifierPrivateInputsFromTx, getRootTreeSiblingPath, getSubtreeSiblingPath, getTreeSnapshot, insertSideEffectsAndBuildBaseRollupHints, validatePartialState, validateTx } from './block-building-helpers.js';
|
|
389
|
-
import {
|
|
385
|
+
import { CheckpointProvingState } from './checkpoint-proving-state.js';
|
|
390
386
|
import { ProvingOrchestratorMetrics } from './orchestrator_metrics.js';
|
|
387
|
+
import { ProvingScheduler } from './proving-scheduler.js';
|
|
391
388
|
import { TxProvingState } from './tx-proving-state.js';
|
|
392
|
-
|
|
393
|
-
_dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
389
|
+
_dec = trackSpan('CheckpointSubTreeOrchestrator.startNewBlock', (blockNumber)=>({
|
|
394
390
|
[Attributes.BLOCK_NUMBER]: blockNumber
|
|
395
|
-
})), _dec1 = trackSpan('
|
|
391
|
+
})), _dec1 = trackSpan('CheckpointSubTreeOrchestrator.addTxs', (txs)=>({
|
|
396
392
|
[Attributes.BLOCK_TXS_COUNT]: txs.length
|
|
397
|
-
})), _dec2 = trackSpan('
|
|
393
|
+
})), _dec2 = trackSpan('CheckpointSubTreeOrchestrator.setBlockCompleted', (blockNumber)=>({
|
|
398
394
|
[Attributes.BLOCK_NUMBER]: blockNumber
|
|
399
|
-
})),
|
|
395
|
+
})), _dec3 = trackSpan('CheckpointSubTreeOrchestrator.prepareBaseRollupInputs', (tx)=>({
|
|
400
396
|
[Attributes.TX_HASH]: tx.hash.toString()
|
|
401
397
|
}));
|
|
402
398
|
/**
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
*
|
|
407
|
-
* 4. Once a transaction is proven, it will be incorporated into a merge proof
|
|
408
|
-
* 5. Merge proofs are produced at each level of the tree until the root proof is produced
|
|
399
|
+
* Orchestrates block-level proving for a single checkpoint, stopping at the boundary
|
|
400
|
+
* where checkpoint root rollup would otherwise begin. Used by the per-checkpoint
|
|
401
|
+
* `CheckpointProver` in production; the top-tree orchestrator then composes the
|
|
402
|
+
* sub-tree's block proofs into the epoch proof.
|
|
409
403
|
*
|
|
410
|
-
*
|
|
411
|
-
|
|
412
|
-
*
|
|
413
|
-
|
|
404
|
+
* Wiring: a single-checkpoint mini-proving session is owned by the constructor. The
|
|
405
|
+
* canonical way to obtain a fully-started sub-tree is the `start` static factory,
|
|
406
|
+
* which also drives the single internal `startCheckpoint` call. The sub-tree never
|
|
407
|
+
* escalates past the checkpoint root boundary; `getSubTreeResult()` resolves once
|
|
408
|
+
* every block-level proof in the checkpoint's tree is ready.
|
|
409
|
+
*/ export class CheckpointSubTreeOrchestrator extends ProvingScheduler {
|
|
414
410
|
dbProvider;
|
|
415
411
|
prover;
|
|
416
412
|
proverId;
|
|
413
|
+
chonkCache;
|
|
414
|
+
epochNumber;
|
|
415
|
+
cancelJobsOnStop;
|
|
417
416
|
static{
|
|
418
417
|
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
419
418
|
[
|
|
@@ -429,36 +428,33 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
429
428
|
[
|
|
430
429
|
_dec2,
|
|
431
430
|
2,
|
|
432
|
-
"startChonkVerifierCircuits"
|
|
433
|
-
],
|
|
434
|
-
[
|
|
435
|
-
_dec3,
|
|
436
|
-
2,
|
|
437
431
|
"setBlockCompleted"
|
|
438
432
|
],
|
|
439
433
|
[
|
|
440
|
-
|
|
434
|
+
_dec3,
|
|
441
435
|
2,
|
|
442
436
|
"prepareBaseRollupInputs"
|
|
443
437
|
]
|
|
444
438
|
], []));
|
|
445
439
|
}
|
|
446
|
-
provingState;
|
|
447
|
-
|
|
448
|
-
provingPromise;
|
|
440
|
+
/** The single checkpoint proving state this sub-tree owns. Allocated in the `start` factory. */ provingState;
|
|
441
|
+
subTreeResult;
|
|
449
442
|
metrics;
|
|
450
|
-
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
451
443
|
dbs;
|
|
452
|
-
constructor(dbProvider, prover, proverId,
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
this.
|
|
459
|
-
this.
|
|
460
|
-
this.
|
|
444
|
+
constructor(dbProvider, prover, proverId, /**
|
|
445
|
+
* Shared chonk-verifier proof cache. Every chonk-verifier proof started by this
|
|
446
|
+
* sub-tree lives on the cache and survives the sub-tree's cancellation, so a tx
|
|
447
|
+
* whose original checkpoint is reorged out and re-appears in a replacement
|
|
448
|
+
* checkpoint reuses the cached proof.
|
|
449
|
+
*/ chonkCache, /** The epoch this sub-tree proves into. */ epochNumber, cancelJobsOnStop = false, deferredJobQueue, telemetryClient = getTelemetryClient(), bindings){
|
|
450
|
+
super(deferredJobQueue, 'prover-client:checkpoint-sub-tree-orchestrator', bindings), this.dbProvider = dbProvider, this.prover = prover, this.proverId = proverId, this.chonkCache = chonkCache, this.epochNumber = epochNumber, this.cancelJobsOnStop = cancelJobsOnStop, this.provingState = (_initProto(this), undefined), this.dbs = new Map(), this.cancelled = false;
|
|
451
|
+
this.metrics = new ProvingOrchestratorMetrics(telemetryClient, 'CheckpointSubTreeOrchestrator');
|
|
452
|
+
this.subTreeResult = promiseWithResolvers();
|
|
453
|
+
// Mark the rejection branch as observed so a `cancel()` or proving failure does not
|
|
454
|
+
// surface an unhandled rejection when no consumer awaits getSubTreeResult().
|
|
455
|
+
this.subTreeResult.promise.catch(()=>{});
|
|
461
456
|
}
|
|
457
|
+
/** Tracks whether `cancel()` has been called; flows into the checkpoint state's isAlive hook. */ cancelled;
|
|
462
458
|
get tracer() {
|
|
463
459
|
return this.metrics.tracer;
|
|
464
460
|
}
|
|
@@ -468,86 +464,90 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
468
464
|
getNumActiveForks() {
|
|
469
465
|
return this.dbs.size;
|
|
470
466
|
}
|
|
471
|
-
|
|
472
|
-
this.
|
|
473
|
-
return Promise.resolve();
|
|
474
|
-
}
|
|
475
|
-
startNewEpoch(epochNumber, totalNumCheckpoints, finalBlobBatchingChallenges) {
|
|
476
|
-
if (this.provingState?.verifyState()) {
|
|
477
|
-
throw new Error(`Cannot start epoch ${epochNumber} when epoch ${this.provingState.epochNumber} is still being processed.`);
|
|
478
|
-
}
|
|
479
|
-
const { promise: _promise, resolve, reject } = promiseWithResolvers();
|
|
480
|
-
const promise = _promise.catch((reason)=>({
|
|
481
|
-
status: 'failure',
|
|
482
|
-
reason
|
|
483
|
-
}));
|
|
484
|
-
logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
|
|
485
|
-
this.provingState = new EpochProvingState(epochNumber, totalNumCheckpoints, finalBlobBatchingChallenges, (provingState)=>this.checkAndEnqueueCheckpointRootRollup(provingState), resolve, reject);
|
|
486
|
-
this.provingPromise = promise;
|
|
467
|
+
/** Returns a promise that resolves when block-level proving completes for the checkpoint. */ getSubTreeResult() {
|
|
468
|
+
return this.subTreeResult.promise;
|
|
487
469
|
}
|
|
488
470
|
/**
|
|
489
|
-
*
|
|
490
|
-
*
|
|
491
|
-
*
|
|
492
|
-
*
|
|
493
|
-
|
|
494
|
-
* @param headerOfLastBlockInPreviousCheckpoint - The header of the last block in the previous checkpoint.
|
|
495
|
-
*/ async startNewCheckpoint(checkpointIndex, constants, l1ToL2Messages, totalNumBlocks, headerOfLastBlockInPreviousCheckpoint) {
|
|
471
|
+
* Returns the archive sibling path captured at the internal checkpoint start.
|
|
472
|
+
* Available synchronously once `start` has resolved, before block-level proving
|
|
473
|
+
* completes. The top-tree consumer uses this to assemble checkpoint root rollup hints
|
|
474
|
+
* up-front so checkpoint root proofs can pipeline against in-flight sub-tree proving.
|
|
475
|
+
*/ getPreviousArchiveSiblingPath() {
|
|
496
476
|
if (!this.provingState) {
|
|
497
|
-
throw new Error('
|
|
477
|
+
throw new Error('Checkpoint not started; call CheckpointSubTreeOrchestrator.start first.');
|
|
498
478
|
}
|
|
499
|
-
|
|
500
|
-
|
|
479
|
+
return this.provingState.getLastArchiveSiblingPath();
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Constructs and starts a sub-tree for a single checkpoint. The returned sub-tree
|
|
483
|
+
* has had its single internal checkpoint state allocated; callers proceed directly
|
|
484
|
+
* to per-block `startNewBlock` / `addTxs` / `setBlockCompleted`.
|
|
485
|
+
*
|
|
486
|
+
* If the internal start rejects, the partially-constructed sub-tree is stopped
|
|
487
|
+
* before the error propagates, so no broker resources leak.
|
|
488
|
+
*/ static async start(dbProvider, prover, proverId, chonkCache, epochNumber, cancelJobsOnStop, deferredJobQueue, checkpointConstants, l1ToL2Messages, totalNumBlocks, headerOfLastBlockInPreviousCheckpoint, telemetryClient = getTelemetryClient(), bindings) {
|
|
489
|
+
const subTree = new CheckpointSubTreeOrchestrator(dbProvider, prover, proverId, chonkCache, epochNumber, cancelJobsOnStop, deferredJobQueue, telemetryClient, bindings);
|
|
490
|
+
try {
|
|
491
|
+
await subTree.startCheckpoint(checkpointConstants, l1ToL2Messages, totalNumBlocks, headerOfLastBlockInPreviousCheckpoint);
|
|
492
|
+
return subTree;
|
|
493
|
+
} catch (err) {
|
|
494
|
+
await subTree.stop().catch(()=>{});
|
|
495
|
+
throw err;
|
|
501
496
|
}
|
|
502
|
-
// Fork world state at the end of the immediately previous block.
|
|
503
|
-
const lastBlockNumber = headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber;
|
|
504
|
-
const db = await this.dbProvider.fork(lastBlockNumber);
|
|
505
|
-
const firstBlockNumber = BlockNumber(lastBlockNumber + 1);
|
|
506
|
-
this.dbs.set(firstBlockNumber, db);
|
|
507
|
-
// Get archive sibling path before any block in this checkpoint lands.
|
|
508
|
-
const lastArchiveSiblingPath = await getLastSiblingPath(MerkleTreeId.ARCHIVE, db);
|
|
509
|
-
// Insert all the l1 to l2 messages into the db. And get the states before and after the insertion.
|
|
510
|
-
const { lastL1ToL2MessageTreeSnapshot, lastL1ToL2MessageSubtreeRootSiblingPath, newL1ToL2MessageTreeSnapshot, newL1ToL2MessageSubtreeRootSiblingPath } = await this.updateL1ToL2MessageTree(l1ToL2Messages, db);
|
|
511
|
-
this.provingState.startNewCheckpoint(checkpointIndex, constants, totalNumBlocks, headerOfLastBlockInPreviousCheckpoint, lastArchiveSiblingPath, l1ToL2Messages, lastL1ToL2MessageTreeSnapshot, lastL1ToL2MessageSubtreeRootSiblingPath, newL1ToL2MessageTreeSnapshot, newL1ToL2MessageSubtreeRootSiblingPath);
|
|
512
497
|
}
|
|
513
498
|
/**
|
|
514
|
-
*
|
|
499
|
+
* Kickstart chonk-verifier circuits via the shared `ChonkCache`. The cache owns the
|
|
500
|
+
* broker job lifecycle, so the proof survives this sub-tree's `cancel()` — a tx that
|
|
501
|
+
* ends up in a replacement checkpoint after a reorg can pick the cached promise up
|
|
502
|
+
* and skip re-proving.
|
|
503
|
+
*/ startChonkVerifierCircuits(txs) {
|
|
504
|
+
if (!this.provingState?.verifyState()) {
|
|
505
|
+
return Promise.reject(new Error('Sub-tree proving state is not active.'));
|
|
506
|
+
}
|
|
507
|
+
const publicTxs = txs.filter((tx)=>tx.data.forPublic);
|
|
508
|
+
for (const tx of publicTxs){
|
|
509
|
+
const txHash = tx.getTxHash().toString();
|
|
510
|
+
const inputs = getPublicChonkVerifierPrivateInputsFromTx(tx, this.getProverId().toField());
|
|
511
|
+
// Fire and forget — getOrEnqueueChonkVerifier later picks up the cached promise
|
|
512
|
+
// when the tx is processed inside its block.
|
|
513
|
+
void this.chonkCache.getOrCompute(txHash, (signal)=>this.prover.getPublicChonkVerifierProof(inputs, signal, this.epochNumber));
|
|
514
|
+
}
|
|
515
|
+
return Promise.resolve();
|
|
516
|
+
}
|
|
517
|
+
// ---------------- per-block driving (called by the per-checkpoint CheckpointProver) ----------------
|
|
518
|
+
/**
|
|
519
|
+
* Starts off a new block.
|
|
515
520
|
* @param blockNumber - The block number
|
|
516
|
-
* @param timestamp - The timestamp of the block.
|
|
517
|
-
*
|
|
518
|
-
* @param totalNumTxs - The total number of txs in the block
|
|
521
|
+
* @param timestamp - The timestamp of the block. Required for empty blocks to construct private inputs.
|
|
522
|
+
* @param totalNumTxs - The total number of txs in the block.
|
|
519
523
|
*/ async startNewBlock(blockNumber, timestamp, totalNumTxs) {
|
|
520
524
|
if (!this.provingState) {
|
|
521
|
-
throw new Error('Empty
|
|
522
|
-
}
|
|
523
|
-
const checkpointProvingState = this.provingState.getCheckpointProvingStateByBlockNumber(blockNumber);
|
|
524
|
-
if (!checkpointProvingState) {
|
|
525
|
-
throw new Error(`Checkpoint not started. Call startNewCheckpoint first.`);
|
|
525
|
+
throw new Error('Empty proving state. The checkpoint sub-tree has not been started.');
|
|
526
526
|
}
|
|
527
|
-
if (!
|
|
527
|
+
if (!this.provingState.isAcceptingBlocks()) {
|
|
528
528
|
throw new Error(`Checkpoint not accepting further blocks.`);
|
|
529
529
|
}
|
|
530
|
-
const constants =
|
|
531
|
-
logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
|
|
532
|
-
// Fork the db only when it's not already set. The db for the first block is set in
|
|
530
|
+
const constants = this.provingState.constants;
|
|
531
|
+
this.logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
|
|
532
|
+
// Fork the db only when it's not already set. The db for the first block is set in startCheckpoint.
|
|
533
533
|
if (!this.dbs.has(blockNumber)) {
|
|
534
|
-
// Fork world state at the end of the immediately previous block
|
|
534
|
+
// Fork world state at the end of the immediately previous block.
|
|
535
535
|
const db = await this.dbProvider.fork(BlockNumber(blockNumber - 1));
|
|
536
536
|
this.dbs.set(blockNumber, db);
|
|
537
537
|
}
|
|
538
|
-
const db = this.
|
|
538
|
+
const db = this.getDbForBlock(blockNumber);
|
|
539
539
|
// Get archive snapshot and sibling path before any txs in this block lands.
|
|
540
540
|
const lastArchiveTreeSnapshot = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
541
541
|
const lastArchiveSiblingPath = await getRootTreeSiblingPath(MerkleTreeId.ARCHIVE, db);
|
|
542
|
-
const blockProvingState =
|
|
542
|
+
const blockProvingState = this.provingState.startNewBlock(blockNumber, timestamp, totalNumTxs, lastArchiveTreeSnapshot, lastArchiveSiblingPath);
|
|
543
543
|
// Enqueue base parity circuits for the first block in the checkpoint.
|
|
544
544
|
if (blockProvingState.index === 0) {
|
|
545
545
|
for(let i = 0; i < NUM_BASE_PARITY_PER_ROOT_PARITY; i++){
|
|
546
|
-
this.enqueueBaseParityCircuit(
|
|
546
|
+
this.enqueueBaseParityCircuit(this.provingState, blockProvingState, i);
|
|
547
547
|
}
|
|
548
548
|
}
|
|
549
|
-
// Because `addTxs` won't be called for a block without txs, and that's where the sponge blob state is computed
|
|
550
|
-
//
|
|
549
|
+
// Because `addTxs` won't be called for a block without txs, and that's where the sponge blob state is computed,
|
|
550
|
+
// set its end sponge blob here. This becomes the start sponge blob for the next block.
|
|
551
551
|
if (totalNumTxs === 0) {
|
|
552
552
|
const endState = await db.getStateReference();
|
|
553
553
|
blockProvingState.setEndState(endState);
|
|
@@ -555,22 +555,19 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
555
555
|
const blockEndBlobFields = blockProvingState.getBlockEndBlobFields();
|
|
556
556
|
await endSpongeBlob.absorb(blockEndBlobFields);
|
|
557
557
|
blockProvingState.setEndSpongeBlob(endSpongeBlob);
|
|
558
|
-
// Try to accumulate the out hashes and blobs as far as we can:
|
|
559
|
-
await this.provingState.accumulateCheckpointOutHashes();
|
|
560
|
-
await this.provingState.setBlobAccumulators();
|
|
561
558
|
}
|
|
562
559
|
}
|
|
563
560
|
/**
|
|
564
|
-
* The interface to add simulated transactions to the scheduler.
|
|
561
|
+
* The interface to add simulated transactions to the scheduler. Called at most once per block.
|
|
565
562
|
* @param txs - The transactions to be proven
|
|
566
563
|
*/ async addTxs(txs) {
|
|
567
564
|
if (!this.provingState) {
|
|
568
|
-
throw new Error(`Empty
|
|
565
|
+
throw new Error(`Empty proving state. The checkpoint sub-tree has not been started.`);
|
|
569
566
|
}
|
|
570
567
|
if (!txs.length) {
|
|
571
|
-
//
|
|
572
|
-
//
|
|
573
|
-
logger.
|
|
568
|
+
// Empty block: setBlockCompleted handles this without addTxs being called. Bail to
|
|
569
|
+
// avoid the throw below (we cannot find the blockNumber without any txs).
|
|
570
|
+
this.logger.verbose(`Provided no txs to addTxs.`);
|
|
574
571
|
return;
|
|
575
572
|
}
|
|
576
573
|
const blockNumber = BlockNumber(txs[0].globalVariables.blockNumber);
|
|
@@ -584,8 +581,8 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
584
581
|
if (!provingState.isAcceptingTxs()) {
|
|
585
582
|
throw new Error(`Block ${blockNumber} has been initialized with transactions.`);
|
|
586
583
|
}
|
|
587
|
-
logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
588
|
-
const db = this.
|
|
584
|
+
this.logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
585
|
+
const db = this.getDbForBlock(blockNumber);
|
|
589
586
|
const lastArchive = provingState.lastArchiveTreeSnapshot;
|
|
590
587
|
const newL1ToL2MessageTreeSnapshot = provingState.newL1ToL2MessageTreeSnapshot;
|
|
591
588
|
const spongeBlobState = provingState.getStartSpongeBlob().clone();
|
|
@@ -595,7 +592,7 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
595
592
|
throw new Error(`Invalid proving state when adding a tx`);
|
|
596
593
|
}
|
|
597
594
|
validateTx(tx);
|
|
598
|
-
logger.debug(`Received transaction: ${tx.hash}`);
|
|
595
|
+
this.logger.debug(`Received transaction: ${tx.hash}`);
|
|
599
596
|
const startSpongeBlob = spongeBlobState.clone();
|
|
600
597
|
const [hints, treeSnapshots] = await this.prepareBaseRollupInputs(tx, lastArchive, newL1ToL2MessageTreeSnapshot, startSpongeBlob, db);
|
|
601
598
|
if (!provingState.verifyState()) {
|
|
@@ -606,10 +603,10 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
606
603
|
const txIndex = provingState.addNewTx(txProvingState);
|
|
607
604
|
if (txProvingState.requireAvmProof) {
|
|
608
605
|
this.getOrEnqueueChonkVerifier(provingState, txIndex);
|
|
609
|
-
logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
606
|
+
this.logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
610
607
|
this.enqueueVM(provingState, txIndex);
|
|
611
608
|
} else {
|
|
612
|
-
logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
609
|
+
this.logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
613
610
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
614
611
|
}
|
|
615
612
|
} catch (err) {
|
|
@@ -623,29 +620,6 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
623
620
|
const blockEndBlobFields = provingState.getBlockEndBlobFields();
|
|
624
621
|
await spongeBlobState.absorb(blockEndBlobFields);
|
|
625
622
|
provingState.setEndSpongeBlob(spongeBlobState);
|
|
626
|
-
// Txs have been added to the block. Now try to accumulate the out hashes and blobs as far as we can:
|
|
627
|
-
await this.provingState.accumulateCheckpointOutHashes();
|
|
628
|
-
await this.provingState.setBlobAccumulators();
|
|
629
|
-
}
|
|
630
|
-
/**
|
|
631
|
-
* Kickstarts chonk verifier circuits for the specified txs. These will be used during epoch proving.
|
|
632
|
-
* Note that if the chonk verifier circuits are not started this way, they will be started nontheless after processing.
|
|
633
|
-
*/ startChonkVerifierCircuits(txs) {
|
|
634
|
-
if (!this.provingState?.verifyState()) {
|
|
635
|
-
throw new Error(`Empty epoch proving state. call startNewEpoch before starting chonk verifier circuits.`);
|
|
636
|
-
}
|
|
637
|
-
const publicTxs = txs.filter((tx)=>tx.data.forPublic);
|
|
638
|
-
for (const tx of publicTxs){
|
|
639
|
-
const txHash = tx.getTxHash().toString();
|
|
640
|
-
const privateInputs = getPublicChonkVerifierPrivateInputsFromTx(tx, this.proverId.toField());
|
|
641
|
-
const tubeProof = promiseWithResolvers();
|
|
642
|
-
logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
|
|
643
|
-
this.doEnqueueChonkVerifier(txHash, privateInputs, (proof)=>{
|
|
644
|
-
tubeProof.resolve(proof);
|
|
645
|
-
});
|
|
646
|
-
this.provingState.cachedChonkVerifierProofs.set(txHash, tubeProof.promise);
|
|
647
|
-
}
|
|
648
|
-
return Promise.resolve();
|
|
649
623
|
}
|
|
650
624
|
/**
|
|
651
625
|
* Marks the block as completed.
|
|
@@ -668,154 +642,70 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
668
642
|
throw new Error(`Block ${blockNumber} is still accepting txs. Call setBlockCompleted after all txs have been added.`);
|
|
669
643
|
}
|
|
670
644
|
// Given we've applied every change from this block, now assemble the block header:
|
|
671
|
-
logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
|
|
645
|
+
this.logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
|
|
672
646
|
const header = await provingState.buildBlockHeader();
|
|
673
647
|
if (expectedHeader && !header.equals(expectedHeader)) {
|
|
674
|
-
logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
648
|
+
this.logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
675
649
|
throw new Error('Block header mismatch');
|
|
676
650
|
}
|
|
677
|
-
// Get db for this block
|
|
678
|
-
const db = this.
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
651
|
+
// Get db for this block and remove from map — no other code should use it after this point.
|
|
652
|
+
const db = this.getDbForBlock(provingState.blockNumber);
|
|
653
|
+
this.dbs.delete(provingState.blockNumber);
|
|
654
|
+
// Update the archive tree, capture the snapshot, and close the fork deterministically.
|
|
655
|
+
try {
|
|
656
|
+
this.logger.verbose(`Updating archive tree with block ${provingState.blockNumber} header ${(await header.hash()).toString()}`);
|
|
657
|
+
await db.updateArchive(header);
|
|
658
|
+
provingState.setBuiltArchive(await getTreeSnapshot(MerkleTreeId.ARCHIVE, db));
|
|
659
|
+
} finally{
|
|
660
|
+
await db.close();
|
|
661
|
+
}
|
|
682
662
|
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
683
663
|
return header;
|
|
684
664
|
}
|
|
685
|
-
//
|
|
686
|
-
async verifyBuiltBlockAgainstSyncedState(provingState) {
|
|
687
|
-
const builtBlockHeader = provingState.getBuiltBlockHeader();
|
|
688
|
-
if (!builtBlockHeader) {
|
|
689
|
-
logger.debug('Block header not built yet, skipping header check.');
|
|
690
|
-
return;
|
|
691
|
-
}
|
|
692
|
-
const output = provingState.getBlockRootRollupOutput();
|
|
693
|
-
if (!output) {
|
|
694
|
-
logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
695
|
-
return;
|
|
696
|
-
}
|
|
697
|
-
const header = await buildHeaderFromCircuitOutputs(output);
|
|
698
|
-
if (!(await header.hash()).equals(await builtBlockHeader.hash())) {
|
|
699
|
-
logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
700
|
-
provingState.reject(`Block header hash mismatch.`);
|
|
701
|
-
return;
|
|
702
|
-
}
|
|
703
|
-
// Get db for this block
|
|
704
|
-
const blockNumber = provingState.blockNumber;
|
|
705
|
-
const db = this.dbs.get(blockNumber);
|
|
706
|
-
const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
707
|
-
const syncedArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.dbProvider.getSnapshot(blockNumber));
|
|
708
|
-
if (!syncedArchive.equals(newArchive)) {
|
|
709
|
-
logger.error(`Archive tree mismatch for block ${blockNumber}: world state synced to ${inspect(syncedArchive)} but built ${inspect(newArchive)}`);
|
|
710
|
-
provingState.reject(`Archive tree mismatch.`);
|
|
711
|
-
return;
|
|
712
|
-
}
|
|
713
|
-
const circuitArchive = output.newArchive;
|
|
714
|
-
if (!newArchive.equals(circuitArchive)) {
|
|
715
|
-
logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
716
|
-
provingState.reject(`New archive mismatch.`);
|
|
717
|
-
return;
|
|
718
|
-
}
|
|
719
|
-
// TODO(palla/prover): This closes the fork only on the happy path. If this epoch orchestrator
|
|
720
|
-
// is aborted and never reaches this point, it will leak the fork. We need to add a global cleanup,
|
|
721
|
-
// but have to make sure it only runs once all operations are completed, otherwise some function here
|
|
722
|
-
// will attempt to access the fork after it was closed.
|
|
723
|
-
void this.cleanupDBFork(blockNumber);
|
|
724
|
-
}
|
|
665
|
+
// ---------------- lifecycle ----------------
|
|
725
666
|
/**
|
|
726
|
-
*
|
|
667
|
+
* Cancels any further proving. If `cancelJobsOnStop` was set, aborts all pending broker jobs
|
|
668
|
+
* (used on reorg). Otherwise jobs remain in the broker queue and can be reused on restart.
|
|
727
669
|
*/ cancel() {
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
670
|
+
this.cancelled = true;
|
|
671
|
+
this.resetSchedulerState(this.cancelJobsOnStop);
|
|
672
|
+
// Reject the proving state (and hence subTreeResult) so anyone awaiting the sub-tree result
|
|
673
|
+
// is released rather than hanging — matching TopTreeOrchestrator.cancel().
|
|
731
674
|
this.provingState?.cancel();
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
* Returns the proof for the current epoch.
|
|
735
|
-
*/ async finalizeEpoch() {
|
|
736
|
-
if (!this.provingState || !this.provingPromise) {
|
|
737
|
-
throw new Error(`Invalid proving state, an epoch must be proven before it can be finalized`);
|
|
738
|
-
}
|
|
739
|
-
const result = await this.provingPromise;
|
|
740
|
-
if (result.status === 'failure') {
|
|
741
|
-
throw new Error(`Epoch proving failed: ${result.reason}`);
|
|
742
|
-
}
|
|
743
|
-
await this.provingState.finalizeBatchedBlob();
|
|
744
|
-
const epochProofResult = this.provingState.getEpochProofResult();
|
|
745
|
-
pushTestData('epochProofResult', {
|
|
746
|
-
proof: epochProofResult.proof.toString(),
|
|
747
|
-
publicInputs: epochProofResult.publicInputs.toString()
|
|
748
|
-
});
|
|
749
|
-
return epochProofResult;
|
|
750
|
-
}
|
|
751
|
-
async cleanupDBFork(blockNumber) {
|
|
752
|
-
logger.debug(`Cleaning up world state fork for ${blockNumber}`);
|
|
753
|
-
const fork = this.dbs.get(blockNumber);
|
|
754
|
-
if (!fork) {
|
|
755
|
-
return;
|
|
756
|
-
}
|
|
757
|
-
try {
|
|
758
|
-
await fork.close();
|
|
759
|
-
this.dbs.delete(blockNumber);
|
|
760
|
-
} catch (err) {
|
|
761
|
-
logger.error(`Error closing db for block ${blockNumber}`, err);
|
|
675
|
+
for (const [blockNumber, db] of this.dbs.entries()){
|
|
676
|
+
void db.close().catch((err)=>this.logger.error(`Error closing db for block ${blockNumber}`, err));
|
|
762
677
|
}
|
|
678
|
+
this.dbs.clear();
|
|
679
|
+
}
|
|
680
|
+
cancelInternal() {
|
|
681
|
+
this.cancel();
|
|
763
682
|
}
|
|
683
|
+
// ---------------- private: per-checkpoint init ----------------
|
|
764
684
|
/**
|
|
765
|
-
*
|
|
766
|
-
*
|
|
767
|
-
*
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
logger.debug(`Not enqueuing job, state no longer valid`);
|
|
772
|
-
return;
|
|
685
|
+
* Internal driver for the single-checkpoint init. Allocates the world-state fork,
|
|
686
|
+
* inserts L1-to-L2 messages, and creates the per-checkpoint proving state with this
|
|
687
|
+
* sub-tree as its parent. Only called once, from the `start` factory.
|
|
688
|
+
*/ async startCheckpoint(constants, l1ToL2Messages, totalNumBlocks, headerOfLastBlockInPreviousCheckpoint) {
|
|
689
|
+
if (this.provingState) {
|
|
690
|
+
throw new Error('Checkpoint sub-tree already started.');
|
|
773
691
|
}
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
const result = await request(controller.signal);
|
|
785
|
-
if (!provingState.verifyState()) {
|
|
786
|
-
logger.debug(`State no longer valid, discarding result`);
|
|
787
|
-
return;
|
|
788
|
-
}
|
|
789
|
-
// we could have been cancelled whilst waiting for the result
|
|
790
|
-
// and the prover ignored the signal. Drop the result in that case
|
|
791
|
-
if (controller.signal.aborted) {
|
|
792
|
-
return;
|
|
793
|
-
}
|
|
794
|
-
await callback(result);
|
|
795
|
-
} catch (err) {
|
|
796
|
-
if (err instanceof AbortError) {
|
|
797
|
-
// operation was cancelled, probably because the block was cancelled
|
|
798
|
-
// drop this result
|
|
799
|
-
return;
|
|
800
|
-
}
|
|
801
|
-
logger.error(`Error thrown when proving job`, err);
|
|
802
|
-
provingState.reject(`${err}`);
|
|
803
|
-
} finally{
|
|
804
|
-
const index = this.pendingProvingJobs.indexOf(controller);
|
|
805
|
-
if (index > -1) {
|
|
806
|
-
this.pendingProvingJobs.splice(index, 1);
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
};
|
|
810
|
-
// let the callstack unwind before adding the job to the queue
|
|
811
|
-
setImmediate(()=>void safeJob());
|
|
692
|
+
// Fork world state at the end of the immediately previous block.
|
|
693
|
+
const lastBlockNumber = headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber;
|
|
694
|
+
const db = await this.dbProvider.fork(lastBlockNumber);
|
|
695
|
+
const firstBlockNumber = BlockNumber(lastBlockNumber + 1);
|
|
696
|
+
this.dbs.set(firstBlockNumber, db);
|
|
697
|
+
// Get archive sibling path before any block in this checkpoint lands.
|
|
698
|
+
const lastArchiveSiblingPath = await getLastSiblingPath(MerkleTreeId.ARCHIVE, db);
|
|
699
|
+
// Insert all the l1 to l2 messages into the db. Get the states before and after the insertion.
|
|
700
|
+
const { lastL1ToL2MessageTreeSnapshot, lastL1ToL2MessageSubtreeRootSiblingPath, newL1ToL2MessageTreeSnapshot, newL1ToL2MessageSubtreeRootSiblingPath } = await this.updateL1ToL2MessageTree(l1ToL2Messages, db);
|
|
701
|
+
this.provingState = new CheckpointProvingState(/* index */ 0, constants, totalNumBlocks, headerOfLastBlockInPreviousCheckpoint, lastArchiveSiblingPath, l1ToL2Messages, lastL1ToL2MessageTreeSnapshot, lastL1ToL2MessageSubtreeRootSiblingPath, newL1ToL2MessageTreeSnapshot, newL1ToL2MessageSubtreeRootSiblingPath, Number(this.epochNumber), /* isAlive */ ()=>!this.cancelled, /* onReject */ (reason)=>this.subTreeResult.reject(new Error(reason)));
|
|
812
702
|
}
|
|
703
|
+
// ---------------- private: per-block proof orchestration ----------------
|
|
813
704
|
async updateL1ToL2MessageTree(l1ToL2Messages, db) {
|
|
814
|
-
const l1ToL2MessagesPadded = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, 'Too many L1 to L2 messages');
|
|
815
705
|
const lastL1ToL2MessageTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
|
|
816
706
|
const lastL1ToL2MessageSubtreeRootSiblingPath = assertLength(await getSubtreeSiblingPath(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, L1_TO_L2_MSG_SUBTREE_HEIGHT, db), L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH);
|
|
817
|
-
// Update the local trees to include the new l1 to l2 messages
|
|
818
|
-
await db
|
|
707
|
+
// Update the local trees to include the new l1 to l2 messages.
|
|
708
|
+
await appendL1ToL2MessagesToTree(db, l1ToL2Messages);
|
|
819
709
|
const newL1ToL2MessageTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
|
|
820
710
|
const newL1ToL2MessageSubtreeRootSiblingPath = assertLength(await getSubtreeSiblingPath(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, L1_TO_L2_MSG_SUBTREE_HEIGHT, db), L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH);
|
|
821
711
|
return {
|
|
@@ -825,12 +715,15 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
825
715
|
newL1ToL2MessageSubtreeRootSiblingPath
|
|
826
716
|
};
|
|
827
717
|
}
|
|
828
|
-
// Updates the merkle trees for a transaction. The first enqueued job for a transaction
|
|
718
|
+
// Updates the merkle trees for a transaction. The first enqueued job for a transaction.
|
|
829
719
|
async prepareBaseRollupInputs(tx, lastArchive, newL1ToL2MessageTreeSnapshot, startSpongeBlob, db) {
|
|
830
|
-
//
|
|
831
|
-
//
|
|
832
|
-
|
|
833
|
-
|
|
720
|
+
// These hints deliberately carry no recursive proof or verification key — see
|
|
721
|
+
// BaseRollupHintsWithoutProofAndVK. The tx's proof + VK are attached later in
|
|
722
|
+
// TxProvingState.getBaseRollupTypeAndInputs from the proven chonk-verifier / kernel / AVM
|
|
723
|
+
// proofs, which are required there and so cannot be silently omitted.
|
|
724
|
+
const start = performance.now();
|
|
725
|
+
const hints = await insertSideEffectsAndBuildBaseRollupHints(tx, lastArchive, newL1ToL2MessageTreeSnapshot, startSpongeBlob, this.proverId.toField(), db);
|
|
726
|
+
this.metrics.recordBaseRollupInputs(performance.now() - start);
|
|
834
727
|
const promises = [
|
|
835
728
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
836
729
|
MerkleTreeId.NULLIFIER_TREE,
|
|
@@ -850,32 +743,32 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
850
743
|
treeSnapshots
|
|
851
744
|
];
|
|
852
745
|
}
|
|
853
|
-
// Executes the base rollup circuit and
|
|
854
|
-
// Executes the next level of merge if all inputs are available
|
|
746
|
+
// Executes the base rollup circuit and stores the output as intermediate state for the parent merge/root circuit.
|
|
747
|
+
// Executes the next level of merge if all inputs are available.
|
|
855
748
|
enqueueBaseRollup(provingState, txIndex) {
|
|
856
749
|
if (!provingState.verifyState()) {
|
|
857
|
-
logger.debug('Not running base rollup, state invalid');
|
|
750
|
+
this.logger.debug('Not running base rollup, state invalid');
|
|
858
751
|
return;
|
|
859
752
|
}
|
|
860
753
|
if (!provingState.tryStartProvingBase(txIndex)) {
|
|
861
|
-
logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
754
|
+
this.logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
862
755
|
return;
|
|
863
756
|
}
|
|
864
757
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
865
758
|
const { processedTx } = txProvingState;
|
|
866
759
|
const { rollupType, inputs } = txProvingState.getBaseRollupTypeAndInputs();
|
|
867
|
-
logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
868
|
-
this.deferredProving(provingState,
|
|
869
|
-
[Attributes.TX_HASH]: processedTx.hash.toString(),
|
|
870
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
|
|
871
|
-
}, (signal)=>{
|
|
760
|
+
this.logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
761
|
+
this.deferredProving(provingState, this.wrapCircuitCall(inputs instanceof PrivateTxBaseRollupPrivateInputs ? 'getPrivateTxBaseRollupProof' : 'getPublicTxBaseRollupProof', (signal)=>{
|
|
872
762
|
if (inputs instanceof PrivateTxBaseRollupPrivateInputs) {
|
|
873
763
|
return this.prover.getPrivateTxBaseRollupProof(inputs, signal, provingState.epochNumber);
|
|
874
764
|
} else {
|
|
875
765
|
return this.prover.getPublicTxBaseRollupProof(inputs, signal, provingState.epochNumber);
|
|
876
766
|
}
|
|
767
|
+
}, {
|
|
768
|
+
[Attributes.TX_HASH]: processedTx.hash.toString(),
|
|
769
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
|
|
877
770
|
}), (result)=>{
|
|
878
|
-
logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
771
|
+
this.logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
879
772
|
validatePartialState(result.inputs.endTreeSnapshots, txProvingState.treeSnapshots);
|
|
880
773
|
const leafLocation = provingState.setBaseRollupProof(txIndex, result);
|
|
881
774
|
if (provingState.totalNumTxs === 1) {
|
|
@@ -885,78 +778,67 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
885
778
|
}
|
|
886
779
|
});
|
|
887
780
|
}
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
781
|
+
/**
|
|
782
|
+
* Route the tx's chonk-verifier dependency through the per-epoch context: read the
|
|
783
|
+
* cached promise (or enqueue if missing), then `.then(handleResult)` to progress to
|
|
784
|
+
* the base rollup once the proof lands.
|
|
785
|
+
*/ getOrEnqueueChonkVerifier(provingState, txIndex) {
|
|
891
786
|
if (!provingState.verifyState()) {
|
|
892
|
-
logger.debug('Not running chonk verifier circuit, state invalid');
|
|
893
787
|
return;
|
|
894
788
|
}
|
|
895
789
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
896
790
|
const txHash = txProvingState.processedTx.hash.toString();
|
|
897
|
-
NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH;
|
|
898
791
|
const handleResult = (result)=>{
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
}
|
|
792
|
+
if (!provingState.verifyState()) {
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
902
795
|
txProvingState.setPublicChonkVerifierProof(result);
|
|
903
|
-
this.provingState?.cachedChonkVerifierProofs.delete(txHash);
|
|
904
796
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
905
797
|
};
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
logger.debug('Not running chonk verifier circuit, state invalid');
|
|
919
|
-
return;
|
|
920
|
-
}
|
|
921
|
-
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getPublicChonkVerifierProof', {
|
|
922
|
-
[Attributes.TX_HASH]: txHash,
|
|
923
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'chonk-verifier-public'
|
|
924
|
-
}, (signal)=>this.prover.getPublicChonkVerifierProof(inputs, signal, provingState.epochNumber)), handler);
|
|
798
|
+
const promise = this.chonkCache.getOrCompute(txHash, (signal)=>this.prover.getPublicChonkVerifierProof(txProvingState.getPublicChonkVerifierPrivateInputs(), signal, this.epochNumber));
|
|
799
|
+
void promise.then(handleResult).catch((err)=>{
|
|
800
|
+
// The cache self-cleans on rejection, so a replacement sub-tree for this tx will see the
|
|
801
|
+
// miss and re-enqueue. But if this proving state is still active, the failure must abort
|
|
802
|
+
// it: otherwise the base rollup for this tx is never enqueued and the checkpoint (and
|
|
803
|
+
// epoch) orchestrators hang forever waiting for a proof that will never arrive.
|
|
804
|
+
if (err instanceof AbortError || !provingState.verifyState()) {
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
this.logger.error(`Chonk verifier proof failed for tx ${txHash}`, err);
|
|
808
|
+
provingState.reject(`Chonk verifier proof failed for tx ${txHash}: ${err}`);
|
|
809
|
+
});
|
|
925
810
|
}
|
|
926
|
-
// Executes the merge rollup circuit
|
|
927
|
-
// Enqueues the next level of merge if all inputs are available
|
|
811
|
+
// Executes the merge rollup circuit. Enqueues the next level of merge if all inputs are available.
|
|
928
812
|
enqueueMergeRollup(provingState, location) {
|
|
929
813
|
if (!provingState.verifyState()) {
|
|
930
|
-
logger.debug('Not running merge rollup. State no longer valid.');
|
|
814
|
+
this.logger.debug('Not running merge rollup. State no longer valid.');
|
|
931
815
|
return;
|
|
932
816
|
}
|
|
933
817
|
if (!provingState.tryStartProvingMerge(location)) {
|
|
934
|
-
logger.debug('Merge rollup already started.');
|
|
818
|
+
this.logger.debug('Merge rollup already started.');
|
|
935
819
|
return;
|
|
936
820
|
}
|
|
937
821
|
const inputs = provingState.getMergeRollupInputs(location);
|
|
938
|
-
this.deferredProving(provingState,
|
|
822
|
+
this.deferredProving(provingState, this.wrapCircuitCall('getTxMergeRollupProof', (signal)=>this.prover.getTxMergeRollupProof(inputs, signal, provingState.epochNumber), {
|
|
939
823
|
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-tx-merge'
|
|
940
|
-
}
|
|
824
|
+
}), (result)=>{
|
|
941
825
|
provingState.setMergeRollupProof(location, result);
|
|
942
826
|
this.checkAndEnqueueNextMergeRollup(provingState, location);
|
|
943
827
|
});
|
|
944
828
|
}
|
|
945
|
-
// Executes the block root rollup circuit
|
|
829
|
+
// Executes the block root rollup circuit.
|
|
946
830
|
enqueueBlockRootRollup(provingState) {
|
|
947
831
|
if (!provingState.verifyState()) {
|
|
948
|
-
logger.debug('Not running block root rollup, state no longer valid');
|
|
832
|
+
this.logger.debug('Not running block root rollup, state no longer valid');
|
|
949
833
|
return;
|
|
950
834
|
}
|
|
951
835
|
if (!provingState.tryStartProvingBlockRoot()) {
|
|
952
|
-
logger.debug('Block root rollup already started.');
|
|
836
|
+
this.logger.debug('Block root rollup already started.');
|
|
953
837
|
return;
|
|
954
838
|
}
|
|
955
839
|
const { rollupType, inputs } = provingState.getBlockRootRollupTypeAndInputs();
|
|
956
|
-
logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
957
|
-
this.deferredProving(provingState,
|
|
958
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
|
|
959
|
-
}, (signal)=>{
|
|
840
|
+
this.logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
841
|
+
this.deferredProving(provingState, this.wrapCircuitCall('getBlockRootRollupProof', (signal)=>{
|
|
960
842
|
if (inputs instanceof BlockRootFirstRollupPrivateInputs) {
|
|
961
843
|
return this.prover.getBlockRootFirstRollupProof(inputs, signal, provingState.epochNumber);
|
|
962
844
|
} else if (inputs instanceof BlockRootSingleTxFirstRollupPrivateInputs) {
|
|
@@ -968,36 +850,40 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
968
850
|
} else {
|
|
969
851
|
return this.prover.getBlockRootRollupProof(inputs, signal, provingState.epochNumber);
|
|
970
852
|
}
|
|
853
|
+
}, {
|
|
854
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
|
|
971
855
|
}), async (result)=>{
|
|
972
|
-
logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}
|
|
856
|
+
this.logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`, {
|
|
857
|
+
blockNumber: provingState.blockNumber,
|
|
858
|
+
checkpointIndex: provingState.parentCheckpoint.index,
|
|
859
|
+
...result.inputs.toInspect()
|
|
860
|
+
});
|
|
973
861
|
const leafLocation = provingState.setBlockRootRollupProof(result);
|
|
974
862
|
const checkpointProvingState = provingState.parentCheckpoint;
|
|
975
|
-
//
|
|
863
|
+
// Verification is called from both here and setBlockCompleted. Whichever runs last
|
|
864
|
+
// will be the first to see all three pieces (header, proof output, archive) and run the checks.
|
|
976
865
|
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
977
866
|
if (checkpointProvingState.totalNumBlocks === 1) {
|
|
978
|
-
this.
|
|
867
|
+
this.checkAndEnqueueSubTreeResolution(checkpointProvingState);
|
|
979
868
|
} else {
|
|
980
869
|
this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
981
870
|
}
|
|
982
|
-
// We are finished with the block at this point, ensure the fork is cleaned up
|
|
983
|
-
void this.cleanupDBFork(provingState.blockNumber);
|
|
984
871
|
});
|
|
985
872
|
}
|
|
986
|
-
// Executes the base parity circuit
|
|
987
|
-
// Enqueues the root parity circuit if all inputs are available
|
|
873
|
+
// Executes the base parity circuit. Enqueues the root parity circuit if all inputs are available.
|
|
988
874
|
enqueueBaseParityCircuit(checkpointProvingState, provingState, baseParityIndex) {
|
|
989
875
|
if (!provingState.verifyState()) {
|
|
990
|
-
logger.debug('Not running base parity. State no longer valid.');
|
|
876
|
+
this.logger.debug('Not running base parity. State no longer valid.');
|
|
991
877
|
return;
|
|
992
878
|
}
|
|
993
879
|
if (!provingState.tryStartProvingBaseParity(baseParityIndex)) {
|
|
994
|
-
logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
880
|
+
this.logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
995
881
|
return;
|
|
996
882
|
}
|
|
997
883
|
const inputs = checkpointProvingState.getBaseParityInputs(baseParityIndex);
|
|
998
|
-
this.deferredProving(provingState,
|
|
884
|
+
this.deferredProving(provingState, this.wrapCircuitCall('getBaseParityProof', (signal)=>this.prover.getBaseParityProof(inputs, signal, provingState.epochNumber), {
|
|
999
885
|
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'parity-base'
|
|
1000
|
-
}
|
|
886
|
+
}), (provingOutput)=>{
|
|
1001
887
|
provingState.setBaseParityProof(baseParityIndex, provingOutput);
|
|
1002
888
|
this.checkAndEnqueueRootParityCircuit(provingState);
|
|
1003
889
|
});
|
|
@@ -1008,135 +894,46 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
1008
894
|
}
|
|
1009
895
|
this.enqueueRootParityCircuit(provingState);
|
|
1010
896
|
}
|
|
1011
|
-
// Runs the root parity circuit
|
|
1012
|
-
// Enqueues the root rollup
|
|
897
|
+
// Runs the root parity circuit and stores the outputs.
|
|
898
|
+
// Enqueues the block root rollup if all inputs are available.
|
|
1013
899
|
enqueueRootParityCircuit(provingState) {
|
|
1014
900
|
if (!provingState.verifyState()) {
|
|
1015
|
-
logger.debug('Not running root parity. State no longer valid.');
|
|
901
|
+
this.logger.debug('Not running root parity. State no longer valid.');
|
|
1016
902
|
return;
|
|
1017
903
|
}
|
|
1018
904
|
if (!provingState.tryStartProvingRootParity()) {
|
|
1019
|
-
logger.debug('Root parity already started.');
|
|
905
|
+
this.logger.debug('Root parity already started.');
|
|
1020
906
|
return;
|
|
1021
907
|
}
|
|
1022
908
|
const inputs = provingState.getParityRootInputs();
|
|
1023
|
-
this.deferredProving(provingState,
|
|
909
|
+
this.deferredProving(provingState, this.wrapCircuitCall('getRootParityProof', (signal)=>this.prover.getRootParityProof(inputs, signal, provingState.epochNumber), {
|
|
1024
910
|
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'parity-root'
|
|
1025
|
-
}
|
|
911
|
+
}), (result)=>{
|
|
1026
912
|
provingState.setRootParityProof(result);
|
|
1027
913
|
this.checkAndEnqueueBlockRootRollup(provingState);
|
|
1028
914
|
});
|
|
1029
915
|
}
|
|
1030
|
-
// Executes the block merge rollup circuit
|
|
1031
|
-
// Enqueues the next level of merge if all inputs are available
|
|
916
|
+
// Executes the block merge rollup circuit.
|
|
1032
917
|
enqueueBlockMergeRollup(provingState, location) {
|
|
1033
918
|
if (!provingState.verifyState()) {
|
|
1034
|
-
logger.debug('Not running block merge rollup. State no longer valid.');
|
|
919
|
+
this.logger.debug('Not running block merge rollup. State no longer valid.');
|
|
1035
920
|
return;
|
|
1036
921
|
}
|
|
1037
922
|
if (!provingState.tryStartProvingBlockMerge(location)) {
|
|
1038
|
-
logger.debug('Block merge rollup already started.');
|
|
923
|
+
this.logger.debug('Block merge rollup already started.');
|
|
1039
924
|
return;
|
|
1040
925
|
}
|
|
1041
926
|
const inputs = provingState.getBlockMergeRollupInputs(location);
|
|
1042
|
-
this.deferredProving(provingState,
|
|
927
|
+
this.deferredProving(provingState, this.wrapCircuitCall('getBlockMergeRollupProof', (signal)=>this.prover.getBlockMergeRollupProof(inputs, signal, provingState.epochNumber), {
|
|
1043
928
|
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-block-merge'
|
|
1044
|
-
}, (signal)=>this.prover.getBlockMergeRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
|
|
1045
|
-
provingState.setBlockMergeRollupProof(location, result);
|
|
1046
|
-
this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
1047
|
-
});
|
|
1048
|
-
}
|
|
1049
|
-
enqueueCheckpointRootRollup(provingState) {
|
|
1050
|
-
if (!provingState.verifyState()) {
|
|
1051
|
-
logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
1052
|
-
return;
|
|
1053
|
-
}
|
|
1054
|
-
if (!provingState.tryStartProvingCheckpointRoot()) {
|
|
1055
|
-
logger.debug('Checkpoint root rollup already started.');
|
|
1056
|
-
return;
|
|
1057
|
-
}
|
|
1058
|
-
const rollupType = provingState.getCheckpointRootRollupType();
|
|
1059
|
-
logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
1060
|
-
const inputs = provingState.getCheckpointRootRollupInputs();
|
|
1061
|
-
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getCheckpointRootRollupProof', {
|
|
1062
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
|
|
1063
|
-
}, (signal)=>{
|
|
1064
|
-
if (inputs instanceof CheckpointRootSingleBlockRollupPrivateInputs) {
|
|
1065
|
-
return this.prover.getCheckpointRootSingleBlockRollupProof(inputs, signal, provingState.epochNumber);
|
|
1066
|
-
} else {
|
|
1067
|
-
return this.prover.getCheckpointRootRollupProof(inputs, signal, provingState.epochNumber);
|
|
1068
|
-
}
|
|
1069
929
|
}), (result)=>{
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
provingState.reject(`Blob accumulator state mismatch.`);
|
|
1075
|
-
return;
|
|
1076
|
-
}
|
|
1077
|
-
logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}.`);
|
|
1078
|
-
const leafLocation = provingState.setCheckpointRootRollupProof(result);
|
|
1079
|
-
const epochProvingState = provingState.parentEpoch;
|
|
1080
|
-
if (epochProvingState.totalNumCheckpoints === 1) {
|
|
1081
|
-
this.enqueueEpochPadding(epochProvingState);
|
|
1082
|
-
} else {
|
|
1083
|
-
this.checkAndEnqueueNextCheckpointMergeRollup(epochProvingState, leafLocation);
|
|
1084
|
-
}
|
|
1085
|
-
});
|
|
1086
|
-
}
|
|
1087
|
-
enqueueCheckpointMergeRollup(provingState, location) {
|
|
1088
|
-
if (!provingState.verifyState()) {
|
|
1089
|
-
logger.debug('Not running checkpoint merge rollup. State no longer valid.');
|
|
1090
|
-
return;
|
|
1091
|
-
}
|
|
1092
|
-
if (!provingState.tryStartProvingCheckpointMerge(location)) {
|
|
1093
|
-
logger.debug('Checkpoint merge rollup already started.');
|
|
1094
|
-
return;
|
|
1095
|
-
}
|
|
1096
|
-
const inputs = provingState.getCheckpointMergeRollupInputs(location);
|
|
1097
|
-
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getCheckpointMergeRollupProof', {
|
|
1098
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-checkpoint-merge'
|
|
1099
|
-
}, (signal)=>this.prover.getCheckpointMergeRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
|
|
1100
|
-
logger.debug('Completed proof for checkpoint merge rollup.');
|
|
1101
|
-
provingState.setCheckpointMergeRollupProof(location, result);
|
|
1102
|
-
this.checkAndEnqueueNextCheckpointMergeRollup(provingState, location);
|
|
1103
|
-
});
|
|
1104
|
-
}
|
|
1105
|
-
enqueueEpochPadding(provingState) {
|
|
1106
|
-
if (!provingState.verifyState()) {
|
|
1107
|
-
logger.debug('Not running epoch padding. State no longer valid.');
|
|
1108
|
-
return;
|
|
1109
|
-
}
|
|
1110
|
-
if (!provingState.tryStartProvingPaddingCheckpoint()) {
|
|
1111
|
-
logger.debug('Padding checkpoint already started.');
|
|
1112
|
-
return;
|
|
1113
|
-
}
|
|
1114
|
-
logger.debug('Padding epoch proof with a padding block root proof.');
|
|
1115
|
-
const inputs = provingState.getPaddingCheckpointInputs();
|
|
1116
|
-
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getCheckpointPaddingRollupProof', {
|
|
1117
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-checkpoint-padding'
|
|
1118
|
-
}, (signal)=>this.prover.getCheckpointPaddingRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
|
|
1119
|
-
logger.debug('Completed proof for padding checkpoint.');
|
|
1120
|
-
provingState.setCheckpointPaddingProof(result);
|
|
1121
|
-
this.checkAndEnqueueRootRollup(provingState);
|
|
1122
|
-
});
|
|
1123
|
-
}
|
|
1124
|
-
// Executes the root rollup circuit
|
|
1125
|
-
enqueueRootRollup(provingState) {
|
|
1126
|
-
if (!provingState.verifyState()) {
|
|
1127
|
-
logger.debug('Not running root rollup, state no longer valid');
|
|
1128
|
-
return;
|
|
1129
|
-
}
|
|
1130
|
-
logger.debug(`Preparing root rollup`);
|
|
1131
|
-
const inputs = provingState.getRootRollupInputs();
|
|
1132
|
-
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getRootRollupProof', {
|
|
1133
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-root'
|
|
1134
|
-
}, (signal)=>this.prover.getRootRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
|
|
1135
|
-
logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
|
|
1136
|
-
provingState.setRootRollupProof(result);
|
|
1137
|
-
provingState.resolve({
|
|
1138
|
-
status: 'success'
|
|
930
|
+
this.logger.debug(`Completed block merge rollup proof for checkpoint ${provingState.index}`, {
|
|
931
|
+
checkpointIndex: provingState.index,
|
|
932
|
+
mergeLocation: location,
|
|
933
|
+
...result.inputs.toInspect()
|
|
1139
934
|
});
|
|
935
|
+
provingState.setBlockMergeRollupProof(location, result);
|
|
936
|
+
this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
1140
937
|
});
|
|
1141
938
|
}
|
|
1142
939
|
checkAndEnqueueNextMergeRollup(provingState, currentLocation) {
|
|
@@ -1152,7 +949,7 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
1152
949
|
}
|
|
1153
950
|
checkAndEnqueueBlockRootRollup(provingState) {
|
|
1154
951
|
if (!provingState.isReadyForBlockRootRollup()) {
|
|
1155
|
-
logger.debug('Not ready for block root rollup');
|
|
952
|
+
this.logger.debug('Not ready for block root rollup');
|
|
1156
953
|
return;
|
|
1157
954
|
}
|
|
1158
955
|
this.enqueueBlockRootRollup(provingState);
|
|
@@ -1163,54 +960,43 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
1163
960
|
}
|
|
1164
961
|
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
1165
962
|
if (parentLocation.level === 0) {
|
|
1166
|
-
this.
|
|
963
|
+
this.checkAndEnqueueSubTreeResolution(provingState);
|
|
1167
964
|
} else {
|
|
1168
965
|
this.enqueueBlockMergeRollup(provingState, parentLocation);
|
|
1169
966
|
}
|
|
1170
967
|
}
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
if (
|
|
1179
|
-
|
|
1180
|
-
}
|
|
1181
|
-
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
1182
|
-
if (parentLocation.level === 0) {
|
|
1183
|
-
this.checkAndEnqueueRootRollup(provingState);
|
|
1184
|
-
} else {
|
|
1185
|
-
this.enqueueCheckpointMergeRollup(provingState, parentLocation);
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
checkAndEnqueueRootRollup(provingState) {
|
|
1189
|
-
if (!provingState.isReadyForRootRollup()) {
|
|
1190
|
-
logger.debug('Not ready for root rollup');
|
|
968
|
+
/**
|
|
969
|
+
* Sub-tree analogue of the orchestrator's `checkAndEnqueueCheckpointRootRollup`:
|
|
970
|
+
* resolves the sub-tree promise with the block-level proof outputs once they're all ready,
|
|
971
|
+
* instead of escalating to the checkpoint root rollup.
|
|
972
|
+
*/ checkAndEnqueueSubTreeResolution(provingState) {
|
|
973
|
+
const proofs = provingState.getSubTreeOutputProofs();
|
|
974
|
+
const nonEmpty = proofs.filter((p)=>!!p);
|
|
975
|
+
if (proofs.length !== nonEmpty.length) {
|
|
976
|
+
// Block merge tree not fully resolved yet — retried as more block proofs land.
|
|
1191
977
|
return;
|
|
1192
978
|
}
|
|
1193
|
-
this.
|
|
979
|
+
this.subTreeResult.resolve({
|
|
980
|
+
blockProofOutputs: nonEmpty,
|
|
981
|
+
previousArchiveSiblingPath: provingState.getLastArchiveSiblingPath()
|
|
982
|
+
});
|
|
1194
983
|
}
|
|
1195
984
|
/**
|
|
1196
|
-
* Executes the VM circuit for a public function
|
|
1197
|
-
*
|
|
1198
|
-
* @param provingState - The proving state being operated on
|
|
1199
|
-
* @param txIndex - The index of the transaction being proven
|
|
985
|
+
* Executes the VM circuit for a public function. Enqueues the base rollup once the
|
|
986
|
+
* tx's chonk-verifier + VM proofs are both ready.
|
|
1200
987
|
*/ enqueueVM(provingState, txIndex) {
|
|
1201
988
|
if (!provingState.verifyState()) {
|
|
1202
|
-
logger.debug(`Not running VM circuit as state is no longer valid`);
|
|
989
|
+
this.logger.debug(`Not running VM circuit as state is no longer valid`);
|
|
1203
990
|
return;
|
|
1204
991
|
}
|
|
1205
992
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
1206
|
-
|
|
1207
|
-
[Attributes.TX_HASH]: txProvingState.processedTx.hash.toString()
|
|
1208
|
-
}, async (signal)=>{
|
|
993
|
+
this.deferredProving(provingState, this.wrapCircuitCall('getAvmProof', async (signal)=>{
|
|
1209
994
|
const inputs = txProvingState.getAvmInputs();
|
|
1210
995
|
return await this.prover.getAvmProof(inputs, signal, provingState.epochNumber);
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1213
|
-
|
|
996
|
+
}, {
|
|
997
|
+
[Attributes.TX_HASH]: txProvingState.processedTx.hash.toString()
|
|
998
|
+
}), (proof)=>{
|
|
999
|
+
this.logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1214
1000
|
txProvingState.setAvmProof(proof);
|
|
1215
1001
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
1216
1002
|
});
|
|
@@ -1220,8 +1006,61 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
1220
1006
|
if (!txProvingState.ready()) {
|
|
1221
1007
|
return;
|
|
1222
1008
|
}
|
|
1223
|
-
//
|
|
1224
|
-
logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1009
|
+
// All upstream proofs (chonk verifier and, if required, vm) are ready — proceed to the base rollup.
|
|
1010
|
+
this.logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1225
1011
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
1226
1012
|
}
|
|
1013
|
+
// Flagged as protected so unit tests can override.
|
|
1014
|
+
async verifyBuiltBlockAgainstSyncedState(provingState) {
|
|
1015
|
+
const builtBlockHeader = provingState.getBuiltBlockHeader();
|
|
1016
|
+
if (!builtBlockHeader) {
|
|
1017
|
+
this.logger.debug('Block header not built yet, skipping header check.');
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
const output = provingState.getBlockRootRollupOutput();
|
|
1021
|
+
if (!output) {
|
|
1022
|
+
this.logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
const newArchive = provingState.getBuiltArchive();
|
|
1026
|
+
if (!newArchive) {
|
|
1027
|
+
this.logger.debug('Archive snapshot not yet captured, skipping header check.');
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
const header = await buildHeaderFromCircuitOutputs(output);
|
|
1031
|
+
if (!(await header.hash()).equals(await builtBlockHeader.hash())) {
|
|
1032
|
+
this.logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
1033
|
+
provingState.reject(`Block header hash mismatch.`);
|
|
1034
|
+
return;
|
|
1035
|
+
}
|
|
1036
|
+
const blockNumber = provingState.blockNumber;
|
|
1037
|
+
const syncedArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.dbProvider.getSnapshot(blockNumber));
|
|
1038
|
+
if (!syncedArchive.equals(newArchive)) {
|
|
1039
|
+
this.logger.error(`Archive tree mismatch for block ${blockNumber}: world state synced to ${inspect(syncedArchive)} but built ${inspect(newArchive)}`);
|
|
1040
|
+
provingState.reject(`Archive tree mismatch.`);
|
|
1041
|
+
return;
|
|
1042
|
+
}
|
|
1043
|
+
const circuitArchive = output.newArchive;
|
|
1044
|
+
if (!newArchive.equals(circuitArchive)) {
|
|
1045
|
+
this.logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
1046
|
+
provingState.reject(`New archive mismatch.`);
|
|
1047
|
+
return;
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
getDbForBlock(blockNumber) {
|
|
1051
|
+
const db = this.dbs.get(blockNumber);
|
|
1052
|
+
if (!db) {
|
|
1053
|
+
throw new Error(`World state fork for block ${blockNumber} not found.`);
|
|
1054
|
+
}
|
|
1055
|
+
return db;
|
|
1056
|
+
}
|
|
1057
|
+
/**
|
|
1058
|
+
* Wraps a circuit call with a tracer span and circuit attributes. Replaces the
|
|
1059
|
+
* `ProvingScheduler.wrapCircuitCall` indirection that used to live on the abstract base.
|
|
1060
|
+
*/ wrapCircuitCall(circuitName, fn, attributes = {}) {
|
|
1061
|
+
return wrapCallbackInSpan(this.tracer, `CheckpointSubTreeOrchestrator.prover.${circuitName}`, {
|
|
1062
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: circuitName,
|
|
1063
|
+
...attributes
|
|
1064
|
+
}, fn);
|
|
1065
|
+
}
|
|
1227
1066
|
}
|