Skip to content

Commit ffb69cb

Browse files
committed
Cleanup.
1 parent e20bb2a commit ffb69cb

13 files changed

Lines changed: 68 additions & 134 deletions

yarn-project/prover-client/src/orchestrator/block-building-helpers.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -412,40 +412,6 @@ export async function getEmptyBlockBlobsHash(): Promise<Fr> {
412412
return sha256ToField(blobHash);
413413
}
414414

415-
// Validate that the roots of all local trees match the output of the root circuit simulation
416-
// TODO: does this get called?
417-
export async function validateBlockRootOutput(
418-
blockRootOutput: BlockRollupPublicInputs,
419-
blockHeader: BlockHeader,
420-
db: MerkleTreeReadOperations,
421-
) {
422-
await Promise.all([
423-
validateState(blockHeader.state, db),
424-
validateSimulatedTree(await getTreeSnapshot(MerkleTreeId.ARCHIVE, db), blockRootOutput.newArchive, 'Archive'),
425-
]);
426-
}
427-
428-
export const validateState = runInSpan(
429-
'BlockBuilderHelpers',
430-
'validateState',
431-
async (_span, state: StateReference, db: MerkleTreeReadOperations) => {
432-
const promises = [MerkleTreeId.NOTE_HASH_TREE, MerkleTreeId.NULLIFIER_TREE, MerkleTreeId.PUBLIC_DATA_TREE].map(
433-
async (id: MerkleTreeId) => {
434-
return { key: id, value: await getTreeSnapshot(id, db) };
435-
},
436-
);
437-
const snapshots: Map<MerkleTreeId, AppendOnlyTreeSnapshot> = new Map(
438-
(await Promise.all(promises)).map(obj => [obj.key, obj.value]),
439-
);
440-
validatePartialState(state.partial, snapshots);
441-
validateSimulatedTree(
442-
await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db),
443-
state.l1ToL2MessageTree,
444-
'L1ToL2MessageTree',
445-
);
446-
},
447-
);
448-
449415
export async function getLastSiblingPath<TID extends MerkleTreeId>(treeId: TID, db: MerkleTreeReadOperations) {
450416
const { size } = await db.getTreeInfo(treeId);
451417
const path = await db.getSiblingPath(treeId, size - 1n);

yarn-project/prover-client/src/orchestrator/orchestrator.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,17 @@ export class ProvingOrchestrator implements EpochProver {
369369
throw new Error(`Block proving state for ${blockNumber} not found`);
370370
}
371371

372+
// Abort with specific error for the block if there's one.
372373
const error = provingState.getError();
373374
if (error) {
374375
throw new Error(`Block proving failed: ${error}`);
375376
}
376377

378+
// Abort if the proving state is not valid due to errors occurred elsewhere.
379+
if (!provingState.verifyState()) {
380+
throw new Error(`Invalid proving state when completing block ${blockNumber}.`);
381+
}
382+
377383
if (provingState.isAcceptingTxs()) {
378384
throw new Error(
379385
`Block ${blockNumber} is still accepting txs. Call setBlockCompleted after all txs have been added.`,
@@ -390,7 +396,7 @@ export class ProvingOrchestrator implements EpochProver {
390396
}
391397

392398
private async buildL2BlockHeader(provingState: BlockProvingState, expectedHeader?: BlockHeader) {
393-
// Collect all new nullifiers, commitments, and contracts from all txs in this block to build body
399+
// Collect all txs in this block to build the header. The function calling this has made sure that all txs have been added.
394400
const txs = provingState.getProcessedTxs();
395401

396402
const startSpongeBlob = provingState.getStartSpongeBlob();
@@ -460,6 +466,17 @@ export class ProvingOrchestrator implements EpochProver {
460466
provingState.reject(`New archive mismatch.`);
461467
return;
462468
}
469+
470+
// TODO(palla/prover): This closes the fork only on the happy path. If this epoch orchestrator
471+
// is aborted and never reaches this point, it will leak the fork. We need to add a global cleanup,
472+
// but have to make sure it only runs once all operations are completed, otherwise some function here
473+
// will attempt to access the fork after it was closed.
474+
logger.debug(`Cleaning up world state fork for ${blockNumber}`);
475+
void this.dbs
476+
.get(blockNumber)
477+
?.close()
478+
.then(() => this.dbs.delete(blockNumber))
479+
.catch(err => logger.error(`Error closing db for block ${blockNumber}`, err));
463480
}
464481

465482
/**
@@ -783,25 +800,12 @@ export class ProvingOrchestrator implements EpochProver {
783800
}
784801
provingState.startProvingBlockRoot();
785802

786-
const blockNumber = provingState.blockNumber;
787-
788-
// TODO(palla/prover): This closes the fork only on the happy path. If this epoch orchestrator
789-
// is aborted and never reaches this point, it will leak the fork. We need to add a global cleanup,
790-
// but have to make sure it only runs once all operations are completed, otherwise some function here
791-
// will attempt to access the fork after it was closed.
792-
logger.debug(`Cleaning up world state fork for ${blockNumber}`);
793-
void this.dbs
794-
.get(blockNumber)
795-
?.close()
796-
.then(() => this.dbs.delete(blockNumber))
797-
.catch(err => logger.error(`Error closing db for block ${blockNumber}`, err));
798-
799803
// The checkpoint has received a new block. Now try to accumulate as far as we can:
800804
await provingState.parentCheckpoint.parentEpoch.setBlobAccumulators();
801805

802806
const { rollupType, inputs } = await provingState.getBlockRootRollupTypeAndInputs();
803807

804-
logger.debug(`Enqueuing ${rollupType} for block ${blockNumber}.`);
808+
logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
805809

806810
this.deferredProving(
807811
provingState,
@@ -826,9 +830,8 @@ export class ProvingOrchestrator implements EpochProver {
826830
},
827831
),
828832
async result => {
829-
// If the proofs were slower than the block building, then we need to try validating the block header hashes here.
833+
// If the proofs were slower than the block header building, then we need to try validating the block header hashes here.
830834
await this.verifyBuiltBlockAgainstSyncedState(provingState);
831-
// validatePartialState(result.inputs.end, tx.treeSnapshots); // TODO(palla/prover)
832835

833836
logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`);
834837

yarn-project/prover-client/src/orchestrator/orchestrator_multiple_blocks.test.ts

Lines changed: 35 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -25,44 +25,8 @@ describe('prover/orchestrator/multi-block', () => {
2525
});
2626

2727
describe('multiple blocks', () => {
28-
// Skipping in the interest of speeding up CI
29-
it.skip.each([1, 4, 5])('builds an epoch with %s blocks in sequence', async (numBlocks: number) => {
30-
logger.info(`Seeding world state with ${numBlocks} blocks`);
31-
// One block per checkpoint.
32-
const numCheckpoints = numBlocks;
33-
const txCount = 2;
34-
const blocks = await timesAsync(numBlocks, i => context.makePendingBlock(txCount, 0, i + 1));
35-
const blockBlobFields = blocks.map(block => block.block.body.toBlobFields());
36-
const blobs = (await Promise.all(blockBlobFields.map(blobFields => Blob.getBlobsPerBlock(blobFields)))).flat();
37-
const finalBlobChallenges = await BatchedBlob.precomputeBatchedBlobChallenges(blobs);
38-
39-
logger.info(`Starting new epoch with ${numBlocks}`);
40-
context.orchestrator.startNewEpoch(1, numCheckpoints, finalBlobChallenges);
41-
42-
for (let i = 0; i < blocks.length; i++) {
43-
const { block, txs } = blocks[i];
44-
const slotNumber = block.header.globalVariables.slotNumber.toNumber();
45-
await context.orchestrator.startNewCheckpoint(
46-
makeCheckpointConstants(slotNumber),
47-
[],
48-
1 /* numBlocks */,
49-
blockBlobFields[i].length,
50-
context.getPreviousBlockHeader(block.number),
51-
);
52-
53-
await context.orchestrator.startNewBlock(block.number, block.header.globalVariables.timestamp, txs.length);
54-
await context.orchestrator.addTxs(txs);
55-
await context.orchestrator.setBlockCompleted(block.number);
56-
}
57-
58-
logger.info('Finalising epoch');
59-
const epoch = await context.orchestrator.finaliseEpoch();
60-
expect(countHeaderHashes(epoch.publicInputs.checkpointHeaderHashes)).toEqual(numCheckpoints);
61-
expect(epoch.proof).toBeDefined();
62-
});
63-
64-
it.each([1, 4])(
65-
'builds an epoch with %s blocks in parallel',
28+
it.each([4, 5])(
29+
'builds an epoch with %s blocks in sequence',
6630
async (numBlocks: number) => {
6731
logger.info(`Seeding world state with ${numBlocks} blocks`);
6832
// One block per checkpoint.
@@ -76,22 +40,21 @@ describe('prover/orchestrator/multi-block', () => {
7640
logger.info(`Starting new epoch with ${numBlocks}`);
7741
context.orchestrator.startNewEpoch(1, numCheckpoints, finalBlobChallenges);
7842

79-
await Promise.all(
80-
blocks.map(async ({ block, txs }, i) => {
81-
const slotNumber = block.header.globalVariables.slotNumber.toNumber();
82-
await context.orchestrator.startNewCheckpoint(
83-
makeCheckpointConstants(slotNumber),
84-
[],
85-
1 /* numBlocks */,
86-
blockBlobFields[i].length,
87-
context.getPreviousBlockHeader(block.number),
88-
);
43+
for (let i = 0; i < blocks.length; i++) {
44+
const { block, txs } = blocks[i];
45+
const slotNumber = block.header.globalVariables.slotNumber.toNumber();
46+
await context.orchestrator.startNewCheckpoint(
47+
makeCheckpointConstants(slotNumber),
48+
[],
49+
1 /* numBlocks */,
50+
blockBlobFields[i].length,
51+
context.getPreviousBlockHeader(block.number),
52+
);
8953

90-
await context.orchestrator.startNewBlock(block.number, block.header.globalVariables.timestamp, txs.length);
91-
await context.orchestrator.addTxs(txs);
92-
await context.orchestrator.setBlockCompleted(block.number);
93-
}),
94-
);
54+
await context.orchestrator.startNewBlock(block.number, block.header.globalVariables.timestamp, txs.length);
55+
await context.orchestrator.addTxs(txs);
56+
await context.orchestrator.setBlockCompleted(block.number);
57+
}
9558

9659
logger.info('Finalising epoch');
9760
const epoch = await context.orchestrator.finaliseEpoch();
@@ -105,7 +68,7 @@ describe('prover/orchestrator/multi-block', () => {
10568
'builds two consecutive epochs',
10669
async () => {
10770
const numEpochs = 2;
108-
const numBlocks = 4;
71+
const numBlocks = 3;
10972
const txCount = 2;
11073
logger.info(`Seeding world state with ${numBlocks * numEpochs} blocks`);
11174
const blocks = await timesAsync(numBlocks * numEpochs, i => context.makePendingBlock(txCount, 0, i + 1));
@@ -122,23 +85,25 @@ describe('prover/orchestrator/multi-block', () => {
12285
).flat();
12386
const finalBlobChallenges = await BatchedBlob.precomputeBatchedBlobChallenges(blobs);
12487
context.orchestrator.startNewEpoch(epochNumber, numCheckpoints, finalBlobChallenges);
88+
for (let i = 0; i < blocksInEpoch.length; i++) {
89+
const { block, txs } = blocksInEpoch[i];
90+
const slotNumber = block.header.globalVariables.slotNumber.toNumber();
91+
await context.orchestrator.startNewCheckpoint(
92+
makeCheckpointConstants(slotNumber),
93+
[],
94+
1 /* numBlocks */,
95+
blockBlobFields[i].length,
96+
context.getPreviousBlockHeader(block.number),
97+
);
98+
99+
await context.orchestrator.startNewBlock(block.number, block.header.globalVariables.timestamp, txs.length);
100+
// txs must be added for each block sequentially.
101+
await context.orchestrator.addTxs(txs);
102+
}
103+
104+
// setBlockCompleted may be called in parallel, but it must be called after all txs have been added.
125105
await Promise.all(
126-
blocksInEpoch.map(async ({ block, txs }, i) => {
127-
const slotNumber = block.header.globalVariables.slotNumber.toNumber();
128-
await context.orchestrator.startNewCheckpoint(
129-
makeCheckpointConstants(slotNumber),
130-
[],
131-
1 /* numBlocks */,
132-
blockBlobFields[i].length,
133-
context.getPreviousBlockHeader(block.number),
134-
);
135-
136-
await context.orchestrator.startNewBlock(
137-
block.number,
138-
block.header.globalVariables.timestamp,
139-
txs.length,
140-
);
141-
await context.orchestrator.addTxs(txs);
106+
blocksInEpoch.map(async ({ block }) => {
142107
await context.orchestrator.setBlockCompleted(block.number);
143108
}),
144109
);

yarn-project/prover-client/src/proving_broker/proving_broker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ function proofTypeComparator(a: ProvingRequestType, b: ProvingRequestType): -1 |
687687
export const PROOF_TYPES_IN_PRIORITY_ORDER: ProvingRequestType[] = [
688688
ProvingRequestType.BLOCK_ROOT_FIRST_ROLLUP,
689689
ProvingRequestType.BLOCK_ROOT_SINGLE_TX_FIRST_ROLLUP,
690+
ProvingRequestType.BLOCK_ROOT_EMPTY_TX_FIRST_ROLLUP,
690691
ProvingRequestType.BLOCK_ROOT_ROLLUP,
691692
ProvingRequestType.BLOCK_ROOT_SINGLE_TX_ROLLUP,
692693
ProvingRequestType.BLOCK_MERGE_ROLLUP,
@@ -702,5 +703,4 @@ export const PROOF_TYPES_IN_PRIORITY_ORDER: ProvingRequestType[] = [
702703
ProvingRequestType.TUBE_PROOF,
703704
ProvingRequestType.ROOT_PARITY,
704705
ProvingRequestType.BASE_PARITY,
705-
ProvingRequestType.BLOCK_ROOT_EMPTY_TX_FIRST_ROLLUP,
706706
];

yarn-project/stdlib/src/block/l2_block.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { bufferToHex, hexToBuffer } from '@aztec/foundation/string';
55
import { z } from 'zod';
66

77
import { AppendOnlyTreeSnapshot } from '../trees/append_only_tree_snapshot.js';
8-
import type { BlockHeader } from '../tx/index.js';
8+
import type { BlockHeader } from '../tx/block_header.js';
99
import { Body } from './body.js';
1010
import { makeAppendOnlyTreeSnapshot, makeL2BlockHeader } from './l2_block_code_to_purge.js';
1111
import { L2BlockHeader } from './l2_block_header.js';

yarn-project/stdlib/src/rollup/block_rollup_public_inputs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { BufferReader, bigintToUInt64BE, serializeToBuffer } from '@aztec/founda
55
import { bufferToHex, hexToBuffer } from '@aztec/foundation/string';
66

77
import { AppendOnlyTreeSnapshot } from '../trees/append_only_tree_snapshot.js';
8-
import { StateReference } from '../tx/index.js';
8+
import { StateReference } from '../tx/state_reference.js';
99
import type { UInt64 } from '../types/shared.js';
1010
import { CheckpointConstantData } from './checkpoint_constant_data.js';
1111

yarn-project/stdlib/src/rollup/block_root_rollup.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { bufferSchemaFor } from '@aztec/foundation/schemas';
55
import { BufferReader, type Tuple, bigintToUInt64BE, serializeToBuffer } from '@aztec/foundation/serialize';
66
import type { FieldsOf } from '@aztec/foundation/types';
77

8-
import { ParityPublicInputs } from '../parity/index.js';
9-
import { ProofData } from '../proofs/index.js';
10-
import { AppendOnlyTreeSnapshot } from '../trees/index.js';
11-
import { StateReference } from '../tx/index.js';
8+
import { ParityPublicInputs } from '../parity/parity_public_inputs.js';
9+
import { ProofData } from '../proofs/proof_data.js';
10+
import { AppendOnlyTreeSnapshot } from '../trees/append_only_tree_snapshot.js';
11+
import { StateReference } from '../tx/state_reference.js';
1212
import type { UInt64 } from '../types/shared.js';
1313
import { BaseOrMergeRollupPublicInputs } from './base_or_merge_rollup_public_inputs.js';
1414
import { CheckpointConstantData } from './checkpoint_constant_data.js';

yarn-project/stdlib/src/rollup/checkpoint_constant_data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
44
import type { FieldsOf } from '@aztec/foundation/types';
55

66
import { AztecAddress } from '../aztec-address/index.js';
7-
import { GasFees } from '../gas/index.js';
7+
import { GasFees } from '../gas/gas_fees.js';
88

99
/**
1010
* Constants that are the same for the entire checkpoint.

yarn-project/stdlib/src/rollup/checkpoint_header.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { z } from 'zod';
1313
import { AztecAddress } from '../aztec-address/index.js';
1414
import { GasFees } from '../gas/index.js';
1515
import { schemas } from '../schemas/index.js';
16-
import { ContentCommitment } from '../tx/index.js';
16+
import { ContentCommitment } from '../tx/content_commitment.js';
1717
import type { UInt64 } from '../types/shared.js';
1818

1919
export class CheckpointHeader {

yarn-project/stdlib/src/rollup/checkpoint_merge_rollup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { bufferSchemaFor } from '@aztec/foundation/schemas';
22
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
33
import { bufferToHex, hexToBuffer } from '@aztec/foundation/string';
44

5-
import { ProofData } from '../proofs/index.js';
5+
import { ProofData } from '../proofs/proof_data.js';
66
import { CheckpointRollupPublicInputs } from './checkpoint_rollup_public_inputs.js';
77
import type { RollupProofData } from './rollup_proof_data.js';
88

0 commit comments

Comments
 (0)