@aztec/prover-client 0.0.1-fake-c83136db25 → 0.0.2-commit.217f559981
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 +48 -0
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -0
- package/dest/light/lightweight_checkpoint_builder.js +202 -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 +119 -116
- package/dest/orchestrator/block-building-helpers.d.ts +18 -20
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +90 -115
- package/dest/orchestrator/block-proving-state.d.ts +20 -11
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +87 -19
- 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 +52 -20
- 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 +40 -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 +562 -176
- 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 +5 -5
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +15 -10
- package/dest/prover-client/server-epoch-prover.d.ts +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 +24 -8
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +26 -3
- 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 -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/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 +7 -4
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +35 -12
- 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 +7 -5
- package/dest/proving_broker/rpc.d.ts.map +1 -1
- package/dest/proving_broker/rpc.js +8 -0
- 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 +5 -6
- 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 +294 -0
- package/src/mocks/fixtures.ts +9 -31
- package/src/mocks/test_context.ts +158 -177
- package/src/orchestrator/block-building-helpers.ts +129 -209
- package/src/orchestrator/block-proving-state.ts +109 -22
- package/src/orchestrator/checkpoint-proving-state.ts +75 -25
- package/src/orchestrator/epoch-proving-state.ts +67 -15
- package/src/orchestrator/orchestrator.ts +172 -169
- 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 +31 -23
- 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 +30 -1
- package/src/proving_broker/fixtures.ts +8 -3
- package/src/proving_broker/proof_store/factory.ts +10 -32
- package/src/proving_broker/proof_store/file_store_proof_store.ts +78 -0
- package/src/proving_broker/proof_store/index.ts +1 -1
- package/src/proving_broker/proving_agent.ts +6 -19
- package/src/proving_broker/proving_broker.ts +36 -10
- 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/proving_broker/rpc.ts +14 -0
- 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/proof_store/gcs_proof_store.d.ts +0 -14
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +0 -1
- package/dest/proving_broker/proof_store/gcs_proof_store.js +0 -52
- package/dest/proving_broker/proving_agent_instrumentation.d.ts +0 -8
- package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +0 -1
- package/dest/proving_broker/proving_agent_instrumentation.js +0 -16
- package/src/block-factory/index.ts +0 -1
- package/src/block-factory/light.ts +0 -140
- package/src/proving_broker/proof_store/gcs_proof_store.ts +0 -76
- 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,8 +71,6 @@ 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
|
-
const logger = createLogger('prover-client:orchestrator');
|
|
75
|
-
|
|
76
74
|
/**
|
|
77
75
|
* Implements an event driven proving scheduler to build the recursive proof tree. The idea being:
|
|
78
76
|
* 1. Transactions are provided to the scheduler post simulation.
|
|
@@ -93,14 +91,19 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
93
91
|
|
|
94
92
|
private provingPromise: Promise<ProvingResult> | undefined = undefined;
|
|
95
93
|
private metrics: ProvingOrchestratorMetrics;
|
|
96
|
-
|
|
94
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
95
|
+
private dbs: Map<BlockNumber, MerkleTreeWriteOperations> = new Map();
|
|
96
|
+
private logger: Logger;
|
|
97
97
|
|
|
98
98
|
constructor(
|
|
99
|
-
private dbProvider: ForkMerkleTreeOperations,
|
|
99
|
+
private dbProvider: ReadonlyWorldStateAccess & ForkMerkleTreeOperations,
|
|
100
100
|
private prover: ServerCircuitProver,
|
|
101
101
|
private readonly proverId: EthAddress,
|
|
102
|
+
private readonly cancelJobsOnStop: boolean = false,
|
|
102
103
|
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
104
|
+
bindings?: LoggerBindings,
|
|
103
105
|
) {
|
|
106
|
+
this.logger = createLogger('prover-client:orchestrator', bindings);
|
|
104
107
|
this.metrics = new ProvingOrchestratorMetrics(telemetryClient, 'ProvingOrchestrator');
|
|
105
108
|
}
|
|
106
109
|
|
|
@@ -112,13 +115,17 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
112
115
|
return this.proverId;
|
|
113
116
|
}
|
|
114
117
|
|
|
118
|
+
public getNumActiveForks() {
|
|
119
|
+
return this.dbs.size;
|
|
120
|
+
}
|
|
121
|
+
|
|
115
122
|
public stop(): Promise<void> {
|
|
116
123
|
this.cancel();
|
|
117
124
|
return Promise.resolve();
|
|
118
125
|
}
|
|
119
126
|
|
|
120
127
|
public startNewEpoch(
|
|
121
|
-
epochNumber:
|
|
128
|
+
epochNumber: EpochNumber,
|
|
122
129
|
totalNumCheckpoints: number,
|
|
123
130
|
finalBlobBatchingChallenges: FinalBlobBatchingChallenges,
|
|
124
131
|
) {
|
|
@@ -130,7 +137,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
130
137
|
|
|
131
138
|
const { promise: _promise, resolve, reject } = promiseWithResolvers<ProvingResult>();
|
|
132
139
|
const promise = _promise.catch((reason): ProvingResult => ({ status: 'failure', reason }));
|
|
133
|
-
logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
|
|
140
|
+
this.logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
|
|
134
141
|
this.provingState = new EpochProvingState(
|
|
135
142
|
epochNumber,
|
|
136
143
|
totalNumCheckpoints,
|
|
@@ -142,12 +149,19 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
142
149
|
this.provingPromise = promise;
|
|
143
150
|
}
|
|
144
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Starts a new checkpoint.
|
|
154
|
+
* @param checkpointIndex - The index of the checkpoint in the epoch.
|
|
155
|
+
* @param constants - The constants for this checkpoint.
|
|
156
|
+
* @param l1ToL2Messages - The set of L1 to L2 messages to be inserted at the beginning of this checkpoint.
|
|
157
|
+
* @param totalNumBlocks - The total number of blocks expected in the checkpoint (must be at least one).
|
|
158
|
+
* @param headerOfLastBlockInPreviousCheckpoint - The header of the last block in the previous checkpoint.
|
|
159
|
+
*/
|
|
145
160
|
public async startNewCheckpoint(
|
|
146
161
|
checkpointIndex: number,
|
|
147
162
|
constants: CheckpointConstantData,
|
|
148
163
|
l1ToL2Messages: Fr[],
|
|
149
164
|
totalNumBlocks: number,
|
|
150
|
-
totalNumBlobFields: number,
|
|
151
165
|
headerOfLastBlockInPreviousCheckpoint: BlockHeader,
|
|
152
166
|
) {
|
|
153
167
|
if (!this.provingState) {
|
|
@@ -162,7 +176,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
162
176
|
const lastBlockNumber = headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber;
|
|
163
177
|
const db = await this.dbProvider.fork(lastBlockNumber);
|
|
164
178
|
|
|
165
|
-
const firstBlockNumber = lastBlockNumber + 1;
|
|
179
|
+
const firstBlockNumber = BlockNumber(lastBlockNumber + 1);
|
|
166
180
|
this.dbs.set(firstBlockNumber, db);
|
|
167
181
|
|
|
168
182
|
// Get archive sibling path before any block in this checkpoint lands.
|
|
@@ -180,7 +194,6 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
180
194
|
checkpointIndex,
|
|
181
195
|
constants,
|
|
182
196
|
totalNumBlocks,
|
|
183
|
-
totalNumBlobFields,
|
|
184
197
|
headerOfLastBlockInPreviousCheckpoint,
|
|
185
198
|
lastArchiveSiblingPath,
|
|
186
199
|
l1ToL2Messages,
|
|
@@ -201,7 +214,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
201
214
|
@trackSpan('ProvingOrchestrator.startNewBlock', blockNumber => ({
|
|
202
215
|
[Attributes.BLOCK_NUMBER]: blockNumber,
|
|
203
216
|
}))
|
|
204
|
-
public async startNewBlock(blockNumber:
|
|
217
|
+
public async startNewBlock(blockNumber: BlockNumber, timestamp: UInt64, totalNumTxs: number) {
|
|
205
218
|
if (!this.provingState) {
|
|
206
219
|
throw new Error('Empty epoch proving state. Call startNewEpoch before starting a block.');
|
|
207
220
|
}
|
|
@@ -216,21 +229,21 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
216
229
|
}
|
|
217
230
|
|
|
218
231
|
const constants = checkpointProvingState.constants;
|
|
219
|
-
logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber
|
|
232
|
+
this.logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
|
|
220
233
|
|
|
221
234
|
// Fork the db only when it's not already set. The db for the first block is set in `startNewCheckpoint`.
|
|
222
235
|
if (!this.dbs.has(blockNumber)) {
|
|
223
236
|
// Fork world state at the end of the immediately previous block
|
|
224
|
-
const db = await this.dbProvider.fork(blockNumber - 1);
|
|
237
|
+
const db = await this.dbProvider.fork(BlockNumber(blockNumber - 1));
|
|
225
238
|
this.dbs.set(blockNumber, db);
|
|
226
239
|
}
|
|
227
|
-
const db = this.
|
|
240
|
+
const db = this.getDbForBlock(blockNumber);
|
|
228
241
|
|
|
229
242
|
// Get archive snapshot and sibling path before any txs in this block lands.
|
|
230
243
|
const lastArchiveTreeSnapshot = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
231
244
|
const lastArchiveSiblingPath = await getRootTreeSiblingPath(MerkleTreeId.ARCHIVE, db);
|
|
232
245
|
|
|
233
|
-
const blockProvingState =
|
|
246
|
+
const blockProvingState = checkpointProvingState.startNewBlock(
|
|
234
247
|
blockNumber,
|
|
235
248
|
timestamp,
|
|
236
249
|
totalNumTxs,
|
|
@@ -248,11 +261,16 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
248
261
|
// Because `addTxs` won't be called for a block without txs, and that's where the sponge blob state is computed.
|
|
249
262
|
// We need to set its end sponge blob here, which will become the start sponge blob for the next block.
|
|
250
263
|
if (totalNumTxs === 0) {
|
|
264
|
+
const endState = await db.getStateReference();
|
|
265
|
+
blockProvingState.setEndState(endState);
|
|
266
|
+
|
|
251
267
|
const endSpongeBlob = blockProvingState.getStartSpongeBlob().clone();
|
|
252
|
-
|
|
268
|
+
const blockEndBlobFields = blockProvingState.getBlockEndBlobFields();
|
|
269
|
+
await endSpongeBlob.absorb(blockEndBlobFields);
|
|
253
270
|
blockProvingState.setEndSpongeBlob(endSpongeBlob);
|
|
254
271
|
|
|
255
|
-
//
|
|
272
|
+
// Try to accumulate the out hashes and blobs as far as we can:
|
|
273
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
256
274
|
await this.provingState.setBlobAccumulators();
|
|
257
275
|
}
|
|
258
276
|
}
|
|
@@ -272,11 +290,11 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
272
290
|
if (!txs.length) {
|
|
273
291
|
// To avoid an ugly throw below. If we require an empty block, we can just call setBlockCompleted
|
|
274
292
|
// 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.`);
|
|
293
|
+
this.logger.warn(`Provided no txs to orchestrator addTxs.`);
|
|
276
294
|
return;
|
|
277
295
|
}
|
|
278
296
|
|
|
279
|
-
const blockNumber = txs[0].globalVariables.blockNumber;
|
|
297
|
+
const blockNumber = BlockNumber(txs[0].globalVariables.blockNumber);
|
|
280
298
|
const provingState = this.provingState.getBlockProvingStateByBlockNumber(blockNumber!);
|
|
281
299
|
if (!provingState) {
|
|
282
300
|
throw new Error(`Proving state for block ${blockNumber} not found. Call startNewBlock first.`);
|
|
@@ -292,9 +310,9 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
292
310
|
throw new Error(`Block ${blockNumber} has been initialized with transactions.`);
|
|
293
311
|
}
|
|
294
312
|
|
|
295
|
-
logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
313
|
+
this.logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
296
314
|
|
|
297
|
-
const db = this.
|
|
315
|
+
const db = this.getDbForBlock(blockNumber);
|
|
298
316
|
const lastArchive = provingState.lastArchiveTreeSnapshot;
|
|
299
317
|
const newL1ToL2MessageTreeSnapshot = provingState.newL1ToL2MessageTreeSnapshot;
|
|
300
318
|
const spongeBlobState = provingState.getStartSpongeBlob().clone();
|
|
@@ -307,7 +325,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
307
325
|
|
|
308
326
|
validateTx(tx);
|
|
309
327
|
|
|
310
|
-
logger.
|
|
328
|
+
this.logger.debug(`Received transaction: ${tx.hash}`);
|
|
311
329
|
|
|
312
330
|
const startSpongeBlob = spongeBlobState.clone();
|
|
313
331
|
const [hints, treeSnapshots] = await this.prepareBaseRollupInputs(
|
|
@@ -328,10 +346,10 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
328
346
|
const txIndex = provingState.addNewTx(txProvingState);
|
|
329
347
|
if (txProvingState.requireAvmProof) {
|
|
330
348
|
this.getOrEnqueueChonkVerifier(provingState, txIndex);
|
|
331
|
-
logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
349
|
+
this.logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
332
350
|
this.enqueueVM(provingState, txIndex);
|
|
333
351
|
} else {
|
|
334
|
-
logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
352
|
+
this.logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
335
353
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
336
354
|
}
|
|
337
355
|
} catch (err: any) {
|
|
@@ -341,11 +359,16 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
341
359
|
}
|
|
342
360
|
}
|
|
343
361
|
|
|
344
|
-
await
|
|
362
|
+
const endState = await db.getStateReference();
|
|
363
|
+
provingState.setEndState(endState);
|
|
364
|
+
|
|
365
|
+
const blockEndBlobFields = provingState.getBlockEndBlobFields();
|
|
366
|
+
await spongeBlobState.absorb(blockEndBlobFields);
|
|
345
367
|
|
|
346
368
|
provingState.setEndSpongeBlob(spongeBlobState);
|
|
347
369
|
|
|
348
|
-
// Txs have been added to the block. Now try to accumulate the blobs as far as we can:
|
|
370
|
+
// Txs have been added to the block. Now try to accumulate the out hashes and blobs as far as we can:
|
|
371
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
349
372
|
await this.provingState.setBlobAccumulators();
|
|
350
373
|
}
|
|
351
374
|
|
|
@@ -369,7 +392,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
369
392
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
370
393
|
>
|
|
371
394
|
>();
|
|
372
|
-
logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
|
|
395
|
+
this.logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
|
|
373
396
|
this.doEnqueueChonkVerifier(txHash, privateInputs, proof => {
|
|
374
397
|
tubeProof.resolve(proof);
|
|
375
398
|
});
|
|
@@ -382,10 +405,10 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
382
405
|
* Marks the block as completed.
|
|
383
406
|
* Computes the block header and updates the archive tree.
|
|
384
407
|
*/
|
|
385
|
-
@trackSpan('ProvingOrchestrator.setBlockCompleted', (blockNumber:
|
|
408
|
+
@trackSpan('ProvingOrchestrator.setBlockCompleted', (blockNumber: BlockNumber) => ({
|
|
386
409
|
[Attributes.BLOCK_NUMBER]: blockNumber,
|
|
387
410
|
}))
|
|
388
|
-
public async setBlockCompleted(blockNumber:
|
|
411
|
+
public async setBlockCompleted(blockNumber: BlockNumber, expectedHeader?: BlockHeader): Promise<BlockHeader> {
|
|
389
412
|
const provingState = this.provingState?.getBlockProvingStateByBlockNumber(blockNumber);
|
|
390
413
|
if (!provingState) {
|
|
391
414
|
throw new Error(`Block proving state for ${blockNumber} not found`);
|
|
@@ -408,39 +431,31 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
408
431
|
);
|
|
409
432
|
}
|
|
410
433
|
|
|
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);
|
|
434
|
+
// Given we've applied every change from this block, now assemble the block header:
|
|
435
|
+
this.logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
|
|
436
|
+
const header = await provingState.buildBlockHeader();
|
|
432
437
|
|
|
433
438
|
if (expectedHeader && !header.equals(expectedHeader)) {
|
|
434
|
-
logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
439
|
+
this.logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
435
440
|
throw new Error('Block header mismatch');
|
|
436
441
|
}
|
|
437
442
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
);
|
|
441
|
-
await db.updateArchive(header);
|
|
443
|
+
// Get db for this block and remove from map — no other code should use it after this point.
|
|
444
|
+
const db = this.getDbForBlock(provingState.blockNumber);
|
|
445
|
+
this.dbs.delete(provingState.blockNumber);
|
|
442
446
|
|
|
443
|
-
|
|
447
|
+
// Update the archive tree, capture the snapshot, and close the fork deterministically.
|
|
448
|
+
try {
|
|
449
|
+
this.logger.verbose(
|
|
450
|
+
`Updating archive tree with block ${provingState.blockNumber} header ${(await header.hash()).toString()}`,
|
|
451
|
+
);
|
|
452
|
+
await db.updateArchive(header);
|
|
453
|
+
provingState.setBuiltArchive(await getTreeSnapshot(MerkleTreeId.ARCHIVE, db));
|
|
454
|
+
} finally {
|
|
455
|
+
await db.close();
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
444
459
|
|
|
445
460
|
return header;
|
|
446
461
|
}
|
|
@@ -449,31 +464,34 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
449
464
|
protected async verifyBuiltBlockAgainstSyncedState(provingState: BlockProvingState) {
|
|
450
465
|
const builtBlockHeader = provingState.getBuiltBlockHeader();
|
|
451
466
|
if (!builtBlockHeader) {
|
|
452
|
-
logger.debug('Block header not built yet, skipping header check.');
|
|
467
|
+
this.logger.debug('Block header not built yet, skipping header check.');
|
|
453
468
|
return;
|
|
454
469
|
}
|
|
455
470
|
|
|
456
471
|
const output = provingState.getBlockRootRollupOutput();
|
|
457
472
|
if (!output) {
|
|
458
|
-
logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
473
|
+
this.logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
459
474
|
return;
|
|
460
475
|
}
|
|
476
|
+
|
|
477
|
+
const newArchive = provingState.getBuiltArchive();
|
|
478
|
+
if (!newArchive) {
|
|
479
|
+
this.logger.debug('Archive snapshot not yet captured, skipping header check.');
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
|
|
461
483
|
const header = await buildHeaderFromCircuitOutputs(output);
|
|
462
484
|
|
|
463
485
|
if (!(await header.hash()).equals(await builtBlockHeader.hash())) {
|
|
464
|
-
logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
486
|
+
this.logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
465
487
|
provingState.reject(`Block header hash mismatch.`);
|
|
466
488
|
return;
|
|
467
489
|
}
|
|
468
490
|
|
|
469
|
-
// Get db for this block
|
|
470
491
|
const blockNumber = provingState.blockNumber;
|
|
471
|
-
const db = this.dbs.get(blockNumber)!;
|
|
472
|
-
|
|
473
|
-
const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
474
492
|
const syncedArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.dbProvider.getSnapshot(blockNumber));
|
|
475
493
|
if (!syncedArchive.equals(newArchive)) {
|
|
476
|
-
logger.error(
|
|
494
|
+
this.logger.error(
|
|
477
495
|
`Archive tree mismatch for block ${blockNumber}: world state synced to ${inspect(
|
|
478
496
|
syncedArchive,
|
|
479
497
|
)} but built ${inspect(newArchive)}`,
|
|
@@ -484,32 +502,38 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
484
502
|
|
|
485
503
|
const circuitArchive = output.newArchive;
|
|
486
504
|
if (!newArchive.equals(circuitArchive)) {
|
|
487
|
-
logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
505
|
+
this.logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
488
506
|
provingState.reject(`New archive mismatch.`);
|
|
489
507
|
return;
|
|
490
508
|
}
|
|
491
|
-
|
|
492
|
-
// TODO(palla/prover): This closes the fork only on the happy path. If this epoch orchestrator
|
|
493
|
-
// is aborted and never reaches this point, it will leak the fork. We need to add a global cleanup,
|
|
494
|
-
// but have to make sure it only runs once all operations are completed, otherwise some function here
|
|
495
|
-
// will attempt to access the fork after it was closed.
|
|
496
|
-
logger.debug(`Cleaning up world state fork for ${blockNumber}`);
|
|
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));
|
|
502
509
|
}
|
|
503
510
|
|
|
504
511
|
/**
|
|
505
|
-
* Cancel any further proving
|
|
512
|
+
* Cancel any further proving.
|
|
513
|
+
* If cancelJobsOnStop is true, aborts all pending jobs with the broker (which marks them as 'Aborted').
|
|
514
|
+
* If cancelJobsOnStop is false (default), jobs remain in the broker queue and can be reused on restart/reorg.
|
|
506
515
|
*/
|
|
507
516
|
public cancel() {
|
|
508
|
-
|
|
509
|
-
controller.
|
|
517
|
+
if (this.cancelJobsOnStop) {
|
|
518
|
+
for (const controller of this.pendingProvingJobs) {
|
|
519
|
+
controller.abort();
|
|
520
|
+
}
|
|
510
521
|
}
|
|
511
522
|
|
|
512
523
|
this.provingState?.cancel();
|
|
524
|
+
|
|
525
|
+
for (const [blockNumber, db] of this.dbs.entries()) {
|
|
526
|
+
void db.close().catch(err => this.logger.error(`Error closing db for block ${blockNumber}`, err));
|
|
527
|
+
}
|
|
528
|
+
this.dbs.clear();
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
private getDbForBlock(blockNumber: BlockNumber): MerkleTreeWriteOperations {
|
|
532
|
+
const db = this.dbs.get(blockNumber);
|
|
533
|
+
if (!db) {
|
|
534
|
+
throw new Error(`World state fork for block ${blockNumber} not found.`);
|
|
535
|
+
}
|
|
536
|
+
return db;
|
|
513
537
|
}
|
|
514
538
|
|
|
515
539
|
/**
|
|
@@ -553,7 +577,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
553
577
|
callback: (result: T) => void | Promise<void>,
|
|
554
578
|
) {
|
|
555
579
|
if (!provingState.verifyState()) {
|
|
556
|
-
logger.debug(`Not enqueuing job, state no longer valid`);
|
|
580
|
+
this.logger.debug(`Not enqueuing job, state no longer valid`);
|
|
557
581
|
return;
|
|
558
582
|
}
|
|
559
583
|
|
|
@@ -571,7 +595,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
571
595
|
|
|
572
596
|
const result = await request(controller.signal);
|
|
573
597
|
if (!provingState.verifyState()) {
|
|
574
|
-
logger.debug(`State no longer valid, discarding result`);
|
|
598
|
+
this.logger.debug(`State no longer valid, discarding result`);
|
|
575
599
|
return;
|
|
576
600
|
}
|
|
577
601
|
|
|
@@ -589,7 +613,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
589
613
|
return;
|
|
590
614
|
}
|
|
591
615
|
|
|
592
|
-
logger.error(`Error thrown when proving job`, err);
|
|
616
|
+
this.logger.error(`Error thrown when proving job`, err);
|
|
593
617
|
provingState!.reject(`${err}`);
|
|
594
618
|
} finally {
|
|
595
619
|
const index = this.pendingProvingJobs.indexOf(controller);
|
|
@@ -674,12 +698,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
674
698
|
// Executes the next level of merge if all inputs are available
|
|
675
699
|
private enqueueBaseRollup(provingState: BlockProvingState, txIndex: number) {
|
|
676
700
|
if (!provingState.verifyState()) {
|
|
677
|
-
logger.debug('Not running base rollup, state invalid');
|
|
701
|
+
this.logger.debug('Not running base rollup, state invalid');
|
|
678
702
|
return;
|
|
679
703
|
}
|
|
680
704
|
|
|
681
705
|
if (!provingState.tryStartProvingBase(txIndex)) {
|
|
682
|
-
logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
706
|
+
this.logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
683
707
|
return;
|
|
684
708
|
}
|
|
685
709
|
|
|
@@ -687,7 +711,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
687
711
|
const { processedTx } = txProvingState;
|
|
688
712
|
const { rollupType, inputs } = txProvingState.getBaseRollupTypeAndInputs();
|
|
689
713
|
|
|
690
|
-
logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
714
|
+
this.logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
691
715
|
|
|
692
716
|
this.deferredProving(
|
|
693
717
|
provingState,
|
|
@@ -711,7 +735,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
711
735
|
},
|
|
712
736
|
),
|
|
713
737
|
result => {
|
|
714
|
-
logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
738
|
+
this.logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
715
739
|
validatePartialState(result.inputs.endTreeSnapshots, txProvingState.treeSnapshots);
|
|
716
740
|
const leafLocation = provingState.setBaseRollupProof(txIndex, result);
|
|
717
741
|
if (provingState.totalNumTxs === 1) {
|
|
@@ -727,7 +751,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
727
751
|
// Once completed, will enqueue the the public tx base rollup.
|
|
728
752
|
private getOrEnqueueChonkVerifier(provingState: BlockProvingState, txIndex: number) {
|
|
729
753
|
if (!provingState.verifyState()) {
|
|
730
|
-
logger.debug('Not running chonk verifier circuit, state invalid');
|
|
754
|
+
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
731
755
|
return;
|
|
732
756
|
}
|
|
733
757
|
|
|
@@ -740,19 +764,19 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
740
764
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
741
765
|
>,
|
|
742
766
|
) => {
|
|
743
|
-
logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, { txHash });
|
|
767
|
+
this.logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, { txHash });
|
|
744
768
|
txProvingState.setPublicChonkVerifierProof(result);
|
|
745
769
|
this.provingState?.cachedChonkVerifierProofs.delete(txHash);
|
|
746
770
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
747
771
|
};
|
|
748
772
|
|
|
749
773
|
if (this.provingState?.cachedChonkVerifierProofs.has(txHash)) {
|
|
750
|
-
logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, { txHash });
|
|
774
|
+
this.logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, { txHash });
|
|
751
775
|
void this.provingState!.cachedChonkVerifierProofs.get(txHash)!.then(handleResult);
|
|
752
776
|
return;
|
|
753
777
|
}
|
|
754
778
|
|
|
755
|
-
logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
|
|
779
|
+
this.logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
|
|
756
780
|
this.doEnqueueChonkVerifier(txHash, txProvingState.getPublicChonkVerifierPrivateInputs(), handleResult);
|
|
757
781
|
}
|
|
758
782
|
|
|
@@ -768,7 +792,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
768
792
|
provingState: EpochProvingState | BlockProvingState = this.provingState!,
|
|
769
793
|
) {
|
|
770
794
|
if (!provingState.verifyState()) {
|
|
771
|
-
logger.debug('Not running chonk verifier circuit, state invalid');
|
|
795
|
+
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
772
796
|
return;
|
|
773
797
|
}
|
|
774
798
|
|
|
@@ -791,12 +815,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
791
815
|
// Enqueues the next level of merge if all inputs are available
|
|
792
816
|
private enqueueMergeRollup(provingState: BlockProvingState, location: TreeNodeLocation) {
|
|
793
817
|
if (!provingState.verifyState()) {
|
|
794
|
-
logger.debug('Not running merge rollup. State no longer valid.');
|
|
818
|
+
this.logger.debug('Not running merge rollup. State no longer valid.');
|
|
795
819
|
return;
|
|
796
820
|
}
|
|
797
821
|
|
|
798
822
|
if (!provingState.tryStartProvingMerge(location)) {
|
|
799
|
-
logger.debug('Merge rollup already started.');
|
|
823
|
+
this.logger.debug('Merge rollup already started.');
|
|
800
824
|
return;
|
|
801
825
|
}
|
|
802
826
|
|
|
@@ -822,18 +846,18 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
822
846
|
// Executes the block root rollup circuit
|
|
823
847
|
private enqueueBlockRootRollup(provingState: BlockProvingState) {
|
|
824
848
|
if (!provingState.verifyState()) {
|
|
825
|
-
logger.debug('Not running block root rollup, state no longer valid');
|
|
849
|
+
this.logger.debug('Not running block root rollup, state no longer valid');
|
|
826
850
|
return;
|
|
827
851
|
}
|
|
828
852
|
|
|
829
853
|
if (!provingState.tryStartProvingBlockRoot()) {
|
|
830
|
-
logger.debug('Block root rollup already started.');
|
|
854
|
+
this.logger.debug('Block root rollup already started.');
|
|
831
855
|
return;
|
|
832
856
|
}
|
|
833
857
|
|
|
834
858
|
const { rollupType, inputs } = provingState.getBlockRootRollupTypeAndInputs();
|
|
835
859
|
|
|
836
|
-
logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
860
|
+
this.logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
837
861
|
|
|
838
862
|
this.deferredProving(
|
|
839
863
|
provingState,
|
|
@@ -858,18 +882,19 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
858
882
|
},
|
|
859
883
|
),
|
|
860
884
|
async result => {
|
|
861
|
-
|
|
862
|
-
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
863
|
-
|
|
864
|
-
logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`);
|
|
885
|
+
this.logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`);
|
|
865
886
|
|
|
866
887
|
const leafLocation = provingState.setBlockRootRollupProof(result);
|
|
867
888
|
const checkpointProvingState = provingState.parentCheckpoint;
|
|
868
889
|
|
|
890
|
+
// Verification is called from both here and setBlockCompleted. Whichever runs last
|
|
891
|
+
// will be the first to see all three pieces (header, proof output, archive) and run the checks.
|
|
892
|
+
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
893
|
+
|
|
869
894
|
if (checkpointProvingState.totalNumBlocks === 1) {
|
|
870
|
-
this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
895
|
+
await this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
871
896
|
} else {
|
|
872
|
-
this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
897
|
+
await this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
873
898
|
}
|
|
874
899
|
},
|
|
875
900
|
);
|
|
@@ -883,12 +908,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
883
908
|
baseParityIndex: number,
|
|
884
909
|
) {
|
|
885
910
|
if (!provingState.verifyState()) {
|
|
886
|
-
logger.debug('Not running base parity. State no longer valid.');
|
|
911
|
+
this.logger.debug('Not running base parity. State no longer valid.');
|
|
887
912
|
return;
|
|
888
913
|
}
|
|
889
914
|
|
|
890
915
|
if (!provingState.tryStartProvingBaseParity(baseParityIndex)) {
|
|
891
|
-
logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
916
|
+
this.logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
892
917
|
return;
|
|
893
918
|
}
|
|
894
919
|
|
|
@@ -923,12 +948,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
923
948
|
// Enqueues the root rollup proof if all inputs are available
|
|
924
949
|
private enqueueRootParityCircuit(provingState: BlockProvingState) {
|
|
925
950
|
if (!provingState.verifyState()) {
|
|
926
|
-
logger.debug('Not running root parity. State no longer valid.');
|
|
951
|
+
this.logger.debug('Not running root parity. State no longer valid.');
|
|
927
952
|
return;
|
|
928
953
|
}
|
|
929
954
|
|
|
930
955
|
if (!provingState.tryStartProvingRootParity()) {
|
|
931
|
-
logger.debug('Root parity already started.');
|
|
956
|
+
this.logger.debug('Root parity already started.');
|
|
932
957
|
return;
|
|
933
958
|
}
|
|
934
959
|
|
|
@@ -955,12 +980,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
955
980
|
// Enqueues the next level of merge if all inputs are available
|
|
956
981
|
private enqueueBlockMergeRollup(provingState: CheckpointProvingState, location: TreeNodeLocation) {
|
|
957
982
|
if (!provingState.verifyState()) {
|
|
958
|
-
logger.debug('Not running block merge rollup. State no longer valid.');
|
|
983
|
+
this.logger.debug('Not running block merge rollup. State no longer valid.');
|
|
959
984
|
return;
|
|
960
985
|
}
|
|
961
986
|
|
|
962
987
|
if (!provingState.tryStartProvingBlockMerge(location)) {
|
|
963
|
-
logger.debug('Block merge rollup already started.');
|
|
988
|
+
this.logger.debug('Block merge rollup already started.');
|
|
964
989
|
return;
|
|
965
990
|
}
|
|
966
991
|
|
|
@@ -975,29 +1000,29 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
975
1000
|
},
|
|
976
1001
|
signal => this.prover.getBlockMergeRollupProof(inputs, signal, provingState.epochNumber),
|
|
977
1002
|
),
|
|
978
|
-
result => {
|
|
1003
|
+
async result => {
|
|
979
1004
|
provingState.setBlockMergeRollupProof(location, result);
|
|
980
|
-
this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
1005
|
+
await this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
981
1006
|
},
|
|
982
1007
|
);
|
|
983
1008
|
}
|
|
984
1009
|
|
|
985
|
-
private enqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
1010
|
+
private async enqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
986
1011
|
if (!provingState.verifyState()) {
|
|
987
|
-
logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
1012
|
+
this.logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
988
1013
|
return;
|
|
989
1014
|
}
|
|
990
1015
|
|
|
991
1016
|
if (!provingState.tryStartProvingCheckpointRoot()) {
|
|
992
|
-
logger.debug('Checkpoint root rollup already started.');
|
|
1017
|
+
this.logger.debug('Checkpoint root rollup already started.');
|
|
993
1018
|
return;
|
|
994
1019
|
}
|
|
995
1020
|
|
|
996
1021
|
const rollupType = provingState.getCheckpointRootRollupType();
|
|
997
1022
|
|
|
998
|
-
logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
1023
|
+
this.logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
999
1024
|
|
|
1000
|
-
const inputs = provingState.getCheckpointRootRollupInputs();
|
|
1025
|
+
const inputs = await provingState.getCheckpointRootRollupInputs();
|
|
1001
1026
|
|
|
1002
1027
|
this.deferredProving(
|
|
1003
1028
|
provingState,
|
|
@@ -1019,7 +1044,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1019
1044
|
const computedEndBlobAccumulatorState = provingState.getEndBlobAccumulator()!.toBlobAccumulator();
|
|
1020
1045
|
const circuitEndBlobAccumulatorState = result.inputs.endBlobAccumulator;
|
|
1021
1046
|
if (!circuitEndBlobAccumulatorState.equals(computedEndBlobAccumulatorState)) {
|
|
1022
|
-
logger.error(
|
|
1047
|
+
this.logger.error(
|
|
1023
1048
|
`Blob accumulator state mismatch.\nCircuit: ${inspect(circuitEndBlobAccumulatorState)}\nComputed: ${inspect(
|
|
1024
1049
|
computedEndBlobAccumulatorState,
|
|
1025
1050
|
)}`,
|
|
@@ -1028,7 +1053,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1028
1053
|
return;
|
|
1029
1054
|
}
|
|
1030
1055
|
|
|
1031
|
-
logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}.`);
|
|
1056
|
+
this.logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}.`);
|
|
1032
1057
|
|
|
1033
1058
|
const leafLocation = provingState.setCheckpointRootRollupProof(result);
|
|
1034
1059
|
const epochProvingState = provingState.parentEpoch;
|
|
@@ -1044,12 +1069,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1044
1069
|
|
|
1045
1070
|
private enqueueCheckpointMergeRollup(provingState: EpochProvingState, location: TreeNodeLocation) {
|
|
1046
1071
|
if (!provingState.verifyState()) {
|
|
1047
|
-
logger.debug('Not running checkpoint merge rollup. State no longer valid.');
|
|
1072
|
+
this.logger.debug('Not running checkpoint merge rollup. State no longer valid.');
|
|
1048
1073
|
return;
|
|
1049
1074
|
}
|
|
1050
1075
|
|
|
1051
1076
|
if (!provingState.tryStartProvingCheckpointMerge(location)) {
|
|
1052
|
-
logger.debug('Checkpoint merge rollup already started.');
|
|
1077
|
+
this.logger.debug('Checkpoint merge rollup already started.');
|
|
1053
1078
|
return;
|
|
1054
1079
|
}
|
|
1055
1080
|
|
|
@@ -1066,7 +1091,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1066
1091
|
signal => this.prover.getCheckpointMergeRollupProof(inputs, signal, provingState.epochNumber),
|
|
1067
1092
|
),
|
|
1068
1093
|
result => {
|
|
1069
|
-
logger.debug('Completed proof for checkpoint merge rollup.');
|
|
1094
|
+
this.logger.debug('Completed proof for checkpoint merge rollup.');
|
|
1070
1095
|
provingState.setCheckpointMergeRollupProof(location, result);
|
|
1071
1096
|
this.checkAndEnqueueNextCheckpointMergeRollup(provingState, location);
|
|
1072
1097
|
},
|
|
@@ -1075,16 +1100,16 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1075
1100
|
|
|
1076
1101
|
private enqueueEpochPadding(provingState: EpochProvingState) {
|
|
1077
1102
|
if (!provingState.verifyState()) {
|
|
1078
|
-
logger.debug('Not running epoch padding. State no longer valid.');
|
|
1103
|
+
this.logger.debug('Not running epoch padding. State no longer valid.');
|
|
1079
1104
|
return;
|
|
1080
1105
|
}
|
|
1081
1106
|
|
|
1082
1107
|
if (!provingState.tryStartProvingPaddingCheckpoint()) {
|
|
1083
|
-
logger.debug('Padding checkpoint already started.');
|
|
1108
|
+
this.logger.debug('Padding checkpoint already started.');
|
|
1084
1109
|
return;
|
|
1085
1110
|
}
|
|
1086
1111
|
|
|
1087
|
-
logger.debug('Padding epoch proof with a padding block root proof.');
|
|
1112
|
+
this.logger.debug('Padding epoch proof with a padding block root proof.');
|
|
1088
1113
|
|
|
1089
1114
|
const inputs = provingState.getPaddingCheckpointInputs();
|
|
1090
1115
|
|
|
@@ -1099,7 +1124,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1099
1124
|
signal => this.prover.getCheckpointPaddingRollupProof(inputs, signal, provingState.epochNumber),
|
|
1100
1125
|
),
|
|
1101
1126
|
result => {
|
|
1102
|
-
logger.debug('Completed proof for padding checkpoint.');
|
|
1127
|
+
this.logger.debug('Completed proof for padding checkpoint.');
|
|
1103
1128
|
provingState.setCheckpointPaddingProof(result);
|
|
1104
1129
|
this.checkAndEnqueueRootRollup(provingState);
|
|
1105
1130
|
},
|
|
@@ -1109,11 +1134,11 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1109
1134
|
// Executes the root rollup circuit
|
|
1110
1135
|
private enqueueRootRollup(provingState: EpochProvingState) {
|
|
1111
1136
|
if (!provingState.verifyState()) {
|
|
1112
|
-
logger.debug('Not running root rollup, state no longer valid');
|
|
1137
|
+
this.logger.debug('Not running root rollup, state no longer valid');
|
|
1113
1138
|
return;
|
|
1114
1139
|
}
|
|
1115
1140
|
|
|
1116
|
-
logger.debug(`Preparing root rollup`);
|
|
1141
|
+
this.logger.debug(`Preparing root rollup`);
|
|
1117
1142
|
|
|
1118
1143
|
const inputs = provingState.getRootRollupInputs();
|
|
1119
1144
|
|
|
@@ -1128,7 +1153,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1128
1153
|
signal => this.prover.getRootRollupProof(inputs, signal, provingState.epochNumber),
|
|
1129
1154
|
),
|
|
1130
1155
|
result => {
|
|
1131
|
-
logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
|
|
1156
|
+
this.logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
|
|
1132
1157
|
provingState.setRootRollupProof(result);
|
|
1133
1158
|
provingState.resolve({ status: 'success' });
|
|
1134
1159
|
},
|
|
@@ -1150,32 +1175,35 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1150
1175
|
|
|
1151
1176
|
private checkAndEnqueueBlockRootRollup(provingState: BlockProvingState) {
|
|
1152
1177
|
if (!provingState.isReadyForBlockRootRollup()) {
|
|
1153
|
-
logger.debug('Not ready for block root rollup');
|
|
1178
|
+
this.logger.debug('Not ready for block root rollup');
|
|
1154
1179
|
return;
|
|
1155
1180
|
}
|
|
1156
1181
|
|
|
1157
1182
|
this.enqueueBlockRootRollup(provingState);
|
|
1158
1183
|
}
|
|
1159
1184
|
|
|
1160
|
-
private checkAndEnqueueNextBlockMergeRollup(
|
|
1185
|
+
private async checkAndEnqueueNextBlockMergeRollup(
|
|
1186
|
+
provingState: CheckpointProvingState,
|
|
1187
|
+
currentLocation: TreeNodeLocation,
|
|
1188
|
+
) {
|
|
1161
1189
|
if (!provingState.isReadyForBlockMerge(currentLocation)) {
|
|
1162
1190
|
return;
|
|
1163
1191
|
}
|
|
1164
1192
|
|
|
1165
1193
|
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
1166
1194
|
if (parentLocation.level === 0) {
|
|
1167
|
-
this.checkAndEnqueueCheckpointRootRollup(provingState);
|
|
1195
|
+
await this.checkAndEnqueueCheckpointRootRollup(provingState);
|
|
1168
1196
|
} else {
|
|
1169
1197
|
this.enqueueBlockMergeRollup(provingState, parentLocation);
|
|
1170
1198
|
}
|
|
1171
1199
|
}
|
|
1172
1200
|
|
|
1173
|
-
private checkAndEnqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
1201
|
+
private async checkAndEnqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
1174
1202
|
if (!provingState.isReadyForCheckpointRoot()) {
|
|
1175
1203
|
return;
|
|
1176
1204
|
}
|
|
1177
1205
|
|
|
1178
|
-
this.enqueueCheckpointRootRollup(provingState);
|
|
1206
|
+
await this.enqueueCheckpointRootRollup(provingState);
|
|
1179
1207
|
}
|
|
1180
1208
|
|
|
1181
1209
|
private checkAndEnqueueNextCheckpointMergeRollup(provingState: EpochProvingState, currentLocation: TreeNodeLocation) {
|
|
@@ -1193,7 +1221,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1193
1221
|
|
|
1194
1222
|
private checkAndEnqueueRootRollup(provingState: EpochProvingState) {
|
|
1195
1223
|
if (!provingState.isReadyForRootRollup()) {
|
|
1196
|
-
logger.debug('Not ready for root rollup');
|
|
1224
|
+
this.logger.debug('Not ready for root rollup');
|
|
1197
1225
|
return;
|
|
1198
1226
|
}
|
|
1199
1227
|
|
|
@@ -1208,14 +1236,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1208
1236
|
*/
|
|
1209
1237
|
private enqueueVM(provingState: BlockProvingState, txIndex: number) {
|
|
1210
1238
|
if (!provingState.verifyState()) {
|
|
1211
|
-
logger.debug(`Not running VM circuit as state is no longer valid`);
|
|
1239
|
+
this.logger.debug(`Not running VM circuit as state is no longer valid`);
|
|
1212
1240
|
return;
|
|
1213
1241
|
}
|
|
1214
1242
|
|
|
1215
1243
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
1216
1244
|
|
|
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
1245
|
const doAvmProving = wrapCallbackInSpan(
|
|
1220
1246
|
this.tracer,
|
|
1221
1247
|
'ProvingOrchestrator.prover.getAvmProof',
|
|
@@ -1224,36 +1250,13 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1224
1250
|
},
|
|
1225
1251
|
async (signal: AbortSignal) => {
|
|
1226
1252
|
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
|
-
}
|
|
1253
|
+
return await this.prover.getAvmProof(inputs, signal, provingState.epochNumber);
|
|
1251
1254
|
},
|
|
1252
1255
|
);
|
|
1253
1256
|
|
|
1254
|
-
this.deferredProving(provingState, doAvmProving,
|
|
1255
|
-
logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1256
|
-
txProvingState.setAvmProof(
|
|
1257
|
+
this.deferredProving(provingState, doAvmProving, proof => {
|
|
1258
|
+
this.logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1259
|
+
txProvingState.setAvmProof(proof);
|
|
1257
1260
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
1258
1261
|
});
|
|
1259
1262
|
}
|
|
@@ -1265,7 +1268,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1265
1268
|
}
|
|
1266
1269
|
|
|
1267
1270
|
// 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`);
|
|
1271
|
+
this.logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1269
1272
|
|
|
1270
1273
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
1271
1274
|
}
|