@aztec/prover-client 0.0.1-commit.96bb3f7 → 0.0.1-commit.993d240
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 +16 -7
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
- package/dest/light/lightweight_checkpoint_builder.js +75 -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 +5 -2
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +23 -9
- package/dest/orchestrator/block-building-helpers.d.ts +5 -5
- 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 +24 -4
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/checkpoint-proving-state.js +47 -5
- 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 +7 -6
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +37 -1
- 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 +29 -24
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +137 -225
- 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 +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/mock_proof_store.d.ts +3 -3
- package/dest/test/mock_proof_store.d.ts.map +1 -1
- package/dest/test/mock_prover.d.ts +4 -4
- package/package.json +19 -21
- package/src/config.ts +18 -2
- package/src/light/lightweight_checkpoint_builder.ts +107 -36
- package/src/mocks/fixtures.ts +2 -1
- package/src/mocks/test_context.ts +18 -10
- 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 +65 -6
- 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 +59 -9
- package/src/orchestrator/index.ts +8 -0
- package/src/orchestrator/orchestrator.ts +161 -290
- 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 +155 -15
- package/src/proving_broker/broker_prover_facade.ts +23 -23
- 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/dest/block-factory/index.d.ts +0 -2
- package/dest/block-factory/index.d.ts.map +0 -1
- package/dest/block-factory/index.js +0 -1
- package/dest/block-factory/light.d.ts +0 -38
- package/dest/block-factory/light.d.ts.map +0 -1
- package/dest/block-factory/light.js +0 -106
- 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/block-factory/index.ts +0 -1
- package/src/block-factory/light.ts +0 -136
- 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,10 +407,10 @@ _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;
|
|
413
|
+
cancelJobsOnStop;
|
|
417
414
|
static{
|
|
418
415
|
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
419
416
|
[
|
|
@@ -444,19 +441,11 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
444
441
|
], []));
|
|
445
442
|
}
|
|
446
443
|
provingState;
|
|
447
|
-
pendingProvingJobs;
|
|
448
444
|
provingPromise;
|
|
449
445
|
metrics;
|
|
450
|
-
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
451
446
|
dbs;
|
|
452
|
-
constructor(dbProvider, prover, proverId, telemetryClient = getTelemetryClient()){
|
|
453
|
-
this.dbProvider = dbProvider;
|
|
454
|
-
this.prover = prover;
|
|
455
|
-
this.proverId = proverId;
|
|
456
|
-
this.provingState = (_initProto(this), undefined);
|
|
457
|
-
this.pendingProvingJobs = [];
|
|
458
|
-
this.provingPromise = undefined;
|
|
459
|
-
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();
|
|
460
449
|
this.metrics = new ProvingOrchestratorMetrics(telemetryClient, 'ProvingOrchestrator');
|
|
461
450
|
}
|
|
462
451
|
get tracer() {
|
|
@@ -465,9 +454,21 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
465
454
|
getProverId() {
|
|
466
455
|
return this.proverId;
|
|
467
456
|
}
|
|
468
|
-
|
|
457
|
+
getNumActiveForks() {
|
|
458
|
+
return this.dbs.size;
|
|
459
|
+
}
|
|
460
|
+
cancelInternal() {
|
|
469
461
|
this.cancel();
|
|
470
|
-
|
|
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
|
+
});
|
|
471
472
|
}
|
|
472
473
|
startNewEpoch(epochNumber, totalNumCheckpoints, finalBlobBatchingChallenges) {
|
|
473
474
|
if (this.provingState?.verifyState()) {
|
|
@@ -478,11 +479,18 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
478
479
|
status: 'failure',
|
|
479
480
|
reason
|
|
480
481
|
}));
|
|
481
|
-
logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
|
|
482
|
+
this.logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
|
|
482
483
|
this.provingState = new EpochProvingState(epochNumber, totalNumCheckpoints, finalBlobBatchingChallenges, (provingState)=>this.checkAndEnqueueCheckpointRootRollup(provingState), resolve, reject);
|
|
483
484
|
this.provingPromise = promise;
|
|
484
485
|
}
|
|
485
|
-
|
|
486
|
+
/**
|
|
487
|
+
* Starts a new checkpoint.
|
|
488
|
+
* @param checkpointIndex - The index of the checkpoint in the epoch.
|
|
489
|
+
* @param constants - The constants for this checkpoint.
|
|
490
|
+
* @param l1ToL2Messages - The set of L1 to L2 messages to be inserted at the beginning of this checkpoint.
|
|
491
|
+
* @param totalNumBlocks - The total number of blocks expected in the checkpoint (must be at least one).
|
|
492
|
+
* @param headerOfLastBlockInPreviousCheckpoint - The header of the last block in the previous checkpoint.
|
|
493
|
+
*/ async startNewCheckpoint(checkpointIndex, constants, l1ToL2Messages, totalNumBlocks, headerOfLastBlockInPreviousCheckpoint) {
|
|
486
494
|
if (!this.provingState) {
|
|
487
495
|
throw new Error('Empty epoch proving state. Call startNewEpoch before starting a checkpoint.');
|
|
488
496
|
}
|
|
@@ -518,14 +526,14 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
518
526
|
throw new Error(`Checkpoint not accepting further blocks.`);
|
|
519
527
|
}
|
|
520
528
|
const constants = checkpointProvingState.constants;
|
|
521
|
-
logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
|
|
529
|
+
this.logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
|
|
522
530
|
// Fork the db only when it's not already set. The db for the first block is set in `startNewCheckpoint`.
|
|
523
531
|
if (!this.dbs.has(blockNumber)) {
|
|
524
532
|
// Fork world state at the end of the immediately previous block
|
|
525
533
|
const db = await this.dbProvider.fork(BlockNumber(blockNumber - 1));
|
|
526
534
|
this.dbs.set(blockNumber, db);
|
|
527
535
|
}
|
|
528
|
-
const db = this.
|
|
536
|
+
const db = this.getDbForBlock(blockNumber);
|
|
529
537
|
// Get archive snapshot and sibling path before any txs in this block lands.
|
|
530
538
|
const lastArchiveTreeSnapshot = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
531
539
|
const lastArchiveSiblingPath = await getRootTreeSiblingPath(MerkleTreeId.ARCHIVE, db);
|
|
@@ -545,7 +553,8 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
545
553
|
const blockEndBlobFields = blockProvingState.getBlockEndBlobFields();
|
|
546
554
|
await endSpongeBlob.absorb(blockEndBlobFields);
|
|
547
555
|
blockProvingState.setEndSpongeBlob(endSpongeBlob);
|
|
548
|
-
//
|
|
556
|
+
// Try to accumulate the out hashes and blobs as far as we can:
|
|
557
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
549
558
|
await this.provingState.setBlobAccumulators();
|
|
550
559
|
}
|
|
551
560
|
}
|
|
@@ -559,7 +568,7 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
559
568
|
if (!txs.length) {
|
|
560
569
|
// To avoid an ugly throw below. If we require an empty block, we can just call setBlockCompleted
|
|
561
570
|
// on a block with no txs. We cannot do that here because we cannot find the blockNumber without any txs.
|
|
562
|
-
logger.warn(`Provided no txs to orchestrator addTxs.`);
|
|
571
|
+
this.logger.warn(`Provided no txs to orchestrator addTxs.`);
|
|
563
572
|
return;
|
|
564
573
|
}
|
|
565
574
|
const blockNumber = BlockNumber(txs[0].globalVariables.blockNumber);
|
|
@@ -573,8 +582,8 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
573
582
|
if (!provingState.isAcceptingTxs()) {
|
|
574
583
|
throw new Error(`Block ${blockNumber} has been initialized with transactions.`);
|
|
575
584
|
}
|
|
576
|
-
logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
577
|
-
const db = this.
|
|
585
|
+
this.logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
586
|
+
const db = this.getDbForBlock(blockNumber);
|
|
578
587
|
const lastArchive = provingState.lastArchiveTreeSnapshot;
|
|
579
588
|
const newL1ToL2MessageTreeSnapshot = provingState.newL1ToL2MessageTreeSnapshot;
|
|
580
589
|
const spongeBlobState = provingState.getStartSpongeBlob().clone();
|
|
@@ -584,7 +593,7 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
584
593
|
throw new Error(`Invalid proving state when adding a tx`);
|
|
585
594
|
}
|
|
586
595
|
validateTx(tx);
|
|
587
|
-
logger.debug(`Received transaction: ${tx.hash}`);
|
|
596
|
+
this.logger.debug(`Received transaction: ${tx.hash}`);
|
|
588
597
|
const startSpongeBlob = spongeBlobState.clone();
|
|
589
598
|
const [hints, treeSnapshots] = await this.prepareBaseRollupInputs(tx, lastArchive, newL1ToL2MessageTreeSnapshot, startSpongeBlob, db);
|
|
590
599
|
if (!provingState.verifyState()) {
|
|
@@ -595,10 +604,10 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
595
604
|
const txIndex = provingState.addNewTx(txProvingState);
|
|
596
605
|
if (txProvingState.requireAvmProof) {
|
|
597
606
|
this.getOrEnqueueChonkVerifier(provingState, txIndex);
|
|
598
|
-
logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
607
|
+
this.logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
599
608
|
this.enqueueVM(provingState, txIndex);
|
|
600
609
|
} else {
|
|
601
|
-
logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
610
|
+
this.logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
602
611
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
603
612
|
}
|
|
604
613
|
} catch (err) {
|
|
@@ -612,7 +621,8 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
612
621
|
const blockEndBlobFields = provingState.getBlockEndBlobFields();
|
|
613
622
|
await spongeBlobState.absorb(blockEndBlobFields);
|
|
614
623
|
provingState.setEndSpongeBlob(spongeBlobState);
|
|
615
|
-
// Txs have been added to the block. Now try to accumulate the blobs as far as we can:
|
|
624
|
+
// Txs have been added to the block. Now try to accumulate the out hashes and blobs as far as we can:
|
|
625
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
616
626
|
await this.provingState.setBlobAccumulators();
|
|
617
627
|
}
|
|
618
628
|
/**
|
|
@@ -627,7 +637,7 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
627
637
|
const txHash = tx.getTxHash().toString();
|
|
628
638
|
const privateInputs = getPublicChonkVerifierPrivateInputsFromTx(tx, this.proverId.toField());
|
|
629
639
|
const tubeProof = promiseWithResolvers();
|
|
630
|
-
logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
|
|
640
|
+
this.logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
|
|
631
641
|
this.doEnqueueChonkVerifier(txHash, privateInputs, (proof)=>{
|
|
632
642
|
tubeProof.resolve(proof);
|
|
633
643
|
});
|
|
@@ -656,17 +666,23 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
656
666
|
throw new Error(`Block ${blockNumber} is still accepting txs. Call setBlockCompleted after all txs have been added.`);
|
|
657
667
|
}
|
|
658
668
|
// Given we've applied every change from this block, now assemble the block header:
|
|
659
|
-
logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
|
|
669
|
+
this.logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
|
|
660
670
|
const header = await provingState.buildBlockHeader();
|
|
661
671
|
if (expectedHeader && !header.equals(expectedHeader)) {
|
|
662
|
-
logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
672
|
+
this.logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
663
673
|
throw new Error('Block header mismatch');
|
|
664
674
|
}
|
|
665
|
-
// Get db for this block
|
|
666
|
-
const db = this.
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
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
|
+
}
|
|
670
686
|
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
671
687
|
return header;
|
|
672
688
|
}
|
|
@@ -674,50 +690,57 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
674
690
|
async verifyBuiltBlockAgainstSyncedState(provingState) {
|
|
675
691
|
const builtBlockHeader = provingState.getBuiltBlockHeader();
|
|
676
692
|
if (!builtBlockHeader) {
|
|
677
|
-
logger.debug('Block header not built yet, skipping header check.');
|
|
693
|
+
this.logger.debug('Block header not built yet, skipping header check.');
|
|
678
694
|
return;
|
|
679
695
|
}
|
|
680
696
|
const output = provingState.getBlockRootRollupOutput();
|
|
681
697
|
if (!output) {
|
|
682
|
-
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.');
|
|
683
704
|
return;
|
|
684
705
|
}
|
|
685
706
|
const header = await buildHeaderFromCircuitOutputs(output);
|
|
686
707
|
if (!(await header.hash()).equals(await builtBlockHeader.hash())) {
|
|
687
|
-
logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
708
|
+
this.logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
688
709
|
provingState.reject(`Block header hash mismatch.`);
|
|
689
710
|
return;
|
|
690
711
|
}
|
|
691
|
-
// Get db for this block
|
|
692
712
|
const blockNumber = provingState.blockNumber;
|
|
693
|
-
const db = this.dbs.get(blockNumber);
|
|
694
|
-
const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
695
713
|
const syncedArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.dbProvider.getSnapshot(blockNumber));
|
|
696
714
|
if (!syncedArchive.equals(newArchive)) {
|
|
697
|
-
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)}`);
|
|
698
716
|
provingState.reject(`Archive tree mismatch.`);
|
|
699
717
|
return;
|
|
700
718
|
}
|
|
701
719
|
const circuitArchive = output.newArchive;
|
|
702
720
|
if (!newArchive.equals(circuitArchive)) {
|
|
703
|
-
logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
721
|
+
this.logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
704
722
|
provingState.reject(`New archive mismatch.`);
|
|
705
723
|
return;
|
|
706
724
|
}
|
|
707
|
-
// TODO(palla/prover): This closes the fork only on the happy path. If this epoch orchestrator
|
|
708
|
-
// is aborted and never reaches this point, it will leak the fork. We need to add a global cleanup,
|
|
709
|
-
// but have to make sure it only runs once all operations are completed, otherwise some function here
|
|
710
|
-
// will attempt to access the fork after it was closed.
|
|
711
|
-
logger.debug(`Cleaning up world state fork for ${blockNumber}`);
|
|
712
|
-
void this.dbs.get(blockNumber)?.close().then(()=>this.dbs.delete(blockNumber)).catch((err)=>logger.error(`Error closing db for block ${blockNumber}`, err));
|
|
713
725
|
}
|
|
714
726
|
/**
|
|
715
|
-
* Cancel any further proving
|
|
727
|
+
* Cancel any further proving.
|
|
728
|
+
* If cancelJobsOnStop is true, aborts all pending jobs with the broker (which marks them as 'Aborted').
|
|
729
|
+
* If cancelJobsOnStop is false (default), jobs remain in the broker queue and can be reused on restart/reorg.
|
|
716
730
|
*/ cancel() {
|
|
717
|
-
|
|
718
|
-
controller.abort();
|
|
719
|
-
}
|
|
731
|
+
this.resetSchedulerState(this.cancelJobsOnStop);
|
|
720
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;
|
|
721
744
|
}
|
|
722
745
|
/**
|
|
723
746
|
* Returns the proof for the current epoch.
|
|
@@ -737,61 +760,11 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
737
760
|
});
|
|
738
761
|
return epochProofResult;
|
|
739
762
|
}
|
|
740
|
-
/**
|
|
741
|
-
* Enqueue a job to be scheduled
|
|
742
|
-
* @param provingState - The proving state object being operated on
|
|
743
|
-
* @param jobType - The type of job to be queued
|
|
744
|
-
* @param job - The actual job, returns a promise notifying of the job's completion
|
|
745
|
-
*/ deferredProving(provingState, request, callback) {
|
|
746
|
-
if (!provingState.verifyState()) {
|
|
747
|
-
logger.debug(`Not enqueuing job, state no longer valid`);
|
|
748
|
-
return;
|
|
749
|
-
}
|
|
750
|
-
const controller = new AbortController();
|
|
751
|
-
this.pendingProvingJobs.push(controller);
|
|
752
|
-
// We use a 'safeJob'. We don't want promise rejections in the proving pool, we want to capture the error here
|
|
753
|
-
// and reject the proving job whilst keeping the event loop free of rejections
|
|
754
|
-
const safeJob = async ()=>{
|
|
755
|
-
try {
|
|
756
|
-
// there's a delay between enqueueing this job and it actually running
|
|
757
|
-
if (controller.signal.aborted) {
|
|
758
|
-
return;
|
|
759
|
-
}
|
|
760
|
-
const result = await request(controller.signal);
|
|
761
|
-
if (!provingState.verifyState()) {
|
|
762
|
-
logger.debug(`State no longer valid, discarding result`);
|
|
763
|
-
return;
|
|
764
|
-
}
|
|
765
|
-
// we could have been cancelled whilst waiting for the result
|
|
766
|
-
// and the prover ignored the signal. Drop the result in that case
|
|
767
|
-
if (controller.signal.aborted) {
|
|
768
|
-
return;
|
|
769
|
-
}
|
|
770
|
-
await callback(result);
|
|
771
|
-
} catch (err) {
|
|
772
|
-
if (err instanceof AbortError) {
|
|
773
|
-
// operation was cancelled, probably because the block was cancelled
|
|
774
|
-
// drop this result
|
|
775
|
-
return;
|
|
776
|
-
}
|
|
777
|
-
logger.error(`Error thrown when proving job`, err);
|
|
778
|
-
provingState.reject(`${err}`);
|
|
779
|
-
} finally{
|
|
780
|
-
const index = this.pendingProvingJobs.indexOf(controller);
|
|
781
|
-
if (index > -1) {
|
|
782
|
-
this.pendingProvingJobs.splice(index, 1);
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
};
|
|
786
|
-
// let the callstack unwind before adding the job to the queue
|
|
787
|
-
setImmediate(()=>void safeJob());
|
|
788
|
-
}
|
|
789
763
|
async updateL1ToL2MessageTree(l1ToL2Messages, db) {
|
|
790
|
-
const l1ToL2MessagesPadded = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, 'Too many L1 to L2 messages');
|
|
791
764
|
const lastL1ToL2MessageTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
|
|
792
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);
|
|
793
766
|
// Update the local trees to include the new l1 to l2 messages
|
|
794
|
-
await db
|
|
767
|
+
await appendL1ToL2MessagesToTree(db, l1ToL2Messages);
|
|
795
768
|
const newL1ToL2MessageTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
|
|
796
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);
|
|
797
770
|
return {
|
|
@@ -830,17 +803,17 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
830
803
|
// Executes the next level of merge if all inputs are available
|
|
831
804
|
enqueueBaseRollup(provingState, txIndex) {
|
|
832
805
|
if (!provingState.verifyState()) {
|
|
833
|
-
logger.debug('Not running base rollup, state invalid');
|
|
806
|
+
this.logger.debug('Not running base rollup, state invalid');
|
|
834
807
|
return;
|
|
835
808
|
}
|
|
836
809
|
if (!provingState.tryStartProvingBase(txIndex)) {
|
|
837
|
-
logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
810
|
+
this.logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
838
811
|
return;
|
|
839
812
|
}
|
|
840
813
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
841
814
|
const { processedTx } = txProvingState;
|
|
842
815
|
const { rollupType, inputs } = txProvingState.getBaseRollupTypeAndInputs();
|
|
843
|
-
logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
816
|
+
this.logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
844
817
|
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, `ProvingOrchestrator.prover.${inputs instanceof PrivateTxBaseRollupPrivateInputs ? 'getPrivateTxBaseRollupProof' : 'getPublicTxBaseRollupProof'}`, {
|
|
845
818
|
[Attributes.TX_HASH]: processedTx.hash.toString(),
|
|
846
819
|
[Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
|
|
@@ -851,7 +824,7 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
851
824
|
return this.prover.getPublicTxBaseRollupProof(inputs, signal, provingState.epochNumber);
|
|
852
825
|
}
|
|
853
826
|
}), (result)=>{
|
|
854
|
-
logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
827
|
+
this.logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
855
828
|
validatePartialState(result.inputs.endTreeSnapshots, txProvingState.treeSnapshots);
|
|
856
829
|
const leafLocation = provingState.setBaseRollupProof(txIndex, result);
|
|
857
830
|
if (provingState.totalNumTxs === 1) {
|
|
@@ -865,14 +838,13 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
865
838
|
// Once completed, will enqueue the the public tx base rollup.
|
|
866
839
|
getOrEnqueueChonkVerifier(provingState, txIndex) {
|
|
867
840
|
if (!provingState.verifyState()) {
|
|
868
|
-
logger.debug('Not running chonk verifier circuit, state invalid');
|
|
841
|
+
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
869
842
|
return;
|
|
870
843
|
}
|
|
871
844
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
872
845
|
const txHash = txProvingState.processedTx.hash.toString();
|
|
873
|
-
NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH;
|
|
874
846
|
const handleResult = (result)=>{
|
|
875
|
-
logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, {
|
|
847
|
+
this.logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, {
|
|
876
848
|
txHash
|
|
877
849
|
});
|
|
878
850
|
txProvingState.setPublicChonkVerifierProof(result);
|
|
@@ -880,18 +852,18 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
880
852
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
881
853
|
};
|
|
882
854
|
if (this.provingState?.cachedChonkVerifierProofs.has(txHash)) {
|
|
883
|
-
logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, {
|
|
855
|
+
this.logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, {
|
|
884
856
|
txHash
|
|
885
857
|
});
|
|
886
858
|
void this.provingState.cachedChonkVerifierProofs.get(txHash).then(handleResult);
|
|
887
859
|
return;
|
|
888
860
|
}
|
|
889
|
-
logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
|
|
861
|
+
this.logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
|
|
890
862
|
this.doEnqueueChonkVerifier(txHash, txProvingState.getPublicChonkVerifierPrivateInputs(), handleResult);
|
|
891
863
|
}
|
|
892
864
|
doEnqueueChonkVerifier(txHash, inputs, handler, provingState = this.provingState) {
|
|
893
865
|
if (!provingState.verifyState()) {
|
|
894
|
-
logger.debug('Not running chonk verifier circuit, state invalid');
|
|
866
|
+
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
895
867
|
return;
|
|
896
868
|
}
|
|
897
869
|
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getPublicChonkVerifierProof', {
|
|
@@ -903,11 +875,11 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
903
875
|
// Enqueues the next level of merge if all inputs are available
|
|
904
876
|
enqueueMergeRollup(provingState, location) {
|
|
905
877
|
if (!provingState.verifyState()) {
|
|
906
|
-
logger.debug('Not running merge rollup. State no longer valid.');
|
|
878
|
+
this.logger.debug('Not running merge rollup. State no longer valid.');
|
|
907
879
|
return;
|
|
908
880
|
}
|
|
909
881
|
if (!provingState.tryStartProvingMerge(location)) {
|
|
910
|
-
logger.debug('Merge rollup already started.');
|
|
882
|
+
this.logger.debug('Merge rollup already started.');
|
|
911
883
|
return;
|
|
912
884
|
}
|
|
913
885
|
const inputs = provingState.getMergeRollupInputs(location);
|
|
@@ -921,15 +893,15 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
921
893
|
// Executes the block root rollup circuit
|
|
922
894
|
enqueueBlockRootRollup(provingState) {
|
|
923
895
|
if (!provingState.verifyState()) {
|
|
924
|
-
logger.debug('Not running block root rollup, state no longer valid');
|
|
896
|
+
this.logger.debug('Not running block root rollup, state no longer valid');
|
|
925
897
|
return;
|
|
926
898
|
}
|
|
927
899
|
if (!provingState.tryStartProvingBlockRoot()) {
|
|
928
|
-
logger.debug('Block root rollup already started.');
|
|
900
|
+
this.logger.debug('Block root rollup already started.');
|
|
929
901
|
return;
|
|
930
902
|
}
|
|
931
903
|
const { rollupType, inputs } = provingState.getBlockRootRollupTypeAndInputs();
|
|
932
|
-
logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
904
|
+
this.logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
933
905
|
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getBlockRootRollupProof', {
|
|
934
906
|
[Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
|
|
935
907
|
}, (signal)=>{
|
|
@@ -945,15 +917,20 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
945
917
|
return this.prover.getBlockRootRollupProof(inputs, signal, provingState.epochNumber);
|
|
946
918
|
}
|
|
947
919
|
}), async (result)=>{
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
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
|
+
});
|
|
951
925
|
const leafLocation = provingState.setBlockRootRollupProof(result);
|
|
952
926
|
const checkpointProvingState = provingState.parentCheckpoint;
|
|
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.
|
|
929
|
+
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
953
930
|
if (checkpointProvingState.totalNumBlocks === 1) {
|
|
954
|
-
this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
931
|
+
await this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
955
932
|
} else {
|
|
956
|
-
this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
933
|
+
await this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
957
934
|
}
|
|
958
935
|
});
|
|
959
936
|
}
|
|
@@ -961,11 +938,11 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
961
938
|
// Enqueues the root parity circuit if all inputs are available
|
|
962
939
|
enqueueBaseParityCircuit(checkpointProvingState, provingState, baseParityIndex) {
|
|
963
940
|
if (!provingState.verifyState()) {
|
|
964
|
-
logger.debug('Not running base parity. State no longer valid.');
|
|
941
|
+
this.logger.debug('Not running base parity. State no longer valid.');
|
|
965
942
|
return;
|
|
966
943
|
}
|
|
967
944
|
if (!provingState.tryStartProvingBaseParity(baseParityIndex)) {
|
|
968
|
-
logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
945
|
+
this.logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
969
946
|
return;
|
|
970
947
|
}
|
|
971
948
|
const inputs = checkpointProvingState.getBaseParityInputs(baseParityIndex);
|
|
@@ -986,11 +963,11 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
986
963
|
// Enqueues the root rollup proof if all inputs are available
|
|
987
964
|
enqueueRootParityCircuit(provingState) {
|
|
988
965
|
if (!provingState.verifyState()) {
|
|
989
|
-
logger.debug('Not running root parity. State no longer valid.');
|
|
966
|
+
this.logger.debug('Not running root parity. State no longer valid.');
|
|
990
967
|
return;
|
|
991
968
|
}
|
|
992
969
|
if (!provingState.tryStartProvingRootParity()) {
|
|
993
|
-
logger.debug('Root parity already started.');
|
|
970
|
+
this.logger.debug('Root parity already started.');
|
|
994
971
|
return;
|
|
995
972
|
}
|
|
996
973
|
const inputs = provingState.getParityRootInputs();
|
|
@@ -1005,33 +982,38 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
1005
982
|
// Enqueues the next level of merge if all inputs are available
|
|
1006
983
|
enqueueBlockMergeRollup(provingState, location) {
|
|
1007
984
|
if (!provingState.verifyState()) {
|
|
1008
|
-
logger.debug('Not running block merge rollup. State no longer valid.');
|
|
985
|
+
this.logger.debug('Not running block merge rollup. State no longer valid.');
|
|
1009
986
|
return;
|
|
1010
987
|
}
|
|
1011
988
|
if (!provingState.tryStartProvingBlockMerge(location)) {
|
|
1012
|
-
logger.debug('Block merge rollup already started.');
|
|
989
|
+
this.logger.debug('Block merge rollup already started.');
|
|
1013
990
|
return;
|
|
1014
991
|
}
|
|
1015
992
|
const inputs = provingState.getBlockMergeRollupInputs(location);
|
|
1016
993
|
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getBlockMergeRollupProof', {
|
|
1017
994
|
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-block-merge'
|
|
1018
|
-
}, (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
|
+
});
|
|
1019
1001
|
provingState.setBlockMergeRollupProof(location, result);
|
|
1020
|
-
this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
1002
|
+
await this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
1021
1003
|
});
|
|
1022
1004
|
}
|
|
1023
|
-
enqueueCheckpointRootRollup(provingState) {
|
|
1005
|
+
async enqueueCheckpointRootRollup(provingState) {
|
|
1024
1006
|
if (!provingState.verifyState()) {
|
|
1025
|
-
logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
1007
|
+
this.logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
1026
1008
|
return;
|
|
1027
1009
|
}
|
|
1028
1010
|
if (!provingState.tryStartProvingCheckpointRoot()) {
|
|
1029
|
-
logger.debug('Checkpoint root rollup already started.');
|
|
1011
|
+
this.logger.debug('Checkpoint root rollup already started.');
|
|
1030
1012
|
return;
|
|
1031
1013
|
}
|
|
1032
1014
|
const rollupType = provingState.getCheckpointRootRollupType();
|
|
1033
|
-
logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
1034
|
-
const inputs = provingState.getCheckpointRootRollupInputs();
|
|
1015
|
+
this.logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
1016
|
+
const inputs = await provingState.getCheckpointRootRollupInputs();
|
|
1035
1017
|
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getCheckpointRootRollupProof', {
|
|
1036
1018
|
[Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType
|
|
1037
1019
|
}, (signal)=>{
|
|
@@ -1044,11 +1026,14 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
1044
1026
|
const computedEndBlobAccumulatorState = provingState.getEndBlobAccumulator().toBlobAccumulator();
|
|
1045
1027
|
const circuitEndBlobAccumulatorState = result.inputs.endBlobAccumulator;
|
|
1046
1028
|
if (!circuitEndBlobAccumulatorState.equals(computedEndBlobAccumulatorState)) {
|
|
1047
|
-
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)}`);
|
|
1048
1030
|
provingState.reject(`Blob accumulator state mismatch.`);
|
|
1049
1031
|
return;
|
|
1050
1032
|
}
|
|
1051
|
-
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
|
+
});
|
|
1052
1037
|
const leafLocation = provingState.setCheckpointRootRollupProof(result);
|
|
1053
1038
|
const epochProvingState = provingState.parentEpoch;
|
|
1054
1039
|
if (epochProvingState.totalNumCheckpoints === 1) {
|
|
@@ -1058,61 +1043,6 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
1058
1043
|
}
|
|
1059
1044
|
});
|
|
1060
1045
|
}
|
|
1061
|
-
enqueueCheckpointMergeRollup(provingState, location) {
|
|
1062
|
-
if (!provingState.verifyState()) {
|
|
1063
|
-
logger.debug('Not running checkpoint merge rollup. State no longer valid.');
|
|
1064
|
-
return;
|
|
1065
|
-
}
|
|
1066
|
-
if (!provingState.tryStartProvingCheckpointMerge(location)) {
|
|
1067
|
-
logger.debug('Checkpoint merge rollup already started.');
|
|
1068
|
-
return;
|
|
1069
|
-
}
|
|
1070
|
-
const inputs = provingState.getCheckpointMergeRollupInputs(location);
|
|
1071
|
-
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getCheckpointMergeRollupProof', {
|
|
1072
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-checkpoint-merge'
|
|
1073
|
-
}, (signal)=>this.prover.getCheckpointMergeRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
|
|
1074
|
-
logger.debug('Completed proof for checkpoint merge rollup.');
|
|
1075
|
-
provingState.setCheckpointMergeRollupProof(location, result);
|
|
1076
|
-
this.checkAndEnqueueNextCheckpointMergeRollup(provingState, location);
|
|
1077
|
-
});
|
|
1078
|
-
}
|
|
1079
|
-
enqueueEpochPadding(provingState) {
|
|
1080
|
-
if (!provingState.verifyState()) {
|
|
1081
|
-
logger.debug('Not running epoch padding. State no longer valid.');
|
|
1082
|
-
return;
|
|
1083
|
-
}
|
|
1084
|
-
if (!provingState.tryStartProvingPaddingCheckpoint()) {
|
|
1085
|
-
logger.debug('Padding checkpoint already started.');
|
|
1086
|
-
return;
|
|
1087
|
-
}
|
|
1088
|
-
logger.debug('Padding epoch proof with a padding block root proof.');
|
|
1089
|
-
const inputs = provingState.getPaddingCheckpointInputs();
|
|
1090
|
-
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getCheckpointPaddingRollupProof', {
|
|
1091
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-checkpoint-padding'
|
|
1092
|
-
}, (signal)=>this.prover.getCheckpointPaddingRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
|
|
1093
|
-
logger.debug('Completed proof for padding checkpoint.');
|
|
1094
|
-
provingState.setCheckpointPaddingProof(result);
|
|
1095
|
-
this.checkAndEnqueueRootRollup(provingState);
|
|
1096
|
-
});
|
|
1097
|
-
}
|
|
1098
|
-
// Executes the root rollup circuit
|
|
1099
|
-
enqueueRootRollup(provingState) {
|
|
1100
|
-
if (!provingState.verifyState()) {
|
|
1101
|
-
logger.debug('Not running root rollup, state no longer valid');
|
|
1102
|
-
return;
|
|
1103
|
-
}
|
|
1104
|
-
logger.debug(`Preparing root rollup`);
|
|
1105
|
-
const inputs = provingState.getRootRollupInputs();
|
|
1106
|
-
this.deferredProving(provingState, wrapCallbackInSpan(this.tracer, 'ProvingOrchestrator.prover.getRootRollupProof', {
|
|
1107
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-root'
|
|
1108
|
-
}, (signal)=>this.prover.getRootRollupProof(inputs, signal, provingState.epochNumber)), (result)=>{
|
|
1109
|
-
logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
|
|
1110
|
-
provingState.setRootRollupProof(result);
|
|
1111
|
-
provingState.resolve({
|
|
1112
|
-
status: 'success'
|
|
1113
|
-
});
|
|
1114
|
-
});
|
|
1115
|
-
}
|
|
1116
1046
|
checkAndEnqueueNextMergeRollup(provingState, currentLocation) {
|
|
1117
1047
|
if (!provingState.isReadyForMergeRollup(currentLocation)) {
|
|
1118
1048
|
return;
|
|
@@ -1126,45 +1056,27 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
1126
1056
|
}
|
|
1127
1057
|
checkAndEnqueueBlockRootRollup(provingState) {
|
|
1128
1058
|
if (!provingState.isReadyForBlockRootRollup()) {
|
|
1129
|
-
logger.debug('Not ready for block root rollup');
|
|
1059
|
+
this.logger.debug('Not ready for block root rollup');
|
|
1130
1060
|
return;
|
|
1131
1061
|
}
|
|
1132
1062
|
this.enqueueBlockRootRollup(provingState);
|
|
1133
1063
|
}
|
|
1134
|
-
checkAndEnqueueNextBlockMergeRollup(provingState, currentLocation) {
|
|
1064
|
+
async checkAndEnqueueNextBlockMergeRollup(provingState, currentLocation) {
|
|
1135
1065
|
if (!provingState.isReadyForBlockMerge(currentLocation)) {
|
|
1136
1066
|
return;
|
|
1137
1067
|
}
|
|
1138
1068
|
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
1139
1069
|
if (parentLocation.level === 0) {
|
|
1140
|
-
this.checkAndEnqueueCheckpointRootRollup(provingState);
|
|
1070
|
+
await this.checkAndEnqueueCheckpointRootRollup(provingState);
|
|
1141
1071
|
} else {
|
|
1142
1072
|
this.enqueueBlockMergeRollup(provingState, parentLocation);
|
|
1143
1073
|
}
|
|
1144
1074
|
}
|
|
1145
|
-
checkAndEnqueueCheckpointRootRollup(provingState) {
|
|
1075
|
+
async checkAndEnqueueCheckpointRootRollup(provingState) {
|
|
1146
1076
|
if (!provingState.isReadyForCheckpointRoot()) {
|
|
1147
1077
|
return;
|
|
1148
1078
|
}
|
|
1149
|
-
this.enqueueCheckpointRootRollup(provingState);
|
|
1150
|
-
}
|
|
1151
|
-
checkAndEnqueueNextCheckpointMergeRollup(provingState, currentLocation) {
|
|
1152
|
-
if (!provingState.isReadyForCheckpointMerge(currentLocation)) {
|
|
1153
|
-
return;
|
|
1154
|
-
}
|
|
1155
|
-
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
1156
|
-
if (parentLocation.level === 0) {
|
|
1157
|
-
this.checkAndEnqueueRootRollup(provingState);
|
|
1158
|
-
} else {
|
|
1159
|
-
this.enqueueCheckpointMergeRollup(provingState, parentLocation);
|
|
1160
|
-
}
|
|
1161
|
-
}
|
|
1162
|
-
checkAndEnqueueRootRollup(provingState) {
|
|
1163
|
-
if (!provingState.isReadyForRootRollup()) {
|
|
1164
|
-
logger.debug('Not ready for root rollup');
|
|
1165
|
-
return;
|
|
1166
|
-
}
|
|
1167
|
-
this.enqueueRootRollup(provingState);
|
|
1079
|
+
await this.enqueueCheckpointRootRollup(provingState);
|
|
1168
1080
|
}
|
|
1169
1081
|
/**
|
|
1170
1082
|
* Executes the VM circuit for a public function, will enqueue the corresponding kernel if the
|
|
@@ -1173,7 +1085,7 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
1173
1085
|
* @param txIndex - The index of the transaction being proven
|
|
1174
1086
|
*/ enqueueVM(provingState, txIndex) {
|
|
1175
1087
|
if (!provingState.verifyState()) {
|
|
1176
|
-
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`);
|
|
1177
1089
|
return;
|
|
1178
1090
|
}
|
|
1179
1091
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
@@ -1184,7 +1096,7 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
1184
1096
|
return await this.prover.getAvmProof(inputs, signal, provingState.epochNumber);
|
|
1185
1097
|
});
|
|
1186
1098
|
this.deferredProving(provingState, doAvmProving, (proof)=>{
|
|
1187
|
-
logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1099
|
+
this.logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1188
1100
|
txProvingState.setAvmProof(proof);
|
|
1189
1101
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
1190
1102
|
});
|
|
@@ -1195,7 +1107,7 @@ _dec = trackSpan('ProvingOrchestrator.startNewBlock', (blockNumber)=>({
|
|
|
1195
1107
|
return;
|
|
1196
1108
|
}
|
|
1197
1109
|
// We must have completed all proving (chonk verifier proof and (if required) vm proof are generated), we now move to the base rollup.
|
|
1198
|
-
logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1110
|
+
this.logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1199
1111
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
1200
1112
|
}
|
|
1201
1113
|
}
|