From cc7d996e935e995b7af17a5d629456117f913732 Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Thu, 28 Nov 2024 16:52:07 -0300 Subject: [PATCH] Update prover client tests --- .../circuit-types/src/test/factories.ts | 9 +- .../composed/integration_l1_publisher.test.ts | 2 +- .../foundation/src/collection/array.test.ts | 20 +++- .../foundation/src/collection/array.ts | 24 +++++ .../prover-client/src/block_builder/light.ts | 20 ++++ .../prover-client/src/mocks/fixtures.ts | 3 - .../prover-client/src/mocks/test_context.ts | 91 +++++++++++++------ .../src/orchestrator/orchestrator.ts | 54 ++++++----- .../orchestrator/orchestrator_errors.test.ts | 88 ++++++++---------- .../orchestrator_failures.test.ts | 36 +++----- .../orchestrator_lifecycle.test.ts | 5 +- .../orchestrator_mixed_blocks.test.ts | 22 +---- ...rchestrator_multi_public_functions.test.ts | 2 +- .../orchestrator_multiple_blocks.test.ts | 57 +++++++----- .../orchestrator_public_functions.test.ts | 2 +- .../orchestrator_single_blocks.test.ts | 11 +-- .../orchestrator_workflow.test.ts | 13 +-- .../src/test/bb_prover_base_rollup.test.ts | 6 +- .../src/test/bb_prover_full_rollup.test.ts | 13 ++- .../src/test/bb_prover_parity.test.ts | 2 +- 20 files changed, 266 insertions(+), 214 deletions(-) diff --git a/yarn-project/circuit-types/src/test/factories.ts b/yarn-project/circuit-types/src/test/factories.ts index a9e4335a2e17..45a8352bb529 100644 --- a/yarn-project/circuit-types/src/test/factories.ts +++ b/yarn-project/circuit-types/src/test/factories.ts @@ -52,14 +52,7 @@ export function makeBloatedProcessedTx({ privateOnly?: boolean; } = {}) { seed *= 0x1000; // Avoid clashing with the previous mock values if seed only increases by 1. - - if (!header) { - if (db) { - header = db.getInitialHeader(); - } else { - header = makeHeader(seed); - } - } + header ??= db?.getInitialHeader() ?? makeHeader(seed); const txConstantData = TxConstantData.empty(); txConstantData.historicalHeader = header; diff --git a/yarn-project/end-to-end/src/composed/integration_l1_publisher.test.ts b/yarn-project/end-to-end/src/composed/integration_l1_publisher.test.ts index b0bdace0d02a..831c8d16f7a0 100644 --- a/yarn-project/end-to-end/src/composed/integration_l1_publisher.test.ts +++ b/yarn-project/end-to-end/src/composed/integration_l1_publisher.test.ts @@ -24,6 +24,7 @@ import { OutboxAbi, RollupAbi } from '@aztec/l1-artifacts'; import { SHA256Trunc, StandardTree } from '@aztec/merkle-tree'; import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types'; import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; +import { LightweightBlockBuilder } from '@aztec/prover-client/block-builder'; import { L1Publisher } from '@aztec/sequencer-client'; import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { @@ -51,7 +52,6 @@ import { } from 'viem'; import { type PrivateKeyAccount, privateKeyToAccount } from 'viem/accounts'; -import { LightweightBlockBuilder } from '../../../sequencer-client/src/block_builder/light.js'; import { sendL1ToL2Message } from '../fixtures/l1_to_l2_messaging.js'; import { setupL1Contracts } from '../fixtures/utils.js'; diff --git a/yarn-project/foundation/src/collection/array.test.ts b/yarn-project/foundation/src/collection/array.test.ts index 97bee2fd7f15..e3be69ff586d 100644 --- a/yarn-project/foundation/src/collection/array.test.ts +++ b/yarn-project/foundation/src/collection/array.test.ts @@ -1,4 +1,4 @@ -import { compactArray, removeArrayPaddingEnd, times, unique } from './array.js'; +import { compactArray, maxBy, removeArrayPaddingEnd, times, unique } from './array.js'; describe('times', () => { it('should return an array with the result from all executions', () => { @@ -61,3 +61,21 @@ describe('unique', () => { expect(unique([1n, 2n, 1n])).toEqual([1n, 2n]); }); }); + +describe('maxBy', () => { + it('returns the max value', () => { + expect(maxBy([1, 2, 3], x => x)).toEqual(3); + }); + + it('returns the first max value', () => { + expect(maxBy([{ a: 1 }, { a: 3, b: 1 }, { a: 3, b: 2 }], ({ a }) => a)).toEqual({ a: 3, b: 1 }); + }); + + it('returns undefined for an empty array', () => { + expect(maxBy([], x => x)).toBeUndefined(); + }); + + it('applies the mapping function', () => { + expect(maxBy([1, 2, 3], x => -x)).toEqual(1); + }); +}); diff --git a/yarn-project/foundation/src/collection/array.ts b/yarn-project/foundation/src/collection/array.ts index ea97385aaba0..9f37779727e1 100644 --- a/yarn-project/foundation/src/collection/array.ts +++ b/yarn-project/foundation/src/collection/array.ts @@ -75,6 +75,20 @@ export function times(n: number, fn: (i: number) => T): T[] { return [...Array(n).keys()].map(i => fn(i)); } +/** + * Executes the given async function n times and returns the results in an array. Awaits each execution before starting the next one. + * @param n - How many times to repeat. + * @param fn - Mapper from index to value. + * @returns The array with the result from all executions. + */ +export async function timesAsync(n: number, fn: (i: number) => Promise): Promise { + const results: T[] = []; + for (let i = 0; i < n; i++) { + results.push(await fn(i)); + } + return results; +} + /** * Returns the serialized size of all non-empty items in an array. * @param arr - Array @@ -121,3 +135,13 @@ export function areArraysEqual(a: T[], b: T[], eq: (a: T, b: T) => boolean = } return true; } + +/** + * Returns the element of the array that has the maximum value of the given function. + * In case of a tie, returns the first element with the maximum value. + * @param arr - The array. + * @param fn - The function to get the value to compare. + */ +export function maxBy(arr: T[], fn: (x: T) => number): T | undefined { + return arr.reduce((max, x) => (fn(x) > fn(max) ? x : max), arr[0]); +} diff --git a/yarn-project/prover-client/src/block_builder/light.ts b/yarn-project/prover-client/src/block_builder/light.ts index 17e430db0944..3bc5d4a299d9 100644 --- a/yarn-project/prover-client/src/block_builder/light.ts +++ b/yarn-project/prover-client/src/block_builder/light.ts @@ -95,3 +95,23 @@ export class LightweightBlockBuilderFactory { return new LightweightBlockBuilder(db, this.telemetry ?? new NoopTelemetryClient()); } } + +/** + * Creates a block builder under the hood with the given txs and messages and creates a block. + * Automatically adds padding txs to get to a minimum of 2 txs in the block. + * @param db - A db fork to use for block building. + */ +export async function buildBlock( + txs: ProcessedTx[], + globalVariables: GlobalVariables, + l1ToL2Messages: Fr[], + db: MerkleTreeWriteOperations, + telemetry: TelemetryClient = new NoopTelemetryClient(), +) { + const builder = new LightweightBlockBuilder(db, telemetry); + await builder.startNewBlock(Math.max(txs.length, 2), globalVariables, l1ToL2Messages); + for (const tx of txs) { + await builder.addNewTx(tx); + } + return await builder.setBlockCompleted(); +} diff --git a/yarn-project/prover-client/src/mocks/fixtures.ts b/yarn-project/prover-client/src/mocks/fixtures.ts index 34b7cee59359..b7dcb72bfd12 100644 --- a/yarn-project/prover-client/src/mocks/fixtures.ts +++ b/yarn-project/prover-client/src/mocks/fixtures.ts @@ -94,9 +94,6 @@ export async function getSimulationProvider( return new WASMSimulator(); } -export const makeBloatedProcessedTxWithVKRoot = (builderDb: MerkleTreeReadOperations, seed = 0x1) => - makeBloatedProcessedTx({ db: builderDb, vkTreeRoot: getVKTreeRoot(), protocolContractTreeRoot, seed }); - // Updates the expectedDb trees based on the new note hashes, contracts, and nullifiers from these txs export const updateExpectedTreesFromTxs = async (db: MerkleTreeWriteOperations, txs: ProcessedTx[]) => { await db.appendLeaves( diff --git a/yarn-project/prover-client/src/mocks/test_context.ts b/yarn-project/prover-client/src/mocks/test_context.ts index b8403e3f16b3..e68b1f517eb5 100644 --- a/yarn-project/prover-client/src/mocks/test_context.ts +++ b/yarn-project/prover-client/src/mocks/test_context.ts @@ -1,7 +1,5 @@ import { type BBProverConfig } from '@aztec/bb-prover'; import { - type ForkMerkleTreeWriteOperations, - type MerkleTreeWriteOperations, type ProcessedTx, type ProcessedTxHandler, type PublicExecutionRequest, @@ -9,10 +7,13 @@ import { type Tx, type TxValidator, } from '@aztec/circuit-types'; +import { makeBloatedProcessedTx } from '@aztec/circuit-types/test'; import { type Gas, type GlobalVariables, Header } from '@aztec/circuits.js'; +import { times } from '@aztec/foundation/collection'; import { Fr } from '@aztec/foundation/fields'; import { type DebugLogger } from '@aztec/foundation/log'; -import { openTmpStore } from '@aztec/kv-store/utils'; +import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types'; +import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; import { PublicProcessor, PublicTxSimulator, @@ -21,30 +22,31 @@ import { type WorldStateDB, } from '@aztec/simulator'; import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; -import { MerkleTrees } from '@aztec/world-state'; +import { type MerkleTreeAdminDatabase } from '@aztec/world-state'; import { NativeWorldStateService } from '@aztec/world-state/native'; import { jest } from '@jest/globals'; import * as fs from 'fs/promises'; -import { type MockProxy, mock } from 'jest-mock-extended'; +import { mock } from 'jest-mock-extended'; import { TestCircuitProver } from '../../../bb-prover/src/test/test_circuit_prover.js'; import { AvmFinalizedCallResult } from '../../../simulator/src/avm/avm_contract_call_result.js'; import { type AvmPersistableStateManager } from '../../../simulator/src/avm/journal/journal.js'; +import { buildBlock } from '../block_builder/light.js'; import { ProvingOrchestrator } from '../orchestrator/index.js'; import { MemoryProvingQueue } from '../prover-agent/memory-proving-queue.js'; import { ProverAgent } from '../prover-agent/prover-agent.js'; import { getEnvironmentConfig, getSimulationProvider, makeGlobals } from './fixtures.js'; export class TestContext { + private headers: Map = new Map(); + constructor( public publicTxSimulator: PublicTxSimulator, - public worldStateDB: MockProxy, + public worldState: MerkleTreeAdminDatabase, public publicProcessor: PublicProcessor, public simulationProvider: SimulationProvider, public globalVariables: GlobalVariables, - public actualDb: MerkleTreeWriteOperations, - public forksProvider: ForkMerkleTreeWriteOperations, public prover: ServerCircuitProver, public proverAgent: ProverAgent, public orchestrator: ProvingOrchestrator, @@ -59,11 +61,10 @@ export class TestContext { static async new( logger: DebugLogger, - worldState: 'native' | 'legacy' = 'native', proverCount = 4, createProver: (bbConfig: BBProverConfig) => Promise = _ => Promise.resolve(new TestCircuitProver(new NoopTelemetryClient(), new WASMSimulator())), - blockNumber = 3, + blockNumber = 1, ) { const directoriesToCleanup: string[] = []; const globalVariables = makeGlobals(blockNumber); @@ -72,21 +73,9 @@ export class TestContext { const telemetry = new NoopTelemetryClient(); // Separated dbs for public processor and prover - see public_processor for context - let publicDb: MerkleTreeWriteOperations; - let proverDb: MerkleTreeWriteOperations; - let forksProvider: ForkMerkleTreeWriteOperations; - - if (worldState === 'native') { - const ws = await NativeWorldStateService.tmp(); - publicDb = await ws.fork(); - proverDb = await ws.fork(); - forksProvider = ws; - } else { - const ws = await MerkleTrees.new(openTmpStore(), telemetry); - publicDb = await ws.getLatest(); - proverDb = await ws.getLatest(); - forksProvider = ws; - } + const ws = await NativeWorldStateService.tmp(); + const publicDb = await ws.fork(); + worldStateDB.getMerkleInterface.mockReturnValue(publicDb); const publicTxSimulator = new PublicTxSimulator(publicDb, worldStateDB, telemetry, globalVariables); @@ -123,7 +112,7 @@ export class TestContext { } const queue = new MemoryProvingQueue(telemetry); - const orchestrator = new ProvingOrchestrator(forksProvider, queue, telemetry, Fr.ZERO); + const orchestrator = new ProvingOrchestrator(ws, queue, telemetry, Fr.ZERO); const agent = new ProverAgent(localProver, proverCount); queue.start(); @@ -131,12 +120,10 @@ export class TestContext { return new this( publicTxSimulator, - worldStateDB, + ws, processor, simulationProvider, globalVariables, - proverDb, - forksProvider, localProver, agent, orchestrator, @@ -146,6 +133,16 @@ export class TestContext { ); } + public getFork() { + return this.worldState.fork(); + } + + public getHeader(blockNumber: 0): Header; + public getHeader(blockNumber: number): Header | undefined; + public getHeader(blockNumber = 0) { + return blockNumber === 0 ? this.worldState.getCommitted().getInitialHeader() : this.headers.get(blockNumber); + } + async cleanup() { await this.proverAgent.stop(); for (const dir of this.directoriesToCleanup.filter(x => x !== '')) { @@ -153,6 +150,42 @@ export class TestContext { } } + public makeProcessedTx(opts?: Parameters[0]): ProcessedTx; + public makeProcessedTx(seed?: number): ProcessedTx; + public makeProcessedTx(seedOrOpts?: Parameters[0] | number): ProcessedTx { + const opts = typeof seedOrOpts === 'number' ? { seed: seedOrOpts } : seedOrOpts; + const blockNum = (opts?.globalVariables ?? this.globalVariables).blockNumber.toNumber(); + const header = this.getHeader(blockNum - 1); + return makeBloatedProcessedTx({ + header, + vkTreeRoot: getVKTreeRoot(), + protocolContractTreeRoot, + globalVariables: this.globalVariables, + ...opts, + }); + } + + /** Creates a block with the given number of txs and adds it to world-state */ + public async makePendingBlock( + numTxs: number, + numMsgs: number = 0, + blockNumOrGlobals: GlobalVariables | number = this.globalVariables, + makeProcessedTxOpts: (index: number) => Partial[0]> = () => ({}), + ) { + const globalVariables = typeof blockNumOrGlobals === 'number' ? makeGlobals(blockNumOrGlobals) : blockNumOrGlobals; + const blockNum = globalVariables.blockNumber.toNumber(); + const db = await this.worldState.fork(); + const msgs = times(numMsgs, i => new Fr(blockNum * 100 + i)); + const txs = times(numTxs, i => + this.makeProcessedTx({ seed: i + blockNum * 1000, globalVariables, ...makeProcessedTxOpts(i) }), + ); + + const block = await buildBlock(txs, globalVariables, msgs, db); + this.headers.set(blockNum, block.header); + await this.worldState.handleL2BlockAndMessages(block, msgs); + return { block, txs, msgs }; + } + public async processPublicFunctions( txs: Tx[], maxTransactions: number, diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator.ts b/yarn-project/prover-client/src/orchestrator/orchestrator.ts index 37036d9618c8..54ea2034daaa 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator.ts @@ -39,7 +39,7 @@ import { makeEmptyRecursiveProof, } from '@aztec/circuits.js'; import { makeTuple } from '@aztec/foundation/array'; -import { padArrayEnd } from '@aztec/foundation/collection'; +import { maxBy, padArrayEnd } from '@aztec/foundation/collection'; import { AbortError } from '@aztec/foundation/error'; import { createDebugLogger } from '@aztec/foundation/log'; import { promiseWithResolvers } from '@aztec/foundation/promise'; @@ -162,7 +162,7 @@ export class ProvingOrchestrator implements EpochProver { } logger.info( - `Starting block ${globalVariables.blockNumber} for slot ${globalVariables.slotNumber} with ${numTxs} transactions`, + `Starting block ${globalVariables.blockNumber.toNumber()} for slot ${globalVariables.slotNumber.toNumber()} with ${numTxs} transactions`, ); // Fork world state at the end of the immediately previous block @@ -235,34 +235,39 @@ export class ProvingOrchestrator implements EpochProver { })) public async addNewTx(tx: ProcessedTx): Promise { const blockNumber = tx.constants.globalVariables.blockNumber.toNumber(); + try { + const provingState = this.provingState?.getBlockProvingStateByBlockNumber(blockNumber); + if (!provingState) { + throw new Error(`Block proving state for ${blockNumber} not found`); + } - const provingState = this.provingState?.getBlockProvingStateByBlockNumber(blockNumber); - if (!provingState) { - throw new Error(`Block proving state for ${blockNumber} not found`); - } - - if (!provingState.isAcceptingTransactions()) { - throw new Error(`Rollup not accepting further transactions`); - } + if (!provingState.isAcceptingTransactions()) { + throw new Error(`Rollup not accepting further transactions`); + } - if (!provingState.verifyState()) { - throw new Error(`Invalid proving state when adding a tx`); - } + if (!provingState.verifyState()) { + throw new Error(`Invalid proving state when adding a tx`); + } - validateTx(tx); + validateTx(tx); - logger.info(`Received transaction: ${tx.hash}`); + logger.info(`Received transaction: ${tx.hash}`); - if (tx.isEmpty) { - logger.warn(`Ignoring empty transaction ${tx.hash} - it will not be added to this block`); - return; - } + if (tx.isEmpty) { + logger.warn(`Ignoring empty transaction ${tx.hash} - it will not be added to this block`); + return; + } - const [hints, treeSnapshots] = await this.prepareTransaction(tx, provingState); - this.enqueueFirstProofs(hints, treeSnapshots, tx, provingState); + const [hints, treeSnapshots] = await this.prepareTransaction(tx, provingState); + this.enqueueFirstProofs(hints, treeSnapshots, tx, provingState); - if (provingState.transactionsReceived === provingState.totalNumTxs) { - logger.verbose(`All transactions received for block ${provingState.globalVariables.blockNumber}.`); + if (provingState.transactionsReceived === provingState.totalNumTxs) { + logger.verbose(`All transactions received for block ${provingState.globalVariables.blockNumber}.`); + } + } catch (err: any) { + throw new Error(`Error adding transaction ${tx.hash.toString()} to block ${blockNumber}: ${err.message}`, { + cause: err, + }); } } @@ -348,7 +353,8 @@ export class ProvingOrchestrator implements EpochProver { }) private padEpoch(): Promise { const provingState = this.provingState!; - const lastBlock = provingState.blocks.at(-1)?.block; + logger.warn(`DA BLOCKS: ${provingState.blocks.map(b => `${b.blockNumber}: ${!!b.block}`).join(', ')}`); + const lastBlock = maxBy(provingState.blocks, b => b.blockNumber)?.block; if (!lastBlock) { return Promise.reject(new Error(`Epoch needs at least one completed block in order to be padded`)); } diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator_errors.test.ts b/yarn-project/prover-client/src/orchestrator/orchestrator_errors.test.ts index 98afe98c1bf8..f1a9374e9495 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator_errors.test.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator_errors.test.ts @@ -1,24 +1,19 @@ -import { makeEmptyProcessedTx } from '@aztec/circuit-types'; import { Fr } from '@aztec/circuits.js'; +import { times } from '@aztec/foundation/collection'; import { createDebugLogger } from '@aztec/foundation/log'; -import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types'; -import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; -import { makeBloatedProcessedTxWithVKRoot } from '../mocks/fixtures.js'; import { TestContext } from '../mocks/test_context.js'; +import { type ProvingOrchestrator } from './orchestrator.js'; const logger = createDebugLogger('aztec:orchestrator-errors'); describe('prover/orchestrator/errors', () => { let context: TestContext; - - const makeEmptyProcessedTestTx = () => { - const header = context.actualDb.getInitialHeader(); - return makeEmptyProcessedTx(header, Fr.ZERO, Fr.ZERO, getVKTreeRoot(), protocolContractTreeRoot); - }; + let orchestrator: ProvingOrchestrator; beforeEach(async () => { context = await TestContext.new(logger); + orchestrator = context.orchestrator; }); afterEach(async () => { @@ -29,73 +24,68 @@ describe('prover/orchestrator/errors', () => { describe('errors', () => { it('throws if adding too many transactions', async () => { - const txs = [ - makeBloatedProcessedTxWithVKRoot(context.actualDb, 1), - makeBloatedProcessedTxWithVKRoot(context.actualDb, 2), - makeBloatedProcessedTxWithVKRoot(context.actualDb, 3), - makeBloatedProcessedTxWithVKRoot(context.actualDb, 4), - ]; + const txs = times(4, i => context.makeProcessedTx(i + 1)); - context.orchestrator.startNewEpoch(1, 1); - await context.orchestrator.startNewBlock(txs.length, context.globalVariables, []); + orchestrator.startNewEpoch(1, 1); + await orchestrator.startNewBlock(txs.length, context.globalVariables, []); for (const tx of txs) { - await context.orchestrator.addNewTx(tx); + await orchestrator.addNewTx(tx); } - await expect(async () => await context.orchestrator.addNewTx(makeEmptyProcessedTestTx())).rejects.toThrow( - 'Rollup not accepting further transactions', + await expect(async () => await orchestrator.addNewTx(context.makeProcessedTx())).rejects.toThrow( + /Rollup not accepting further transactions/, ); - const block = await context.orchestrator.setBlockCompleted(context.blockNumber); + const block = await orchestrator.setBlockCompleted(context.blockNumber); expect(block.number).toEqual(context.blockNumber); - await context.orchestrator.finaliseEpoch(); + await orchestrator.finaliseEpoch(); }); it('throws if adding too many blocks', async () => { - context.orchestrator.startNewEpoch(1, 1); - await context.orchestrator.startNewBlock(2, context.globalVariables, []); - await context.orchestrator.setBlockCompleted(context.blockNumber); + orchestrator.startNewEpoch(1, 1); + await orchestrator.startNewBlock(2, context.globalVariables, []); + await orchestrator.setBlockCompleted(context.blockNumber); - await expect( - async () => await context.orchestrator.startNewBlock(2, context.globalVariables, []), - ).rejects.toThrow('Epoch not accepting further blocks'); + await expect(async () => await orchestrator.startNewBlock(2, context.globalVariables, [])).rejects.toThrow( + 'Epoch not accepting further blocks', + ); }); it('throws if adding a transaction before starting epoch', async () => { - await expect(async () => await context.orchestrator.addNewTx(makeEmptyProcessedTestTx())).rejects.toThrow( - `Invalid proving state, call startNewBlock before adding transactions`, + await expect(async () => await orchestrator.addNewTx(context.makeProcessedTx())).rejects.toThrow( + /Block proving state for 1 not found/, ); }); it('throws if adding a transaction before starting block', async () => { - context.orchestrator.startNewEpoch(1, 1); - await expect(async () => await context.orchestrator.addNewTx(makeEmptyProcessedTestTx())).rejects.toThrow( - `Invalid proving state, call startNewBlock before adding transactions`, + orchestrator.startNewEpoch(1, 1); + await expect(async () => await orchestrator.addNewTx(context.makeProcessedTx())).rejects.toThrow( + /Block proving state for 1 not found/, ); }); it('throws if completing a block before start', async () => { - context.orchestrator.startNewEpoch(1, 1); - await expect(async () => await context.orchestrator.setBlockCompleted(context.blockNumber)).rejects.toThrow( - 'Invalid proving state, call startNewBlock before adding transactions or completing the block', + orchestrator.startNewEpoch(1, 1); + await expect(async () => await orchestrator.setBlockCompleted(context.blockNumber)).rejects.toThrow( + /Block proving state for 1 not found/, ); }); it('throws if setting an incomplete block as completed', async () => { - context.orchestrator.startNewEpoch(1, 1); - await context.orchestrator.startNewBlock(3, context.globalVariables, []); - await expect(async () => await context.orchestrator.setBlockCompleted(context.blockNumber)).rejects.toThrow( + orchestrator.startNewEpoch(1, 1); + await orchestrator.startNewBlock(3, context.globalVariables, []); + await expect(async () => await orchestrator.setBlockCompleted(context.blockNumber)).rejects.toThrow( `Block not ready for completion: expecting ${3} more transactions.`, ); }); it('throws if adding to a cancelled block', async () => { - context.orchestrator.startNewEpoch(1, 1); - await context.orchestrator.startNewBlock(2, context.globalVariables, []); - context.orchestrator.cancel(); + orchestrator.startNewEpoch(1, 1); + await orchestrator.startNewBlock(2, context.globalVariables, []); + orchestrator.cancel(); - await expect(async () => await context.orchestrator.addNewTx(makeEmptyProcessedTestTx())).rejects.toThrow( + await expect(async () => await orchestrator.addNewTx(context.makeProcessedTx())).rejects.toThrow( 'Invalid proving state when adding a tx', ); }); @@ -103,25 +93,25 @@ describe('prover/orchestrator/errors', () => { it.each([[-4], [0], [1], [8.1]] as const)( 'fails to start a block with %i transactions', async (blockSize: number) => { - context.orchestrator.startNewEpoch(1, 1); + orchestrator.startNewEpoch(1, 1); await expect( - async () => await context.orchestrator.startNewBlock(blockSize, context.globalVariables, []), + async () => await orchestrator.startNewBlock(blockSize, context.globalVariables, []), ).rejects.toThrow(`Invalid number of txs for block (got ${blockSize})`); }, ); it.each([[-4], [0], [8.1]] as const)('fails to start an epoch with %i blocks', (epochSize: number) => { - context.orchestrator.startNewEpoch(1, 1); - expect(() => context.orchestrator.startNewEpoch(1, epochSize)).toThrow( + orchestrator.startNewEpoch(1, 1); + expect(() => orchestrator.startNewEpoch(1, epochSize)).toThrow( `Invalid number of blocks for epoch (got ${epochSize})`, ); }); it('rejects if too many l1 to l2 messages are provided', async () => { const l1ToL2Messages = new Array(100).fill(new Fr(0n)); - context.orchestrator.startNewEpoch(1, 1); + orchestrator.startNewEpoch(1, 1); await expect( - async () => await context.orchestrator.startNewBlock(2, context.globalVariables, l1ToL2Messages), + async () => await orchestrator.startNewBlock(2, context.globalVariables, l1ToL2Messages), ).rejects.toThrow('Too many L1 to L2 messages'); }); }); diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator_failures.test.ts b/yarn-project/prover-client/src/orchestrator/orchestrator_failures.test.ts index 835d0a9e56b2..709f044575f5 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator_failures.test.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator_failures.test.ts @@ -1,17 +1,12 @@ +import { TestCircuitProver } from '@aztec/bb-prover'; import { type ServerCircuitProver } from '@aztec/circuit-types'; -import { makeBloatedProcessedTx } from '@aztec/circuit-types/test'; -import { Fr } from '@aztec/circuits.js'; -import { times } from '@aztec/foundation/collection'; +import { timesAsync } from '@aztec/foundation/collection'; import { createDebugLogger } from '@aztec/foundation/log'; -import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types'; -import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; import { WASMSimulator } from '@aztec/simulator'; import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { jest } from '@jest/globals'; -import { TestCircuitProver } from '../../../bb-prover/src/test/test_circuit_prover.js'; -import { makeGlobals } from '../mocks/fixtures.js'; import { TestContext } from '../mocks/test_context.js'; import { ProvingOrchestrator } from './orchestrator.js'; @@ -34,29 +29,20 @@ describe('prover/orchestrator/failures', () => { beforeEach(() => { mockProver = new TestCircuitProver(new NoopTelemetryClient(), new WASMSimulator()); - orchestrator = new ProvingOrchestrator(context.forksProvider, mockProver, new NoopTelemetryClient()); + orchestrator = new ProvingOrchestrator(context.worldState, mockProver, new NoopTelemetryClient()); }); const run = async (message: string) => { + // We need at least 3 blocks, 3 txs, and 1 message to ensure all circuits are used + // We generate them and add them as part of the pending chain + const blocks = await timesAsync(3, i => context.makePendingBlock(3, 1, i + 1, j => ({ privateOnly: j === 1 }))); + orchestrator.startNewEpoch(1, 3); - // We need at least 3 blocks and 3 txs to ensure all circuits are used - for (let i = 0; i < 3; i++) { - const globalVariables = makeGlobals(i + 1); - const txs = times(3, j => - makeBloatedProcessedTx({ - db: context.actualDb, - globalVariables, - vkTreeRoot: getVKTreeRoot(), - protocolContractTreeRoot, - seed: i * 10 + j + 1, - privateOnly: j === 1, - }), - ); - const msgs = [new Fr(i + 100)]; + for (const { block, txs, msgs } of blocks) { // these operations could fail if the target circuit fails before adding all blocks or txs try { - await orchestrator.startNewBlock(txs.length, globalVariables, msgs); + await orchestrator.startNewBlock(txs.length, block.header.globalVariables, msgs); let allTxsAdded = true; for (const tx of txs) { try { @@ -68,11 +54,11 @@ describe('prover/orchestrator/failures', () => { } if (!allTxsAdded) { - await expect(orchestrator.setBlockCompleted(context.blockNumber)).rejects.toThrow( + await expect(orchestrator.setBlockCompleted(block.number)).rejects.toThrow( `Block proving failed: ${message}`, ); } else { - await orchestrator.setBlockCompleted(context.blockNumber); + await orchestrator.setBlockCompleted(block.number); } } catch (err) { break; diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator_lifecycle.test.ts b/yarn-project/prover-client/src/orchestrator/orchestrator_lifecycle.test.ts index bbd23615349e..5325d22cd017 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator_lifecycle.test.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator_lifecycle.test.ts @@ -1,6 +1,5 @@ import { type ServerCircuitProver } from '@aztec/circuit-types'; import { NUM_BASE_PARITY_PER_ROOT_PARITY } from '@aztec/circuits.js'; -import { makeGlobalVariables } from '@aztec/circuits.js/testing'; import { createDebugLogger } from '@aztec/foundation/log'; import { type PromiseWithResolvers, promiseWithResolvers } from '@aztec/foundation/promise'; import { sleep } from '@aztec/foundation/sleep'; @@ -28,7 +27,7 @@ describe('prover/orchestrator/lifecycle', () => { describe('lifecycle', () => { it('cancels proving requests', async () => { const prover: ServerCircuitProver = new TestCircuitProver(new NoopTelemetryClient()); - const orchestrator = new ProvingOrchestrator(context.forksProvider, prover, new NoopTelemetryClient()); + const orchestrator = new ProvingOrchestrator(context.worldState, prover, new NoopTelemetryClient()); const spy = jest.spyOn(prover, 'getBaseParityProof'); const deferredPromises: PromiseWithResolvers[] = []; @@ -39,7 +38,7 @@ describe('prover/orchestrator/lifecycle', () => { }); orchestrator.startNewEpoch(1, 1); - await orchestrator.startNewBlock(2, makeGlobalVariables(1), []); + await orchestrator.startNewBlock(2, context.globalVariables, []); await sleep(1); diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator_mixed_blocks.test.ts b/yarn-project/prover-client/src/orchestrator/orchestrator_mixed_blocks.test.ts index e361386816a9..1f133d6a4074 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator_mixed_blocks.test.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator_mixed_blocks.test.ts @@ -1,38 +1,27 @@ -import { MerkleTreeId } from '@aztec/circuit-types'; import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/circuits.js'; import { fr } from '@aztec/circuits.js/testing'; import { range } from '@aztec/foundation/array'; import { times } from '@aztec/foundation/collection'; import { createDebugLogger } from '@aztec/foundation/log'; -import { type MerkleTreeAdminDatabase } from '@aztec/world-state'; -import { NativeWorldStateService } from '@aztec/world-state/native'; -import { makeBloatedProcessedTxWithVKRoot, updateExpectedTreesFromTxs } from '../mocks/fixtures.js'; import { TestContext } from '../mocks/test_context.js'; const logger = createDebugLogger('aztec:orchestrator-mixed-blocks'); describe('prover/orchestrator/mixed-blocks', () => { let context: TestContext; - let expectsDb: MerkleTreeAdminDatabase; beforeEach(async () => { context = await TestContext.new(logger); - expectsDb = await NativeWorldStateService.tmp(); }); afterEach(async () => { await context.cleanup(); - await expectsDb.close(); }); describe('blocks', () => { it('builds an unbalanced L2 block', async () => { - const txs = [ - makeBloatedProcessedTxWithVKRoot(context.actualDb, 1), - makeBloatedProcessedTxWithVKRoot(context.actualDb, 2), - makeBloatedProcessedTxWithVKRoot(context.actualDb, 3), - ]; + const txs = times(3, i => context.makeProcessedTx(i + 1)); const l1ToL2Messages = range(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, 1 + 0x400).map(fr); @@ -48,7 +37,7 @@ describe('prover/orchestrator/mixed-blocks', () => { }); it.each([2, 4, 5, 8] as const)('builds an L2 block with %i bloated txs', async (totalCount: number) => { - const txs = times(totalCount, (i: number) => makeBloatedProcessedTxWithVKRoot(context.actualDb, i)); + const txs = times(totalCount, i => context.makeProcessedTx(i)); const l1ToL2Messages = range(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, 1 + 0x400).map(fr); @@ -62,13 +51,6 @@ describe('prover/orchestrator/mixed-blocks', () => { const block = await context.orchestrator.setBlockCompleted(context.blockNumber); await context.orchestrator.finaliseEpoch(); expect(block.number).toEqual(context.blockNumber); - - const fork = await expectsDb.fork(); - await updateExpectedTreesFromTxs(fork, txs); - const noteHashTreeAfter = await context.actualDb.getTreeInfo(MerkleTreeId.NOTE_HASH_TREE); - - const expectedNoteHashTreeAfter = await fork.getTreeInfo(MerkleTreeId.NOTE_HASH_TREE).then(t => t.root); - expect(noteHashTreeAfter.root).toEqual(expectedNoteHashTreeAfter); }); }); }); diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator_multi_public_functions.test.ts b/yarn-project/prover-client/src/orchestrator/orchestrator_multi_public_functions.test.ts index 693d5d0e7647..a84f751ec637 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator_multi_public_functions.test.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator_multi_public_functions.test.ts @@ -35,7 +35,7 @@ describe('prover/orchestrator/public-functions', () => { }), ); for (const tx of txs) { - tx.data.constants.historicalHeader = context.actualDb.getInitialHeader(); + tx.data.constants.historicalHeader = context.getHeader(0); tx.data.constants.vkTreeRoot = getVKTreeRoot(); tx.data.constants.protocolContractTreeRoot = protocolContractTreeRoot; } diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator_multiple_blocks.test.ts b/yarn-project/prover-client/src/orchestrator/orchestrator_multiple_blocks.test.ts index 84c630a4f35f..47be03cac99d 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator_multiple_blocks.test.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator_multiple_blocks.test.ts @@ -1,9 +1,6 @@ -import { makeBloatedProcessedTx } from '@aztec/circuit-types/test'; +import { timesAsync } from '@aztec/foundation/collection'; import { createDebugLogger } from '@aztec/foundation/log'; -import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types'; -import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; -import { makeGlobals } from '../mocks/fixtures.js'; import { TestContext } from '../mocks/test_context.js'; const logger = createDebugLogger('aztec:orchestrator-multi-blocks'); @@ -21,34 +18,44 @@ describe('prover/orchestrator/multi-block', () => { describe('multiple blocks', () => { it.each([1, 4, 5])('builds an epoch with %s blocks in sequence', async (numBlocks: number) => { - context.orchestrator.startNewEpoch(1, numBlocks); - let header = context.actualDb.getInitialHeader(); - - for (let i = 0; i < numBlocks; i++) { - logger.info(`Creating block ${i + 1000}`); - const tx = makeBloatedProcessedTx({ - header, - vkTreeRoot: getVKTreeRoot(), - protocolContractTreeRoot, - seed: i + 1, - }); + logger.info(`Seeding world state with ${numBlocks} blocks`); + const txCount = 1; + const blocks = await timesAsync(numBlocks, i => context.makePendingBlock(txCount, 0, i + 1)); - const blockNum = i + 1000; - const globals = makeGlobals(blockNum); + logger.info(`Starting new epoch with ${numBlocks}`); + context.orchestrator.startNewEpoch(1, numBlocks); + for (const { block, txs } of blocks) { + await context.orchestrator.startNewBlock(Math.max(txCount, 2), block.header.globalVariables, []); + for (const tx of txs) { + await context.orchestrator.addNewTx(tx); + } + await context.orchestrator.setBlockCompleted(block.number); + } - // This will need to be a 2 tx block - await context.orchestrator.startNewBlock(2, globals, []); + logger.info('Finalising epoch'); + const epoch = await context.orchestrator.finaliseEpoch(); + expect(epoch.publicInputs.endBlockNumber.toNumber()).toEqual(numBlocks); + expect(epoch.proof).toBeDefined(); + }); - await context.orchestrator.addNewTx(tx); + it.each([1, 4, 5])('builds an epoch with %s blocks in parallel', async (numBlocks: number) => { + logger.info(`Seeding world state with ${numBlocks} blocks`); + const txCount = 1; + const blocks = await timesAsync(numBlocks, i => context.makePendingBlock(txCount, 0, i + 1)); - // we need to complete the block as we have not added a full set of txs - const block = await context.orchestrator.setBlockCompleted(blockNum); - header = block!.header; - } + logger.info(`Starting new epoch with ${numBlocks}`); + context.orchestrator.startNewEpoch(1, numBlocks); + await Promise.all( + blocks.map(async ({ block, txs }) => { + await context.orchestrator.startNewBlock(Math.max(txCount, 2), block.header.globalVariables, []); + await Promise.all(txs.map(tx => context.orchestrator.addNewTx(tx))); + await context.orchestrator.setBlockCompleted(block.number); + }), + ); logger.info('Finalising epoch'); const epoch = await context.orchestrator.finaliseEpoch(); - expect(epoch.publicInputs.endBlockNumber.toNumber()).toEqual(1000 + numBlocks - 1); + expect(epoch.publicInputs.endBlockNumber.toNumber()).toEqual(numBlocks); expect(epoch.proof).toBeDefined(); }); }); diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator_public_functions.test.ts b/yarn-project/prover-client/src/orchestrator/orchestrator_public_functions.test.ts index 9f55a3da50c0..7e0221fc716d 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator_public_functions.test.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator_public_functions.test.ts @@ -35,7 +35,7 @@ describe('prover/orchestrator/public-functions', () => { numberOfNonRevertiblePublicCallRequests, numberOfRevertiblePublicCallRequests, }); - tx.data.constants.historicalHeader = context.actualDb.getInitialHeader(); + tx.data.constants.historicalHeader = context.getHeader(0); tx.data.constants.vkTreeRoot = getVKTreeRoot(); tx.data.constants.protocolContractTreeRoot = protocolContractTreeRoot; diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator_single_blocks.test.ts b/yarn-project/prover-client/src/orchestrator/orchestrator_single_blocks.test.ts index 4cf9f363d137..e790fa7d3784 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator_single_blocks.test.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator_single_blocks.test.ts @@ -1,10 +1,10 @@ import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/circuits.js'; import { fr } from '@aztec/circuits.js/testing'; import { range } from '@aztec/foundation/array'; +import { times } from '@aztec/foundation/collection'; import { createDebugLogger } from '@aztec/foundation/log'; import { sleep } from '@aztec/foundation/sleep'; -import { makeBloatedProcessedTxWithVKRoot } from '../mocks/fixtures.js'; import { TestContext } from '../mocks/test_context.js'; const logger = createDebugLogger('aztec:orchestrator-single-blocks'); @@ -31,7 +31,7 @@ describe('prover/orchestrator/blocks', () => { }); it('builds a block with 1 transaction', async () => { - const txs = [makeBloatedProcessedTxWithVKRoot(context.actualDb, 1)]; + const txs = [context.makeProcessedTx(1)]; // This will need to be a 2 tx block context.orchestrator.startNewEpoch(1, 1); @@ -47,12 +47,7 @@ describe('prover/orchestrator/blocks', () => { }); it('builds a block concurrently with transaction simulation', async () => { - const txs = [ - makeBloatedProcessedTxWithVKRoot(context.actualDb, 1), - makeBloatedProcessedTxWithVKRoot(context.actualDb, 2), - makeBloatedProcessedTxWithVKRoot(context.actualDb, 3), - makeBloatedProcessedTxWithVKRoot(context.actualDb, 4), - ]; + const txs = times(4, i => context.makeProcessedTx(i + 1)); const l1ToL2Messages = range(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, 1 + 0x400).map(fr); diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator_workflow.test.ts b/yarn-project/prover-client/src/orchestrator/orchestrator_workflow.test.ts index b626f10830f2..7525c9e16ed8 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator_workflow.test.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator_workflow.test.ts @@ -17,11 +17,9 @@ import { createDebugLogger } from '@aztec/foundation/log'; import { promiseWithResolvers } from '@aztec/foundation/promise'; import { sleep } from '@aztec/foundation/sleep'; import { ProtocolCircuitVks } from '@aztec/noir-protocol-circuits-types'; -import { type MerkleTreeReadOperations } from '@aztec/world-state'; import { type MockProxy, mock } from 'jest-mock-extended'; -import { makeBloatedProcessedTxWithVKRoot } from '../mocks/fixtures.js'; import { TestContext } from '../mocks/test_context.js'; import { type ProvingOrchestrator } from './orchestrator.js'; @@ -30,7 +28,6 @@ const logger = createDebugLogger('aztec:orchestrator-workflow'); describe('prover/orchestrator', () => { describe('workflow', () => { let orchestrator: ProvingOrchestrator; - let actualDb: MerkleTreeReadOperations; let globalVariables: GlobalVariables; let context: TestContext; @@ -39,8 +36,8 @@ describe('prover/orchestrator', () => { beforeEach(async () => { mockProver = mock(); - context = await TestContext.new(logger, 'native', 4, () => Promise.resolve(mockProver)); - ({ actualDb, orchestrator, globalVariables } = context); + context = await TestContext.new(logger, 4, () => Promise.resolve(mockProver)); + ({ orchestrator, globalVariables } = context); }); it('calls root parity circuit only when ready', async () => { @@ -103,14 +100,14 @@ describe('prover/orchestrator', () => { describe('with simulated prover', () => { beforeEach(async () => { context = await TestContext.new(logger); - ({ actualDb, orchestrator, globalVariables } = context); + ({ orchestrator, globalVariables } = context); }); it('waits for block to be completed before enqueueing block root proof', async () => { orchestrator.startNewEpoch(1, 1); await orchestrator.startNewBlock(2, globalVariables, []); - await orchestrator.addNewTx(makeBloatedProcessedTxWithVKRoot(actualDb, 1)); - await orchestrator.addNewTx(makeBloatedProcessedTxWithVKRoot(actualDb, 2)); + await orchestrator.addNewTx(context.makeProcessedTx(1)); + await orchestrator.addNewTx(context.makeProcessedTx(2)); // wait for the block root proof to try to be enqueued await sleep(1000); diff --git a/yarn-project/prover-client/src/test/bb_prover_base_rollup.test.ts b/yarn-project/prover-client/src/test/bb_prover_base_rollup.test.ts index e8b644a8a266..154ac6c71dd9 100644 --- a/yarn-project/prover-client/src/test/bb_prover_base_rollup.test.ts +++ b/yarn-project/prover-client/src/test/bb_prover_base_rollup.test.ts @@ -27,7 +27,7 @@ describe('prover/bb_prover/base-rollup', () => { prover = await BBNativeRollupProver.new(bbConfig, new NoopTelemetryClient()); return prover; }; - context = await TestContext.new(logger, 'native', 1, buildProver); + context = await TestContext.new(logger, 1, buildProver); }); afterAll(async () => { @@ -35,7 +35,7 @@ describe('prover/bb_prover/base-rollup', () => { }); it('proves the base rollup', async () => { - const header = context.actualDb.getInitialHeader(); + const header = context.getHeader(0); const chainId = context.globalVariables.chainId; const version = context.globalVariables.version; const vkTreeRoot = getVKTreeRoot(); @@ -59,7 +59,7 @@ describe('prover/bb_prover/base-rollup', () => { const tubeData = new PrivateTubeData(tubeProof.inputs, tubeProof.proof, vkData); - const baseRollupHints = await buildBaseRollupHints(tx, context.globalVariables, context.actualDb); + const baseRollupHints = await buildBaseRollupHints(tx, context.globalVariables, await context.getFork()); const baseRollupInputs = new PrivateBaseRollupInputs(tubeData, baseRollupHints as PrivateBaseRollupHints); logger.verbose('Proving base rollups'); diff --git a/yarn-project/prover-client/src/test/bb_prover_full_rollup.test.ts b/yarn-project/prover-client/src/test/bb_prover_full_rollup.test.ts index 1ade794ae8ed..8dd372afe99a 100644 --- a/yarn-project/prover-client/src/test/bb_prover_full_rollup.test.ts +++ b/yarn-project/prover-client/src/test/bb_prover_full_rollup.test.ts @@ -8,6 +8,7 @@ import { getTestData, isGenerateTestDataEnabled, writeTestData } from '@aztec/fo import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types'; import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { buildBlock } from '../block_builder/light.js'; import { makeGlobals } from '../mocks/fixtures.js'; import { TestContext } from '../mocks/test_context.js'; @@ -22,7 +23,7 @@ describe('prover/bb_prover/full-rollup', () => { return prover; }; log = createDebugLogger('aztec:bb-prover-full-rollup'); - context = await TestContext.new(log, 'legacy', 1, buildProver); + context = await TestContext.new(log, 1, buildProver); }); afterAll(async () => { @@ -38,7 +39,7 @@ describe('prover/bb_prover/full-rollup', () => { async (blockCount, totalBlocks, nonEmptyTxs, totalTxs) => { log.info(`Proving epoch with ${blockCount}/${totalBlocks} blocks with ${nonEmptyTxs}/${totalTxs} non-empty txs`); - const initialHeader = context.actualDb.getInitialHeader(); + const initialHeader = context.getHeader(0); context.orchestrator.startNewEpoch(1, totalBlocks); for (let blockNum = 1; blockNum <= blockCount; blockNum++) { @@ -60,7 +61,11 @@ describe('prover/bb_prover/full-rollup', () => { expect(failed.length).toBe(0); log.info(`Setting block as completed`); - await context.orchestrator.setBlockCompleted(context.blockNumber); + await context.orchestrator.setBlockCompleted(blockNum); + + log.info(`Updating world state with new block`); + const block = await buildBlock(processed, globals, l1ToL2Messages, await context.worldState.fork()); + await context.worldState.handleL2BlockAndMessages(block, l1ToL2Messages); } log.info(`Awaiting proofs`); @@ -89,7 +94,7 @@ describe('prover/bb_prover/full-rollup', () => { }), ); for (const tx of txs) { - tx.data.constants.historicalHeader = context.actualDb.getInitialHeader(); + tx.data.constants.historicalHeader = context.getHeader(0); } const l1ToL2Messages = makeTuple( diff --git a/yarn-project/prover-client/src/test/bb_prover_parity.test.ts b/yarn-project/prover-client/src/test/bb_prover_parity.test.ts index a845a1de4cc3..1763fd1b4000 100644 --- a/yarn-project/prover-client/src/test/bb_prover_parity.test.ts +++ b/yarn-project/prover-client/src/test/bb_prover_parity.test.ts @@ -36,7 +36,7 @@ describe('prover/bb_prover/parity', () => { bbProver = await BBNativeRollupProver.new(bbConfig, new NoopTelemetryClient()); return bbProver; }; - context = await TestContext.new(logger, 'native', 1, buildProver); + context = await TestContext.new(logger, 1, buildProver); }); afterAll(async () => {