@aztec/prover-client 0.0.1-commit.2ed92850 → 0.0.1-commit.2f68f620
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 +13 -5
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
- package/dest/light/lightweight_checkpoint_builder.js +61 -24
- 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 +3 -1
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +19 -9
- 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 +4 -4
- 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 +10 -3
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/checkpoint-proving-state.js +13 -4
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts +107 -0
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts.map +1 -0
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.js +151 -0
- package/dest/orchestrator/epoch-proving-context.d.ts +51 -0
- package/dest/orchestrator/epoch-proving-context.d.ts.map +1 -0
- package/dest/orchestrator/epoch-proving-context.js +81 -0
- package/dest/orchestrator/epoch-proving-state.d.ts +3 -3
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +5 -3
- package/dest/orchestrator/index.d.ts +4 -1
- package/dest/orchestrator/index.d.ts.map +1 -1
- package/dest/orchestrator/index.js +3 -0
- package/dest/orchestrator/orchestrator.d.ts +16 -24
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +119 -248
- package/dest/orchestrator/proving-scheduler.d.ts +72 -0
- package/dest/orchestrator/proving-scheduler.d.ts.map +1 -0
- package/dest/orchestrator/proving-scheduler.js +117 -0
- package/dest/orchestrator/top-tree-orchestrator.d.ts +83 -0
- package/dest/orchestrator/top-tree-orchestrator.d.ts.map +1 -0
- package/dest/orchestrator/top-tree-orchestrator.js +182 -0
- package/dest/orchestrator/top-tree-proving-scheduler.d.ts +62 -0
- package/dest/orchestrator/top-tree-proving-scheduler.d.ts.map +1 -0
- package/dest/orchestrator/top-tree-proving-scheduler.js +73 -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/prover-client/prover-client.d.ts +64 -5
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +64 -11
- package/dest/proving_broker/broker_prover_facade.d.ts +4 -3
- 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 +11 -67
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +16 -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/mock_prover.d.ts +4 -4
- package/package.json +18 -19
- package/src/config.ts +18 -2
- package/src/light/lightweight_checkpoint_builder.ts +73 -27
- package/src/mocks/fixtures.ts +2 -1
- package/src/mocks/test_context.ts +14 -10
- package/src/orchestrator/block-building-helpers.ts +4 -4
- package/src/orchestrator/block-proving-state.ts +9 -0
- package/src/orchestrator/checkpoint-proving-state.ts +18 -5
- package/src/orchestrator/checkpoint-sub-tree-orchestrator.ts +271 -0
- package/src/orchestrator/epoch-proving-context.ts +101 -0
- package/src/orchestrator/epoch-proving-state.ts +6 -4
- package/src/orchestrator/index.ts +8 -0
- package/src/orchestrator/orchestrator.ts +142 -311
- package/src/orchestrator/proving-scheduler.ts +156 -0
- package/src/orchestrator/top-tree-orchestrator.ts +314 -0
- package/src/orchestrator/top-tree-proving-scheduler.ts +154 -0
- package/src/orchestrator/top-tree-proving-state.ts +220 -0
- package/src/prover-client/prover-client.ts +148 -14
- package/src/proving_broker/broker_prover_facade.ts +23 -23
- package/src/proving_broker/config.ts +16 -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/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/proving_broker/proof_store/gcs_proof_store.ts +0 -76
|
@@ -371,16 +371,13 @@ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
|
371
371
|
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
372
372
|
}
|
|
373
373
|
var _dec, _dec1, _dec2, _dec3, _dec4, _initProto;
|
|
374
|
-
import { L1_TO_L2_MSG_SUBTREE_HEIGHT, L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
|
|
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
|
-
import { AbortError } from '@aztec/foundation/error';
|
|
379
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
380
376
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
381
377
|
import { assertLength } from '@aztec/foundation/serialize';
|
|
382
378
|
import { pushTestData } from '@aztec/foundation/testing';
|
|
383
379
|
import { elapsed } from '@aztec/foundation/timer';
|
|
380
|
+
import { appendL1ToL2MessagesToTree } from '@aztec/stdlib/messaging';
|
|
384
381
|
import { BlockRootEmptyTxFirstRollupPrivateInputs, BlockRootFirstRollupPrivateInputs, BlockRootSingleTxFirstRollupPrivateInputs, BlockRootSingleTxRollupPrivateInputs, CheckpointRootSingleBlockRollupPrivateInputs, PrivateTxBaseRollupPrivateInputs } from '@aztec/stdlib/rollup';
|
|
385
382
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
386
383
|
import { Attributes, getTelemetryClient, trackSpan, wrapCallbackInSpan } from '@aztec/telemetry-client';
|
|
@@ -388,8 +385,8 @@ import { inspect } from 'util';
|
|
|
388
385
|
import { buildHeaderFromCircuitOutputs, getLastSiblingPath, getPublicChonkVerifierPrivateInputsFromTx, getRootTreeSiblingPath, getSubtreeSiblingPath, getTreeSnapshot, insertSideEffectsAndBuildBaseRollupHints, validatePartialState, validateTx } from './block-building-helpers.js';
|
|
389
386
|
import { EpochProvingState } from './epoch-proving-state.js';
|
|
390
387
|
import { ProvingOrchestratorMetrics } from './orchestrator_metrics.js';
|
|
388
|
+
import { TopTreeProvingScheduler } from './top-tree-proving-scheduler.js';
|
|
391
389
|
import { TxProvingState } from './tx-proving-state.js';
|
|
392
|
-
const logger = createLogger('prover-client:orchestrator');
|
|
393
390
|
_dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
394
391
|
[Attributes.BLOCK_NUMBER]: blockNumber
|
|
395
392
|
})), _dec1 = trackSpan('ProvingOrchestrator.addTxs', (txs)=>({
|
|
@@ -410,9 +407,8 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
410
407
|
* The proving implementation is determined by the provided prover. This could be for example a local prover or a remote prover pool.
|
|
411
408
|
*/ /**
|
|
412
409
|
* The orchestrator, managing the flow of recursive proving operations required to build the rollup proof tree.
|
|
413
|
-
*/ export class ProvingOrchestrator {
|
|
410
|
+
*/ export class ProvingOrchestrator extends TopTreeProvingScheduler {
|
|
414
411
|
dbProvider;
|
|
415
|
-
prover;
|
|
416
412
|
proverId;
|
|
417
413
|
cancelJobsOnStop;
|
|
418
414
|
static{
|
|
@@ -445,20 +441,11 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
445
441
|
], []));
|
|
446
442
|
}
|
|
447
443
|
provingState;
|
|
448
|
-
pendingProvingJobs;
|
|
449
444
|
provingPromise;
|
|
450
445
|
metrics;
|
|
451
|
-
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
452
446
|
dbs;
|
|
453
|
-
constructor(dbProvider, prover, proverId, cancelJobsOnStop = false, telemetryClient = getTelemetryClient()){
|
|
454
|
-
this.dbProvider = dbProvider;
|
|
455
|
-
this.prover = prover;
|
|
456
|
-
this.proverId = proverId;
|
|
457
|
-
this.cancelJobsOnStop = cancelJobsOnStop;
|
|
458
|
-
this.provingState = (_initProto(this), undefined);
|
|
459
|
-
this.pendingProvingJobs = [];
|
|
460
|
-
this.provingPromise = undefined;
|
|
461
|
-
this.dbs = new Map();
|
|
447
|
+
constructor(dbProvider, prover, proverId, cancelJobsOnStop = false, enqueueConcurrency, telemetryClient = getTelemetryClient(), bindings){
|
|
448
|
+
super(prover, enqueueConcurrency, 'prover-client:orchestrator', bindings), this.dbProvider = dbProvider, this.proverId = proverId, this.cancelJobsOnStop = cancelJobsOnStop, this.provingState = (_initProto(this), undefined), this.provingPromise = undefined, this.dbs = new Map();
|
|
462
449
|
this.metrics = new ProvingOrchestratorMetrics(telemetryClient, 'ProvingOrchestrator');
|
|
463
450
|
}
|
|
464
451
|
get tracer() {
|
|
@@ -470,9 +457,18 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
470
457
|
getNumActiveForks() {
|
|
471
458
|
return this.dbs.size;
|
|
472
459
|
}
|
|
473
|
-
|
|
460
|
+
cancelInternal() {
|
|
474
461
|
this.cancel();
|
|
475
|
-
|
|
462
|
+
}
|
|
463
|
+
wrapCircuitCall(circuitName, fn) {
|
|
464
|
+
return wrapCallbackInSpan(this.tracer, `ProvingOrchestrator.prover.${circuitName}`, {
|
|
465
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: circuitName
|
|
466
|
+
}, fn);
|
|
467
|
+
}
|
|
468
|
+
onRootRollupComplete(state) {
|
|
469
|
+
state.resolve({
|
|
470
|
+
status: 'success'
|
|
471
|
+
});
|
|
476
472
|
}
|
|
477
473
|
startNewEpoch(epochNumber, totalNumCheckpoints, finalBlobBatchingChallenges) {
|
|
478
474
|
if (this.provingState?.verifyState()) {
|
|
@@ -483,7 +479,7 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
483
479
|
status: 'failure',
|
|
484
480
|
reason
|
|
485
481
|
}));
|
|
486
|
-
logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
|
|
482
|
+
this.logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
|
|
487
483
|
this.provingState = new EpochProvingState(epochNumber, totalNumCheckpoints, finalBlobBatchingChallenges, (provingState)=>this.checkAndEnqueueCheckpointRootRollup(provingState), resolve, reject);
|
|
488
484
|
this.provingPromise = promise;
|
|
489
485
|
}
|
|
@@ -505,10 +501,7 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
505
501
|
const lastBlockNumber = headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber;
|
|
506
502
|
const db = await this.dbProvider.fork(lastBlockNumber);
|
|
507
503
|
const firstBlockNumber = BlockNumber(lastBlockNumber + 1);
|
|
508
|
-
this.dbs.set(firstBlockNumber,
|
|
509
|
-
fork: db,
|
|
510
|
-
cleanupPromise: undefined
|
|
511
|
-
});
|
|
504
|
+
this.dbs.set(firstBlockNumber, db);
|
|
512
505
|
// Get archive sibling path before any block in this checkpoint lands.
|
|
513
506
|
const lastArchiveSiblingPath = await getLastSiblingPath(MerkleTreeId.ARCHIVE, db);
|
|
514
507
|
// Insert all the l1 to l2 messages into the db. And get the states before and after the insertion.
|
|
@@ -533,17 +526,14 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
533
526
|
throw new Error(`Checkpoint not accepting further blocks.`);
|
|
534
527
|
}
|
|
535
528
|
const constants = checkpointProvingState.constants;
|
|
536
|
-
logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
|
|
529
|
+
this.logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
|
|
537
530
|
// Fork the db only when it's not already set. The db for the first block is set in `startNewCheckpoint`.
|
|
538
531
|
if (!this.dbs.has(blockNumber)) {
|
|
539
532
|
// Fork world state at the end of the immediately previous block
|
|
540
533
|
const db = await this.dbProvider.fork(BlockNumber(blockNumber - 1));
|
|
541
|
-
this.dbs.set(blockNumber,
|
|
542
|
-
fork: db,
|
|
543
|
-
cleanupPromise: undefined
|
|
544
|
-
});
|
|
534
|
+
this.dbs.set(blockNumber, db);
|
|
545
535
|
}
|
|
546
|
-
const db = this.
|
|
536
|
+
const db = this.getDbForBlock(blockNumber);
|
|
547
537
|
// Get archive snapshot and sibling path before any txs in this block lands.
|
|
548
538
|
const lastArchiveTreeSnapshot = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
549
539
|
const lastArchiveSiblingPath = await getRootTreeSiblingPath(MerkleTreeId.ARCHIVE, db);
|
|
@@ -578,7 +568,7 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
578
568
|
if (!txs.length) {
|
|
579
569
|
// To avoid an ugly throw below. If we require an empty block, we can just call setBlockCompleted
|
|
580
570
|
// on a block with no txs. We cannot do that here because we cannot find the blockNumber without any txs.
|
|
581
|
-
logger.warn(`Provided no txs to orchestrator addTxs.`);
|
|
571
|
+
this.logger.warn(`Provided no txs to orchestrator addTxs.`);
|
|
582
572
|
return;
|
|
583
573
|
}
|
|
584
574
|
const blockNumber = BlockNumber(txs[0].globalVariables.blockNumber);
|
|
@@ -592,8 +582,8 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
592
582
|
if (!provingState.isAcceptingTxs()) {
|
|
593
583
|
throw new Error(`Block ${blockNumber} has been initialized with transactions.`);
|
|
594
584
|
}
|
|
595
|
-
logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
596
|
-
const db = this.
|
|
585
|
+
this.logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
586
|
+
const db = this.getDbForBlock(blockNumber);
|
|
597
587
|
const lastArchive = provingState.lastArchiveTreeSnapshot;
|
|
598
588
|
const newL1ToL2MessageTreeSnapshot = provingState.newL1ToL2MessageTreeSnapshot;
|
|
599
589
|
const spongeBlobState = provingState.getStartSpongeBlob().clone();
|
|
@@ -603,7 +593,7 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
603
593
|
throw new Error(`Invalid proving state when adding a tx`);
|
|
604
594
|
}
|
|
605
595
|
validateTx(tx);
|
|
606
|
-
logger.debug(`Received transaction: ${tx.hash}`);
|
|
596
|
+
this.logger.debug(`Received transaction: ${tx.hash}`);
|
|
607
597
|
const startSpongeBlob = spongeBlobState.clone();
|
|
608
598
|
const [hints, treeSnapshots] = await this.prepareBaseRollupInputs(tx, lastArchive, newL1ToL2MessageTreeSnapshot, startSpongeBlob, db);
|
|
609
599
|
if (!provingState.verifyState()) {
|
|
@@ -614,10 +604,10 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
614
604
|
const txIndex = provingState.addNewTx(txProvingState);
|
|
615
605
|
if (txProvingState.requireAvmProof) {
|
|
616
606
|
this.getOrEnqueueChonkVerifier(provingState, txIndex);
|
|
617
|
-
logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
607
|
+
this.logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
618
608
|
this.enqueueVM(provingState, txIndex);
|
|
619
609
|
} else {
|
|
620
|
-
logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
610
|
+
this.logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
621
611
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
622
612
|
}
|
|
623
613
|
} catch (err) {
|
|
@@ -647,7 +637,7 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
647
637
|
const txHash = tx.getTxHash().toString();
|
|
648
638
|
const privateInputs = getPublicChonkVerifierPrivateInputsFromTx(tx, this.proverId.toField());
|
|
649
639
|
const tubeProof = promiseWithResolvers();
|
|
650
|
-
logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
|
|
640
|
+
this.logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
|
|
651
641
|
this.doEnqueueChonkVerifier(txHash, privateInputs, (proof)=>{
|
|
652
642
|
tubeProof.resolve(proof);
|
|
653
643
|
});
|
|
@@ -676,17 +666,23 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
676
666
|
throw new Error(`Block ${blockNumber} is still accepting txs. Call setBlockCompleted after all txs have been added.`);
|
|
677
667
|
}
|
|
678
668
|
// Given we've applied every change from this block, now assemble the block header:
|
|
679
|
-
logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
|
|
669
|
+
this.logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
|
|
680
670
|
const header = await provingState.buildBlockHeader();
|
|
681
671
|
if (expectedHeader && !header.equals(expectedHeader)) {
|
|
682
|
-
logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
672
|
+
this.logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
683
673
|
throw new Error('Block header mismatch');
|
|
684
674
|
}
|
|
685
|
-
// Get db for this block
|
|
686
|
-
const db = this.
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
675
|
+
// Get db for this block and remove from map — no other code should use it after this point.
|
|
676
|
+
const db = this.getDbForBlock(provingState.blockNumber);
|
|
677
|
+
this.dbs.delete(provingState.blockNumber);
|
|
678
|
+
// Update the archive tree, capture the snapshot, and close the fork deterministically.
|
|
679
|
+
try {
|
|
680
|
+
this.logger.verbose(`Updating archive tree with block ${provingState.blockNumber} header ${(await header.hash()).toString()}`);
|
|
681
|
+
await db.updateArchive(header);
|
|
682
|
+
provingState.setBuiltArchive(await getTreeSnapshot(MerkleTreeId.ARCHIVE, db));
|
|
683
|
+
} finally{
|
|
684
|
+
await db.close();
|
|
685
|
+
}
|
|
690
686
|
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
691
687
|
return header;
|
|
692
688
|
}
|
|
@@ -694,53 +690,57 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
694
690
|
async verifyBuiltBlockAgainstSyncedState(provingState) {
|
|
695
691
|
const builtBlockHeader = provingState.getBuiltBlockHeader();
|
|
696
692
|
if (!builtBlockHeader) {
|
|
697
|
-
logger.debug('Block header not built yet, skipping header check.');
|
|
693
|
+
this.logger.debug('Block header not built yet, skipping header check.');
|
|
698
694
|
return;
|
|
699
695
|
}
|
|
700
696
|
const output = provingState.getBlockRootRollupOutput();
|
|
701
697
|
if (!output) {
|
|
702
|
-
logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
698
|
+
this.logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
const newArchive = provingState.getBuiltArchive();
|
|
702
|
+
if (!newArchive) {
|
|
703
|
+
this.logger.debug('Archive snapshot not yet captured, skipping header check.');
|
|
703
704
|
return;
|
|
704
705
|
}
|
|
705
706
|
const header = await buildHeaderFromCircuitOutputs(output);
|
|
706
707
|
if (!(await header.hash()).equals(await builtBlockHeader.hash())) {
|
|
707
|
-
logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
708
|
+
this.logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
708
709
|
provingState.reject(`Block header hash mismatch.`);
|
|
709
710
|
return;
|
|
710
711
|
}
|
|
711
|
-
// Get db for this block
|
|
712
712
|
const blockNumber = provingState.blockNumber;
|
|
713
|
-
const db = this.dbs.get(blockNumber).fork;
|
|
714
|
-
const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
715
713
|
const syncedArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.dbProvider.getSnapshot(blockNumber));
|
|
716
714
|
if (!syncedArchive.equals(newArchive)) {
|
|
717
|
-
logger.error(`Archive tree mismatch for block ${blockNumber}: world state synced to ${inspect(syncedArchive)} but built ${inspect(newArchive)}`);
|
|
715
|
+
this.logger.error(`Archive tree mismatch for block ${blockNumber}: world state synced to ${inspect(syncedArchive)} but built ${inspect(newArchive)}`);
|
|
718
716
|
provingState.reject(`Archive tree mismatch.`);
|
|
719
717
|
return;
|
|
720
718
|
}
|
|
721
719
|
const circuitArchive = output.newArchive;
|
|
722
720
|
if (!newArchive.equals(circuitArchive)) {
|
|
723
|
-
logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
721
|
+
this.logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
724
722
|
provingState.reject(`New archive mismatch.`);
|
|
725
723
|
return;
|
|
726
724
|
}
|
|
727
|
-
// TODO(palla/prover): This closes the fork only on the happy path. If this epoch orchestrator
|
|
728
|
-
// is aborted and never reaches this point, it will leak the fork. We need to add a global cleanup,
|
|
729
|
-
// but have to make sure it only runs once all operations are completed, otherwise some function here
|
|
730
|
-
// will attempt to access the fork after it was closed.
|
|
731
|
-
void this.cleanupDBFork(blockNumber);
|
|
732
725
|
}
|
|
733
726
|
/**
|
|
734
727
|
* Cancel any further proving.
|
|
735
728
|
* If cancelJobsOnStop is true, aborts all pending jobs with the broker (which marks them as 'Aborted').
|
|
736
729
|
* If cancelJobsOnStop is false (default), jobs remain in the broker queue and can be reused on restart/reorg.
|
|
737
730
|
*/ cancel() {
|
|
738
|
-
|
|
739
|
-
for (const controller of this.pendingProvingJobs){
|
|
740
|
-
controller.abort();
|
|
741
|
-
}
|
|
742
|
-
}
|
|
731
|
+
this.resetSchedulerState(this.cancelJobsOnStop);
|
|
743
732
|
this.provingState?.cancel();
|
|
733
|
+
for (const [blockNumber, db] of this.dbs.entries()){
|
|
734
|
+
void db.close().catch((err)=>this.logger.error(`Error closing db for block ${blockNumber}`, err));
|
|
735
|
+
}
|
|
736
|
+
this.dbs.clear();
|
|
737
|
+
}
|
|
738
|
+
getDbForBlock(blockNumber) {
|
|
739
|
+
const db = this.dbs.get(blockNumber);
|
|
740
|
+
if (!db) {
|
|
741
|
+
throw new Error(`World state fork for block ${blockNumber} not found.`);
|
|
742
|
+
}
|
|
743
|
+
return db;
|
|
744
744
|
}
|
|
745
745
|
/**
|
|
746
746
|
* Returns the proof for the current epoch.
|
|
@@ -760,77 +760,11 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
760
760
|
});
|
|
761
761
|
return epochProofResult;
|
|
762
762
|
}
|
|
763
|
-
async cleanupDBFork(blockNumber) {
|
|
764
|
-
logger.debug(`Cleaning up world state fork for ${blockNumber}`);
|
|
765
|
-
const fork = this.dbs.get(blockNumber);
|
|
766
|
-
if (!fork) {
|
|
767
|
-
return;
|
|
768
|
-
}
|
|
769
|
-
try {
|
|
770
|
-
if (!fork.cleanupPromise) {
|
|
771
|
-
fork.cleanupPromise = fork.fork.close();
|
|
772
|
-
}
|
|
773
|
-
await fork.cleanupPromise;
|
|
774
|
-
this.dbs.delete(blockNumber);
|
|
775
|
-
} catch (err) {
|
|
776
|
-
logger.error(`Error closing db for block ${blockNumber}`, err);
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
/**
|
|
780
|
-
* Enqueue a job to be scheduled
|
|
781
|
-
* @param provingState - The proving state object being operated on
|
|
782
|
-
* @param jobType - The type of job to be queued
|
|
783
|
-
* @param job - The actual job, returns a promise notifying of the job's completion
|
|
784
|
-
*/ deferredProving(provingState, request, callback) {
|
|
785
|
-
if (!provingState.verifyState()) {
|
|
786
|
-
logger.debug(`Not enqueuing job, state no longer valid`);
|
|
787
|
-
return;
|
|
788
|
-
}
|
|
789
|
-
const controller = new AbortController();
|
|
790
|
-
this.pendingProvingJobs.push(controller);
|
|
791
|
-
// We use a 'safeJob'. We don't want promise rejections in the proving pool, we want to capture the error here
|
|
792
|
-
// and reject the proving job whilst keeping the event loop free of rejections
|
|
793
|
-
const safeJob = async ()=>{
|
|
794
|
-
try {
|
|
795
|
-
// there's a delay between enqueueing this job and it actually running
|
|
796
|
-
if (controller.signal.aborted) {
|
|
797
|
-
return;
|
|
798
|
-
}
|
|
799
|
-
const result = await request(controller.signal);
|
|
800
|
-
if (!provingState.verifyState()) {
|
|
801
|
-
logger.debug(`State no longer valid, discarding result`);
|
|
802
|
-
return;
|
|
803
|
-
}
|
|
804
|
-
// we could have been cancelled whilst waiting for the result
|
|
805
|
-
// and the prover ignored the signal. Drop the result in that case
|
|
806
|
-
if (controller.signal.aborted) {
|
|
807
|
-
return;
|
|
808
|
-
}
|
|
809
|
-
await callback(result);
|
|
810
|
-
} catch (err) {
|
|
811
|
-
if (err instanceof AbortError) {
|
|
812
|
-
// operation was cancelled, probably because the block was cancelled
|
|
813
|
-
// drop this result
|
|
814
|
-
return;
|
|
815
|
-
}
|
|
816
|
-
logger.error(`Error thrown when proving job`, err);
|
|
817
|
-
provingState.reject(`${err}`);
|
|
818
|
-
} finally{
|
|
819
|
-
const index = this.pendingProvingJobs.indexOf(controller);
|
|
820
|
-
if (index > -1) {
|
|
821
|
-
this.pendingProvingJobs.splice(index, 1);
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
};
|
|
825
|
-
// let the callstack unwind before adding the job to the queue
|
|
826
|
-
setImmediate(()=>void safeJob());
|
|
827
|
-
}
|
|
828
763
|
async updateL1ToL2MessageTree(l1ToL2Messages, db) {
|
|
829
|
-
const l1ToL2MessagesPadded = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, 'Too many L1 to L2 messages');
|
|
830
764
|
const lastL1ToL2MessageTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
|
|
831
765
|
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);
|
|
832
766
|
// Update the local trees to include the new l1 to l2 messages
|
|
833
|
-
await db
|
|
767
|
+
await appendL1ToL2MessagesToTree(db, l1ToL2Messages);
|
|
834
768
|
const newL1ToL2MessageTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
|
|
835
769
|
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);
|
|
836
770
|
return {
|
|
@@ -869,17 +803,17 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
869
803
|
// Executes the next level of merge if all inputs are available
|
|
870
804
|
enqueueBaseRollup(provingState, txIndex) {
|
|
871
805
|
if (!provingState.verifyState()) {
|
|
872
|
-
logger.debug('Not running base rollup, state invalid');
|
|
806
|
+
this.logger.debug('Not running base rollup, state invalid');
|
|
873
807
|
return;
|
|
874
808
|
}
|
|
875
809
|
if (!provingState.tryStartProvingBase(txIndex)) {
|
|
876
|
-
logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
810
|
+
this.logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
877
811
|
return;
|
|
878
812
|
}
|
|
879
813
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
880
814
|
const { processedTx } = txProvingState;
|
|
881
815
|
const { rollupType, inputs } = txProvingState.getBaseRollupTypeAndInputs();
|
|
882
|
-
logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
816
|
+
this.logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
883
817
|
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, `ProvingOrchestrator.prover.${inputs instanceof PrivateTxBaseRollupPrivateInputs ? 'getPrivateTxBaseRollupProof' : 'getPublicTxBaseRollupProof'}`, {
|
|
884
818
|
[Attributes.TX_HASH]: processedTx.hash.toString(),
|
|
885
819
|
[Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
|
|
@@ -890,7 +824,7 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
890
824
|
return this.prover.getPublicTxBaseRollupProof(inputs, signal, provingState.epochNumber);
|
|
891
825
|
}
|
|
892
826
|
}), (result)=>{
|
|
893
|
-
logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
827
|
+
this.logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
894
828
|
validatePartialState(result.inputs.endTreeSnapshots, txProvingState.treeSnapshots);
|
|
895
829
|
const leafLocation = provingState.setBaseRollupProof(txIndex, result);
|
|
896
830
|
if (provingState.totalNumTxs === 1) {
|
|
@@ -904,14 +838,13 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
904
838
|
// Once completed, will enqueue the the public tx base rollup.
|
|
905
839
|
getOrEnqueueChonkVerifier(provingState, txIndex) {
|
|
906
840
|
if (!provingState.verifyState()) {
|
|
907
|
-
logger.debug('Not running chonk verifier circuit, state invalid');
|
|
841
|
+
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
908
842
|
return;
|
|
909
843
|
}
|
|
910
844
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
911
845
|
const txHash = txProvingState.processedTx.hash.toString();
|
|
912
|
-
NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH;
|
|
913
846
|
const handleResult = (result)=>{
|
|
914
|
-
logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, {
|
|
847
|
+
this.logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, {
|
|
915
848
|
txHash
|
|
916
849
|
});
|
|
917
850
|
txProvingState.setPublicChonkVerifierProof(result);
|
|
@@ -919,18 +852,18 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
919
852
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
920
853
|
};
|
|
921
854
|
if (this.provingState?.cachedChonkVerifierProofs.has(txHash)) {
|
|
922
|
-
logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, {
|
|
855
|
+
this.logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, {
|
|
923
856
|
txHash
|
|
924
857
|
});
|
|
925
858
|
void this.provingState.cachedChonkVerifierProofs.get(txHash).then(handleResult);
|
|
926
859
|
return;
|
|
927
860
|
}
|
|
928
|
-
logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
|
|
861
|
+
this.logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
|
|
929
862
|
this.doEnqueueChonkVerifier(txHash, txProvingState.getPublicChonkVerifierPrivateInputs(), handleResult);
|
|
930
863
|
}
|
|
931
864
|
doEnqueueChonkVerifier(txHash, inputs, handler, provingState = this.provingState) {
|
|
932
865
|
if (!provingState.verifyState()) {
|
|
933
|
-
logger.debug('Not running chonk verifier circuit, state invalid');
|
|
866
|
+
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
934
867
|
return;
|
|
935
868
|
}
|
|
936
869
|
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getPublicChonkVerifierProof', {
|
|
@@ -942,11 +875,11 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
942
875
|
// Enqueues the next level of merge if all inputs are available
|
|
943
876
|
enqueueMergeRollup(provingState, location) {
|
|
944
877
|
if (!provingState.verifyState()) {
|
|
945
|
-
logger.debug('Not running merge rollup. State no longer valid.');
|
|
878
|
+
this.logger.debug('Not running merge rollup. State no longer valid.');
|
|
946
879
|
return;
|
|
947
880
|
}
|
|
948
881
|
if (!provingState.tryStartProvingMerge(location)) {
|
|
949
|
-
logger.debug('Merge rollup already started.');
|
|
882
|
+
this.logger.debug('Merge rollup already started.');
|
|
950
883
|
return;
|
|
951
884
|
}
|
|
952
885
|
const inputs = provingState.getMergeRollupInputs(location);
|
|
@@ -960,15 +893,15 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
960
893
|
// Executes the block root rollup circuit
|
|
961
894
|
enqueueBlockRootRollup(provingState) {
|
|
962
895
|
if (!provingState.verifyState()) {
|
|
963
|
-
logger.debug('Not running block root rollup, state no longer valid');
|
|
896
|
+
this.logger.debug('Not running block root rollup, state no longer valid');
|
|
964
897
|
return;
|
|
965
898
|
}
|
|
966
899
|
if (!provingState.tryStartProvingBlockRoot()) {
|
|
967
|
-
logger.debug('Block root rollup already started.');
|
|
900
|
+
this.logger.debug('Block root rollup already started.');
|
|
968
901
|
return;
|
|
969
902
|
}
|
|
970
903
|
const { rollupType, inputs } = provingState.getBlockRootRollupTypeAndInputs();
|
|
971
|
-
logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
904
|
+
this.logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
972
905
|
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getBlockRootRollupProof', {
|
|
973
906
|
[Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
|
|
974
907
|
}, (signal)=>{
|
|
@@ -984,29 +917,32 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
984
917
|
return this.prover.getBlockRootRollupProof(inputs, signal, provingState.epochNumber);
|
|
985
918
|
}
|
|
986
919
|
}), async (result)=>{
|
|
987
|
-
logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}
|
|
920
|
+
this.logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`, {
|
|
921
|
+
blockNumber: provingState.blockNumber,
|
|
922
|
+
checkpointIndex: provingState.parentCheckpoint.index,
|
|
923
|
+
...result.inputs.toInspect()
|
|
924
|
+
});
|
|
988
925
|
const leafLocation = provingState.setBlockRootRollupProof(result);
|
|
989
926
|
const checkpointProvingState = provingState.parentCheckpoint;
|
|
990
|
-
//
|
|
927
|
+
// Verification is called from both here and setBlockCompleted. Whichever runs last
|
|
928
|
+
// will be the first to see all three pieces (header, proof output, archive) and run the checks.
|
|
991
929
|
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
992
930
|
if (checkpointProvingState.totalNumBlocks === 1) {
|
|
993
|
-
this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
931
|
+
await this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
994
932
|
} else {
|
|
995
|
-
this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
933
|
+
await this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
996
934
|
}
|
|
997
|
-
// We are finished with the block at this point, ensure the fork is cleaned up
|
|
998
|
-
void this.cleanupDBFork(provingState.blockNumber);
|
|
999
935
|
});
|
|
1000
936
|
}
|
|
1001
937
|
// Executes the base parity circuit and stores the intermediate state for the root parity circuit
|
|
1002
938
|
// Enqueues the root parity circuit if all inputs are available
|
|
1003
939
|
enqueueBaseParityCircuit(checkpointProvingState, provingState, baseParityIndex) {
|
|
1004
940
|
if (!provingState.verifyState()) {
|
|
1005
|
-
logger.debug('Not running base parity. State no longer valid.');
|
|
941
|
+
this.logger.debug('Not running base parity. State no longer valid.');
|
|
1006
942
|
return;
|
|
1007
943
|
}
|
|
1008
944
|
if (!provingState.tryStartProvingBaseParity(baseParityIndex)) {
|
|
1009
|
-
logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
945
|
+
this.logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
1010
946
|
return;
|
|
1011
947
|
}
|
|
1012
948
|
const inputs = checkpointProvingState.getBaseParityInputs(baseParityIndex);
|
|
@@ -1027,11 +963,11 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
1027
963
|
// Enqueues the root rollup proof if all inputs are available
|
|
1028
964
|
enqueueRootParityCircuit(provingState) {
|
|
1029
965
|
if (!provingState.verifyState()) {
|
|
1030
|
-
logger.debug('Not running root parity. State no longer valid.');
|
|
966
|
+
this.logger.debug('Not running root parity. State no longer valid.');
|
|
1031
967
|
return;
|
|
1032
968
|
}
|
|
1033
969
|
if (!provingState.tryStartProvingRootParity()) {
|
|
1034
|
-
logger.debug('Root parity already started.');
|
|
970
|
+
this.logger.debug('Root parity already started.');
|
|
1035
971
|
return;
|
|
1036
972
|
}
|
|
1037
973
|
const inputs = provingState.getParityRootInputs();
|
|
@@ -1046,33 +982,38 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
1046
982
|
// Enqueues the next level of merge if all inputs are available
|
|
1047
983
|
enqueueBlockMergeRollup(provingState, location) {
|
|
1048
984
|
if (!provingState.verifyState()) {
|
|
1049
|
-
logger.debug('Not running block merge rollup. State no longer valid.');
|
|
985
|
+
this.logger.debug('Not running block merge rollup. State no longer valid.');
|
|
1050
986
|
return;
|
|
1051
987
|
}
|
|
1052
988
|
if (!provingState.tryStartProvingBlockMerge(location)) {
|
|
1053
|
-
logger.debug('Block merge rollup already started.');
|
|
989
|
+
this.logger.debug('Block merge rollup already started.');
|
|
1054
990
|
return;
|
|
1055
991
|
}
|
|
1056
992
|
const inputs = provingState.getBlockMergeRollupInputs(location);
|
|
1057
993
|
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getBlockMergeRollupProof', {
|
|
1058
994
|
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-block-merge'
|
|
1059
|
-
}, (signal)=>this.prover.getBlockMergeRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
|
|
995
|
+
}, (signal)=>this.prover.getBlockMergeRollupProof(inputs, signal, provingState.epochNumber)), async (result)=>{
|
|
996
|
+
this.logger.debug(`Completed block merge rollup proof for checkpoint ${provingState.index}`, {
|
|
997
|
+
checkpointIndex: provingState.index,
|
|
998
|
+
mergeLocation: location,
|
|
999
|
+
...result.inputs.toInspect()
|
|
1000
|
+
});
|
|
1060
1001
|
provingState.setBlockMergeRollupProof(location, result);
|
|
1061
|
-
this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
1002
|
+
await this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
1062
1003
|
});
|
|
1063
1004
|
}
|
|
1064
|
-
enqueueCheckpointRootRollup(provingState) {
|
|
1005
|
+
async enqueueCheckpointRootRollup(provingState) {
|
|
1065
1006
|
if (!provingState.verifyState()) {
|
|
1066
|
-
logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
1007
|
+
this.logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
1067
1008
|
return;
|
|
1068
1009
|
}
|
|
1069
1010
|
if (!provingState.tryStartProvingCheckpointRoot()) {
|
|
1070
|
-
logger.debug('Checkpoint root rollup already started.');
|
|
1011
|
+
this.logger.debug('Checkpoint root rollup already started.');
|
|
1071
1012
|
return;
|
|
1072
1013
|
}
|
|
1073
1014
|
const rollupType = provingState.getCheckpointRootRollupType();
|
|
1074
|
-
logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
1075
|
-
const inputs = provingState.getCheckpointRootRollupInputs();
|
|
1015
|
+
this.logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
1016
|
+
const inputs = await provingState.getCheckpointRootRollupInputs();
|
|
1076
1017
|
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getCheckpointRootRollupProof', {
|
|
1077
1018
|
[Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
|
|
1078
1019
|
}, (signal)=>{
|
|
@@ -1085,11 +1026,14 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
1085
1026
|
const computedEndBlobAccumulatorState = provingState.getEndBlobAccumulator().toBlobAccumulator();
|
|
1086
1027
|
const circuitEndBlobAccumulatorState = result.inputs.endBlobAccumulator;
|
|
1087
1028
|
if (!circuitEndBlobAccumulatorState.equals(computedEndBlobAccumulatorState)) {
|
|
1088
|
-
logger.error(`Blob accumulator state mismatch.\nCircuit: ${inspect(circuitEndBlobAccumulatorState)}\nComputed: ${inspect(computedEndBlobAccumulatorState)}`);
|
|
1029
|
+
this.logger.error(`Blob accumulator state mismatch.\nCircuit: ${inspect(circuitEndBlobAccumulatorState)}\nComputed: ${inspect(computedEndBlobAccumulatorState)}`);
|
|
1089
1030
|
provingState.reject(`Blob accumulator state mismatch.`);
|
|
1090
1031
|
return;
|
|
1091
1032
|
}
|
|
1092
|
-
logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}
|
|
1033
|
+
this.logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}`, {
|
|
1034
|
+
checkpointIndex: provingState.index,
|
|
1035
|
+
...result.inputs.toInspect()
|
|
1036
|
+
});
|
|
1093
1037
|
const leafLocation = provingState.setCheckpointRootRollupProof(result);
|
|
1094
1038
|
const epochProvingState = provingState.parentEpoch;
|
|
1095
1039
|
if (epochProvingState.totalNumCheckpoints === 1) {
|
|
@@ -1099,61 +1043,6 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
1099
1043
|
}
|
|
1100
1044
|
});
|
|
1101
1045
|
}
|
|
1102
|
-
enqueueCheckpointMergeRollup(provingState, location) {
|
|
1103
|
-
if (!provingState.verifyState()) {
|
|
1104
|
-
logger.debug('Not running checkpoint merge rollup. State no longer valid.');
|
|
1105
|
-
return;
|
|
1106
|
-
}
|
|
1107
|
-
if (!provingState.tryStartProvingCheckpointMerge(location)) {
|
|
1108
|
-
logger.debug('Checkpoint merge rollup already started.');
|
|
1109
|
-
return;
|
|
1110
|
-
}
|
|
1111
|
-
const inputs = provingState.getCheckpointMergeRollupInputs(location);
|
|
1112
|
-
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getCheckpointMergeRollupProof', {
|
|
1113
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-checkpoint-merge'
|
|
1114
|
-
}, (signal)=>this.prover.getCheckpointMergeRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
|
|
1115
|
-
logger.debug('Completed proof for checkpoint merge rollup.');
|
|
1116
|
-
provingState.setCheckpointMergeRollupProof(location, result);
|
|
1117
|
-
this.checkAndEnqueueNextCheckpointMergeRollup(provingState, location);
|
|
1118
|
-
});
|
|
1119
|
-
}
|
|
1120
|
-
enqueueEpochPadding(provingState) {
|
|
1121
|
-
if (!provingState.verifyState()) {
|
|
1122
|
-
logger.debug('Not running epoch padding. State no longer valid.');
|
|
1123
|
-
return;
|
|
1124
|
-
}
|
|
1125
|
-
if (!provingState.tryStartProvingPaddingCheckpoint()) {
|
|
1126
|
-
logger.debug('Padding checkpoint already started.');
|
|
1127
|
-
return;
|
|
1128
|
-
}
|
|
1129
|
-
logger.debug('Padding epoch proof with a padding block root proof.');
|
|
1130
|
-
const inputs = provingState.getPaddingCheckpointInputs();
|
|
1131
|
-
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getCheckpointPaddingRollupProof', {
|
|
1132
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-checkpoint-padding'
|
|
1133
|
-
}, (signal)=>this.prover.getCheckpointPaddingRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
|
|
1134
|
-
logger.debug('Completed proof for padding checkpoint.');
|
|
1135
|
-
provingState.setCheckpointPaddingProof(result);
|
|
1136
|
-
this.checkAndEnqueueRootRollup(provingState);
|
|
1137
|
-
});
|
|
1138
|
-
}
|
|
1139
|
-
// Executes the root rollup circuit
|
|
1140
|
-
enqueueRootRollup(provingState) {
|
|
1141
|
-
if (!provingState.verifyState()) {
|
|
1142
|
-
logger.debug('Not running root rollup, state no longer valid');
|
|
1143
|
-
return;
|
|
1144
|
-
}
|
|
1145
|
-
logger.debug(`Preparing root rollup`);
|
|
1146
|
-
const inputs = provingState.getRootRollupInputs();
|
|
1147
|
-
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getRootRollupProof', {
|
|
1148
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-root'
|
|
1149
|
-
}, (signal)=>this.prover.getRootRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
|
|
1150
|
-
logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
|
|
1151
|
-
provingState.setRootRollupProof(result);
|
|
1152
|
-
provingState.resolve({
|
|
1153
|
-
status: 'success'
|
|
1154
|
-
});
|
|
1155
|
-
});
|
|
1156
|
-
}
|
|
1157
1046
|
checkAndEnqueueNextMergeRollup(provingState, currentLocation) {
|
|
1158
1047
|
if (!provingState.isReadyForMergeRollup(currentLocation)) {
|
|
1159
1048
|
return;
|
|
@@ -1167,45 +1056,27 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
1167
1056
|
}
|
|
1168
1057
|
checkAndEnqueueBlockRootRollup(provingState) {
|
|
1169
1058
|
if (!provingState.isReadyForBlockRootRollup()) {
|
|
1170
|
-
logger.debug('Not ready for block root rollup');
|
|
1059
|
+
this.logger.debug('Not ready for block root rollup');
|
|
1171
1060
|
return;
|
|
1172
1061
|
}
|
|
1173
1062
|
this.enqueueBlockRootRollup(provingState);
|
|
1174
1063
|
}
|
|
1175
|
-
checkAndEnqueueNextBlockMergeRollup(provingState, currentLocation) {
|
|
1064
|
+
async checkAndEnqueueNextBlockMergeRollup(provingState, currentLocation) {
|
|
1176
1065
|
if (!provingState.isReadyForBlockMerge(currentLocation)) {
|
|
1177
1066
|
return;
|
|
1178
1067
|
}
|
|
1179
1068
|
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
1180
1069
|
if (parentLocation.level === 0) {
|
|
1181
|
-
this.checkAndEnqueueCheckpointRootRollup(provingState);
|
|
1070
|
+
await this.checkAndEnqueueCheckpointRootRollup(provingState);
|
|
1182
1071
|
} else {
|
|
1183
1072
|
this.enqueueBlockMergeRollup(provingState, parentLocation);
|
|
1184
1073
|
}
|
|
1185
1074
|
}
|
|
1186
|
-
checkAndEnqueueCheckpointRootRollup(provingState) {
|
|
1075
|
+
async checkAndEnqueueCheckpointRootRollup(provingState) {
|
|
1187
1076
|
if (!provingState.isReadyForCheckpointRoot()) {
|
|
1188
1077
|
return;
|
|
1189
1078
|
}
|
|
1190
|
-
this.enqueueCheckpointRootRollup(provingState);
|
|
1191
|
-
}
|
|
1192
|
-
checkAndEnqueueNextCheckpointMergeRollup(provingState, currentLocation) {
|
|
1193
|
-
if (!provingState.isReadyForCheckpointMerge(currentLocation)) {
|
|
1194
|
-
return;
|
|
1195
|
-
}
|
|
1196
|
-
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
1197
|
-
if (parentLocation.level === 0) {
|
|
1198
|
-
this.checkAndEnqueueRootRollup(provingState);
|
|
1199
|
-
} else {
|
|
1200
|
-
this.enqueueCheckpointMergeRollup(provingState, parentLocation);
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
checkAndEnqueueRootRollup(provingState) {
|
|
1204
|
-
if (!provingState.isReadyForRootRollup()) {
|
|
1205
|
-
logger.debug('Not ready for root rollup');
|
|
1206
|
-
return;
|
|
1207
|
-
}
|
|
1208
|
-
this.enqueueRootRollup(provingState);
|
|
1079
|
+
await this.enqueueCheckpointRootRollup(provingState);
|
|
1209
1080
|
}
|
|
1210
1081
|
/**
|
|
1211
1082
|
* Executes the VM circuit for a public function, will enqueue the corresponding kernel if the
|
|
@@ -1214,7 +1085,7 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
1214
1085
|
* @param txIndex - The index of the transaction being proven
|
|
1215
1086
|
*/ enqueueVM(provingState, txIndex) {
|
|
1216
1087
|
if (!provingState.verifyState()) {
|
|
1217
|
-
logger.debug(`Not running VM circuit as state is no longer valid`);
|
|
1088
|
+
this.logger.debug(`Not running VM circuit as state is no longer valid`);
|
|
1218
1089
|
return;
|
|
1219
1090
|
}
|
|
1220
1091
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
@@ -1225,7 +1096,7 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
1225
1096
|
return await this.prover.getAvmProof(inputs, signal, provingState.epochNumber);
|
|
1226
1097
|
});
|
|
1227
1098
|
this.deferredProving(provingState, doAvmProving, (proof)=>{
|
|
1228
|
-
logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1099
|
+
this.logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1229
1100
|
txProvingState.setAvmProof(proof);
|
|
1230
1101
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
1231
1102
|
});
|
|
@@ -1236,7 +1107,7 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
1236
1107
|
return;
|
|
1237
1108
|
}
|
|
1238
1109
|
// We must have completed all proving (chonk verifier proof and (if required) vm proof are generated), we now move to the base rollup.
|
|
1239
|
-
logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1110
|
+
this.logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1240
1111
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
1241
1112
|
}
|
|
1242
1113
|
}
|