@aztec/prover-client 0.0.1-commit.1142ef1 → 0.0.1-commit.1bea0213
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/light/lightweight_checkpoint_builder.d.ts +8 -7
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
- package/dest/light/lightweight_checkpoint_builder.js +20 -9
- package/dest/mocks/test_context.d.ts +3 -2
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +6 -1
- package/dest/orchestrator/block-building-helpers.d.ts +1 -1
- package/dest/orchestrator/block-building-helpers.js +1 -1
- package/dest/orchestrator/checkpoint-proving-state.d.ts +15 -2
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/checkpoint-proving-state.js +34 -1
- package/dest/orchestrator/epoch-proving-state.d.ts +5 -4
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +35 -1
- package/dest/orchestrator/orchestrator.d.ts +16 -3
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +58 -17
- package/dest/prover-client/prover-client.d.ts +1 -1
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +1 -1
- package/dest/proving_broker/config.d.ts +5 -1
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +7 -1
- package/dest/test/mock_proof_store.d.ts +3 -3
- package/dest/test/mock_proof_store.d.ts.map +1 -1
- package/package.json +16 -17
- package/src/light/lightweight_checkpoint_builder.ts +35 -10
- package/src/mocks/test_context.ts +5 -0
- package/src/orchestrator/block-building-helpers.ts +1 -1
- package/src/orchestrator/checkpoint-proving-state.ts +47 -1
- package/src/orchestrator/epoch-proving-state.ts +56 -8
- package/src/orchestrator/orchestrator.ts +61 -21
- package/src/prover-client/prover-client.ts +7 -1
- package/src/proving_broker/config.ts +9 -0
- package/dest/block-factory/index.d.ts +0 -2
- package/dest/block-factory/index.d.ts.map +0 -1
- package/dest/block-factory/index.js +0 -1
- package/dest/block-factory/light.d.ts +0 -38
- package/dest/block-factory/light.d.ts.map +0 -1
- package/dest/block-factory/light.js +0 -106
- package/src/block-factory/index.ts +0 -1
- package/src/block-factory/light.ts +0 -136
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
type L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
|
|
12
12
|
type NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
|
|
13
13
|
NUM_MSGS_PER_BASE_PARITY,
|
|
14
|
+
OUT_HASH_TREE_HEIGHT,
|
|
14
15
|
} from '@aztec/constants';
|
|
15
16
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
16
17
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
@@ -19,6 +20,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
19
20
|
import type { Tuple } from '@aztec/foundation/serialize';
|
|
20
21
|
import { type TreeNodeLocation, UnbalancedTreeStore } from '@aztec/foundation/trees';
|
|
21
22
|
import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
|
|
23
|
+
import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
|
|
22
24
|
import { ParityBasePrivateInputs } from '@aztec/stdlib/parity';
|
|
23
25
|
import {
|
|
24
26
|
BlockMergeRollupPrivateInputs,
|
|
@@ -38,6 +40,11 @@ import { accumulateBlobs, buildBlobHints, toProofData } from './block-building-h
|
|
|
38
40
|
import { BlockProvingState, type ProofState } from './block-proving-state.js';
|
|
39
41
|
import type { EpochProvingState } from './epoch-proving-state.js';
|
|
40
42
|
|
|
43
|
+
type OutHashHint = {
|
|
44
|
+
treeSnapshot: AppendOnlyTreeSnapshot;
|
|
45
|
+
siblingPath: Tuple<Fr, typeof OUT_HASH_TREE_HEIGHT>;
|
|
46
|
+
};
|
|
47
|
+
|
|
41
48
|
export class CheckpointProvingState {
|
|
42
49
|
private blockProofs: UnbalancedTreeStore<
|
|
43
50
|
ProofState<BlockRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
|
|
@@ -46,6 +53,11 @@ export class CheckpointProvingState {
|
|
|
46
53
|
| ProofState<CheckpointRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
|
|
47
54
|
| undefined;
|
|
48
55
|
private blocks: (BlockProvingState | undefined)[] = [];
|
|
56
|
+
private previousOutHashHint: OutHashHint | undefined;
|
|
57
|
+
private outHash: Fr | undefined;
|
|
58
|
+
// The snapshot and sibling path after the checkpoint's out hash is inserted.
|
|
59
|
+
// Stored here to be retrieved for the next checkpoint when it's added.
|
|
60
|
+
private newOutHashHint: OutHashHint | undefined;
|
|
49
61
|
private startBlobAccumulator: BatchedBlobAccumulator | undefined;
|
|
50
62
|
private endBlobAccumulator: BatchedBlobAccumulator | undefined;
|
|
51
63
|
private blobFields: Fr[] | undefined;
|
|
@@ -195,6 +207,35 @@ export class CheckpointProvingState {
|
|
|
195
207
|
return new ParityBasePrivateInputs(messages, this.constants.vkTreeRoot);
|
|
196
208
|
}
|
|
197
209
|
|
|
210
|
+
public setOutHashHint(hint: OutHashHint) {
|
|
211
|
+
this.previousOutHashHint = hint;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
public getOutHashHint() {
|
|
215
|
+
return this.previousOutHashHint;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
public accumulateBlockOutHashes() {
|
|
219
|
+
if (this.isAcceptingBlocks() || this.blocks.some(b => !b?.hasEndState())) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (!this.outHash) {
|
|
224
|
+
const messagesPerBlock = this.blocks.map(b => b!.getTxEffects().map(tx => tx.l2ToL1Msgs));
|
|
225
|
+
this.outHash = computeCheckpointOutHash(messagesPerBlock);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return this.outHash;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
public setOutHashHintForNextCheckpoint(hint: OutHashHint) {
|
|
232
|
+
this.newOutHashHint = hint;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
public getOutHashHintForNextCheckpoint() {
|
|
236
|
+
return this.newOutHashHint;
|
|
237
|
+
}
|
|
238
|
+
|
|
198
239
|
public async accumulateBlobs(startBlobAccumulator: BatchedBlobAccumulator) {
|
|
199
240
|
if (this.isAcceptingBlocks() || this.blocks.some(b => !b?.hasEndState())) {
|
|
200
241
|
return;
|
|
@@ -236,6 +277,9 @@ export class CheckpointProvingState {
|
|
|
236
277
|
if (proofs.length !== nonEmptyProofs.length) {
|
|
237
278
|
throw new Error('At least one child is not ready for the checkpoint root rollup.');
|
|
238
279
|
}
|
|
280
|
+
if (!this.previousOutHashHint) {
|
|
281
|
+
throw new Error('Out hash hint is not set.');
|
|
282
|
+
}
|
|
239
283
|
if (!this.startBlobAccumulator) {
|
|
240
284
|
throw new Error('Start blob accumulator is not set.');
|
|
241
285
|
}
|
|
@@ -248,6 +292,8 @@ export class CheckpointProvingState {
|
|
|
248
292
|
const hints = CheckpointRootRollupHints.from({
|
|
249
293
|
previousBlockHeader: this.headerOfLastBlockInPreviousCheckpoint,
|
|
250
294
|
previousArchiveSiblingPath: this.lastArchiveSiblingPath,
|
|
295
|
+
previousOutHash: this.previousOutHashHint.treeSnapshot,
|
|
296
|
+
newOutHashSiblingPath: this.previousOutHashHint.siblingPath,
|
|
251
297
|
startBlobAccumulator: this.startBlobAccumulator.toBlobAccumulator(),
|
|
252
298
|
finalBlobChallenges: this.finalBlobBatchingChallenges,
|
|
253
299
|
blobFields: padArrayEnd(blobFields, Fr.ZERO, FIELDS_PER_BLOB * BLOBS_PER_CHECKPOINT),
|
|
@@ -273,7 +319,7 @@ export class CheckpointProvingState {
|
|
|
273
319
|
|
|
274
320
|
public isReadyForCheckpointRoot() {
|
|
275
321
|
const allChildProofsReady = this.#getChildProofsForRoot().every(p => !!p);
|
|
276
|
-
return allChildProofsReady && !!this.startBlobAccumulator;
|
|
322
|
+
return allChildProofsReady && !!this.previousOutHashHint && !!this.startBlobAccumulator;
|
|
277
323
|
}
|
|
278
324
|
|
|
279
325
|
public verifyState() {
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { BatchedBlob, BatchedBlobAccumulator, type FinalBlobBatchingChallenges } from '@aztec/blob-lib';
|
|
2
|
-
import
|
|
3
|
-
ARCHIVE_HEIGHT,
|
|
4
|
-
L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
|
|
5
|
-
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
6
|
-
NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
|
|
2
|
+
import {
|
|
3
|
+
type ARCHIVE_HEIGHT,
|
|
4
|
+
type L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
|
|
5
|
+
type NESTED_RECURSIVE_PROOF_LENGTH,
|
|
6
|
+
type NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
|
|
7
|
+
OUT_HASH_TREE_HEIGHT,
|
|
7
8
|
} from '@aztec/constants';
|
|
8
9
|
import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
9
|
-
import
|
|
10
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
10
11
|
import type { Tuple } from '@aztec/foundation/serialize';
|
|
11
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
MerkleTreeCalculator,
|
|
14
|
+
type TreeNodeLocation,
|
|
15
|
+
UnbalancedTreeStore,
|
|
16
|
+
shaMerkleHash,
|
|
17
|
+
} from '@aztec/foundation/trees';
|
|
12
18
|
import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
|
|
13
19
|
import type { Proof } from '@aztec/stdlib/proofs';
|
|
14
20
|
import {
|
|
@@ -20,7 +26,7 @@ import {
|
|
|
20
26
|
RootRollupPrivateInputs,
|
|
21
27
|
type RootRollupPublicInputs,
|
|
22
28
|
} from '@aztec/stdlib/rollup';
|
|
23
|
-
import
|
|
29
|
+
import { AppendOnlyTreeSnapshot, type MerkleTreeId } from '@aztec/stdlib/trees';
|
|
24
30
|
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
25
31
|
|
|
26
32
|
import { toProofData } from './block-building-helpers.js';
|
|
@@ -212,6 +218,48 @@ export class EpochProvingState {
|
|
|
212
218
|
this.checkpointPaddingProof = { provingOutput };
|
|
213
219
|
}
|
|
214
220
|
|
|
221
|
+
public async accumulateCheckpointOutHashes() {
|
|
222
|
+
const treeCalculator = await MerkleTreeCalculator.create(OUT_HASH_TREE_HEIGHT, undefined, (left, right) =>
|
|
223
|
+
Promise.resolve(shaMerkleHash(left, right)),
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
const computeOutHashHint = async (leaves: Fr[]) => {
|
|
227
|
+
const tree = await treeCalculator.computeTree(leaves.map(l => l.toBuffer()));
|
|
228
|
+
const nextAvailableLeafIndex = leaves.length;
|
|
229
|
+
return {
|
|
230
|
+
treeSnapshot: new AppendOnlyTreeSnapshot(Fr.fromBuffer(tree.root), nextAvailableLeafIndex),
|
|
231
|
+
siblingPath: tree.getSiblingPath(nextAvailableLeafIndex).map(Fr.fromBuffer) as Tuple<
|
|
232
|
+
Fr,
|
|
233
|
+
typeof OUT_HASH_TREE_HEIGHT
|
|
234
|
+
>,
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
let hint = this.checkpoints[0]?.getOutHashHint();
|
|
239
|
+
const outHashes = [];
|
|
240
|
+
for (let i = 0; i < this.totalNumCheckpoints; i++) {
|
|
241
|
+
const checkpoint = this.checkpoints[i];
|
|
242
|
+
if (!checkpoint) {
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// If hints are not set yet, it must be the first checkpoint. Compute the hints with an empty tree.
|
|
247
|
+
hint ??= await computeOutHashHint([]);
|
|
248
|
+
checkpoint.setOutHashHint(hint);
|
|
249
|
+
|
|
250
|
+
// Get the out hash for this checkpoint.
|
|
251
|
+
const outHash = checkpoint.accumulateBlockOutHashes();
|
|
252
|
+
if (!outHash) {
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
outHashes.push(outHash);
|
|
256
|
+
|
|
257
|
+
// Get or create hints for the next checkpoint.
|
|
258
|
+
hint = checkpoint.getOutHashHintForNextCheckpoint() ?? (await computeOutHashHint(outHashes));
|
|
259
|
+
checkpoint.setOutHashHintForNextCheckpoint(hint);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
215
263
|
public async setBlobAccumulators() {
|
|
216
264
|
let previousAccumulator = this.startBlobAccumulator;
|
|
217
265
|
// Accumulate blobs as far as we can for this epoch.
|
|
@@ -73,6 +73,11 @@ import { TxProvingState } from './tx-proving-state.js';
|
|
|
73
73
|
|
|
74
74
|
const logger = createLogger('prover-client:orchestrator');
|
|
75
75
|
|
|
76
|
+
type WorldStateFork = {
|
|
77
|
+
fork: MerkleTreeWriteOperations;
|
|
78
|
+
cleanupPromise: Promise<void> | undefined;
|
|
79
|
+
};
|
|
80
|
+
|
|
76
81
|
/**
|
|
77
82
|
* Implements an event driven proving scheduler to build the recursive proof tree. The idea being:
|
|
78
83
|
* 1. Transactions are provided to the scheduler post simulation.
|
|
@@ -94,12 +99,13 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
94
99
|
private provingPromise: Promise<ProvingResult> | undefined = undefined;
|
|
95
100
|
private metrics: ProvingOrchestratorMetrics;
|
|
96
101
|
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
97
|
-
private dbs: Map<BlockNumber,
|
|
102
|
+
private dbs: Map<BlockNumber, WorldStateFork> = new Map();
|
|
98
103
|
|
|
99
104
|
constructor(
|
|
100
105
|
private dbProvider: ReadonlyWorldStateAccess & ForkMerkleTreeOperations,
|
|
101
106
|
private prover: ServerCircuitProver,
|
|
102
107
|
private readonly proverId: EthAddress,
|
|
108
|
+
private readonly cancelJobsOnStop: boolean = false,
|
|
103
109
|
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
104
110
|
) {
|
|
105
111
|
this.metrics = new ProvingOrchestratorMetrics(telemetryClient, 'ProvingOrchestrator');
|
|
@@ -113,6 +119,10 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
113
119
|
return this.proverId;
|
|
114
120
|
}
|
|
115
121
|
|
|
122
|
+
public getNumActiveForks() {
|
|
123
|
+
return this.dbs.size;
|
|
124
|
+
}
|
|
125
|
+
|
|
116
126
|
public stop(): Promise<void> {
|
|
117
127
|
this.cancel();
|
|
118
128
|
return Promise.resolve();
|
|
@@ -143,6 +153,14 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
143
153
|
this.provingPromise = promise;
|
|
144
154
|
}
|
|
145
155
|
|
|
156
|
+
/**
|
|
157
|
+
* Starts a new checkpoint.
|
|
158
|
+
* @param checkpointIndex - The index of the checkpoint in the epoch.
|
|
159
|
+
* @param constants - The constants for this checkpoint.
|
|
160
|
+
* @param l1ToL2Messages - The set of L1 to L2 messages to be inserted at the beginning of this checkpoint.
|
|
161
|
+
* @param totalNumBlocks - The total number of blocks expected in the checkpoint (must be at least one).
|
|
162
|
+
* @param headerOfLastBlockInPreviousCheckpoint - The header of the last block in the previous checkpoint.
|
|
163
|
+
*/
|
|
146
164
|
public async startNewCheckpoint(
|
|
147
165
|
checkpointIndex: number,
|
|
148
166
|
constants: CheckpointConstantData,
|
|
@@ -163,7 +181,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
163
181
|
const db = await this.dbProvider.fork(lastBlockNumber);
|
|
164
182
|
|
|
165
183
|
const firstBlockNumber = BlockNumber(lastBlockNumber + 1);
|
|
166
|
-
this.dbs.set(firstBlockNumber, db);
|
|
184
|
+
this.dbs.set(firstBlockNumber, { fork: db, cleanupPromise: undefined });
|
|
167
185
|
|
|
168
186
|
// Get archive sibling path before any block in this checkpoint lands.
|
|
169
187
|
const lastArchiveSiblingPath = await getLastSiblingPath(MerkleTreeId.ARCHIVE, db);
|
|
@@ -221,9 +239,9 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
221
239
|
if (!this.dbs.has(blockNumber)) {
|
|
222
240
|
// Fork world state at the end of the immediately previous block
|
|
223
241
|
const db = await this.dbProvider.fork(BlockNumber(blockNumber - 1));
|
|
224
|
-
this.dbs.set(blockNumber, db);
|
|
242
|
+
this.dbs.set(blockNumber, { fork: db, cleanupPromise: undefined });
|
|
225
243
|
}
|
|
226
|
-
const db = this.dbs.get(blockNumber)
|
|
244
|
+
const db = this.dbs.get(blockNumber)!.fork;
|
|
227
245
|
|
|
228
246
|
// Get archive snapshot and sibling path before any txs in this block lands.
|
|
229
247
|
const lastArchiveTreeSnapshot = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
@@ -255,7 +273,8 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
255
273
|
await endSpongeBlob.absorb(blockEndBlobFields);
|
|
256
274
|
blockProvingState.setEndSpongeBlob(endSpongeBlob);
|
|
257
275
|
|
|
258
|
-
//
|
|
276
|
+
// Try to accumulate the out hashes and blobs as far as we can:
|
|
277
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
259
278
|
await this.provingState.setBlobAccumulators();
|
|
260
279
|
}
|
|
261
280
|
}
|
|
@@ -297,7 +316,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
297
316
|
|
|
298
317
|
logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
299
318
|
|
|
300
|
-
const db = this.dbs.get(blockNumber)
|
|
319
|
+
const db = this.dbs.get(blockNumber)!.fork;
|
|
301
320
|
const lastArchive = provingState.lastArchiveTreeSnapshot;
|
|
302
321
|
const newL1ToL2MessageTreeSnapshot = provingState.newL1ToL2MessageTreeSnapshot;
|
|
303
322
|
const spongeBlobState = provingState.getStartSpongeBlob().clone();
|
|
@@ -352,7 +371,8 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
352
371
|
|
|
353
372
|
provingState.setEndSpongeBlob(spongeBlobState);
|
|
354
373
|
|
|
355
|
-
// Txs have been added to the block. Now try to accumulate the blobs as far as we can:
|
|
374
|
+
// Txs have been added to the block. Now try to accumulate the out hashes and blobs as far as we can:
|
|
375
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
356
376
|
await this.provingState.setBlobAccumulators();
|
|
357
377
|
}
|
|
358
378
|
|
|
@@ -425,7 +445,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
425
445
|
}
|
|
426
446
|
|
|
427
447
|
// Get db for this block
|
|
428
|
-
const db = this.dbs.get(provingState.blockNumber)
|
|
448
|
+
const db = this.dbs.get(provingState.blockNumber)!.fork;
|
|
429
449
|
|
|
430
450
|
// Update the archive tree, so we're ready to start processing the next block:
|
|
431
451
|
logger.verbose(
|
|
@@ -461,7 +481,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
461
481
|
|
|
462
482
|
// Get db for this block
|
|
463
483
|
const blockNumber = provingState.blockNumber;
|
|
464
|
-
const db = this.dbs.get(blockNumber)
|
|
484
|
+
const db = this.dbs.get(blockNumber)!.fork;
|
|
465
485
|
|
|
466
486
|
const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
467
487
|
const syncedArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.dbProvider.getSnapshot(blockNumber));
|
|
@@ -486,20 +506,19 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
486
506
|
// is aborted and never reaches this point, it will leak the fork. We need to add a global cleanup,
|
|
487
507
|
// but have to make sure it only runs once all operations are completed, otherwise some function here
|
|
488
508
|
// will attempt to access the fork after it was closed.
|
|
489
|
-
|
|
490
|
-
void this.dbs
|
|
491
|
-
.get(blockNumber)
|
|
492
|
-
?.close()
|
|
493
|
-
.then(() => this.dbs.delete(blockNumber))
|
|
494
|
-
.catch(err => logger.error(`Error closing db for block ${blockNumber}`, err));
|
|
509
|
+
void this.cleanupDBFork(blockNumber);
|
|
495
510
|
}
|
|
496
511
|
|
|
497
512
|
/**
|
|
498
|
-
* Cancel any further proving
|
|
513
|
+
* Cancel any further proving.
|
|
514
|
+
* If cancelJobsOnStop is true, aborts all pending jobs with the broker (which marks them as 'Aborted').
|
|
515
|
+
* If cancelJobsOnStop is false (default), jobs remain in the broker queue and can be reused on restart/reorg.
|
|
499
516
|
*/
|
|
500
517
|
public cancel() {
|
|
501
|
-
|
|
502
|
-
controller.
|
|
518
|
+
if (this.cancelJobsOnStop) {
|
|
519
|
+
for (const controller of this.pendingProvingJobs) {
|
|
520
|
+
controller.abort();
|
|
521
|
+
}
|
|
503
522
|
}
|
|
504
523
|
|
|
505
524
|
this.provingState?.cancel();
|
|
@@ -534,6 +553,24 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
534
553
|
return epochProofResult;
|
|
535
554
|
}
|
|
536
555
|
|
|
556
|
+
private async cleanupDBFork(blockNumber: BlockNumber): Promise<void> {
|
|
557
|
+
logger.debug(`Cleaning up world state fork for ${blockNumber}`);
|
|
558
|
+
const fork = this.dbs.get(blockNumber);
|
|
559
|
+
if (!fork) {
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
try {
|
|
564
|
+
if (!fork.cleanupPromise) {
|
|
565
|
+
fork.cleanupPromise = fork.fork.close();
|
|
566
|
+
}
|
|
567
|
+
await fork.cleanupPromise;
|
|
568
|
+
this.dbs.delete(blockNumber);
|
|
569
|
+
} catch (err) {
|
|
570
|
+
logger.error(`Error closing db for block ${blockNumber}`, err);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
537
574
|
/**
|
|
538
575
|
* Enqueue a job to be scheduled
|
|
539
576
|
* @param provingState - The proving state object being operated on
|
|
@@ -851,19 +888,22 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
851
888
|
},
|
|
852
889
|
),
|
|
853
890
|
async result => {
|
|
854
|
-
// If the proofs were slower than the block header building, then we need to try validating the block header hashes here.
|
|
855
|
-
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
856
|
-
|
|
857
891
|
logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`);
|
|
858
892
|
|
|
859
893
|
const leafLocation = provingState.setBlockRootRollupProof(result);
|
|
860
894
|
const checkpointProvingState = provingState.parentCheckpoint;
|
|
861
895
|
|
|
896
|
+
// If the proofs were slower than the block header building, then we need to try validating the block header hashes here.
|
|
897
|
+
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
898
|
+
|
|
862
899
|
if (checkpointProvingState.totalNumBlocks === 1) {
|
|
863
900
|
this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
864
901
|
} else {
|
|
865
902
|
this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
866
903
|
}
|
|
904
|
+
|
|
905
|
+
// We are finished with the block at this point, ensure the fork is cleaned up
|
|
906
|
+
void this.cleanupDBFork(provingState.blockNumber);
|
|
867
907
|
},
|
|
868
908
|
);
|
|
869
909
|
}
|
|
@@ -46,7 +46,13 @@ export class ProverClient implements EpochProverManager {
|
|
|
46
46
|
|
|
47
47
|
public createEpochProver(): EpochProver {
|
|
48
48
|
const facade = new BrokerCircuitProverFacade(this.orchestratorClient, this.proofStore, this.failedProofStore);
|
|
49
|
-
const orchestrator = new ProvingOrchestrator(
|
|
49
|
+
const orchestrator = new ProvingOrchestrator(
|
|
50
|
+
this.worldState,
|
|
51
|
+
facade,
|
|
52
|
+
this.config.proverId,
|
|
53
|
+
this.config.cancelJobsOnStop,
|
|
54
|
+
this.telemetry,
|
|
55
|
+
);
|
|
50
56
|
return new ServerEpochProver(facade, orchestrator);
|
|
51
57
|
}
|
|
52
58
|
|
|
@@ -100,6 +100,8 @@ export const ProverAgentConfig = z.object({
|
|
|
100
100
|
proverTestDelayFactor: z.number(),
|
|
101
101
|
/** The delay (ms) to inject during fake proof verification */
|
|
102
102
|
proverTestVerificationDelayMs: z.number().optional(),
|
|
103
|
+
/** Whether to abort pending proving jobs when the orchestrator is cancelled */
|
|
104
|
+
cancelJobsOnStop: z.boolean(),
|
|
103
105
|
});
|
|
104
106
|
|
|
105
107
|
export type ProverAgentConfig = z.infer<typeof ProverAgentConfig>;
|
|
@@ -153,4 +155,11 @@ export const proverAgentConfigMappings: ConfigMappingsType<ProverAgentConfig> =
|
|
|
153
155
|
description: 'The delay (ms) to inject during fake proof verification',
|
|
154
156
|
...numberConfigHelper(10),
|
|
155
157
|
},
|
|
158
|
+
cancelJobsOnStop: {
|
|
159
|
+
env: 'PROVER_CANCEL_JOBS_ON_STOP',
|
|
160
|
+
description:
|
|
161
|
+
'Whether to abort pending proving jobs when the orchestrator is cancelled. ' +
|
|
162
|
+
'When false (default), jobs remain in the broker queue and can be reused on restart/reorg.',
|
|
163
|
+
...booleanConfigHelper(false),
|
|
164
|
+
},
|
|
156
165
|
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/block-factory/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './light.js';
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
-
import { L2Block } from '@aztec/stdlib/block';
|
|
3
|
-
import type { IBlockFactory, MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
4
|
-
import type { GlobalVariables, ProcessedTx } from '@aztec/stdlib/tx';
|
|
5
|
-
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
6
|
-
/**
|
|
7
|
-
* Builds a block and its header from a set of processed tx without running any circuits.
|
|
8
|
-
*
|
|
9
|
-
* NOTE: the onus is ON THE CALLER to update the db that is passed in with the notes hashes, nullifiers, etc
|
|
10
|
-
* PRIOR to calling `buildBlock`.
|
|
11
|
-
*
|
|
12
|
-
* Why? Because if you are, e.g. building a block in practice from TxObjects, you are using the
|
|
13
|
-
* PublicProcessor which will do this for you as it processes transactions.
|
|
14
|
-
*
|
|
15
|
-
* If you haven't already inserted the side effects, e.g. because you are in a testing context, you can use the helper
|
|
16
|
-
* function `buildBlockWithCleanDB`, which calls `insertSideEffects` for you.
|
|
17
|
-
*
|
|
18
|
-
* @deprecated Use LightweightCheckpointBuilder instead. This only works for one block per checkpoint.
|
|
19
|
-
*/
|
|
20
|
-
export declare class LightweightBlockFactory implements IBlockFactory {
|
|
21
|
-
private db;
|
|
22
|
-
private telemetry;
|
|
23
|
-
private globalVariables?;
|
|
24
|
-
private l1ToL2Messages?;
|
|
25
|
-
private txs;
|
|
26
|
-
private readonly logger;
|
|
27
|
-
constructor(db: MerkleTreeWriteOperations, telemetry?: TelemetryClient);
|
|
28
|
-
startNewBlock(globalVariables: GlobalVariables, l1ToL2Messages: Fr[]): Promise<void>;
|
|
29
|
-
addTxs(txs: ProcessedTx[]): Promise<void>;
|
|
30
|
-
setBlockCompleted(): Promise<L2Block>;
|
|
31
|
-
private buildBlock;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Inserts the processed transactions into the DB, then creates a block.
|
|
35
|
-
* @param db - A db fork to use for block building which WILL BE MODIFIED.
|
|
36
|
-
*/
|
|
37
|
-
export declare function buildBlockWithCleanDB(txs: ProcessedTx[], globalVariables: GlobalVariables, l1ToL2Messages: Fr[], db: MerkleTreeWriteOperations, telemetry?: TelemetryClient): Promise<L2Block>;
|
|
38
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlnaHQuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ibG9jay1mYWN0b3J5L2xpZ2h0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUdBLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FB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,EAAE,EACpB,EAAE,EAAE,yBAAyB,EAC7B,SAAS,GAAE,eAAsC,oBAWlD"}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { SpongeBlob, computeBlobsHashFromBlobs, encodeCheckpointEndMarker, getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
2
|
-
import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
3
|
-
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
4
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
-
import { L2Block, L2BlockHeader } from '@aztec/stdlib/block';
|
|
7
|
-
import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
8
|
-
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
9
|
-
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
10
|
-
import { buildHeaderAndBodyFromTxs, getTreeSnapshot, insertSideEffects } from '../orchestrator/block-building-helpers.js';
|
|
11
|
-
/**
|
|
12
|
-
* Builds a block and its header from a set of processed tx without running any circuits.
|
|
13
|
-
*
|
|
14
|
-
* NOTE: the onus is ON THE CALLER to update the db that is passed in with the notes hashes, nullifiers, etc
|
|
15
|
-
* PRIOR to calling `buildBlock`.
|
|
16
|
-
*
|
|
17
|
-
* Why? Because if you are, e.g. building a block in practice from TxObjects, you are using the
|
|
18
|
-
* PublicProcessor which will do this for you as it processes transactions.
|
|
19
|
-
*
|
|
20
|
-
* If you haven't already inserted the side effects, e.g. because you are in a testing context, you can use the helper
|
|
21
|
-
* function `buildBlockWithCleanDB`, which calls `insertSideEffects` for you.
|
|
22
|
-
*
|
|
23
|
-
* @deprecated Use LightweightCheckpointBuilder instead. This only works for one block per checkpoint.
|
|
24
|
-
*/ export class LightweightBlockFactory {
|
|
25
|
-
db;
|
|
26
|
-
telemetry;
|
|
27
|
-
globalVariables;
|
|
28
|
-
l1ToL2Messages;
|
|
29
|
-
txs;
|
|
30
|
-
logger;
|
|
31
|
-
constructor(db, telemetry = getTelemetryClient()){
|
|
32
|
-
this.db = db;
|
|
33
|
-
this.telemetry = telemetry;
|
|
34
|
-
this.logger = createLogger('lightweight-block-factory');
|
|
35
|
-
}
|
|
36
|
-
async startNewBlock(globalVariables, l1ToL2Messages) {
|
|
37
|
-
this.logger.debug('Starting new block', {
|
|
38
|
-
globalVariables: globalVariables.toInspect(),
|
|
39
|
-
l1ToL2Messages
|
|
40
|
-
});
|
|
41
|
-
this.globalVariables = globalVariables;
|
|
42
|
-
this.l1ToL2Messages = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
|
|
43
|
-
this.txs = undefined;
|
|
44
|
-
// Update L1 to L2 tree
|
|
45
|
-
await this.db.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, this.l1ToL2Messages);
|
|
46
|
-
}
|
|
47
|
-
addTxs(txs) {
|
|
48
|
-
// Most times, `addTxs` is only called once per block.
|
|
49
|
-
// So avoid copies.
|
|
50
|
-
if (this.txs === undefined) {
|
|
51
|
-
this.txs = txs;
|
|
52
|
-
} else {
|
|
53
|
-
this.txs.push(...txs);
|
|
54
|
-
}
|
|
55
|
-
return Promise.resolve();
|
|
56
|
-
}
|
|
57
|
-
setBlockCompleted() {
|
|
58
|
-
return this.buildBlock();
|
|
59
|
-
}
|
|
60
|
-
async buildBlock() {
|
|
61
|
-
const lastArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db);
|
|
62
|
-
const state = await this.db.getStateReference();
|
|
63
|
-
const txs = this.txs ?? [];
|
|
64
|
-
const startSpongeBlob = SpongeBlob.init();
|
|
65
|
-
const { header, body, blockBlobFields } = await buildHeaderAndBodyFromTxs(txs, lastArchive, state, this.globalVariables, startSpongeBlob, true);
|
|
66
|
-
header.state.validate();
|
|
67
|
-
await this.db.updateArchive(header);
|
|
68
|
-
const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db);
|
|
69
|
-
const inHash = computeInHashFromL1ToL2Messages(this.l1ToL2Messages);
|
|
70
|
-
const numBlobFields = blockBlobFields.length + 1;
|
|
71
|
-
const blobFields = blockBlobFields.concat([
|
|
72
|
-
encodeCheckpointEndMarker({
|
|
73
|
-
numBlobFields
|
|
74
|
-
})
|
|
75
|
-
]);
|
|
76
|
-
const blobsHash = computeBlobsHashFromBlobs(getBlobsPerL1Block(blobFields));
|
|
77
|
-
const blockHeaderHash = await header.hash();
|
|
78
|
-
const l2BlockHeader = L2BlockHeader.from({
|
|
79
|
-
...header,
|
|
80
|
-
blockHeadersHash: blockHeaderHash,
|
|
81
|
-
blobsHash,
|
|
82
|
-
inHash
|
|
83
|
-
});
|
|
84
|
-
const block = new L2Block(newArchive, l2BlockHeader, body);
|
|
85
|
-
this.logger.debug(`Built block ${block.number}`, {
|
|
86
|
-
globalVariables: this.globalVariables?.toInspect(),
|
|
87
|
-
archiveRoot: newArchive.root.toString(),
|
|
88
|
-
stateReference: header.state.toInspect(),
|
|
89
|
-
blockHash: (await block.hash()).toString(),
|
|
90
|
-
txs: block.body.txEffects.map((tx)=>tx.txHash.toString())
|
|
91
|
-
});
|
|
92
|
-
return block;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Inserts the processed transactions into the DB, then creates a block.
|
|
97
|
-
* @param db - A db fork to use for block building which WILL BE MODIFIED.
|
|
98
|
-
*/ export async function buildBlockWithCleanDB(txs, globalVariables, l1ToL2Messages, db, telemetry = getTelemetryClient()) {
|
|
99
|
-
const builder = new LightweightBlockFactory(db, telemetry);
|
|
100
|
-
await builder.startNewBlock(globalVariables, l1ToL2Messages);
|
|
101
|
-
for (const tx of txs){
|
|
102
|
-
await insertSideEffects(tx, db);
|
|
103
|
-
}
|
|
104
|
-
await builder.addTxs(txs);
|
|
105
|
-
return await builder.setBlockCompleted();
|
|
106
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './light.js';
|