@aztec/prover-client 0.0.1-commit.b655e406 → 0.0.1-commit.c31f2472
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/config.d.ts +2 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +1 -1
- package/dest/index.d.ts +1 -1
- package/dest/light/index.d.ts +2 -0
- package/dest/light/index.d.ts.map +1 -0
- package/dest/light/index.js +1 -0
- package/dest/light/lightweight_checkpoint_builder.d.ts +45 -0
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -0
- package/dest/light/lightweight_checkpoint_builder.js +197 -0
- package/dest/mocks/fixtures.d.ts +1 -4
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +9 -18
- package/dest/mocks/test_context.d.ts +29 -46
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +116 -116
- package/dest/orchestrator/block-building-helpers.d.ts +17 -19
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +88 -113
- package/dest/orchestrator/block-proving-state.d.ts +17 -11
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +81 -20
- package/dest/orchestrator/checkpoint-proving-state.d.ts +22 -9
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/checkpoint-proving-state.js +49 -17
- package/dest/orchestrator/epoch-proving-state.d.ts +12 -10
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +38 -4
- package/dest/orchestrator/index.d.ts +1 -1
- package/dest/orchestrator/orchestrator.d.ts +26 -11
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +556 -161
- package/dest/orchestrator/orchestrator_metrics.d.ts +1 -3
- package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator_metrics.js +2 -15
- package/dest/orchestrator/tx-proving-state.d.ts +6 -5
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +7 -16
- package/dest/prover-client/factory.d.ts +3 -3
- package/dest/prover-client/factory.d.ts.map +1 -1
- package/dest/prover-client/index.d.ts +1 -1
- package/dest/prover-client/prover-client.d.ts +3 -3
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +7 -4
- package/dest/prover-client/server-epoch-prover.d.ts +8 -7
- package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
- package/dest/prover-client/server-epoch-prover.js +2 -2
- package/dest/proving_broker/broker_prover_facade.d.ts +25 -23
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +9 -15
- package/dest/proving_broker/config.d.ts +16 -8
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +14 -2
- package/dest/proving_broker/factory.d.ts +1 -1
- package/dest/proving_broker/fixtures.d.ts +3 -2
- package/dest/proving_broker/fixtures.d.ts.map +1 -1
- package/dest/proving_broker/fixtures.js +3 -2
- package/dest/proving_broker/index.d.ts +1 -1
- package/dest/proving_broker/proof_store/factory.d.ts +2 -2
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +1 -1
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/index.d.ts +1 -1
- package/dest/proving_broker/proof_store/inline_proof_store.d.ts +1 -1
- package/dest/proving_broker/proof_store/inline_proof_store.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/proof_store.d.ts +1 -1
- package/dest/proving_broker/proving_agent.d.ts +5 -9
- package/dest/proving_broker/proving_agent.d.ts.map +1 -1
- package/dest/proving_broker/proving_agent.js +4 -19
- package/dest/proving_broker/proving_broker.d.ts +2 -2
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +6 -11
- package/dest/proving_broker/proving_broker_database/memory.d.ts +3 -2
- package/dest/proving_broker/proving_broker_database/memory.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.d.ts +5 -3
- package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.js +392 -3
- package/dest/proving_broker/proving_broker_database.d.ts +3 -2
- package/dest/proving_broker/proving_broker_database.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.d.ts +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.js +15 -35
- package/dest/proving_broker/proving_job_controller.d.ts +5 -3
- package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
- package/dest/proving_broker/proving_job_controller.js +8 -6
- package/dest/proving_broker/rpc.d.ts +4 -4
- package/dest/test/mock_proof_store.d.ts +1 -1
- package/dest/test/mock_proof_store.d.ts.map +1 -1
- package/dest/test/mock_prover.d.ts +3 -4
- package/dest/test/mock_prover.d.ts.map +1 -1
- package/dest/test/mock_prover.js +4 -4
- package/package.json +20 -18
- package/src/config.ts +1 -1
- package/src/light/index.ts +1 -0
- package/src/light/lightweight_checkpoint_builder.ts +284 -0
- package/src/mocks/fixtures.ts +9 -31
- package/src/mocks/test_context.ts +158 -177
- package/src/orchestrator/block-building-helpers.ts +127 -207
- package/src/orchestrator/block-proving-state.ts +103 -25
- package/src/orchestrator/checkpoint-proving-state.ts +71 -21
- package/src/orchestrator/epoch-proving-state.ts +64 -14
- package/src/orchestrator/orchestrator.ts +158 -149
- package/src/orchestrator/orchestrator_metrics.ts +2 -25
- package/src/orchestrator/tx-proving-state.ts +10 -27
- package/src/prover-client/factory.ts +6 -2
- package/src/prover-client/prover-client.ts +25 -15
- package/src/prover-client/server-epoch-prover.ts +6 -7
- package/src/proving_broker/broker_prover_facade.ts +31 -37
- package/src/proving_broker/config.ts +17 -1
- package/src/proving_broker/fixtures.ts +8 -3
- package/src/proving_broker/proving_agent.ts +6 -19
- package/src/proving_broker/proving_broker.ts +6 -9
- package/src/proving_broker/proving_broker_database/memory.ts +2 -1
- package/src/proving_broker/proving_broker_database/persisted.ts +20 -5
- package/src/proving_broker/proving_broker_database.ts +2 -1
- package/src/proving_broker/proving_broker_instrumentation.ts +14 -35
- package/src/proving_broker/proving_job_controller.ts +13 -7
- package/src/test/mock_prover.ts +2 -14
- package/dest/block-factory/index.d.ts +0 -2
- package/dest/block-factory/index.d.ts.map +0 -1
- package/dest/block-factory/index.js +0 -1
- package/dest/block-factory/light.d.ts +0 -38
- package/dest/block-factory/light.d.ts.map +0 -1
- package/dest/block-factory/light.js +0 -94
- package/dest/proving_broker/proving_agent_instrumentation.d.ts +0 -8
- package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +0 -1
- package/dest/proving_broker/proving_agent_instrumentation.js +0 -16
- package/src/block-factory/index.ts +0 -1
- package/src/block-factory/light.ts +0 -140
- package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BatchedBlob, FinalBlobBatchingChallenges, SpongeBlob } from '@aztec/blob-lib';
|
|
1
|
+
import { BatchedBlob, FinalBlobBatchingChallenges, SpongeBlob } from '@aztec/blob-lib/types';
|
|
2
2
|
import {
|
|
3
3
|
L1_TO_L2_MSG_SUBTREE_HEIGHT,
|
|
4
4
|
L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
|
|
@@ -6,22 +6,23 @@ import {
|
|
|
6
6
|
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
7
7
|
NUM_BASE_PARITY_PER_ROOT_PARITY,
|
|
8
8
|
} from '@aztec/constants';
|
|
9
|
+
import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
9
10
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
11
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
10
12
|
import { AbortError } from '@aztec/foundation/error';
|
|
11
|
-
import {
|
|
12
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
13
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
13
14
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
14
15
|
import { assertLength } from '@aztec/foundation/serialize';
|
|
15
16
|
import { pushTestData } from '@aztec/foundation/testing';
|
|
16
17
|
import { elapsed } from '@aztec/foundation/timer';
|
|
17
18
|
import type { TreeNodeLocation } from '@aztec/foundation/trees';
|
|
18
|
-
import {
|
|
19
|
-
import { EthAddress, createBlockEndMarker } from '@aztec/stdlib/block';
|
|
19
|
+
import { EthAddress } from '@aztec/stdlib/block';
|
|
20
20
|
import type {
|
|
21
21
|
EpochProver,
|
|
22
22
|
ForkMerkleTreeOperations,
|
|
23
23
|
MerkleTreeWriteOperations,
|
|
24
24
|
PublicInputsAndRecursiveProof,
|
|
25
|
+
ReadonlyWorldStateAccess,
|
|
25
26
|
ServerCircuitProver,
|
|
26
27
|
} from '@aztec/stdlib/interfaces/server';
|
|
27
28
|
import type { Proof } from '@aztec/stdlib/proofs';
|
|
@@ -54,7 +55,6 @@ import {
|
|
|
54
55
|
import { inspect } from 'util';
|
|
55
56
|
|
|
56
57
|
import {
|
|
57
|
-
buildBlockHeaderFromTxs,
|
|
58
58
|
buildHeaderFromCircuitOutputs,
|
|
59
59
|
getLastSiblingPath,
|
|
60
60
|
getPublicChonkVerifierPrivateInputsFromTx,
|
|
@@ -71,7 +71,10 @@ import { EpochProvingState, type ProvingResult, type TreeSnapshots } from './epo
|
|
|
71
71
|
import { ProvingOrchestratorMetrics } from './orchestrator_metrics.js';
|
|
72
72
|
import { TxProvingState } from './tx-proving-state.js';
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
type WorldStateFork = {
|
|
75
|
+
fork: MerkleTreeWriteOperations;
|
|
76
|
+
cleanupPromise: Promise<void> | undefined;
|
|
77
|
+
};
|
|
75
78
|
|
|
76
79
|
/**
|
|
77
80
|
* Implements an event driven proving scheduler to build the recursive proof tree. The idea being:
|
|
@@ -93,14 +96,19 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
93
96
|
|
|
94
97
|
private provingPromise: Promise<ProvingResult> | undefined = undefined;
|
|
95
98
|
private metrics: ProvingOrchestratorMetrics;
|
|
96
|
-
|
|
99
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
100
|
+
private dbs: Map<BlockNumber, WorldStateFork> = new Map();
|
|
101
|
+
private logger: Logger;
|
|
97
102
|
|
|
98
103
|
constructor(
|
|
99
|
-
private dbProvider: ForkMerkleTreeOperations,
|
|
104
|
+
private dbProvider: ReadonlyWorldStateAccess & ForkMerkleTreeOperations,
|
|
100
105
|
private prover: ServerCircuitProver,
|
|
101
106
|
private readonly proverId: EthAddress,
|
|
107
|
+
private readonly cancelJobsOnStop: boolean = false,
|
|
102
108
|
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
109
|
+
bindings?: LoggerBindings,
|
|
103
110
|
) {
|
|
111
|
+
this.logger = createLogger('prover-client:orchestrator', bindings);
|
|
104
112
|
this.metrics = new ProvingOrchestratorMetrics(telemetryClient, 'ProvingOrchestrator');
|
|
105
113
|
}
|
|
106
114
|
|
|
@@ -112,13 +120,17 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
112
120
|
return this.proverId;
|
|
113
121
|
}
|
|
114
122
|
|
|
123
|
+
public getNumActiveForks() {
|
|
124
|
+
return this.dbs.size;
|
|
125
|
+
}
|
|
126
|
+
|
|
115
127
|
public stop(): Promise<void> {
|
|
116
128
|
this.cancel();
|
|
117
129
|
return Promise.resolve();
|
|
118
130
|
}
|
|
119
131
|
|
|
120
132
|
public startNewEpoch(
|
|
121
|
-
epochNumber:
|
|
133
|
+
epochNumber: EpochNumber,
|
|
122
134
|
totalNumCheckpoints: number,
|
|
123
135
|
finalBlobBatchingChallenges: FinalBlobBatchingChallenges,
|
|
124
136
|
) {
|
|
@@ -130,7 +142,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
130
142
|
|
|
131
143
|
const { promise: _promise, resolve, reject } = promiseWithResolvers<ProvingResult>();
|
|
132
144
|
const promise = _promise.catch((reason): ProvingResult => ({ status: 'failure', reason }));
|
|
133
|
-
logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
|
|
145
|
+
this.logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
|
|
134
146
|
this.provingState = new EpochProvingState(
|
|
135
147
|
epochNumber,
|
|
136
148
|
totalNumCheckpoints,
|
|
@@ -142,12 +154,19 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
142
154
|
this.provingPromise = promise;
|
|
143
155
|
}
|
|
144
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Starts a new checkpoint.
|
|
159
|
+
* @param checkpointIndex - The index of the checkpoint in the epoch.
|
|
160
|
+
* @param constants - The constants for this checkpoint.
|
|
161
|
+
* @param l1ToL2Messages - The set of L1 to L2 messages to be inserted at the beginning of this checkpoint.
|
|
162
|
+
* @param totalNumBlocks - The total number of blocks expected in the checkpoint (must be at least one).
|
|
163
|
+
* @param headerOfLastBlockInPreviousCheckpoint - The header of the last block in the previous checkpoint.
|
|
164
|
+
*/
|
|
145
165
|
public async startNewCheckpoint(
|
|
146
166
|
checkpointIndex: number,
|
|
147
167
|
constants: CheckpointConstantData,
|
|
148
168
|
l1ToL2Messages: Fr[],
|
|
149
169
|
totalNumBlocks: number,
|
|
150
|
-
totalNumBlobFields: number,
|
|
151
170
|
headerOfLastBlockInPreviousCheckpoint: BlockHeader,
|
|
152
171
|
) {
|
|
153
172
|
if (!this.provingState) {
|
|
@@ -162,8 +181,8 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
162
181
|
const lastBlockNumber = headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber;
|
|
163
182
|
const db = await this.dbProvider.fork(lastBlockNumber);
|
|
164
183
|
|
|
165
|
-
const firstBlockNumber = lastBlockNumber + 1;
|
|
166
|
-
this.dbs.set(firstBlockNumber, db);
|
|
184
|
+
const firstBlockNumber = BlockNumber(lastBlockNumber + 1);
|
|
185
|
+
this.dbs.set(firstBlockNumber, { fork: db, cleanupPromise: undefined });
|
|
167
186
|
|
|
168
187
|
// Get archive sibling path before any block in this checkpoint lands.
|
|
169
188
|
const lastArchiveSiblingPath = await getLastSiblingPath(MerkleTreeId.ARCHIVE, db);
|
|
@@ -180,7 +199,6 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
180
199
|
checkpointIndex,
|
|
181
200
|
constants,
|
|
182
201
|
totalNumBlocks,
|
|
183
|
-
totalNumBlobFields,
|
|
184
202
|
headerOfLastBlockInPreviousCheckpoint,
|
|
185
203
|
lastArchiveSiblingPath,
|
|
186
204
|
l1ToL2Messages,
|
|
@@ -201,7 +219,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
201
219
|
@trackSpan('ProvingOrchestrator.startNewBlock', blockNumber => ({
|
|
202
220
|
[Attributes.BLOCK_NUMBER]: blockNumber,
|
|
203
221
|
}))
|
|
204
|
-
public async startNewBlock(blockNumber:
|
|
222
|
+
public async startNewBlock(blockNumber: BlockNumber, timestamp: UInt64, totalNumTxs: number) {
|
|
205
223
|
if (!this.provingState) {
|
|
206
224
|
throw new Error('Empty epoch proving state. Call startNewEpoch before starting a block.');
|
|
207
225
|
}
|
|
@@ -216,21 +234,21 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
216
234
|
}
|
|
217
235
|
|
|
218
236
|
const constants = checkpointProvingState.constants;
|
|
219
|
-
logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber
|
|
237
|
+
this.logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
|
|
220
238
|
|
|
221
239
|
// Fork the db only when it's not already set. The db for the first block is set in `startNewCheckpoint`.
|
|
222
240
|
if (!this.dbs.has(blockNumber)) {
|
|
223
241
|
// Fork world state at the end of the immediately previous block
|
|
224
|
-
const db = await this.dbProvider.fork(blockNumber - 1);
|
|
225
|
-
this.dbs.set(blockNumber, db);
|
|
242
|
+
const db = await this.dbProvider.fork(BlockNumber(blockNumber - 1));
|
|
243
|
+
this.dbs.set(blockNumber, { fork: db, cleanupPromise: undefined });
|
|
226
244
|
}
|
|
227
|
-
const db = this.dbs.get(blockNumber)
|
|
245
|
+
const db = this.dbs.get(blockNumber)!.fork;
|
|
228
246
|
|
|
229
247
|
// Get archive snapshot and sibling path before any txs in this block lands.
|
|
230
248
|
const lastArchiveTreeSnapshot = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
231
249
|
const lastArchiveSiblingPath = await getRootTreeSiblingPath(MerkleTreeId.ARCHIVE, db);
|
|
232
250
|
|
|
233
|
-
const blockProvingState =
|
|
251
|
+
const blockProvingState = checkpointProvingState.startNewBlock(
|
|
234
252
|
blockNumber,
|
|
235
253
|
timestamp,
|
|
236
254
|
totalNumTxs,
|
|
@@ -248,11 +266,16 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
248
266
|
// Because `addTxs` won't be called for a block without txs, and that's where the sponge blob state is computed.
|
|
249
267
|
// We need to set its end sponge blob here, which will become the start sponge blob for the next block.
|
|
250
268
|
if (totalNumTxs === 0) {
|
|
269
|
+
const endState = await db.getStateReference();
|
|
270
|
+
blockProvingState.setEndState(endState);
|
|
271
|
+
|
|
251
272
|
const endSpongeBlob = blockProvingState.getStartSpongeBlob().clone();
|
|
252
|
-
|
|
273
|
+
const blockEndBlobFields = blockProvingState.getBlockEndBlobFields();
|
|
274
|
+
await endSpongeBlob.absorb(blockEndBlobFields);
|
|
253
275
|
blockProvingState.setEndSpongeBlob(endSpongeBlob);
|
|
254
276
|
|
|
255
|
-
//
|
|
277
|
+
// Try to accumulate the out hashes and blobs as far as we can:
|
|
278
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
256
279
|
await this.provingState.setBlobAccumulators();
|
|
257
280
|
}
|
|
258
281
|
}
|
|
@@ -272,11 +295,11 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
272
295
|
if (!txs.length) {
|
|
273
296
|
// To avoid an ugly throw below. If we require an empty block, we can just call setBlockCompleted
|
|
274
297
|
// on a block with no txs. We cannot do that here because we cannot find the blockNumber without any txs.
|
|
275
|
-
logger.warn(`Provided no txs to orchestrator addTxs.`);
|
|
298
|
+
this.logger.warn(`Provided no txs to orchestrator addTxs.`);
|
|
276
299
|
return;
|
|
277
300
|
}
|
|
278
301
|
|
|
279
|
-
const blockNumber = txs[0].globalVariables.blockNumber;
|
|
302
|
+
const blockNumber = BlockNumber(txs[0].globalVariables.blockNumber);
|
|
280
303
|
const provingState = this.provingState.getBlockProvingStateByBlockNumber(blockNumber!);
|
|
281
304
|
if (!provingState) {
|
|
282
305
|
throw new Error(`Proving state for block ${blockNumber} not found. Call startNewBlock first.`);
|
|
@@ -292,9 +315,9 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
292
315
|
throw new Error(`Block ${blockNumber} has been initialized with transactions.`);
|
|
293
316
|
}
|
|
294
317
|
|
|
295
|
-
logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
318
|
+
this.logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
296
319
|
|
|
297
|
-
const db = this.dbs.get(blockNumber)
|
|
320
|
+
const db = this.dbs.get(blockNumber)!.fork;
|
|
298
321
|
const lastArchive = provingState.lastArchiveTreeSnapshot;
|
|
299
322
|
const newL1ToL2MessageTreeSnapshot = provingState.newL1ToL2MessageTreeSnapshot;
|
|
300
323
|
const spongeBlobState = provingState.getStartSpongeBlob().clone();
|
|
@@ -307,7 +330,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
307
330
|
|
|
308
331
|
validateTx(tx);
|
|
309
332
|
|
|
310
|
-
logger.
|
|
333
|
+
this.logger.debug(`Received transaction: ${tx.hash}`);
|
|
311
334
|
|
|
312
335
|
const startSpongeBlob = spongeBlobState.clone();
|
|
313
336
|
const [hints, treeSnapshots] = await this.prepareBaseRollupInputs(
|
|
@@ -328,10 +351,10 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
328
351
|
const txIndex = provingState.addNewTx(txProvingState);
|
|
329
352
|
if (txProvingState.requireAvmProof) {
|
|
330
353
|
this.getOrEnqueueChonkVerifier(provingState, txIndex);
|
|
331
|
-
logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
354
|
+
this.logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
332
355
|
this.enqueueVM(provingState, txIndex);
|
|
333
356
|
} else {
|
|
334
|
-
logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
357
|
+
this.logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
335
358
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
336
359
|
}
|
|
337
360
|
} catch (err: any) {
|
|
@@ -341,11 +364,16 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
341
364
|
}
|
|
342
365
|
}
|
|
343
366
|
|
|
344
|
-
await
|
|
367
|
+
const endState = await db.getStateReference();
|
|
368
|
+
provingState.setEndState(endState);
|
|
369
|
+
|
|
370
|
+
const blockEndBlobFields = provingState.getBlockEndBlobFields();
|
|
371
|
+
await spongeBlobState.absorb(blockEndBlobFields);
|
|
345
372
|
|
|
346
373
|
provingState.setEndSpongeBlob(spongeBlobState);
|
|
347
374
|
|
|
348
|
-
// Txs have been added to the block. Now try to accumulate the blobs as far as we can:
|
|
375
|
+
// Txs have been added to the block. Now try to accumulate the out hashes and blobs as far as we can:
|
|
376
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
349
377
|
await this.provingState.setBlobAccumulators();
|
|
350
378
|
}
|
|
351
379
|
|
|
@@ -369,7 +397,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
369
397
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
370
398
|
>
|
|
371
399
|
>();
|
|
372
|
-
logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
|
|
400
|
+
this.logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
|
|
373
401
|
this.doEnqueueChonkVerifier(txHash, privateInputs, proof => {
|
|
374
402
|
tubeProof.resolve(proof);
|
|
375
403
|
});
|
|
@@ -382,10 +410,10 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
382
410
|
* Marks the block as completed.
|
|
383
411
|
* Computes the block header and updates the archive tree.
|
|
384
412
|
*/
|
|
385
|
-
@trackSpan('ProvingOrchestrator.setBlockCompleted', (blockNumber:
|
|
413
|
+
@trackSpan('ProvingOrchestrator.setBlockCompleted', (blockNumber: BlockNumber) => ({
|
|
386
414
|
[Attributes.BLOCK_NUMBER]: blockNumber,
|
|
387
415
|
}))
|
|
388
|
-
public async setBlockCompleted(blockNumber:
|
|
416
|
+
public async setBlockCompleted(blockNumber: BlockNumber, expectedHeader?: BlockHeader): Promise<BlockHeader> {
|
|
389
417
|
const provingState = this.provingState?.getBlockProvingStateByBlockNumber(blockNumber);
|
|
390
418
|
if (!provingState) {
|
|
391
419
|
throw new Error(`Block proving state for ${blockNumber} not found`);
|
|
@@ -408,39 +436,25 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
408
436
|
);
|
|
409
437
|
}
|
|
410
438
|
|
|
411
|
-
//
|
|
412
|
-
logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
|
|
413
|
-
const header = await
|
|
414
|
-
|
|
415
|
-
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
416
|
-
|
|
417
|
-
return header;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
private async buildL2BlockHeader(provingState: BlockProvingState, expectedHeader?: BlockHeader) {
|
|
421
|
-
// Collect all txs in this block to build the header. The function calling this has made sure that all txs have been added.
|
|
422
|
-
const txs = provingState.getProcessedTxs();
|
|
423
|
-
|
|
424
|
-
const startSpongeBlob = provingState.getStartSpongeBlob();
|
|
425
|
-
|
|
426
|
-
// Get db for this block
|
|
427
|
-
const db = this.dbs.get(provingState.blockNumber)!;
|
|
428
|
-
|
|
429
|
-
// Given we've applied every change from this block, now assemble the block header
|
|
430
|
-
// and update the archive tree, so we're ready to start processing the next block
|
|
431
|
-
const header = await buildBlockHeaderFromTxs(txs, provingState.getGlobalVariables(), startSpongeBlob, db);
|
|
439
|
+
// Given we've applied every change from this block, now assemble the block header:
|
|
440
|
+
this.logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
|
|
441
|
+
const header = await provingState.buildBlockHeader();
|
|
432
442
|
|
|
433
443
|
if (expectedHeader && !header.equals(expectedHeader)) {
|
|
434
|
-
logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
444
|
+
this.logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
435
445
|
throw new Error('Block header mismatch');
|
|
436
446
|
}
|
|
437
447
|
|
|
438
|
-
|
|
448
|
+
// Get db for this block
|
|
449
|
+
const db = this.dbs.get(provingState.blockNumber)!.fork;
|
|
450
|
+
|
|
451
|
+
// Update the archive tree, so we're ready to start processing the next block:
|
|
452
|
+
this.logger.verbose(
|
|
439
453
|
`Updating archive tree with block ${provingState.blockNumber} header ${(await header.hash()).toString()}`,
|
|
440
454
|
);
|
|
441
455
|
await db.updateArchive(header);
|
|
442
456
|
|
|
443
|
-
|
|
457
|
+
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
444
458
|
|
|
445
459
|
return header;
|
|
446
460
|
}
|
|
@@ -449,31 +463,31 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
449
463
|
protected async verifyBuiltBlockAgainstSyncedState(provingState: BlockProvingState) {
|
|
450
464
|
const builtBlockHeader = provingState.getBuiltBlockHeader();
|
|
451
465
|
if (!builtBlockHeader) {
|
|
452
|
-
logger.debug('Block header not built yet, skipping header check.');
|
|
466
|
+
this.logger.debug('Block header not built yet, skipping header check.');
|
|
453
467
|
return;
|
|
454
468
|
}
|
|
455
469
|
|
|
456
470
|
const output = provingState.getBlockRootRollupOutput();
|
|
457
471
|
if (!output) {
|
|
458
|
-
logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
472
|
+
this.logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
459
473
|
return;
|
|
460
474
|
}
|
|
461
475
|
const header = await buildHeaderFromCircuitOutputs(output);
|
|
462
476
|
|
|
463
477
|
if (!(await header.hash()).equals(await builtBlockHeader.hash())) {
|
|
464
|
-
logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
478
|
+
this.logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
465
479
|
provingState.reject(`Block header hash mismatch.`);
|
|
466
480
|
return;
|
|
467
481
|
}
|
|
468
482
|
|
|
469
483
|
// Get db for this block
|
|
470
484
|
const blockNumber = provingState.blockNumber;
|
|
471
|
-
const db = this.dbs.get(blockNumber)
|
|
485
|
+
const db = this.dbs.get(blockNumber)!.fork;
|
|
472
486
|
|
|
473
487
|
const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
474
488
|
const syncedArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.dbProvider.getSnapshot(blockNumber));
|
|
475
489
|
if (!syncedArchive.equals(newArchive)) {
|
|
476
|
-
logger.error(
|
|
490
|
+
this.logger.error(
|
|
477
491
|
`Archive tree mismatch for block ${blockNumber}: world state synced to ${inspect(
|
|
478
492
|
syncedArchive,
|
|
479
493
|
)} but built ${inspect(newArchive)}`,
|
|
@@ -484,7 +498,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
484
498
|
|
|
485
499
|
const circuitArchive = output.newArchive;
|
|
486
500
|
if (!newArchive.equals(circuitArchive)) {
|
|
487
|
-
logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
501
|
+
this.logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
488
502
|
provingState.reject(`New archive mismatch.`);
|
|
489
503
|
return;
|
|
490
504
|
}
|
|
@@ -493,20 +507,19 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
493
507
|
// is aborted and never reaches this point, it will leak the fork. We need to add a global cleanup,
|
|
494
508
|
// but have to make sure it only runs once all operations are completed, otherwise some function here
|
|
495
509
|
// will attempt to access the fork after it was closed.
|
|
496
|
-
|
|
497
|
-
void this.dbs
|
|
498
|
-
.get(blockNumber)
|
|
499
|
-
?.close()
|
|
500
|
-
.then(() => this.dbs.delete(blockNumber))
|
|
501
|
-
.catch(err => logger.error(`Error closing db for block ${blockNumber}`, err));
|
|
510
|
+
void this.cleanupDBFork(blockNumber);
|
|
502
511
|
}
|
|
503
512
|
|
|
504
513
|
/**
|
|
505
|
-
* Cancel any further proving
|
|
514
|
+
* Cancel any further proving.
|
|
515
|
+
* If cancelJobsOnStop is true, aborts all pending jobs with the broker (which marks them as 'Aborted').
|
|
516
|
+
* If cancelJobsOnStop is false (default), jobs remain in the broker queue and can be reused on restart/reorg.
|
|
506
517
|
*/
|
|
507
518
|
public cancel() {
|
|
508
|
-
|
|
509
|
-
controller.
|
|
519
|
+
if (this.cancelJobsOnStop) {
|
|
520
|
+
for (const controller of this.pendingProvingJobs) {
|
|
521
|
+
controller.abort();
|
|
522
|
+
}
|
|
510
523
|
}
|
|
511
524
|
|
|
512
525
|
this.provingState?.cancel();
|
|
@@ -541,6 +554,24 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
541
554
|
return epochProofResult;
|
|
542
555
|
}
|
|
543
556
|
|
|
557
|
+
private async cleanupDBFork(blockNumber: BlockNumber): Promise<void> {
|
|
558
|
+
this.logger.debug(`Cleaning up world state fork for ${blockNumber}`);
|
|
559
|
+
const fork = this.dbs.get(blockNumber);
|
|
560
|
+
if (!fork) {
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
try {
|
|
565
|
+
if (!fork.cleanupPromise) {
|
|
566
|
+
fork.cleanupPromise = fork.fork.close();
|
|
567
|
+
}
|
|
568
|
+
await fork.cleanupPromise;
|
|
569
|
+
this.dbs.delete(blockNumber);
|
|
570
|
+
} catch (err) {
|
|
571
|
+
this.logger.error(`Error closing db for block ${blockNumber}`, err);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
544
575
|
/**
|
|
545
576
|
* Enqueue a job to be scheduled
|
|
546
577
|
* @param provingState - The proving state object being operated on
|
|
@@ -553,7 +584,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
553
584
|
callback: (result: T) => void | Promise<void>,
|
|
554
585
|
) {
|
|
555
586
|
if (!provingState.verifyState()) {
|
|
556
|
-
logger.debug(`Not enqueuing job, state no longer valid`);
|
|
587
|
+
this.logger.debug(`Not enqueuing job, state no longer valid`);
|
|
557
588
|
return;
|
|
558
589
|
}
|
|
559
590
|
|
|
@@ -571,7 +602,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
571
602
|
|
|
572
603
|
const result = await request(controller.signal);
|
|
573
604
|
if (!provingState.verifyState()) {
|
|
574
|
-
logger.debug(`State no longer valid, discarding result`);
|
|
605
|
+
this.logger.debug(`State no longer valid, discarding result`);
|
|
575
606
|
return;
|
|
576
607
|
}
|
|
577
608
|
|
|
@@ -589,7 +620,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
589
620
|
return;
|
|
590
621
|
}
|
|
591
622
|
|
|
592
|
-
logger.error(`Error thrown when proving job`, err);
|
|
623
|
+
this.logger.error(`Error thrown when proving job`, err);
|
|
593
624
|
provingState!.reject(`${err}`);
|
|
594
625
|
} finally {
|
|
595
626
|
const index = this.pendingProvingJobs.indexOf(controller);
|
|
@@ -674,12 +705,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
674
705
|
// Executes the next level of merge if all inputs are available
|
|
675
706
|
private enqueueBaseRollup(provingState: BlockProvingState, txIndex: number) {
|
|
676
707
|
if (!provingState.verifyState()) {
|
|
677
|
-
logger.debug('Not running base rollup, state invalid');
|
|
708
|
+
this.logger.debug('Not running base rollup, state invalid');
|
|
678
709
|
return;
|
|
679
710
|
}
|
|
680
711
|
|
|
681
712
|
if (!provingState.tryStartProvingBase(txIndex)) {
|
|
682
|
-
logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
713
|
+
this.logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
683
714
|
return;
|
|
684
715
|
}
|
|
685
716
|
|
|
@@ -687,7 +718,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
687
718
|
const { processedTx } = txProvingState;
|
|
688
719
|
const { rollupType, inputs } = txProvingState.getBaseRollupTypeAndInputs();
|
|
689
720
|
|
|
690
|
-
logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
721
|
+
this.logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
691
722
|
|
|
692
723
|
this.deferredProving(
|
|
693
724
|
provingState,
|
|
@@ -711,7 +742,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
711
742
|
},
|
|
712
743
|
),
|
|
713
744
|
result => {
|
|
714
|
-
logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
745
|
+
this.logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
715
746
|
validatePartialState(result.inputs.endTreeSnapshots, txProvingState.treeSnapshots);
|
|
716
747
|
const leafLocation = provingState.setBaseRollupProof(txIndex, result);
|
|
717
748
|
if (provingState.totalNumTxs === 1) {
|
|
@@ -727,7 +758,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
727
758
|
// Once completed, will enqueue the the public tx base rollup.
|
|
728
759
|
private getOrEnqueueChonkVerifier(provingState: BlockProvingState, txIndex: number) {
|
|
729
760
|
if (!provingState.verifyState()) {
|
|
730
|
-
logger.debug('Not running chonk verifier circuit, state invalid');
|
|
761
|
+
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
731
762
|
return;
|
|
732
763
|
}
|
|
733
764
|
|
|
@@ -740,19 +771,19 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
740
771
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
741
772
|
>,
|
|
742
773
|
) => {
|
|
743
|
-
logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, { txHash });
|
|
774
|
+
this.logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, { txHash });
|
|
744
775
|
txProvingState.setPublicChonkVerifierProof(result);
|
|
745
776
|
this.provingState?.cachedChonkVerifierProofs.delete(txHash);
|
|
746
777
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
747
778
|
};
|
|
748
779
|
|
|
749
780
|
if (this.provingState?.cachedChonkVerifierProofs.has(txHash)) {
|
|
750
|
-
logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, { txHash });
|
|
781
|
+
this.logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, { txHash });
|
|
751
782
|
void this.provingState!.cachedChonkVerifierProofs.get(txHash)!.then(handleResult);
|
|
752
783
|
return;
|
|
753
784
|
}
|
|
754
785
|
|
|
755
|
-
logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
|
|
786
|
+
this.logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
|
|
756
787
|
this.doEnqueueChonkVerifier(txHash, txProvingState.getPublicChonkVerifierPrivateInputs(), handleResult);
|
|
757
788
|
}
|
|
758
789
|
|
|
@@ -768,7 +799,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
768
799
|
provingState: EpochProvingState | BlockProvingState = this.provingState!,
|
|
769
800
|
) {
|
|
770
801
|
if (!provingState.verifyState()) {
|
|
771
|
-
logger.debug('Not running chonk verifier circuit, state invalid');
|
|
802
|
+
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
772
803
|
return;
|
|
773
804
|
}
|
|
774
805
|
|
|
@@ -791,12 +822,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
791
822
|
// Enqueues the next level of merge if all inputs are available
|
|
792
823
|
private enqueueMergeRollup(provingState: BlockProvingState, location: TreeNodeLocation) {
|
|
793
824
|
if (!provingState.verifyState()) {
|
|
794
|
-
logger.debug('Not running merge rollup. State no longer valid.');
|
|
825
|
+
this.logger.debug('Not running merge rollup. State no longer valid.');
|
|
795
826
|
return;
|
|
796
827
|
}
|
|
797
828
|
|
|
798
829
|
if (!provingState.tryStartProvingMerge(location)) {
|
|
799
|
-
logger.debug('Merge rollup already started.');
|
|
830
|
+
this.logger.debug('Merge rollup already started.');
|
|
800
831
|
return;
|
|
801
832
|
}
|
|
802
833
|
|
|
@@ -822,18 +853,18 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
822
853
|
// Executes the block root rollup circuit
|
|
823
854
|
private enqueueBlockRootRollup(provingState: BlockProvingState) {
|
|
824
855
|
if (!provingState.verifyState()) {
|
|
825
|
-
logger.debug('Not running block root rollup, state no longer valid');
|
|
856
|
+
this.logger.debug('Not running block root rollup, state no longer valid');
|
|
826
857
|
return;
|
|
827
858
|
}
|
|
828
859
|
|
|
829
860
|
if (!provingState.tryStartProvingBlockRoot()) {
|
|
830
|
-
logger.debug('Block root rollup already started.');
|
|
861
|
+
this.logger.debug('Block root rollup already started.');
|
|
831
862
|
return;
|
|
832
863
|
}
|
|
833
864
|
|
|
834
865
|
const { rollupType, inputs } = provingState.getBlockRootRollupTypeAndInputs();
|
|
835
866
|
|
|
836
|
-
logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
867
|
+
this.logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
837
868
|
|
|
838
869
|
this.deferredProving(
|
|
839
870
|
provingState,
|
|
@@ -858,19 +889,22 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
858
889
|
},
|
|
859
890
|
),
|
|
860
891
|
async result => {
|
|
861
|
-
|
|
862
|
-
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
863
|
-
|
|
864
|
-
logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`);
|
|
892
|
+
this.logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`);
|
|
865
893
|
|
|
866
894
|
const leafLocation = provingState.setBlockRootRollupProof(result);
|
|
867
895
|
const checkpointProvingState = provingState.parentCheckpoint;
|
|
868
896
|
|
|
897
|
+
// If the proofs were slower than the block header building, then we need to try validating the block header hashes here.
|
|
898
|
+
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
899
|
+
|
|
869
900
|
if (checkpointProvingState.totalNumBlocks === 1) {
|
|
870
901
|
this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
871
902
|
} else {
|
|
872
903
|
this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
873
904
|
}
|
|
905
|
+
|
|
906
|
+
// We are finished with the block at this point, ensure the fork is cleaned up
|
|
907
|
+
void this.cleanupDBFork(provingState.blockNumber);
|
|
874
908
|
},
|
|
875
909
|
);
|
|
876
910
|
}
|
|
@@ -883,12 +917,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
883
917
|
baseParityIndex: number,
|
|
884
918
|
) {
|
|
885
919
|
if (!provingState.verifyState()) {
|
|
886
|
-
logger.debug('Not running base parity. State no longer valid.');
|
|
920
|
+
this.logger.debug('Not running base parity. State no longer valid.');
|
|
887
921
|
return;
|
|
888
922
|
}
|
|
889
923
|
|
|
890
924
|
if (!provingState.tryStartProvingBaseParity(baseParityIndex)) {
|
|
891
|
-
logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
925
|
+
this.logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
892
926
|
return;
|
|
893
927
|
}
|
|
894
928
|
|
|
@@ -923,12 +957,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
923
957
|
// Enqueues the root rollup proof if all inputs are available
|
|
924
958
|
private enqueueRootParityCircuit(provingState: BlockProvingState) {
|
|
925
959
|
if (!provingState.verifyState()) {
|
|
926
|
-
logger.debug('Not running root parity. State no longer valid.');
|
|
960
|
+
this.logger.debug('Not running root parity. State no longer valid.');
|
|
927
961
|
return;
|
|
928
962
|
}
|
|
929
963
|
|
|
930
964
|
if (!provingState.tryStartProvingRootParity()) {
|
|
931
|
-
logger.debug('Root parity already started.');
|
|
965
|
+
this.logger.debug('Root parity already started.');
|
|
932
966
|
return;
|
|
933
967
|
}
|
|
934
968
|
|
|
@@ -955,12 +989,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
955
989
|
// Enqueues the next level of merge if all inputs are available
|
|
956
990
|
private enqueueBlockMergeRollup(provingState: CheckpointProvingState, location: TreeNodeLocation) {
|
|
957
991
|
if (!provingState.verifyState()) {
|
|
958
|
-
logger.debug('Not running block merge rollup. State no longer valid.');
|
|
992
|
+
this.logger.debug('Not running block merge rollup. State no longer valid.');
|
|
959
993
|
return;
|
|
960
994
|
}
|
|
961
995
|
|
|
962
996
|
if (!provingState.tryStartProvingBlockMerge(location)) {
|
|
963
|
-
logger.debug('Block merge rollup already started.');
|
|
997
|
+
this.logger.debug('Block merge rollup already started.');
|
|
964
998
|
return;
|
|
965
999
|
}
|
|
966
1000
|
|
|
@@ -984,18 +1018,18 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
984
1018
|
|
|
985
1019
|
private enqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
986
1020
|
if (!provingState.verifyState()) {
|
|
987
|
-
logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
1021
|
+
this.logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
988
1022
|
return;
|
|
989
1023
|
}
|
|
990
1024
|
|
|
991
1025
|
if (!provingState.tryStartProvingCheckpointRoot()) {
|
|
992
|
-
logger.debug('Checkpoint root rollup already started.');
|
|
1026
|
+
this.logger.debug('Checkpoint root rollup already started.');
|
|
993
1027
|
return;
|
|
994
1028
|
}
|
|
995
1029
|
|
|
996
1030
|
const rollupType = provingState.getCheckpointRootRollupType();
|
|
997
1031
|
|
|
998
|
-
logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
1032
|
+
this.logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
999
1033
|
|
|
1000
1034
|
const inputs = provingState.getCheckpointRootRollupInputs();
|
|
1001
1035
|
|
|
@@ -1019,7 +1053,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1019
1053
|
const computedEndBlobAccumulatorState = provingState.getEndBlobAccumulator()!.toBlobAccumulator();
|
|
1020
1054
|
const circuitEndBlobAccumulatorState = result.inputs.endBlobAccumulator;
|
|
1021
1055
|
if (!circuitEndBlobAccumulatorState.equals(computedEndBlobAccumulatorState)) {
|
|
1022
|
-
logger.error(
|
|
1056
|
+
this.logger.error(
|
|
1023
1057
|
`Blob accumulator state mismatch.\nCircuit: ${inspect(circuitEndBlobAccumulatorState)}\nComputed: ${inspect(
|
|
1024
1058
|
computedEndBlobAccumulatorState,
|
|
1025
1059
|
)}`,
|
|
@@ -1028,7 +1062,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1028
1062
|
return;
|
|
1029
1063
|
}
|
|
1030
1064
|
|
|
1031
|
-
logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}.`);
|
|
1065
|
+
this.logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}.`);
|
|
1032
1066
|
|
|
1033
1067
|
const leafLocation = provingState.setCheckpointRootRollupProof(result);
|
|
1034
1068
|
const epochProvingState = provingState.parentEpoch;
|
|
@@ -1044,12 +1078,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1044
1078
|
|
|
1045
1079
|
private enqueueCheckpointMergeRollup(provingState: EpochProvingState, location: TreeNodeLocation) {
|
|
1046
1080
|
if (!provingState.verifyState()) {
|
|
1047
|
-
logger.debug('Not running checkpoint merge rollup. State no longer valid.');
|
|
1081
|
+
this.logger.debug('Not running checkpoint merge rollup. State no longer valid.');
|
|
1048
1082
|
return;
|
|
1049
1083
|
}
|
|
1050
1084
|
|
|
1051
1085
|
if (!provingState.tryStartProvingCheckpointMerge(location)) {
|
|
1052
|
-
logger.debug('Checkpoint merge rollup already started.');
|
|
1086
|
+
this.logger.debug('Checkpoint merge rollup already started.');
|
|
1053
1087
|
return;
|
|
1054
1088
|
}
|
|
1055
1089
|
|
|
@@ -1066,7 +1100,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1066
1100
|
signal => this.prover.getCheckpointMergeRollupProof(inputs, signal, provingState.epochNumber),
|
|
1067
1101
|
),
|
|
1068
1102
|
result => {
|
|
1069
|
-
logger.debug('Completed proof for checkpoint merge rollup.');
|
|
1103
|
+
this.logger.debug('Completed proof for checkpoint merge rollup.');
|
|
1070
1104
|
provingState.setCheckpointMergeRollupProof(location, result);
|
|
1071
1105
|
this.checkAndEnqueueNextCheckpointMergeRollup(provingState, location);
|
|
1072
1106
|
},
|
|
@@ -1075,16 +1109,16 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1075
1109
|
|
|
1076
1110
|
private enqueueEpochPadding(provingState: EpochProvingState) {
|
|
1077
1111
|
if (!provingState.verifyState()) {
|
|
1078
|
-
logger.debug('Not running epoch padding. State no longer valid.');
|
|
1112
|
+
this.logger.debug('Not running epoch padding. State no longer valid.');
|
|
1079
1113
|
return;
|
|
1080
1114
|
}
|
|
1081
1115
|
|
|
1082
1116
|
if (!provingState.tryStartProvingPaddingCheckpoint()) {
|
|
1083
|
-
logger.debug('Padding checkpoint already started.');
|
|
1117
|
+
this.logger.debug('Padding checkpoint already started.');
|
|
1084
1118
|
return;
|
|
1085
1119
|
}
|
|
1086
1120
|
|
|
1087
|
-
logger.debug('Padding epoch proof with a padding block root proof.');
|
|
1121
|
+
this.logger.debug('Padding epoch proof with a padding block root proof.');
|
|
1088
1122
|
|
|
1089
1123
|
const inputs = provingState.getPaddingCheckpointInputs();
|
|
1090
1124
|
|
|
@@ -1099,7 +1133,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1099
1133
|
signal => this.prover.getCheckpointPaddingRollupProof(inputs, signal, provingState.epochNumber),
|
|
1100
1134
|
),
|
|
1101
1135
|
result => {
|
|
1102
|
-
logger.debug('Completed proof for padding checkpoint.');
|
|
1136
|
+
this.logger.debug('Completed proof for padding checkpoint.');
|
|
1103
1137
|
provingState.setCheckpointPaddingProof(result);
|
|
1104
1138
|
this.checkAndEnqueueRootRollup(provingState);
|
|
1105
1139
|
},
|
|
@@ -1109,11 +1143,11 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1109
1143
|
// Executes the root rollup circuit
|
|
1110
1144
|
private enqueueRootRollup(provingState: EpochProvingState) {
|
|
1111
1145
|
if (!provingState.verifyState()) {
|
|
1112
|
-
logger.debug('Not running root rollup, state no longer valid');
|
|
1146
|
+
this.logger.debug('Not running root rollup, state no longer valid');
|
|
1113
1147
|
return;
|
|
1114
1148
|
}
|
|
1115
1149
|
|
|
1116
|
-
logger.debug(`Preparing root rollup`);
|
|
1150
|
+
this.logger.debug(`Preparing root rollup`);
|
|
1117
1151
|
|
|
1118
1152
|
const inputs = provingState.getRootRollupInputs();
|
|
1119
1153
|
|
|
@@ -1128,7 +1162,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1128
1162
|
signal => this.prover.getRootRollupProof(inputs, signal, provingState.epochNumber),
|
|
1129
1163
|
),
|
|
1130
1164
|
result => {
|
|
1131
|
-
logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
|
|
1165
|
+
this.logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
|
|
1132
1166
|
provingState.setRootRollupProof(result);
|
|
1133
1167
|
provingState.resolve({ status: 'success' });
|
|
1134
1168
|
},
|
|
@@ -1150,7 +1184,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1150
1184
|
|
|
1151
1185
|
private checkAndEnqueueBlockRootRollup(provingState: BlockProvingState) {
|
|
1152
1186
|
if (!provingState.isReadyForBlockRootRollup()) {
|
|
1153
|
-
logger.debug('Not ready for block root rollup');
|
|
1187
|
+
this.logger.debug('Not ready for block root rollup');
|
|
1154
1188
|
return;
|
|
1155
1189
|
}
|
|
1156
1190
|
|
|
@@ -1193,7 +1227,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1193
1227
|
|
|
1194
1228
|
private checkAndEnqueueRootRollup(provingState: EpochProvingState) {
|
|
1195
1229
|
if (!provingState.isReadyForRootRollup()) {
|
|
1196
|
-
logger.debug('Not ready for root rollup');
|
|
1230
|
+
this.logger.debug('Not ready for root rollup');
|
|
1197
1231
|
return;
|
|
1198
1232
|
}
|
|
1199
1233
|
|
|
@@ -1208,14 +1242,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1208
1242
|
*/
|
|
1209
1243
|
private enqueueVM(provingState: BlockProvingState, txIndex: number) {
|
|
1210
1244
|
if (!provingState.verifyState()) {
|
|
1211
|
-
logger.debug(`Not running VM circuit as state is no longer valid`);
|
|
1245
|
+
this.logger.debug(`Not running VM circuit as state is no longer valid`);
|
|
1212
1246
|
return;
|
|
1213
1247
|
}
|
|
1214
1248
|
|
|
1215
1249
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
1216
1250
|
|
|
1217
|
-
// This function tries to do AVM proving. If there is a failure, it fakes the proof unless AVM_PROVING_STRICT is defined.
|
|
1218
|
-
// Nothing downstream depends on the AVM proof yet. So having this mode lets us incrementally build the AVM circuit.
|
|
1219
1251
|
const doAvmProving = wrapCallbackInSpan(
|
|
1220
1252
|
this.tracer,
|
|
1221
1253
|
'ProvingOrchestrator.prover.getAvmProof',
|
|
@@ -1224,36 +1256,13 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1224
1256
|
},
|
|
1225
1257
|
async (signal: AbortSignal) => {
|
|
1226
1258
|
const inputs = txProvingState.getAvmInputs();
|
|
1227
|
-
|
|
1228
|
-
// TODO(#14234)[Unconditional PIs validation]: Remove the whole try-catch logic and
|
|
1229
|
-
// just keep the next line but removing the second argument (false).
|
|
1230
|
-
return await this.prover.getAvmProof(inputs, false, signal, provingState.epochNumber);
|
|
1231
|
-
} catch (err) {
|
|
1232
|
-
if (process.env.AVM_PROVING_STRICT) {
|
|
1233
|
-
logger.error(`Error thrown when proving AVM circuit with AVM_PROVING_STRICT on`, err);
|
|
1234
|
-
throw err;
|
|
1235
|
-
} else {
|
|
1236
|
-
logger.warn(
|
|
1237
|
-
`Error thrown when proving AVM circuit but AVM_PROVING_STRICT is off. Use snapshotted
|
|
1238
|
-
AVM inputs and carrying on. ${inspect(err)}.`,
|
|
1239
|
-
);
|
|
1240
|
-
|
|
1241
|
-
try {
|
|
1242
|
-
this.metrics.incAvmFallback();
|
|
1243
|
-
const snapshotAvmPrivateInputs = readAvmMinimalPublicTxInputsFromFile();
|
|
1244
|
-
return await this.prover.getAvmProof(snapshotAvmPrivateInputs, true, signal, provingState.epochNumber);
|
|
1245
|
-
} catch (err) {
|
|
1246
|
-
logger.error(`Error thrown when proving snapshotted AVM inputs.`, err);
|
|
1247
|
-
throw err;
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1259
|
+
return await this.prover.getAvmProof(inputs, signal, provingState.epochNumber);
|
|
1251
1260
|
},
|
|
1252
1261
|
);
|
|
1253
1262
|
|
|
1254
|
-
this.deferredProving(provingState, doAvmProving,
|
|
1255
|
-
logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1256
|
-
txProvingState.setAvmProof(
|
|
1263
|
+
this.deferredProving(provingState, doAvmProving, proof => {
|
|
1264
|
+
this.logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1265
|
+
txProvingState.setAvmProof(proof);
|
|
1257
1266
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
1258
1267
|
});
|
|
1259
1268
|
}
|
|
@@ -1265,7 +1274,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1265
1274
|
}
|
|
1266
1275
|
|
|
1267
1276
|
// We must have completed all proving (chonk verifier proof and (if required) vm proof are generated), we now move to the base rollup.
|
|
1268
|
-
logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1277
|
+
this.logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1269
1278
|
|
|
1270
1279
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
1271
1280
|
}
|