From 964cc6f6d125c5f3641c6c26ae80a9c9194021eb Mon Sep 17 00:00:00 2001 From: LHerskind Date: Thu, 3 Aug 2023 12:00:44 +0000 Subject: [PATCH] feat: AztecNodeService creates public processor --- yarn-project/aztec-node/src/aztec-node/server.ts | 14 ++++++++++++-- .../src/client/sequencer-client.ts | 12 +++++------- .../sequencer-client/src/sequencer/index.ts | 1 + .../src/sequencer/sequencer.test.ts | 6 +----- .../sequencer-client/src/sequencer/sequencer.ts | 9 ++++----- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index f6bf19bc260..405e89373dd 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -9,7 +9,12 @@ import { import { AztecAddress } from '@aztec/foundation/aztec-address'; import { createDebugLogger } from '@aztec/foundation/log'; import { InMemoryTxPool, P2P, createP2PClient } from '@aztec/p2p'; -import { SequencerClient, getCombinedHistoricTreeRoots } from '@aztec/sequencer-client'; +import { + PublicProcessor, + PublicProcessorFactory, + SequencerClient, + getCombinedHistoricTreeRoots, +} from '@aztec/sequencer-client'; import { AztecNode, ContractData, @@ -57,6 +62,7 @@ export class AztecNodeService implements AztecNode { protected sequencer: SequencerClient, protected chainId: number, protected version: number, + protected publicProcessor: PublicProcessor, private log = createDebugLogger('aztec:node'), ) {} @@ -83,6 +89,9 @@ export class AztecNodeService implements AztecNode { // start both and wait for them to sync from the block source await Promise.all([p2pClient.start(), worldStateSynchroniser.start()]); + const publicProcessorFactory = new PublicProcessorFactory(worldStateSynchroniser.getLatest(), archiver, archiver); + const publicProcessor = publicProcessorFactory.create(); + // now create the sequencer const sequencer = await SequencerClient.new( config, @@ -90,7 +99,7 @@ export class AztecNodeService implements AztecNode { worldStateSynchroniser, archiver, archiver, - archiver, + publicProcessor, ); return new AztecNodeService( p2pClient, @@ -104,6 +113,7 @@ export class AztecNodeService implements AztecNode { sequencer, config.chainId, config.version, + publicProcessor, ); } diff --git a/yarn-project/sequencer-client/src/client/sequencer-client.ts b/yarn-project/sequencer-client/src/client/sequencer-client.ts index 47d9b976df7..1c84365952c 100644 --- a/yarn-project/sequencer-client/src/client/sequencer-client.ts +++ b/yarn-project/sequencer-client/src/client/sequencer-client.ts @@ -1,5 +1,5 @@ import { P2P } from '@aztec/p2p'; -import { ContractDataSource, L1ToL2MessageSource, L2BlockSource } from '@aztec/types'; +import { L1ToL2MessageSource, L2BlockSource } from '@aztec/types'; import { WorldStateSynchroniser } from '@aztec/world-state'; import { SoloBlockBuilder } from '../block_builder/solo_block_builder.js'; @@ -7,7 +7,7 @@ import { SequencerClientConfig } from '../config.js'; import { getGlobalVariableBuilder } from '../global_variable_builder/index.js'; import { Sequencer, getL1Publisher, getVerificationKeys } from '../index.js'; import { EmptyRollupProver } from '../prover/empty.js'; -import { PublicProcessorFactory } from '../sequencer/public_processor.js'; +import { PublicProcessor } from '../sequencer/public_processor.js'; import { WasmRollupCircuitSimulator } from '../simulator/rollup.js'; /** @@ -21,18 +21,18 @@ export class SequencerClient { * @param config - Configuration for the sequencer, publisher, and L1 tx sender. * @param p2pClient - P2P client that provides the txs to be sequenced. * @param worldStateSynchroniser - Provides access to world state. - * @param contractDataSource - Provides access to contract bytecode for public executions. * @param l2BlockSource - Provides information about the previously published blocks. * @param l1ToL2MessageSource - Provides access to L1 to L2 messages. + * @param publicProcessor - Public processor. * @returns A new running instance. */ public static async new( config: SequencerClientConfig, p2pClient: P2P, worldStateSynchroniser: WorldStateSynchroniser, - contractDataSource: ContractDataSource, l2BlockSource: L2BlockSource, l1ToL2MessageSource: L1ToL2MessageSource, + publicProcessor: PublicProcessor, ) { const publisher = getL1Publisher(config); const globalsBuilder = getGlobalVariableBuilder(config); @@ -45,8 +45,6 @@ export class SequencerClient { new EmptyRollupProver(), ); - const publicProcessorFactory = new PublicProcessorFactory(merkleTreeDb, contractDataSource, l1ToL2MessageSource); - const sequencer = new Sequencer( publisher, globalsBuilder, @@ -55,7 +53,7 @@ export class SequencerClient { blockBuilder, l2BlockSource, l1ToL2MessageSource, - publicProcessorFactory, + publicProcessor, config, ); diff --git a/yarn-project/sequencer-client/src/sequencer/index.ts b/yarn-project/sequencer-client/src/sequencer/index.ts index 43a83d121a1..830cada5eb6 100644 --- a/yarn-project/sequencer-client/src/sequencer/index.ts +++ b/yarn-project/sequencer-client/src/sequencer/index.ts @@ -1,3 +1,4 @@ export * from './sequencer.js'; export * from './config.js'; export * from './utils.js'; +export * from './public_processor.js'; \ No newline at end of file diff --git a/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts index 8de7c6f38ac..db4298bde41 100644 --- a/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts +++ b/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts @@ -60,10 +60,6 @@ describe('sequencer', () => { makeEmptyProcessedTx: () => makeEmptyProcessedTx(CombinedHistoricTreeRoots.empty(), chainId, version), }); - publicProcessorFactory = mock({ - create: () => publicProcessor, - }); - l2BlockSource = mock({ getBlockHeight: () => Promise.resolve(lastBlockNumber), }); @@ -80,7 +76,7 @@ describe('sequencer', () => { blockBuilder, l2BlockSource, l1ToL2MessageSource, - publicProcessorFactory, + publicProcessor, { chainId: Number(chainId.value), version: Number(version.value), diff --git a/yarn-project/sequencer-client/src/sequencer/sequencer.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.ts index 5b701754a01..7ad9beb984d 100644 --- a/yarn-project/sequencer-client/src/sequencer/sequencer.ts +++ b/yarn-project/sequencer-client/src/sequencer/sequencer.ts @@ -22,7 +22,7 @@ import { L1Publisher } from '../publisher/l1-publisher.js'; import { ceilPowerOfTwo } from '../utils.js'; import { SequencerConfig } from './config.js'; import { ProcessedTx } from './processed_tx.js'; -import { PublicProcessorFactory } from './public_processor.js'; +import { PublicProcessor } from './public_processor.js'; /** * Sequencer client @@ -51,7 +51,7 @@ export class Sequencer { private blockBuilder: BlockBuilder, private l2BlockSource: L2BlockSource, private l1ToL2MessageSource: L1ToL2MessageSource, - private publicProcessorFactory: PublicProcessorFactory, + private publicProcessor: PublicProcessor, config: SequencerConfig, private log = createDebugLogger('aztec:sequencer'), ) { @@ -145,8 +145,7 @@ export class Sequencer { // Process txs and drop the ones that fail processing // We create a fresh processor each time to reset any cached state (eg storage writes) - const processor = this.publicProcessorFactory.create(); - const [processedTxs, failedTxs] = await processor.process(validTxs, globalVariables); + const [processedTxs, failedTxs] = await this.publicProcessor.process(validTxs, globalVariables); if (failedTxs.length > 0) { this.log(`Dropping failed txs ${(await Tx.getHashes(failedTxs)).join(', ')}`); await this.p2pClient.deleteTxs(await Tx.getHashes(failedTxs)); @@ -164,7 +163,7 @@ export class Sequencer { // Build the new block by running the rollup circuits this.log(`Assembling block with txs ${processedTxs.map(tx => tx.hash).join(', ')}`); - const emptyTx = await processor.makeEmptyProcessedTx(this.chainId, this.version); + const emptyTx = await this.publicProcessor.makeEmptyProcessedTx(this.chainId, this.version); const block = await this.buildBlock(processedTxs, l1ToL2Messages, emptyTx, globalVariables); this.log(`Assembled block ${block.number}`);