From 74420bb0415940a772092ef1d9e8a9a6248e3a5a Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 9 Dec 2024 16:37:54 +0000 Subject: [PATCH 1/7] wait for pxe to synch before checking balances --- yarn-project/end-to-end/src/e2e_2_pxes.test.ts | 2 +- yarn-project/pxe/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts index d3dded0788d..db08c3bc033 100644 --- a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts +++ b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts @@ -58,7 +58,7 @@ describe('e2e_2_pxes', () => { }); // TODO #10296 - it.skip('transfers funds from user A to B via PXE A followed by transfer from B to A via PXE B', async () => { + it('transfers funds from user A to B via PXE A followed by transfer from B to A via PXE B', async () => { const initialBalance = 987n; const transferAmount1 = 654n; const transferAmount2 = 323n; diff --git a/yarn-project/pxe/package.json b/yarn-project/pxe/package.json index 043184ef30c..5d8768902c7 100644 --- a/yarn-project/pxe/package.json +++ b/yarn-project/pxe/package.json @@ -112,4 +112,4 @@ "engines": { "node": ">=18" } -} \ No newline at end of file +} From 92ba76967a25231f5cdceb7a24109489cde8d86e Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 9 Dec 2024 16:40:28 +0000 Subject: [PATCH 2/7] actually commit --- yarn-project/end-to-end/src/fixtures/token_utils.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/yarn-project/end-to-end/src/fixtures/token_utils.ts b/yarn-project/end-to-end/src/fixtures/token_utils.ts index f623bcf3d5d..0afbd12ba20 100644 --- a/yarn-project/end-to-end/src/fixtures/token_utils.ts +++ b/yarn-project/end-to-end/src/fixtures/token_utils.ts @@ -1,5 +1,5 @@ // docs:start:token_utils -import { type AztecAddress, type DebugLogger, type Wallet } from '@aztec/aztec.js'; +import { type AztecAddress, type DebugLogger, type Wallet, retryUntil } from '@aztec/aztec.js'; import { TokenContract } from '@aztec/noir-contracts.js'; export async function deployToken(adminWallet: Wallet, initialAdminBalance: bigint, logger: DebugLogger) { @@ -37,6 +37,17 @@ export async function expectTokenBalance( expectedBalance: bigint, logger: DebugLogger, ) { + // Check if the wallet + const blockNumber = await wallet.getBlockNumber(); + await retryUntil( + async () => { + const status = await wallet.getSyncStatus(); + return blockNumber <= status.blocks; + }, + 'pxe synch', + 3600, + 1, + ); // Then check the balance const contractWithWallet = await TokenContract.at(token.address, wallet); const balance = await contractWithWallet.methods.balance_of_private(owner).simulate({ from: owner }); From 0337f73b2c2d49c7c4ee31b1374a2d21f395e039 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 9 Dec 2024 17:04:00 +0000 Subject: [PATCH 3/7] comment --- yarn-project/end-to-end/src/fixtures/token_utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/end-to-end/src/fixtures/token_utils.ts b/yarn-project/end-to-end/src/fixtures/token_utils.ts index 0afbd12ba20..320d3ef6347 100644 --- a/yarn-project/end-to-end/src/fixtures/token_utils.ts +++ b/yarn-project/end-to-end/src/fixtures/token_utils.ts @@ -37,7 +37,7 @@ export async function expectTokenBalance( expectedBalance: bigint, logger: DebugLogger, ) { - // Check if the wallet + // Check if PXE has synced up to the latest block before checking the balances const blockNumber = await wallet.getBlockNumber(); await retryUntil( async () => { From a0483dbd86572d140af47c7604ba1b8100f5a7f9 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 9 Dec 2024 17:35:37 +0000 Subject: [PATCH 4/7] fix --- yarn-project/end-to-end/src/fixtures/token_utils.ts | 11 ----------- yarn-project/simulator/src/client/view_data_oracle.ts | 2 +- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/yarn-project/end-to-end/src/fixtures/token_utils.ts b/yarn-project/end-to-end/src/fixtures/token_utils.ts index 320d3ef6347..f69bb492fda 100644 --- a/yarn-project/end-to-end/src/fixtures/token_utils.ts +++ b/yarn-project/end-to-end/src/fixtures/token_utils.ts @@ -37,17 +37,6 @@ export async function expectTokenBalance( expectedBalance: bigint, logger: DebugLogger, ) { - // Check if PXE has synced up to the latest block before checking the balances - const blockNumber = await wallet.getBlockNumber(); - await retryUntil( - async () => { - const status = await wallet.getSyncStatus(); - return blockNumber <= status.blocks; - }, - 'pxe synch', - 3600, - 1, - ); // Then check the balance const contractWithWallet = await TokenContract.at(token.address, wallet); const balance = await contractWithWallet.methods.balance_of_private(owner).simulate({ from: owner }); diff --git a/yarn-project/simulator/src/client/view_data_oracle.ts b/yarn-project/simulator/src/client/view_data_oracle.ts index 67af9e77df3..bb69d8240c9 100644 --- a/yarn-project/simulator/src/client/view_data_oracle.ts +++ b/yarn-project/simulator/src/client/view_data_oracle.ts @@ -312,7 +312,7 @@ export class ViewDataOracle extends TypedOracle { public override async syncNotes() { const taggedLogsByRecipient = await this.db.syncTaggedLogs( this.contractAddress, - await this.aztecNode.getBlockNumber(), + await this.db.getBlockNumber(), this.scopes, ); for (const [recipient, taggedLogs] of taggedLogsByRecipient.entries()) { From 0fde995d8302a5555702f9eb4726db9341b321a5 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 9 Dec 2024 19:43:35 +0000 Subject: [PATCH 5/7] merge --- yarn-project/ethereum/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/ethereum/package.json b/yarn-project/ethereum/package.json index 0e34d8dcbf1..3300f21bba8 100644 --- a/yarn-project/ethereum/package.json +++ b/yarn-project/ethereum/package.json @@ -91,4 +91,4 @@ "engines": { "node": ">=18" } -} \ No newline at end of file +} From fe40d4fd92142bf2a34455ffc630369dc1a3ccbe Mon Sep 17 00:00:00 2001 From: thunkar Date: Tue, 10 Dec 2024 05:48:49 +0000 Subject: [PATCH 6/7] fmt --- yarn-project/end-to-end/src/fixtures/token_utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/end-to-end/src/fixtures/token_utils.ts b/yarn-project/end-to-end/src/fixtures/token_utils.ts index f69bb492fda..f623bcf3d5d 100644 --- a/yarn-project/end-to-end/src/fixtures/token_utils.ts +++ b/yarn-project/end-to-end/src/fixtures/token_utils.ts @@ -1,5 +1,5 @@ // docs:start:token_utils -import { type AztecAddress, type DebugLogger, type Wallet, retryUntil } from '@aztec/aztec.js'; +import { type AztecAddress, type DebugLogger, type Wallet } from '@aztec/aztec.js'; import { TokenContract } from '@aztec/noir-contracts.js'; export async function deployToken(adminWallet: Wallet, initialAdminBalance: bigint, logger: DebugLogger) { From 712f25e25cc6ba838aa0d48aeb2530c3e16e3117 Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 11 Dec 2024 11:47:59 +0000 Subject: [PATCH 7/7] synchronize on demand --- .../aztec.js/src/contract/sent_tx.test.ts | 14 ---- yarn-project/aztec.js/src/contract/sent_tx.ts | 11 +-- yarn-project/aztec.js/src/index.ts | 1 - .../aztec.js/src/wallet/base_wallet.ts | 7 -- yarn-project/bot/src/factory.ts | 11 --- .../circuit-types/src/interfaces/index.ts | 1 - .../circuit-types/src/interfaces/pxe.test.ts | 19 ------ .../circuit-types/src/interfaces/pxe.ts | 19 ------ .../src/interfaces/sync-status.ts | 13 ---- yarn-project/cli/src/cmds/pxe/get_block.ts | 23 +------ yarn-project/cli/src/cmds/pxe/index.ts | 3 +- .../benchmarks/bench_process_history.test.ts | 4 +- .../benchmarks/bench_publish_rollup.test.ts | 4 +- .../end-to-end/src/benchmarks/utils.ts | 7 +- .../end-to-end/src/e2e_2_pxes.test.ts | 12 ---- .../end-to-end/src/e2e_block_building.test.ts | 8 --- yarn-project/pxe/src/bin/index.ts | 2 +- .../pxe/src/database/kv_pxe_database.ts | 10 --- yarn-project/pxe/src/database/pxe_database.ts | 13 ---- yarn-project/pxe/src/index.ts | 1 - .../pxe/src/pxe_service/create_pxe_service.ts | 6 +- yarn-project/pxe/src/pxe_service/index.ts | 1 + .../pxe/src/pxe_service/pxe_service.ts | 26 ++----- .../src/pxe_service/test/pxe_test_suite.ts | 3 - yarn-project/pxe/src/simulator/index.ts | 3 + .../pxe/src/simulator_oracle/index.ts | 23 ++++++- .../simulator_oracle/simulator_oracle.test.ts | 5 +- .../pxe/src/synchronizer/synchronizer.ts | 64 ++---------------- yarn-project/pxe/src/utils/index.ts | 67 ------------------- .../simulator/src/client/db_oracle.ts | 8 +++ .../simulator/src/client/view_data_oracle.ts | 11 +-- 31 files changed, 64 insertions(+), 336 deletions(-) delete mode 100644 yarn-project/circuit-types/src/interfaces/sync-status.ts delete mode 100644 yarn-project/pxe/src/utils/index.ts diff --git a/yarn-project/aztec.js/src/contract/sent_tx.test.ts b/yarn-project/aztec.js/src/contract/sent_tx.test.ts index c2bf65adb6a..c0f7daf8a57 100644 --- a/yarn-project/aztec.js/src/contract/sent_tx.test.ts +++ b/yarn-project/aztec.js/src/contract/sent_tx.test.ts @@ -23,22 +23,8 @@ describe('SentTx', () => { pxe.getTxReceipt.mockResolvedValue(txReceipt); }); - it('waits for all notes of the accounts to be available', async () => { - pxe.getSyncStatus.mockResolvedValueOnce({ blocks: 25 }).mockResolvedValueOnce({ blocks: 25 }); - - const actual = await sentTx.wait({ timeout: 1, interval: 0.4 }); - expect(actual).toEqual(txReceipt); - }); - - it('does not wait for notes sync', async () => { - pxe.getSyncStatus.mockResolvedValue({ blocks: 19 }); - const actual = await sentTx.wait({ timeout: 1, interval: 0.4, waitForNotesAvailable: false }); - expect(actual).toEqual(txReceipt); - }); - it('throws if tx is dropped', async () => { pxe.getTxReceipt.mockResolvedValue({ ...txReceipt, status: TxStatus.DROPPED } as TxReceipt); - pxe.getSyncStatus.mockResolvedValue({ blocks: 19 }); await expect(sentTx.wait({ timeout: 1, interval: 0.4, ignoreDroppedReceiptsFor: 0 })).rejects.toThrow(/dropped/); }); diff --git a/yarn-project/aztec.js/src/contract/sent_tx.ts b/yarn-project/aztec.js/src/contract/sent_tx.ts index b7803975b16..fb2d0e87549 100644 --- a/yarn-project/aztec.js/src/contract/sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/sent_tx.ts @@ -124,16 +124,7 @@ export class SentTx { } return undefined; } - // If we don't care about waiting for notes to be synced, return the receipt - const waitForNotesAvailable = opts?.waitForNotesAvailable ?? DefaultWaitOpts.waitForNotesAvailable; - if (!waitForNotesAvailable) { - return txReceipt; - } - // Check if all sync blocks on the PXE Service are greater or equal than the block in which the tx was mined - const { blocks } = await this.pxe.getSyncStatus(); - const targetBlock = txReceipt.blockNumber!; - const areNotesAvailable = blocks >= targetBlock; - return areNotesAvailable ? txReceipt : undefined; + return txReceipt; }, 'isMined', opts?.timeout ?? DefaultWaitOpts.timeout, diff --git a/yarn-project/aztec.js/src/index.ts b/yarn-project/aztec.js/src/index.ts index 4c42ac375de..c4a15950273 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -149,7 +149,6 @@ export { type PXE, type PartialAddress, type PublicKey, - type SyncStatus, } from '@aztec/circuit-types'; // TODO: These kinds of things have no place on our public api. diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index 35694b490f5..e455ee4c0be 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -10,7 +10,6 @@ import { type PXEInfo, type PrivateExecutionResult, type SiblingPath, - type SyncStatus, type Tx, type TxExecutionRequest, type TxHash, @@ -170,12 +169,6 @@ export abstract class BaseWallet implements Wallet { getNodeInfo(): Promise { return this.pxe.getNodeInfo(); } - isGlobalStateSynchronized() { - return this.pxe.isGlobalStateSynchronized(); - } - getSyncStatus(): Promise { - return this.pxe.getSyncStatus(); - } addAuthWitness(authWitness: AuthWitness) { return this.pxe.addAuthWitness(authWitness); } diff --git a/yarn-project/bot/src/factory.ts b/yarn-project/bot/src/factory.ts index aac66847624..03098a3095c 100644 --- a/yarn-project/bot/src/factory.ts +++ b/yarn-project/bot/src/factory.ts @@ -6,7 +6,6 @@ import { type DeployOptions, createLogger, createPXEClient, - retryUntil, } from '@aztec/aztec.js'; import { type AztecNode, type FunctionCall, type PXE } from '@aztec/circuit-types'; import { Fr, deriveSigningKey } from '@aztec/circuits.js'; @@ -67,16 +66,6 @@ export class BotFactory { if (isInit) { this.log.info(`Account at ${account.getAddress().toString()} already initialized`); const wallet = await account.register(); - const blockNumber = await this.pxe.getBlockNumber(); - await retryUntil( - async () => { - const status = await this.pxe.getSyncStatus(); - return blockNumber <= status.blocks; - }, - 'pxe synch', - 3600, - 1, - ); return wallet; } else { this.log.info(`Initializing account at ${account.getAddress().toString()}`); diff --git a/yarn-project/circuit-types/src/interfaces/index.ts b/yarn-project/circuit-types/src/interfaces/index.ts index 3f05c960e1b..2b880ad7550 100644 --- a/yarn-project/circuit-types/src/interfaces/index.ts +++ b/yarn-project/circuit-types/src/interfaces/index.ts @@ -18,7 +18,6 @@ export * from './proving-job.js'; export * from './pxe.js'; export * from './server_circuit_prover.js'; export * from './service.js'; -export * from './sync-status.js'; export * from './world_state.js'; export * from './prover-broker.js'; export * from './p2p.js'; diff --git a/yarn-project/circuit-types/src/interfaces/pxe.test.ts b/yarn-project/circuit-types/src/interfaces/pxe.test.ts index 8530f731bd1..9bf3ca99f59 100644 --- a/yarn-project/circuit-types/src/interfaces/pxe.test.ts +++ b/yarn-project/circuit-types/src/interfaces/pxe.test.ts @@ -43,7 +43,6 @@ import { Tx, TxHash, TxProvingResult, TxReceipt, TxSimulationResult } from '../t import { TxEffect } from '../tx_effect.js'; import { TxExecutionRequest } from '../tx_execution_request.js'; import { type EventMetadataDefinition, type PXE, type PXEInfo, PXESchema } from './pxe.js'; -import { type SyncStatus } from './sync-status.js'; jest.setTimeout(12_000); @@ -258,16 +257,6 @@ describe('PXESchema', () => { expect(result).toEqual(await handler.getPXEInfo()); }); - it('isGlobalStateSynchronized', async () => { - const result = await context.client.isGlobalStateSynchronized(); - expect(result).toBe(true); - }); - - it('getSyncStatus', async () => { - const result = await context.client.getSyncStatus(); - expect(result).toEqual(await handler.getSyncStatus()); - }); - it('getContractInstance', async () => { const result = await context.client.getContractInstance(address); expect(result).toEqual(instance); @@ -502,14 +491,6 @@ class MockPXE implements PXE { pxeVersion: '1.0', }); } - isGlobalStateSynchronized(): Promise { - return Promise.resolve(true); - } - getSyncStatus(): Promise { - return Promise.resolve({ - blocks: 1, - }); - } getContractInstance(address: AztecAddress): Promise { expect(address).toEqual(this.address); return Promise.resolve(this.instance); diff --git a/yarn-project/circuit-types/src/interfaces/pxe.ts b/yarn-project/circuit-types/src/interfaces/pxe.ts index 363511bad80..62c99eb84ba 100644 --- a/yarn-project/circuit-types/src/interfaces/pxe.ts +++ b/yarn-project/circuit-types/src/interfaces/pxe.ts @@ -43,7 +43,6 @@ import { SiblingPath } from '../sibling_path/sibling_path.js'; import { Tx, TxHash, TxProvingResult, TxReceipt, TxSimulationResult } from '../tx/index.js'; import { TxEffect } from '../tx_effect.js'; import { TxExecutionRequest } from '../tx_execution_request.js'; -import { type SyncStatus, SyncStatusSchema } from './sync-status.js'; // docs:start:pxe-interface /** @@ -351,22 +350,6 @@ export interface PXE { */ getPXEInfo(): Promise; - /** - * Checks whether all the blocks were processed (tree roots updated, txs updated with block info, etc.). - * @returns True if there are no outstanding blocks to be synched. - * @remarks This indicates that blocks and transactions are synched even if notes are not. Compares local block number with the block number from aztec node. - * @deprecated Use `getSyncStatus` instead. - */ - isGlobalStateSynchronized(): Promise; - - /** - * Returns the latest block that has been synchronized globally and for each account. The global block number - * indicates whether global state has been updated up to that block, whereas each address indicates up to which - * block the private state has been synced for that account. - * @returns The latest block synchronized for blocks, and the latest block synched for notes for each public key being tracked. - */ - getSyncStatus(): Promise; - /** * Returns a Contract Instance given its address, which includes the contract class identifier, * initialization hash, deployment salt, and public keys hash. @@ -540,8 +523,6 @@ export const PXESchema: ApiSchemaFor = { getProvenBlockNumber: z.function().returns(z.number()), getNodeInfo: z.function().returns(NodeInfoSchema), getPXEInfo: z.function().returns(PXEInfoSchema), - isGlobalStateSynchronized: z.function().returns(z.boolean()), - getSyncStatus: z.function().returns(SyncStatusSchema), getContractInstance: z .function() .args(schemas.AztecAddress) diff --git a/yarn-project/circuit-types/src/interfaces/sync-status.ts b/yarn-project/circuit-types/src/interfaces/sync-status.ts deleted file mode 100644 index b85a13620d6..00000000000 --- a/yarn-project/circuit-types/src/interfaces/sync-status.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { type ZodFor } from '@aztec/foundation/schemas'; - -import { z } from 'zod'; - -/** Provides up to which block has been synced by different components. */ -export type SyncStatus = { - /** Up to which block has been synched for blocks and txs. */ - blocks: number; -}; - -export const SyncStatusSchema = z.object({ - blocks: z.number(), -}) satisfies ZodFor; diff --git a/yarn-project/cli/src/cmds/pxe/get_block.ts b/yarn-project/cli/src/cmds/pxe/get_block.ts index d1584950ff1..f2951a9c8f6 100644 --- a/yarn-project/cli/src/cmds/pxe/get_block.ts +++ b/yarn-project/cli/src/cmds/pxe/get_block.ts @@ -3,29 +3,8 @@ import { type LogFn, type Logger } from '@aztec/foundation/log'; import { inspectBlock } from '../../utils/inspect.js'; -export async function getBlock( - rpcUrl: string, - maybeBlockNumber: number | undefined, - follow: boolean, - debugLogger: Logger, - log: LogFn, -) { +export async function getBlock(rpcUrl: string, maybeBlockNumber: number | undefined, debugLogger: Logger, log: LogFn) { const client = await createCompatibleClient(rpcUrl, debugLogger); const blockNumber = maybeBlockNumber ?? (await client.getBlockNumber()); await inspectBlock(client, blockNumber, log, { showTxs: true }); - - if (follow) { - let lastBlock = blockNumber; - setInterval(async () => { - const newBlock = await client.getBlockNumber(); - if (newBlock > lastBlock) { - const { blocks } = await client.getSyncStatus(); - if (blocks >= newBlock) { - log(''); - await inspectBlock(client, newBlock, log, { showTxs: true }); - lastBlock = newBlock; - } - } - }, 1000); - } } diff --git a/yarn-project/cli/src/cmds/pxe/index.ts b/yarn-project/cli/src/cmds/pxe/index.ts index e6e1f862725..dc8a7a4bb6a 100644 --- a/yarn-project/cli/src/cmds/pxe/index.ts +++ b/yarn-project/cli/src/cmds/pxe/index.ts @@ -54,11 +54,10 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: Logger .command('get-block') .description('Gets info for a given block or latest.') .argument('[blockNumber]', 'Block height', parseOptionalInteger) - .option('-f, --follow', 'Keep polling for new blocks') .addOption(pxeOption) .action(async (blockNumber, options) => { const { getBlock } = await import('./get_block.js'); - await getBlock(options.rpcUrl, blockNumber, options.follow, debugLogger, log); + await getBlock(options.rpcUrl, blockNumber, debugLogger, log); }); program diff --git a/yarn-project/end-to-end/src/benchmarks/bench_process_history.test.ts b/yarn-project/end-to-end/src/benchmarks/bench_process_history.test.ts index adc29c28d63..d0b9c33de3e 100644 --- a/yarn-project/end-to-end/src/benchmarks/bench_process_history.test.ts +++ b/yarn-project/end-to-end/src/benchmarks/bench_process_history.test.ts @@ -9,7 +9,7 @@ import { type BenchmarkingContract } from '@aztec/noir-contracts.js/Benchmarking import { type SequencerClient } from '@aztec/sequencer-client'; import { type EndToEndContext } from '../fixtures/utils.js'; -import { benchmarkSetup, getFolderSize, makeDataDirectory, sendTxs, waitNewPXESynced } from './utils.js'; +import { benchmarkSetup, createNewPXE, getFolderSize, makeDataDirectory, sendTxs } from './utils.js'; const BLOCK_SIZE = BENCHMARK_HISTORY_BLOCK_SIZE; const CHAIN_LENGTHS = BENCHMARK_HISTORY_CHAIN_LENGTHS; @@ -69,7 +69,7 @@ describe('benchmarks/process_history', () => { // Create a new pxe and measure how much time it takes it to sync with failed and successful decryption // Skip the first two blocks used for setup (create account contract and deploy benchmarking contract) context.logger.info(`Starting new pxe`); - const pxe = await waitNewPXESynced(node, contract, INITIAL_L2_BLOCK_NUM + setupBlockCount); + const pxe = await createNewPXE(node, contract, INITIAL_L2_BLOCK_NUM + setupBlockCount); // Register the owner account and wait until it's synced so we measure how much time it took context.logger.info(`Registering owner account on new pxe`); diff --git a/yarn-project/end-to-end/src/benchmarks/bench_publish_rollup.test.ts b/yarn-project/end-to-end/src/benchmarks/bench_publish_rollup.test.ts index 21612ccbe85..de9ecfd5797 100644 --- a/yarn-project/end-to-end/src/benchmarks/bench_publish_rollup.test.ts +++ b/yarn-project/end-to-end/src/benchmarks/bench_publish_rollup.test.ts @@ -5,7 +5,7 @@ import { type BenchmarkingContract } from '@aztec/noir-contracts.js/Benchmarking import { type SequencerClient } from '@aztec/sequencer-client'; import { type EndToEndContext } from '../fixtures/utils.js'; -import { benchmarkSetup, sendTxs, waitNewPXESynced } from './utils.js'; +import { benchmarkSetup, createNewPXE, sendTxs } from './utils.js'; describe('benchmarks/publish_rollup', () => { let context: EndToEndContext; @@ -41,7 +41,7 @@ describe('benchmarks/publish_rollup', () => { // Spin up a new pxe and sync it, we'll use it to test sync times of new accounts for the last block context.logger.info(`Starting new pxe`); - const pxe = await waitNewPXESynced(node, contract, blockNumber! - 1); + const pxe = await createNewPXE(node, contract, blockNumber! - 1); // Register the owner account and wait until it's synced so we measure how much time it took context.logger.info(`Registering owner account on new pxe`); diff --git a/yarn-project/end-to-end/src/benchmarks/utils.ts b/yarn-project/end-to-end/src/benchmarks/utils.ts index 5dbebfa26ce..05c90892ae7 100644 --- a/yarn-project/end-to-end/src/benchmarks/utils.ts +++ b/yarn-project/end-to-end/src/benchmarks/utils.ts @@ -1,5 +1,5 @@ import { type AztecNodeConfig, type AztecNodeService } from '@aztec/aztec-node'; -import { type AztecNode, BatchCall, INITIAL_L2_BLOCK_NUM, type SentTx, retryUntil, sleep } from '@aztec/aztec.js'; +import { type AztecNode, BatchCall, INITIAL_L2_BLOCK_NUM, type SentTx, sleep } from '@aztec/aztec.js'; import { times } from '@aztec/foundation/collection'; import { randomInt } from '@aztec/foundation/crypto'; import { BenchmarkingContract } from '@aztec/noir-contracts.js/Benchmarking'; @@ -90,13 +90,13 @@ export async function sendTxs( } /** - * Creates a new PXE and awaits until it's synced with the node. + * Creates a new PXE * @param node - Node to connect the pxe to. * @param contract - Benchmark contract to add to the pxe. * @param startingBlock - First l2 block to process. * @returns The new PXE. */ -export async function waitNewPXESynced( +export async function createNewPXE( node: AztecNode, contract: BenchmarkingContract, startingBlock: number = INITIAL_L2_BLOCK_NUM, @@ -111,6 +111,5 @@ export async function waitNewPXESynced( } as PXEServiceConfig; const pxe = await createPXEService(node, pxeConfig); await pxe.registerContract(contract); - await retryUntil(() => pxe.isGlobalStateSynchronized(), 'pxe-global-sync'); return pxe; } diff --git a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts index 271d96b4b6a..76a9fb47a39 100644 --- a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts +++ b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts @@ -8,7 +8,6 @@ import { type Logger, type PXE, type Wallet, - retryUntil, sleep, } from '@aztec/aztec.js'; import { ChildContract, TestContract, TokenContract } from '@aztec/noir-contracts.js'; @@ -103,21 +102,12 @@ describe('e2e_2_pxes', () => { return contract.instance; }; - const awaitServerSynchronized = async (server: PXE) => { - const isServerSynchronized = async () => { - return await server.isGlobalStateSynchronized(); - }; - await retryUntil(isServerSynchronized, 'server sync', 10); - }; - const getChildStoredValue = (child: { address: AztecAddress }, pxe: PXE) => pxe.getPublicStorageAt(child.address, new Fr(1)); it('user calls a public function on a contract deployed by a different user using a different PXE', async () => { const childCompleteAddress = await deployChildContractViaServerA(); - await awaitServerSynchronized(pxeA); - // Add Child to PXE B await pxeB.registerContract({ artifact: ChildContract.artifact, @@ -129,8 +119,6 @@ describe('e2e_2_pxes', () => { const childContractWithWalletB = await ChildContract.at(childCompleteAddress.address, walletB); await childContractWithWalletB.methods.pub_inc_value(newValueToSet).send().wait({ interval: 0.1 }); - await awaitServerSynchronized(pxeA); - const storedValueOnB = await getChildStoredValue(childCompleteAddress, pxeB); expect(storedValueOnB).toEqual(newValueToSet); diff --git a/yarn-project/end-to-end/src/e2e_block_building.test.ts b/yarn-project/end-to-end/src/e2e_block_building.test.ts index 38ff8cce2e1..942e558d83e 100644 --- a/yarn-project/end-to-end/src/e2e_block_building.test.ts +++ b/yarn-project/end-to-end/src/e2e_block_building.test.ts @@ -483,14 +483,6 @@ describe('e2e_block_building', () => { // PXE should have cleared out the 30-note from tx2, but reapplied the 20-note from tx1 expect(await contract.methods.summed_values(ownerAddress).simulate()).toEqual(21n); - // PXE should be synced to the block number on the new chain - await retryUntil( - async () => (await pxe.getSyncStatus()).blocks === newTx1Receipt.blockNumber, - 'wait for pxe block header sync', - 15, - 1, - ); - // And we should be able to send a new tx on the new chain logger.info('Sending new tx on reorgd chain'); const tx3 = await contract.methods.create_note(ownerAddress, ownerAddress, 10).send().wait(); diff --git a/yarn-project/pxe/src/bin/index.ts b/yarn-project/pxe/src/bin/index.ts index 5ba7ce5aa0e..d2c4c6d5cf3 100644 --- a/yarn-project/pxe/src/bin/index.ts +++ b/yarn-project/pxe/src/bin/index.ts @@ -5,7 +5,7 @@ import { createLogger } from '@aztec/foundation/log'; import { getPXEServiceConfig } from '../config/index.js'; import { startPXEHttpServer } from '../pxe_http/index.js'; -import { createPXEService } from '../utils/index.js'; +import { createPXEService } from '../pxe_service/create_pxe_service.js'; const { PXE_PORT = 8080, AZTEC_NODE_URL = 'http://localhost:8079' } = process.env; diff --git a/yarn-project/pxe/src/database/kv_pxe_database.ts b/yarn-project/pxe/src/database/kv_pxe_database.ts index 866d2df92c7..5439afa717b 100644 --- a/yarn-project/pxe/src/database/kv_pxe_database.ts +++ b/yarn-project/pxe/src/database/kv_pxe_database.ts @@ -46,7 +46,6 @@ export class KVPxeDatabase implements PxeDatabase { #nullifiedNotesByTxHash: AztecAsyncMultiMap; #nullifiedNotesByAddressPoint: AztecAsyncMultiMap; #nullifiedNotesByNullifier: AztecAsyncMap; - #syncedBlockPerPublicKey: AztecAsyncMap; #contractArtifacts: AztecAsyncMap; #contractInstances: AztecAsyncMap; #db: AztecAsyncKVStore; @@ -79,7 +78,6 @@ export class KVPxeDatabase implements PxeDatabase { this.#contractInstances = db.openMap('contracts_instances'); this.#synchronizedBlock = db.openSingleton('header'); - this.#syncedBlockPerPublicKey = db.openMap('synced_block_per_public_key'); this.#notes = db.openMap('notes'); this.#nullifiedNotes = db.openMap('nullified_notes'); @@ -564,14 +562,6 @@ export class KVPxeDatabase implements PxeDatabase { return true; } - getSynchedBlockNumberForAccount(account: AztecAddress): Promise { - return this.#syncedBlockPerPublicKey.getAsync(account.toString()); - } - - setSynchedBlockNumberForAccount(account: AztecAddress, blockNumber: number): Promise { - return this.#syncedBlockPerPublicKey.set(account.toString(), blockNumber); - } - async estimateSize(): Promise { const incomingNotesSize = (await this.getIncomingNotes({})).reduce((sum, note) => sum + note.getSize(), 0); diff --git a/yarn-project/pxe/src/database/pxe_database.ts b/yarn-project/pxe/src/database/pxe_database.ts index 0b24e77b99a..4f2fd1557f2 100644 --- a/yarn-project/pxe/src/database/pxe_database.ts +++ b/yarn-project/pxe/src/database/pxe_database.ts @@ -160,19 +160,6 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD */ getCompleteAddresses(): Promise; - /** - * Updates up to which block number we have processed notes for a given public key. - * @param account - The account to set the synched block number for. - * @param blockNumber - The block number to set. - */ - setSynchedBlockNumberForAccount(account: AztecAddress, blockNumber: number): Promise; - - /** - * Get the synched block number for a given public key. - * @param account - The account to get the synched block number for. - */ - getSynchedBlockNumberForAccount(account: AztecAddress): Promise; - /** * Returns the estimated size in bytes of this db. * @returns The estimated size in bytes of this db. diff --git a/yarn-project/pxe/src/index.ts b/yarn-project/pxe/src/index.ts index ae998668621..d6e46f5ad84 100644 --- a/yarn-project/pxe/src/index.ts +++ b/yarn-project/pxe/src/index.ts @@ -10,6 +10,5 @@ export * from '@aztec/foundation/eth-address'; export * from '@aztec/foundation/aztec-address'; export * from '@aztec/key-store'; export * from './database/index.js'; -export * from './utils/index.js'; export { ContractDataOracle } from './contract_data_oracle/index.js'; export { PrivateFunctionsTree } from './contract_data_oracle/private_functions_tree.js'; diff --git a/yarn-project/pxe/src/pxe_service/create_pxe_service.ts b/yarn-project/pxe/src/pxe_service/create_pxe_service.ts index bd168463788..a8209e51504 100644 --- a/yarn-project/pxe/src/pxe_service/create_pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/create_pxe_service.ts @@ -47,9 +47,9 @@ export async function createPXEService( const tips = new L2TipsStore(store, 'pxe'); const prover = proofCreator ?? (await createProver(config, logSuffix)); - const server = new PXEService(keyStore, aztecNode, db, tips, prover, config, logSuffix); - await server.start(); - return server; + const pxe = new PXEService(keyStore, aztecNode, db, tips, prover, config, logSuffix); + await pxe.init(); + return pxe; } function createProver(config: PXEServiceConfig, logSuffix?: string) { diff --git a/yarn-project/pxe/src/pxe_service/index.ts b/yarn-project/pxe/src/pxe_service/index.ts index 66f9aae2add..c9018d7ba8c 100644 --- a/yarn-project/pxe/src/pxe_service/index.ts +++ b/yarn-project/pxe/src/pxe_service/index.ts @@ -1,3 +1,4 @@ export * from './pxe_service.js'; +export * from './create_pxe_service.js'; export { enrichPublicSimulationError } from './error_enriching.js'; export { pxeTestSuite } from './test/pxe_test_suite.js'; diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 9f80b18ae39..3eccde42ec5 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -105,7 +105,7 @@ export class PXEService implements PXE { this.log = createLogger(logSuffix ? `pxe:service:${logSuffix}` : `pxe:service`); this.synchronizer = new Synchronizer(node, db, tipsStore, config, logSuffix); this.contractDataOracle = new ContractDataOracle(db); - this.simulator = getAcirSimulator(db, node, keyStore, this.contractDataOracle); + this.simulator = getAcirSimulator(this.synchronizer, db, node, keyStore, this.contractDataOracle); this.packageVersion = getPackageInfo().version; this.jobQueue.start(); @@ -116,8 +116,7 @@ export class PXEService implements PXE { * * @returns A promise that resolves when the server has started successfully. */ - public async start() { - await this.synchronizer.start(); + public async init() { await this.#registerProtocolContracts(); const info = await this.getNodeInfo(); this.log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.protocolVersion}`); @@ -133,8 +132,6 @@ export class PXEService implements PXE { public async stop() { await this.jobQueue.cancel(); this.log.info('Cancelled Job Queue'); - await this.synchronizer.stop(); - this.log.info('Stopped Synchronizer'); } isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise { @@ -513,6 +510,7 @@ export class PXEService implements PXE { ): Promise { return await this.jobQueue .put(async () => { + await this.synchronizer.trigger(); const privateExecutionResult = await this.#executePrivate(txRequest, msgSender, scopes); let publicInputs: PrivateKernelTailCircuitPublicInputs; @@ -704,7 +702,7 @@ export class PXEService implements PXE { const { address, contractClass, instance, artifact } = getCanonicalProtocolContract(name); await this.db.addContractArtifact(contractClass.id, artifact); await this.db.addContractInstance(instance); - this.log.info(`Added protocol contract ${name} at ${address.toString()}`); + this.log.verbose(`Added protocol contract ${name} at ${address.toString()}`); } } @@ -821,11 +819,9 @@ export class PXEService implements PXE { } /** - * Simulate a transaction, generate a kernel proof, and create a private transaction object. - * The function takes in a transaction request, simulates it, and then generates a kernel proof - * using the simulation result. Finally, it creates a private - * transaction object with the generated proof and public inputs. If a new contract address is provided, - * the function will also include the new contract's public functions in the transaction object. + * Generate a kernel proof, and create a private kernel output. + * The function takes in a transaction execution request, and the result of private simulation + * and then generates a kernel proof. * * @param txExecutionRequest - The transaction request to be simulated and proved. * @param proofCreator - The proof creator to use for proving the execution. @@ -848,14 +844,6 @@ export class PXEService implements PXE { return await kernelProver.prove(txExecutionRequest.toTxRequest(), privateExecutionResult); } - public async isGlobalStateSynchronized() { - return await this.synchronizer.isGlobalStateSynchronized(); - } - - public getSyncStatus() { - return Promise.resolve(this.synchronizer.getSyncStatus()); - } - public async isContractClassPubliclyRegistered(id: Fr): Promise { return !!(await this.node.getContractClass(id)); } diff --git a/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts b/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts index c5fc6219e01..686c5b9f9a1 100644 --- a/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts +++ b/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts @@ -115,8 +115,5 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise) => expect(typeof nodeInfo.l1ChainId).toEqual('number'); expect(nodeInfo.l1ContractAddresses.rollupAddress.toString()).toMatch(/0x[a-fA-F0-9]+/); }); - - // Note: Not testing `isGlobalStateSynchronized`, `isAccountStateSynchronized` and `getSyncStatus` as these methods - // only call synchronizer. }); }; diff --git a/yarn-project/pxe/src/simulator/index.ts b/yarn-project/pxe/src/simulator/index.ts index 8f41547a15e..fe0f3458a07 100644 --- a/yarn-project/pxe/src/simulator/index.ts +++ b/yarn-project/pxe/src/simulator/index.ts @@ -5,17 +5,20 @@ import { AcirSimulator } from '@aztec/simulator/client'; import { ContractDataOracle } from '../contract_data_oracle/index.js'; import { type PxeDatabase } from '../database/pxe_database.js'; import { SimulatorOracle } from '../simulator_oracle/index.js'; +import { type Synchronizer } from '../synchronizer/synchronizer.js'; /** * Helper method to create an instance of the acir simulator. */ export function getAcirSimulator( + synchronizer: Synchronizer, db: PxeDatabase, aztecNode: AztecNode, keyStore: KeyStore, contractDataOracle?: ContractDataOracle, ) { const simulatorOracle = new SimulatorOracle( + synchronizer, contractDataOracle ?? new ContractDataOracle(db), db, keyStore, diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index 27b70628c2b..7d04dca8e13 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -13,7 +13,7 @@ import { getNonNullifiedL1ToL2MessageWitness, } from '@aztec/circuit-types'; import { - type AztecAddress, + AztecAddress, type BlockHeader, type CompleteAddress, type ContractInstance, @@ -38,12 +38,14 @@ import { type IncomingNoteDao } from '../database/incoming_note_dao.js'; import { type PxeDatabase } from '../database/index.js'; import { produceNoteDaos } from '../note_decryption_utils/produce_note_daos.js'; import { getAcirSimulator } from '../simulator/index.js'; +import { type Synchronizer } from '../synchronizer/synchronizer.js'; /** * A data oracle that provides information needed for simulating a transaction. */ export class SimulatorOracle implements DBOracle { constructor( + private synchronizer: Synchronizer, private contractDataOracle: ContractDataOracle, private db: PxeDatabase, private keyStore: KeyStore, @@ -231,7 +233,7 @@ export class SimulatorOracle implements DBOracle { * @returns A Promise that resolves to a BlockHeader object. */ getBlockHeader(): Promise { - return Promise.resolve(this.db.getBlockHeader()); + return this.db.getBlockHeader(); } /** @@ -570,7 +572,8 @@ export class SimulatorOracle implements DBOracle { // I don't like this at all, but we need a simulator to run `computeNoteHashAndOptionallyANullifier`. This generates // a chicken-and-egg problem due to this oracle requiring a simulator, which in turn requires this oracle. Furthermore, since jest doesn't allow // mocking ESM exports, we have to pollute the method even more by providing a simulator parameter so tests can inject a fake one. - simulator ?? getAcirSimulator(this.db, this.aztecNode, this.keyStore, this.contractDataOracle), + simulator ?? + getAcirSimulator(this.synchronizer, this.db, this.aztecNode, this.keyStore, this.contractDataOracle), this.db, incomingNotePayload ? recipient.toAddressPoint() : undefined, payload!, @@ -635,4 +638,18 @@ export class SimulatorOracle implements DBOracle { ); }); } + + /** + * Synchronizes the notes for a contract address, retrieving the logs from the node, + * decrypting them and storing them in the database. + * @param contractAddress - The contract address to synchronize notes for. + * @param scopes - The scopes allowed to synchronize. + */ + public async syncNotes(contractAddress: AztecAddress, scopes?: AztecAddress[]) { + await this.synchronizer.trigger(); + const taggedLogsByRecipient = await this.syncTaggedLogs(contractAddress, await this.getBlockNumber(), scopes); + for (const [recipient, taggedLogs] of taggedLogsByRecipient.entries()) { + await this.processTaggedLogs(taggedLogs, AztecAddress.fromString(recipient)); + } + } } diff --git a/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts b/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts index 363da40fdf6..e28571138bd 100644 --- a/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts +++ b/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts @@ -34,6 +34,7 @@ import { type IncomingNoteDao } from '../database/incoming_note_dao.js'; import { type PxeDatabase } from '../database/index.js'; import { KVPxeDatabase } from '../database/kv_pxe_database.js'; import { ContractDataOracle } from '../index.js'; +import { type Synchronizer } from '../synchronizer/synchronizer.js'; import { SimulatorOracle } from './index.js'; const TXS_PER_BLOCK = 4; @@ -112,6 +113,7 @@ function computeSiloedTagForIndex( describe('Simulator oracle', () => { let aztecNode: MockProxy; let database: PxeDatabase; + let synchronizer: Synchronizer; let contractDataOracle: ContractDataOracle; let simulatorOracle: SimulatorOracle; let keyStore: KeyStore; @@ -122,11 +124,12 @@ describe('Simulator oracle', () => { beforeEach(async () => { const db = openTmpStore(); aztecNode = mock(); + synchronizer = mock(); database = await KVPxeDatabase.create(db); contractDataOracle = new ContractDataOracle(database); jest.spyOn(contractDataOracle, 'getDebugContractName').mockImplementation(() => Promise.resolve('TestContract')); keyStore = new KeyStore(db); - simulatorOracle = new SimulatorOracle(contractDataOracle, database, keyStore, aztecNode); + simulatorOracle = new SimulatorOracle(synchronizer, contractDataOracle, database, keyStore, aztecNode); // Set up contract address contractAddress = AztecAddress.random(); // Set up recipient account diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.ts b/yarn-project/pxe/src/synchronizer/synchronizer.ts index fe1c607e7da..a89c90a2b71 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.ts @@ -15,8 +15,7 @@ import { type PxeDatabase } from '../database/index.js'; * The Synchronizer class manages the synchronization of note processors and interacts with the Aztec node * to obtain encrypted logs, blocks, and other necessary information for the accounts. * It provides methods to start or stop the synchronization process, add new accounts, retrieve account - * details, and fetch transactions by hash. The Synchronizer ensures that it maintains the note processors - * in sync with the blockchain while handling retries and errors gracefully. + * details, and fetch transactions by hash. */ export class Synchronizer implements L2BlockStreamEventHandler { private running = false; @@ -65,18 +64,8 @@ export class Synchronizer implements L2BlockStreamEventHandler { } } - /** - * Starts the synchronization process by fetching encrypted logs and blocks from a specified position. - * Continuously processes the fetched data for all note processors until stopped. If there is no data - * available, it retries after a specified interval. - * - * @param limit - The maximum number of encrypted, unencrypted logs and blocks to fetch in each iteration. - * @param retryInterval - The time interval (in ms) to wait before retrying if no data is available. - */ - public async start() { - if (this.running) { - return; - } + /** Triggers a single run. */ + public async trigger() { this.running = true; let currentHeader; @@ -90,54 +79,11 @@ export class Synchronizer implements L2BlockStreamEventHandler { // REFACTOR: We should know the header of the genesis block without having to request it from the node. await this.db.setHeader(await this.node.getBlockHeader(0)); } - - await this.trigger(); - this.log.info('Initial sync complete'); - this.blockStream.start(); - this.log.debug('Started loop'); - } - - /** - * Stops the synchronizer gracefully, interrupting any ongoing sleep and waiting for the current - * iteration to complete before setting the running state to false. Once stopped, the synchronizer - * will no longer process blocks or encrypted logs and must be restarted using the start method. - * - * @returns A promise that resolves when the synchronizer has successfully stopped. - */ - public async stop() { - this.running = false; - await this.blockStream.stop(); - this.log.info('Stopped'); - } - - /** Triggers a single run. */ - public async trigger() { await this.blockStream.sync(); + this.running = false; } - private async getSynchedBlockNumber() { + public async getSynchedBlockNumber() { return (await this.db.getBlockNumber()) ?? this.initialSyncBlockNumber; } - - /** - * Checks whether all the blocks were processed (tree roots updated, txs updated with block info, etc.). - * @returns True if there are no outstanding blocks to be synched. - * @remarks This indicates that blocks and transactions are synched even if notes are not. - * @remarks Compares local block number with the block number from aztec node. - */ - public async isGlobalStateSynchronized() { - const latest = await this.node.getBlockNumber(); - return latest <= (await this.getSynchedBlockNumber()); - } - - /** - * Returns the latest block that has been synchronized by the synchronizer and each account. - * @returns The latest block synchronized for blocks, and the latest block synched for notes for each public key being tracked. - */ - public async getSyncStatus() { - const lastBlockNumber = await this.getSynchedBlockNumber(); - return { - blocks: lastBlockNumber, - }; - } } diff --git a/yarn-project/pxe/src/utils/index.ts b/yarn-project/pxe/src/utils/index.ts deleted file mode 100644 index f971258aca0..00000000000 --- a/yarn-project/pxe/src/utils/index.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { BBNativePrivateKernelProver } from '@aztec/bb-prover'; -import { type AztecNode, type PrivateKernelProver } from '@aztec/circuit-types'; -import { randomBytes } from '@aztec/foundation/crypto'; -import { createLogger } from '@aztec/foundation/log'; -import { KeyStore } from '@aztec/key-store'; -import { createStore } from '@aztec/kv-store/lmdb'; -import { L2TipsStore } from '@aztec/kv-store/stores'; - -import { type PXEServiceConfig } from '../config/index.js'; -import { KVPxeDatabase } from '../database/kv_pxe_database.js'; -import { TestPrivateKernelProver } from '../kernel_prover/test/test_circuit_prover.js'; -import { PXEService } from '../pxe_service/pxe_service.js'; - -/** - * Create and start an PXEService instance with the given AztecNode. - * If no keyStore or database is provided, it will use KeyStore and MemoryDB as default values. - * Returns a Promise that resolves to the started PXEService instance. - * - * @param aztecNode - The AztecNode instance to be used by the server. - * @param config - The PXE Service Config to use - * @param options - (Optional) Optional information for creating an PXEService. - * @param proofCreator - An optional proof creator to use in place of any other configuration - * @returns A Promise that resolves to the started PXEService instance. - */ -export async function createPXEService( - aztecNode: AztecNode, - config: PXEServiceConfig, - useLogSuffix: string | boolean | undefined = undefined, - proofCreator?: PrivateKernelProver, -) { - const logSuffix = - typeof useLogSuffix === 'boolean' ? (useLogSuffix ? randomBytes(3).toString('hex') : undefined) : useLogSuffix; - - const l1Contracts = await aztecNode.getL1ContractAddresses(); - const configWithContracts = { - ...config, - l1Contracts, - } as PXEServiceConfig; - - const keyStore = new KeyStore( - await createStore('pxe_key_store', configWithContracts, createLogger('pxe:keystore:lmdb')), - ); - - const store = await createStore('pxe_data', configWithContracts, createLogger('pxe:data:lmdb')); - - const db = await KVPxeDatabase.create(store); - const tips = new L2TipsStore(store, 'pxe'); - - const prover = proofCreator ?? (await createProver(config, logSuffix)); - const server = new PXEService(keyStore, aztecNode, db, tips, prover, config, logSuffix); - await server.start(); - return server; -} - -function createProver(config: PXEServiceConfig, logSuffix?: string) { - if (!config.proverEnabled) { - return new TestPrivateKernelProver(); - } - - // (@PhilWindle) Temporary validation until WASM is implemented - if (!config.bbBinaryPath || !config.bbWorkingDirectory) { - throw new Error(`Prover must be configured with binary path and working directory`); - } - const bbConfig = config as Required> & PXEServiceConfig; - const log = createLogger('pxe:bb-native-prover' + (logSuffix ? `:${logSuffix}` : '')); - return BBNativePrivateKernelProver.new({ bbSkipCleanup: false, ...bbConfig }, log); -} diff --git a/yarn-project/simulator/src/client/db_oracle.ts b/yarn-project/simulator/src/client/db_oracle.ts index 6702810c86a..34a2b1317ed 100644 --- a/yarn-project/simulator/src/client/db_oracle.ts +++ b/yarn-project/simulator/src/client/db_oracle.ts @@ -242,4 +242,12 @@ export interface DBOracle extends CommitmentsDB { * @param recipient - The recipient of the logs. */ processTaggedLogs(logs: TxScopedL2Log[], recipient: AztecAddress): Promise; + + /** + * Synchronizes the notes for a contract address, retrieving the logs from the node, + * decrypting them and storing them in the database. + * @param contractAddress - The contract address to synchronize notes for. + * @param scopes - The scopes allowed to synchronize. + */ + syncNotes(contractAddress: AztecAddress, scopes?: AztecAddress[]): Promise; } diff --git a/yarn-project/simulator/src/client/view_data_oracle.ts b/yarn-project/simulator/src/client/view_data_oracle.ts index e138a3eef4f..2e14b9b12f9 100644 --- a/yarn-project/simulator/src/client/view_data_oracle.ts +++ b/yarn-project/simulator/src/client/view_data_oracle.ts @@ -14,7 +14,7 @@ import { type KeyValidationRequest, } from '@aztec/circuits.js'; import { siloNullifier } from '@aztec/circuits.js/hash'; -import { AztecAddress } from '@aztec/foundation/aztec-address'; +import { type AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; import { applyStringFormatting, createLogger } from '@aztec/foundation/log'; @@ -310,13 +310,6 @@ export class ViewDataOracle extends TypedOracle { } public override async syncNotes() { - const taggedLogsByRecipient = await this.db.syncTaggedLogs( - this.contractAddress, - await this.db.getBlockNumber(), - this.scopes, - ); - for (const [recipient, taggedLogs] of taggedLogsByRecipient.entries()) { - await this.db.processTaggedLogs(taggedLogs, AztecAddress.fromString(recipient)); - } + return await this.db.syncNotes(this.contractAddress, this.scopes); } }