From 74420bb0415940a772092ef1d9e8a9a6248e3a5a Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 9 Dec 2024 16:37:54 +0000 Subject: [PATCH 01/18] 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 d3dded0788d4..db08c3bc0332 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 043184ef30cb..5d8768902c70 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 02/18] 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 f623bcf3d5da..0afbd12ba20b 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 03/18] 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 0afbd12ba20b..320d3ef63472 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 04/18] 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 320d3ef63472..f69bb492fda1 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 67af9e77df39..bb69d8240c93 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 05/18] 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 0e34d8dcbf15..3300f21bba8c 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 06/18] 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 f69bb492fda1..f623bcf3d5da 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 07/18] 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 c2bf65adb6a3..c0f7daf8a57b 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 b7803975b160..fb2d0e875496 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 4c42ac375de9..c4a15950273f 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 35694b490f5d..e455ee4c0be9 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 aac668476240..03098a3095cf 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 3f05c960e1ba..2b880ad7550c 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 8530f731bd12..9bf3ca99f591 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 363511bad80c..62c99eb84baf 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 b85a13620d6b..000000000000 --- 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 d1584950ff19..f2951a9c8f6a 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 e6e1f8627259..dc8a7a4bb6a2 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 adc29c28d637..d0b9c33de3e5 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 21612ccbe85f..de9ecfd5797b 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 5dbebfa26ce4..05c90892ae7c 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 271d96b4b6ac..76a9fb47a39a 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 38ff8cce2e11..942e558d83e6 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 5ba7ce5aa0ea..d2c4c6d5cf3d 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 866d2df92c78..5439afa717b9 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 0b24e77b99a2..4f2fd1557f29 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 ae998668621e..d6e46f5ad840 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 bd168463788e..a8209e515041 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 66f9aae2adda..c9018d7ba8c8 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 9f80b18ae396..3eccde42ec58 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 c5fc6219e010..686c5b9f9a1a 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 8f41547a15e4..fe0f3458a07c 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 27b70628c2ba..7d04dca8e131 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 363da40fdf65..e28571138bd3 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 fe1c607e7daa..a89c90a2b712 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 f971258aca0f..000000000000 --- 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 6702810c86a3..34a2b1317ed5 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 e138a3eef4f0..2e14b9b12f99 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); } } From a120e995bf63629b8be48578f1a30a781d99dab4 Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 11 Dec 2024 12:57:54 +0000 Subject: [PATCH 08/18] improvements and comments --- spartan/aztec-network/templates/pxe.yaml | 2 +- yarn-project/end-to-end/src/e2e_2_pxes.test.ts | 1 - yarn-project/pxe/src/synchronizer/synchronizer.ts | 6 +++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/spartan/aztec-network/templates/pxe.yaml b/spartan/aztec-network/templates/pxe.yaml index d61df752190a..982fcdca872e 100644 --- a/spartan/aztec-network/templates/pxe.yaml +++ b/spartan/aztec-network/templates/pxe.yaml @@ -101,7 +101,7 @@ spec: - | curl -s -X POST -H 'content-type: application/json' \ -d '{"jsonrpc":"2.0","method":"pxe_isGlobalStateSynchronized","params":[],"id":67}' \ - 127.0.0.1:{{ .Values.pxe.service.nodePort }} | grep -q '"result":true' + 127.0.0.1:{{ .Values.pxe.service.nodePort }} | grep -q '"protocolVersion":1' initialDelaySeconds: {{ .Values.pxe.readinessProbe.initialDelaySeconds }} periodSeconds: {{ .Values.pxe.readinessProbe.periodSeconds }} timeoutSeconds: {{ .Values.pxe.readinessProbe.timeoutSeconds }} 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 76a9fb47a39a..eaa70fa10ff0 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 @@ -56,7 +56,6 @@ describe('e2e_2_pxes', () => { await teardownA(); }); - // TODO #10296 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; diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.ts b/yarn-project/pxe/src/synchronizer/synchronizer.ts index a89c90a2b712..b3bb416de321 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.ts @@ -12,9 +12,9 @@ import { type PXEConfig } from '../config/index.js'; 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 + * The Synchronizer class manages the synchronization with the aztec node, allowing PXE to retrieve the + * latest block header and handle reorgs. + * It provides methods to trigger a sync and get the block number we are syncec to * details, and fetch transactions by hash. */ export class Synchronizer implements L2BlockStreamEventHandler { From 5a2a6f7ee8815410d138c9d2e7e6de36873015cf Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 11 Dec 2024 14:24:04 +0000 Subject: [PATCH 09/18] don't sync on note sync --- yarn-project/aztec.js/src/contract/sent_tx.ts | 6 ------ .../pxe/src/pxe_service/pxe_service.ts | 3 ++- yarn-project/pxe/src/simulator/index.ts | 2 -- yarn-project/pxe/src/simulator_oracle/index.ts | 18 +----------------- .../simulator_oracle/simulator_oracle.test.ts | 4 +--- yarn-project/simulator/src/client/db_oracle.ts | 8 -------- .../simulator/src/client/view_data_oracle.ts | 11 +++++++++-- 7 files changed, 13 insertions(+), 39 deletions(-) diff --git a/yarn-project/aztec.js/src/contract/sent_tx.ts b/yarn-project/aztec.js/src/contract/sent_tx.ts index fb2d0e875496..99c4eec86500 100644 --- a/yarn-project/aztec.js/src/contract/sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/sent_tx.ts @@ -14,11 +14,6 @@ export type WaitOpts = { interval?: number; /** Whether to wait for the tx to be proven. */ proven?: boolean; - /** - * Whether to wait for the node to notify that the block in which this tx was mined is available to fetch notes from. - * If false, then any queries that depend on state set by this transaction may return stale data. Defaults to true. - **/ - waitForNotesAvailable?: boolean; /** Whether to include information useful for debugging/testing in the receipt. */ debug?: boolean; /** Whether to accept a revert as a status code for the tx when waiting for it. If false, will throw if the tx reverts. */ @@ -31,7 +26,6 @@ export const DefaultWaitOpts: WaitOpts = { provenTimeout: 600, interval: 1, debug: false, - waitForNotesAvailable: true, }; /** diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 3eccde42ec58..fe90e47908ca 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(this.synchronizer, db, node, keyStore, this.contractDataOracle); + this.simulator = getAcirSimulator(db, node, keyStore, this.contractDataOracle); this.packageVersion = getPackageInfo().version; this.jobQueue.start(); @@ -587,6 +587,7 @@ export class PXEService implements PXE { // all simulations must be serialized w.r.t. the synchronizer return await this.jobQueue .put(async () => { + await this.synchronizer.trigger(); // TODO - Should check if `from` has the permission to call the view function. const functionCall = await this.#getFunctionCall(functionName, args, to); const executionResult = await this.#simulateUnconstrained(functionCall, scopes); diff --git a/yarn-project/pxe/src/simulator/index.ts b/yarn-project/pxe/src/simulator/index.ts index fe0f3458a07c..cdb3ddf55ffb 100644 --- a/yarn-project/pxe/src/simulator/index.ts +++ b/yarn-project/pxe/src/simulator/index.ts @@ -11,14 +11,12 @@ 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 7d04dca8e131..bfb4db005d56 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -45,7 +45,6 @@ import { type Synchronizer } from '../synchronizer/synchronizer.js'; */ export class SimulatorOracle implements DBOracle { constructor( - private synchronizer: Synchronizer, private contractDataOracle: ContractDataOracle, private db: PxeDatabase, private keyStore: KeyStore, @@ -572,8 +571,7 @@ 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.synchronizer, this.db, this.aztecNode, this.keyStore, this.contractDataOracle), + simulator ?? getAcirSimulator(this.db, this.aztecNode, this.keyStore, this.contractDataOracle), this.db, incomingNotePayload ? recipient.toAddressPoint() : undefined, payload!, @@ -638,18 +636,4 @@ 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 e28571138bd3..978b2598bdf5 100644 --- a/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts +++ b/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts @@ -113,7 +113,6 @@ function computeSiloedTagForIndex( describe('Simulator oracle', () => { let aztecNode: MockProxy; let database: PxeDatabase; - let synchronizer: Synchronizer; let contractDataOracle: ContractDataOracle; let simulatorOracle: SimulatorOracle; let keyStore: KeyStore; @@ -124,12 +123,11 @@ 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(synchronizer, contractDataOracle, database, keyStore, aztecNode); + simulatorOracle = new SimulatorOracle(contractDataOracle, database, keyStore, aztecNode); // Set up contract address contractAddress = AztecAddress.random(); // Set up recipient account diff --git a/yarn-project/simulator/src/client/db_oracle.ts b/yarn-project/simulator/src/client/db_oracle.ts index 34a2b1317ed5..6702810c86a3 100644 --- a/yarn-project/simulator/src/client/db_oracle.ts +++ b/yarn-project/simulator/src/client/db_oracle.ts @@ -242,12 +242,4 @@ 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 2e14b9b12f99..de71ba38b813 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 { type AztecAddress } from '@aztec/foundation/aztec-address'; +import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; import { applyStringFormatting, createLogger } from '@aztec/foundation/log'; @@ -310,6 +310,13 @@ export class ViewDataOracle extends TypedOracle { } public override async syncNotes() { - return await this.db.syncNotes(this.contractAddress, this.scopes); + const taggedLogsByRecipient = await this.db.syncTaggedLogs( + this.contractAddress, + await this.aztecNode.getBlockNumber(), + this.scopes, + ); + for (const [recipient, taggedLogs] of taggedLogsByRecipient.entries()) { + await this.db.processTaggedLogs(taggedLogs, AztecAddress.fromString(recipient)); + } } } From 13ff2a62048923253ef4c3b007a93406d6175bd7 Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 11 Dec 2024 15:50:29 +0000 Subject: [PATCH 10/18] fmt --- yarn-project/pxe/src/simulator/index.ts | 1 - yarn-project/pxe/src/simulator_oracle/index.ts | 3 +-- yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/yarn-project/pxe/src/simulator/index.ts b/yarn-project/pxe/src/simulator/index.ts index cdb3ddf55ffb..8f41547a15e4 100644 --- a/yarn-project/pxe/src/simulator/index.ts +++ b/yarn-project/pxe/src/simulator/index.ts @@ -5,7 +5,6 @@ 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. diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index bfb4db005d56..beef6c7d4688 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 { - AztecAddress, + type AztecAddress, type BlockHeader, type CompleteAddress, type ContractInstance, @@ -38,7 +38,6 @@ 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. 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 978b2598bdf5..363da40fdf65 100644 --- a/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts +++ b/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts @@ -34,7 +34,6 @@ 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; From 2f9a2eeb23c98595ed8723052aea53e4b97e1235 Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 11 Dec 2024 17:39:59 +0000 Subject: [PATCH 11/18] fix --- yarn-project/pxe/src/bin/index.ts | 2 +- yarn-project/pxe/src/index.ts | 1 + yarn-project/pxe/src/pxe_service/index.ts | 1 - yarn-project/pxe/src/pxe_service/pxe_service.ts | 9 +++------ yarn-project/pxe/src/synchronizer/synchronizer.ts | 5 ++++- .../pxe/src/{pxe_service => utils}/create_pxe_service.ts | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) rename yarn-project/pxe/src/{pxe_service => utils}/create_pxe_service.ts (97%) diff --git a/yarn-project/pxe/src/bin/index.ts b/yarn-project/pxe/src/bin/index.ts index d2c4c6d5cf3d..d8b42d5ff72a 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 '../pxe_service/create_pxe_service.js'; +import { createPXEService } from '../utils/create_pxe_service.js'; const { PXE_PORT = 8080, AZTEC_NODE_URL = 'http://localhost:8079' } = process.env; diff --git a/yarn-project/pxe/src/index.ts b/yarn-project/pxe/src/index.ts index d6e46f5ad840..9c36ad7384e6 100644 --- a/yarn-project/pxe/src/index.ts +++ b/yarn-project/pxe/src/index.ts @@ -1,6 +1,7 @@ export * from './pxe_service/index.js'; export * from './pxe_http/index.js'; export * from './config/index.js'; +export * from './utils/create_pxe_service.js'; export { Tx, TxHash } from '@aztec/circuit-types'; diff --git a/yarn-project/pxe/src/pxe_service/index.ts b/yarn-project/pxe/src/pxe_service/index.ts index c9018d7ba8c8..66f9aae2adda 100644 --- a/yarn-project/pxe/src/pxe_service/index.ts +++ b/yarn-project/pxe/src/pxe_service/index.ts @@ -1,4 +1,3 @@ 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 fe90e47908ca..429360ef19d3 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -821,16 +821,13 @@ export class PXEService implements PXE { /** * Generate a kernel proof, and create a private kernel output. - * The function takes in a transaction execution request, and the result of private simulation + * The function takes in a transaction execution request, and the result of private execution * 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. - * @param msgSender - (Optional) The message sender to use for the simulation. - * @param scopes - The accounts whose notes we can access in this call. Currently optional and will default to all. - * @returns An object that contains: - * A private transaction object containing the proof, public inputs, and encrypted logs. - * The return values of the private execution + * @param privateExecutionResult - The result of the private execution + * @returns An object that contains the output of the kernel execution, including the ClientIvcProof if proving is enabled. */ async #prove( txExecutionRequest: TxExecutionRequest, diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.ts b/yarn-project/pxe/src/synchronizer/synchronizer.ts index b3bb416de321..1e0f05af6c25 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.ts @@ -64,7 +64,10 @@ export class Synchronizer implements L2BlockStreamEventHandler { } } - /** Triggers a single run. */ + /** + * Syncs PXE and the node by dowloading the metadata of the latest blocks, allowing simulations to use + * recent data (e.g. notes), and handling any reorgs that might have occurred. + */ public async trigger() { this.running = true; diff --git a/yarn-project/pxe/src/pxe_service/create_pxe_service.ts b/yarn-project/pxe/src/utils/create_pxe_service.ts similarity index 97% rename from yarn-project/pxe/src/pxe_service/create_pxe_service.ts rename to yarn-project/pxe/src/utils/create_pxe_service.ts index a8209e515041..773c7fa08aac 100644 --- a/yarn-project/pxe/src/pxe_service/create_pxe_service.ts +++ b/yarn-project/pxe/src/utils/create_pxe_service.ts @@ -9,7 +9,7 @@ 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.js'; +import { PXEService } from '../pxe_service/pxe_service.js'; /** * Create and start an PXEService instance with the given AztecNode. From 278c6fe5efa7a08776b2f8fa5d2110ae97043f7c Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 11 Dec 2024 20:14:52 +0000 Subject: [PATCH 12/18] ffs --- spartan/aztec-network/templates/pxe.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spartan/aztec-network/templates/pxe.yaml b/spartan/aztec-network/templates/pxe.yaml index 01bccc233daf..09bd358625b5 100644 --- a/spartan/aztec-network/templates/pxe.yaml +++ b/spartan/aztec-network/templates/pxe.yaml @@ -100,7 +100,7 @@ spec: - -c - | curl -s -X POST -H 'content-type: application/json' \ - -d '{"jsonrpc":"2.0","method":"pxe_isGlobalStateSynchronized","params":[],"id":67}' \ + -d '{"jsonrpc":"2.0","method":"pxe_getNodeInfo","params":[],"id":67}' \ 127.0.0.1:{{ .Values.pxe.service.nodePort }} | grep -q '"protocolVersion":1' initialDelaySeconds: {{ .Values.pxe.readinessProbe.initialDelaySeconds }} periodSeconds: {{ .Values.pxe.readinessProbe.periodSeconds }} From 725759e2a0f2fde802b7e48674b0322c152208ca Mon Sep 17 00:00:00 2001 From: thunkar Date: Thu, 12 Dec 2024 07:46:58 +0000 Subject: [PATCH 13/18] removed jobqueue, stop, etc --- aztec-up/bin/docker-compose.sandbox.yml | 1 - boxes/boxes/vite/src/config.ts | 25 ++- boxes/docker-compose.yml | 1 - .../sandbox_reference/sandbox-reference.md | 2 - yarn-project/aztec/docker-compose.yml | 1 - yarn-project/aztec/src/cli/cmds/start_pxe.ts | 3 - yarn-project/aztec/src/sandbox.ts | 1 - yarn-project/cli-wallet/src/bin/index.ts | 5 - .../scripts/docker-compose-no-sandbox.yml | 1 - .../scripts/docker-compose-wallet.yml | 1 - .../end-to-end/scripts/docker-compose.yml | 1 - .../benchmarks/bench_process_history.test.ts | 3 +- .../src/benchmarks/bench_prover.test.ts | 3 - .../benchmarks/bench_publish_rollup.test.ts | 3 +- .../src/fixtures/snapshot_manager.ts | 1 - yarn-project/end-to-end/src/fixtures/utils.ts | 7 +- yarn-project/foundation/src/config/env_var.ts | 1 - yarn-project/pxe/src/bin/index.ts | 1 - yarn-project/pxe/src/config/index.ts | 7 - .../pxe/src/pxe_service/pxe_service.ts | 206 ++++++++---------- .../src/pxe_service/test/pxe_service.test.ts | 2 - .../pxe/src/synchronizer/synchronizer.ts | 9 +- 22 files changed, 112 insertions(+), 173 deletions(-) diff --git a/aztec-up/bin/docker-compose.sandbox.yml b/aztec-up/bin/docker-compose.sandbox.yml index 186ba3dec698..999aa5676850 100644 --- a/aztec-up/bin/docker-compose.sandbox.yml +++ b/aztec-up/bin/docker-compose.sandbox.yml @@ -28,7 +28,6 @@ services: P2P_BLOCK_CHECK_INTERVAL_MS: 50 SEQ_TX_POLLING_INTERVAL_MS: 50 WS_BLOCK_CHECK_INTERVAL_MS: 50 - PXE_BLOCK_POLLING_INTERVAL_MS: 50 ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 PXE_PORT: ${PXE_PORT:-8080} PORT: ${AZTEC_NODE_PORT:-8080} diff --git a/boxes/boxes/vite/src/config.ts b/boxes/boxes/vite/src/config.ts index e17120a3fc55..bced26cc0942 100644 --- a/boxes/boxes/vite/src/config.ts +++ b/boxes/boxes/vite/src/config.ts @@ -24,7 +24,10 @@ export class PrivateEnv { accountContract; account: AccountManager; - constructor(private secretKey: Fr, private nodeURL: string) {} + constructor( + private secretKey: Fr, + private nodeURL: string, + ) {} async init() { const config = getPXEServiceConfig(); @@ -33,20 +36,20 @@ export class PrivateEnv { const proofCreator = new TestPrivateKernelProver(); this.pxe = await this.createPXEService(aztecNode, config, proofCreator); const encryptionPrivateKey = deriveMasterIncomingViewingSecretKey( - this.secretKey + this.secretKey, ); this.accountContract = new SingleKeyAccountContract(encryptionPrivateKey); this.account = new AccountManager( this.pxe, this.secretKey, - this.accountContract + this.accountContract, ); } async createPXEService( aztecNode: AztecNode, config: PXEServiceConfig, - proofCreator?: PrivateKernelProver + proofCreator?: PrivateKernelProver, ) { const l1Contracts = await aztecNode.getL1ContractAddresses(); const configWithContracts = { @@ -57,7 +60,7 @@ export class PrivateEnv { const store = await createStore( "pxe_data", configWithContracts, - createLogger("pxe:data:indexeddb") + createLogger("pxe:data:indexeddb"), ); const keyStore = new KeyStore(store); @@ -65,16 +68,16 @@ export class PrivateEnv { const db = await KVPxeDatabase.create(store); const tips = new L2TipsStore(store, "pxe"); - const server = new PXEService( + const pxe = new PXEService( keyStore, aztecNode, db, tips, proofCreator, - config + config, ); - await server.start(); - return server; + await pxe.init(); + return pxe; } async getWallet() { @@ -85,7 +88,7 @@ export class PrivateEnv { export const deployerEnv = new PrivateEnv( SECRET_KEY, - process.env.PXE_URL || "http://localhost:8080" + process.env.PXE_URL || "http://localhost:8080", ); const IGNORE_FUNCTIONS = [ @@ -94,5 +97,5 @@ const IGNORE_FUNCTIONS = [ "sync_notes", ]; export const filteredInterface = BoxReactContractArtifact.functions.filter( - (f) => !IGNORE_FUNCTIONS.includes(f.name) + (f) => !IGNORE_FUNCTIONS.includes(f.name), ); diff --git a/boxes/docker-compose.yml b/boxes/docker-compose.yml index b06cca7ebc8c..a19c72fbc17a 100644 --- a/boxes/docker-compose.yml +++ b/boxes/docker-compose.yml @@ -17,7 +17,6 @@ services: P2P_BLOCK_CHECK_INTERVAL_MS: 50 SEQ_TX_POLLING_INTERVAL_MS: 50 WS_BLOCK_CHECK_INTERVAL_MS: 50 - PXE_BLOCK_POLLING_INTERVAL_MS: 50 ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 depends_on: - ethereum diff --git a/docs/docs/reference/developer_references/sandbox_reference/sandbox-reference.md b/docs/docs/reference/developer_references/sandbox_reference/sandbox-reference.md index ce0f32341b58..d00ef025751b 100644 --- a/docs/docs/reference/developer_references/sandbox_reference/sandbox-reference.md +++ b/docs/docs/reference/developer_references/sandbox_reference/sandbox-reference.md @@ -37,7 +37,6 @@ ARCHIVER_POLLING_INTERVAL_MS=50 P2P_BLOCK_CHECK_INTERVAL_MS=50 SEQ_TX_POLLING_INTERVAL_MS=50 WS_BLOCK_CHECK_INTERVAL_MS=50 -PXE_BLOCK_POLLING_INTERVAL_MS=50 ARCHIVER_VIEM_POLLING_INTERVAL_MS=500 ``` @@ -90,7 +89,6 @@ Variables like `TEST_ACCOUNTS` & `PXE_PORT` are valid here as described above. AZTEC_NODE_URL='http://localhost:8079' # The address of an Aztec Node URL that the PXE will connect to (default: http://localhost:8079) PXE_PORT=8080 # The port that the PXE will be listening to (default: 8080) TEST_ACCOUNTS='true' # Option to deploy 3 test account when sandbox starts. (default: true) -PXE_BLOCK_POLLING_INTERVAL_MS=50 # Interval to check for new L2 blocks. (default: 50) PXE_L2_STARTING_BLOCK=1 # L2 Block to start synching the PXE from (default: 1) ``` diff --git a/yarn-project/aztec/docker-compose.yml b/yarn-project/aztec/docker-compose.yml index 3fe35cd42f82..7d158f93f30e 100644 --- a/yarn-project/aztec/docker-compose.yml +++ b/yarn-project/aztec/docker-compose.yml @@ -29,7 +29,6 @@ services: P2P_BLOCK_CHECK_INTERVAL_MS: 50 SEQ_TX_POLLING_INTERVAL_MS: 50 WS_BLOCK_CHECK_INTERVAL_MS: 50 - PXE_BLOCK_POLLING_INTERVAL_MS: 50 ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 volumes: - ./log:/usr/src/yarn-project/aztec/log:rw diff --git a/yarn-project/aztec/src/cli/cmds/start_pxe.ts b/yarn-project/aztec/src/cli/cmds/start_pxe.ts index f1d8681982c5..55bea808d2d1 100644 --- a/yarn-project/aztec/src/cli/cmds/start_pxe.ts +++ b/yarn-project/aztec/src/cli/cmds/start_pxe.ts @@ -117,8 +117,5 @@ export async function addPXE( // Add PXE to services list services.pxe = [pxe, PXESchema]; - // Add PXE stop function to signal handlers - signalHandlers.push(pxe.stop); - return pxe; } diff --git a/yarn-project/aztec/src/sandbox.ts b/yarn-project/aztec/src/sandbox.ts index 0545db16714c..d720894da3a4 100644 --- a/yarn-project/aztec/src/sandbox.ts +++ b/yarn-project/aztec/src/sandbox.ts @@ -157,7 +157,6 @@ export async function createSandbox(config: Partial = {}) { } const stop = async () => { - await pxe.stop(); await node.stop(); await watcher?.stop(); }; diff --git a/yarn-project/cli-wallet/src/bin/index.ts b/yarn-project/cli-wallet/src/bin/index.ts index bcdbb4d50a1b..df08765c1005 100644 --- a/yarn-project/cli-wallet/src/bin/index.ts +++ b/yarn-project/cli-wallet/src/bin/index.ts @@ -94,11 +94,6 @@ async function main() { await pxeWrapper.init(nodeUrl, join(dataDir, 'pxe')); } db.init(AztecLmdbStore.open(dataDir)); - }) - .hook('postAction', async () => { - if (pxeWrapper.getPXE()) { - await (pxeWrapper.getPXE() as PXEService).stop(); - } }); injectCommands(program, userLog, debugLogger, db, pxeWrapper); diff --git a/yarn-project/end-to-end/scripts/docker-compose-no-sandbox.yml b/yarn-project/end-to-end/scripts/docker-compose-no-sandbox.yml index 2fbbabb4d6dd..b219e4d01de7 100644 --- a/yarn-project/end-to-end/scripts/docker-compose-no-sandbox.yml +++ b/yarn-project/end-to-end/scripts/docker-compose-no-sandbox.yml @@ -18,7 +18,6 @@ services: P2P_BLOCK_CHECK_INTERVAL_MS: 50 SEQ_TX_POLLING_INTERVAL_MS: 50 WS_BLOCK_CHECK_INTERVAL_MS: 50 - PXE_BLOCK_POLLING_INTERVAL_MS: 50 ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 ENABLE_GAS: ${ENABLE_GAS:-''} JOB_NAME: ${JOB_NAME:-''} diff --git a/yarn-project/end-to-end/scripts/docker-compose-wallet.yml b/yarn-project/end-to-end/scripts/docker-compose-wallet.yml index b1a421ed5752..d7e4541e7fb6 100644 --- a/yarn-project/end-to-end/scripts/docker-compose-wallet.yml +++ b/yarn-project/end-to-end/scripts/docker-compose-wallet.yml @@ -18,7 +18,6 @@ services: P2P_BLOCK_CHECK_INTERVAL_MS: 50 SEQ_TX_POLLING_INTERVAL_MS: 50 WS_BLOCK_CHECK_INTERVAL_MS: 50 - PXE_BLOCK_POLLING_INTERVAL_MS: 50 ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 ENABLE_GAS: ${ENABLE_GAS:-} HARDWARE_CONCURRENCY: ${HARDWARE_CONCURRENCY:-} diff --git a/yarn-project/end-to-end/scripts/docker-compose.yml b/yarn-project/end-to-end/scripts/docker-compose.yml index 4a96de1088dc..eae41741bb50 100644 --- a/yarn-project/end-to-end/scripts/docker-compose.yml +++ b/yarn-project/end-to-end/scripts/docker-compose.yml @@ -18,7 +18,6 @@ services: P2P_BLOCK_CHECK_INTERVAL_MS: 50 SEQ_TX_POLLING_INTERVAL_MS: 50 WS_BLOCK_CHECK_INTERVAL_MS: 50 - PXE_BLOCK_POLLING_INTERVAL_MS: 50 ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 ENABLE_GAS: ${ENABLE_GAS:-} HARDWARE_CONCURRENCY: ${HARDWARE_CONCURRENCY:-} 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 d0b9c33de3e5..167548937a75 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 @@ -81,8 +81,7 @@ describe('benchmarks/process_history', () => { context.logger.info(`Registering fresh account on new pxe`); await pxe.registerAccount(Fr.random(), Fr.random()); - // Stop the external node and pxe - await pxe.stop(); + // Stop the external node await node.stop(); lastBlock = chainLength; diff --git a/yarn-project/end-to-end/src/benchmarks/bench_prover.test.ts b/yarn-project/end-to-end/src/benchmarks/bench_prover.test.ts index d77451f317f2..49a09404359c 100644 --- a/yarn-project/end-to-end/src/benchmarks/bench_prover.test.ts +++ b/yarn-project/end-to-end/src/benchmarks/bench_prover.test.ts @@ -177,9 +177,6 @@ describe('benchmarks/proving', () => { }); afterAll(async () => { - for (const pxe of provingPxes) { - await pxe.stop(); - } await ctx.teardown(); await acvmCleanup(); await bbCleanup(); 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 de9ecfd5797b..97d7fb4b17b7 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 @@ -53,8 +53,7 @@ describe('benchmarks/publish_rollup', () => { context.logger.info(`Registering fresh account on new pxe`); await pxe.registerAccount(Fr.random(), Fr.random()); - // Stop the external node and pxe - await pxe.stop(); + // Stop the external node await node.stop(); }, 20 * 60_000, diff --git a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts index 7a0507a6e630..6743a7ef2c4e 100644 --- a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts +++ b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts @@ -247,7 +247,6 @@ async function teardown(context: SubsystemsContext | undefined) { getLogger().info('Tearing down subsystems'); await context.proverNode?.stop(); await context.aztecNode.stop(); - await context.pxe.stop(); await context.acvmConfig?.cleanup(); await context.anvil.stop(); await context.watcher.stop(); diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index 8c71ccb4d9ab..c343015cda2d 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -146,9 +146,7 @@ export async function setupPXEService( const pxeServiceConfig = { ...getPXEServiceConfig(), ...opts }; const pxe = await createPXEService(aztecNode, pxeServiceConfig, useLogSuffix, proofCreator); - const teardown = async () => { - await pxe.stop(); - }; + const teardown = async () => {}; return { pxe, @@ -445,9 +443,6 @@ export async function setup( if (aztecNode instanceof AztecNodeService) { await aztecNode?.stop(); } - if (pxe instanceof PXEService) { - await pxe?.stop(); - } if (acvmConfig?.cleanup) { // remove the temp directory created for the acvm diff --git a/yarn-project/foundation/src/config/env_var.ts b/yarn-project/foundation/src/config/env_var.ts index cb43781825f4..ea13f2f97118 100644 --- a/yarn-project/foundation/src/config/env_var.ts +++ b/yarn-project/foundation/src/config/env_var.ts @@ -126,7 +126,6 @@ export type EnvVar = | 'PROVER_REQUIRED_CONFIRMATIONS' | 'PROVER_TEST_DELAY_MS' | 'PROVER_CACHE_DIR' - | 'PXE_BLOCK_POLLING_INTERVAL_MS' | 'PXE_L2_STARTING_BLOCK' | 'PXE_PROVER_ENABLED' | 'QUOTE_PROVIDER_BASIS_POINT_FEE' diff --git a/yarn-project/pxe/src/bin/index.ts b/yarn-project/pxe/src/bin/index.ts index d8b42d5ff72a..60a3d2da4cc4 100644 --- a/yarn-project/pxe/src/bin/index.ts +++ b/yarn-project/pxe/src/bin/index.ts @@ -25,7 +25,6 @@ async function main() { const shutdown = async () => { logger.info('Shutting down...'); - await pxeService.stop(); process.exit(0); }; diff --git a/yarn-project/pxe/src/config/index.ts b/yarn-project/pxe/src/config/index.ts index 4841f7ce6fd5..7eeb270453fa 100644 --- a/yarn-project/pxe/src/config/index.ts +++ b/yarn-project/pxe/src/config/index.ts @@ -28,8 +28,6 @@ export interface KernelProverConfig { * Configuration settings for the PXE. */ export interface PXEConfig { - /** The interval to wait between polling for new blocks. */ - l2BlockPollingIntervalMS: number; /** L2 block to start scanning from for new accounts */ l2StartingBlock: number; } @@ -47,11 +45,6 @@ export type CliPXEOptions = { export const pxeConfigMappings: ConfigMappingsType = { ...dataConfigMappings, - l2BlockPollingIntervalMS: { - env: 'PXE_BLOCK_POLLING_INTERVAL_MS', - description: 'The interval to wait between polling for new blocks.', - ...numberConfigHelper(1_000), - }, l2StartingBlock: { env: 'PXE_L2_STARTING_BLOCK', ...numberConfigHelper(INITIAL_L2_BLOCK_NUM), diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index c04785cfd335..c69cc9453256 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -89,9 +89,6 @@ export class PXEService implements PXE { private simulator: AcirSimulator; private log: Logger; private packageVersion: string; - // serialize synchronizer and calls to proveTx. - // ensures that state is not changed while simulating - private jobQueue = new SerialQueue(); constructor( private keyStore: KeyStore, @@ -107,8 +104,6 @@ export class PXEService implements PXE { this.contractDataOracle = new ContractDataOracle(db); this.simulator = getAcirSimulator(db, node, keyStore, this.contractDataOracle); this.packageVersion = getPackageInfo().version; - - this.jobQueue.start(); } /** @@ -122,18 +117,6 @@ export class PXEService implements PXE { this.log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.protocolVersion}`); } - /** - * Stops the PXE Service, halting processing of new transactions and shutting down the synchronizer. - * This function ensures that all ongoing tasks are completed before stopping the server. - * It is useful for gracefully shutting down the server during maintenance or restarts. - * - * @returns A Promise resolving once the server has been stopped successfully. - */ - public async stop() { - await this.jobQueue.cancel(); - this.log.info('Cancelled Job Queue'); - } - isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise { return this.node.isL1ToL2MessageSynced(l1ToL2Message); } @@ -481,22 +464,16 @@ export class PXEService implements PXE { return result.publicInputs; } - public proveTx( + public async proveTx( txRequest: TxExecutionRequest, privateExecutionResult: PrivateExecutionResult, ): Promise { - return this.jobQueue - .put(async () => { - const { publicInputs, clientIvcProof } = await this.#prove( - txRequest, - this.proofCreator, - privateExecutionResult, - ); - return new TxProvingResult(privateExecutionResult, publicInputs, clientIvcProof!); - }) - .catch(err => { - throw this.contextualizeError(err, inspect(txRequest), inspect(privateExecutionResult)); - }); + try { + const { publicInputs, clientIvcProof } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult); + return new TxProvingResult(privateExecutionResult, publicInputs, clientIvcProof!); + } catch (err: any) { + throw this.contextualizeError(err, inspect(txRequest), inspect(privateExecutionResult)); + } } // TODO(#7456) Prevent msgSender being defined here for the first call @@ -508,79 +485,77 @@ export class PXEService implements PXE { profile: boolean = false, scopes?: AztecAddress[], ): Promise { - return await this.jobQueue - .put(async () => { - const txInfo = { - origin: txRequest.origin, - functionSelector: txRequest.functionSelector, - simulatePublic, - msgSender, - chainId: txRequest.txContext.chainId, - version: txRequest.txContext.version, - authWitnesses: txRequest.authWitnesses.map(w => w.requestHash), - }; - this.log.verbose( - `Simulating transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`, - txInfo, - ); - await this.synchronizer.trigger(); - const privateExecutionResult = await this.#executePrivate(txRequest, msgSender, scopes); - - let publicInputs: PrivateKernelTailCircuitPublicInputs; - let profileResult; - if (profile) { - ({ publicInputs, profileResult } = await this.#profileKernelProver( - txRequest, - this.proofCreator, - privateExecutionResult, - )); - } else { - publicInputs = await this.#simulateKernels(txRequest, privateExecutionResult); - } + try { + const txInfo = { + origin: txRequest.origin, + functionSelector: txRequest.functionSelector, + simulatePublic, + msgSender, + chainId: txRequest.txContext.chainId, + version: txRequest.txContext.version, + authWitnesses: txRequest.authWitnesses.map(w => w.requestHash), + }; + this.log.verbose( + `Simulating transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`, + txInfo, + ); + await this.synchronizer.trigger(); + const privateExecutionResult = await this.#executePrivate(txRequest, msgSender, scopes); - const privateSimulationResult = new PrivateSimulationResult(privateExecutionResult, publicInputs); - const simulatedTx = privateSimulationResult.toSimulatedTx(); - let publicOutput: PublicSimulationOutput | undefined; - if (simulatePublic) { - publicOutput = await this.#simulatePublicCalls(simulatedTx); - } + let publicInputs: PrivateKernelTailCircuitPublicInputs; + let profileResult; + if (profile) { + ({ publicInputs, profileResult } = await this.#profileKernelProver( + txRequest, + this.proofCreator, + privateExecutionResult, + )); + } else { + publicInputs = await this.#simulateKernels(txRequest, privateExecutionResult); + } - if (!skipTxValidation) { - if (!(await this.node.isValidTx(simulatedTx, true))) { - throw new Error('The simulated transaction is unable to be added to state and is invalid.'); - } + const privateSimulationResult = new PrivateSimulationResult(privateExecutionResult, publicInputs); + const simulatedTx = privateSimulationResult.toSimulatedTx(); + let publicOutput: PublicSimulationOutput | undefined; + if (simulatePublic) { + publicOutput = await this.#simulatePublicCalls(simulatedTx); + } + + if (!skipTxValidation) { + if (!(await this.node.isValidTx(simulatedTx, true))) { + throw new Error('The simulated transaction is unable to be added to state and is invalid.'); } + } - this.log.info(`Simulation completed for ${simulatedTx.tryGetTxHash()}`, { - txHash: simulatedTx.tryGetTxHash(), - ...txInfo, - ...(profileResult ? { gateCounts: profileResult.gateCounts } : {}), - ...(publicOutput - ? { - gasUsed: publicOutput.gasUsed, - revertCode: publicOutput.txEffect.revertCode.getCode(), - revertReason: publicOutput.revertReason, - } - : {}), - }); - - return TxSimulationResult.fromPrivateSimulationResultAndPublicOutput( - privateSimulationResult, - publicOutput, - profileResult, - ); - }) - .catch(err => { - throw this.contextualizeError( - err, - inspect(txRequest), - `simulatePublic=${simulatePublic}`, - `msgSender=${msgSender?.toString() ?? 'undefined'}`, - `skipTxValidation=${skipTxValidation}`, - `profile=${profile}`, - `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`, - ); + this.log.info(`Simulation completed for ${simulatedTx.tryGetTxHash()}`, { + txHash: simulatedTx.tryGetTxHash(), + ...txInfo, + ...(profileResult ? { gateCounts: profileResult.gateCounts } : {}), + ...(publicOutput + ? { + gasUsed: publicOutput.gasUsed, + revertCode: publicOutput.txEffect.revertCode.getCode(), + revertReason: publicOutput.revertReason, + } + : {}), }); + + return TxSimulationResult.fromPrivateSimulationResultAndPublicOutput( + privateSimulationResult, + publicOutput, + profileResult, + ); + } catch (err: any) { + throw this.contextualizeError( + err, + inspect(txRequest), + `simulatePublic=${simulatePublic}`, + `msgSender=${msgSender?.toString() ?? 'undefined'}`, + `skipTxValidation=${skipTxValidation}`, + `profile=${profile}`, + `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`, + ); + } } public async sendTx(tx: Tx): Promise { @@ -603,25 +578,22 @@ export class PXEService implements PXE { _from?: AztecAddress, scopes?: AztecAddress[], ): Promise { - // all simulations must be serialized w.r.t. the synchronizer - return await this.jobQueue - .put(async () => { - await this.synchronizer.trigger(); - // TODO - Should check if `from` has the permission to call the view function. - const functionCall = await this.#getFunctionCall(functionName, args, to); - const executionResult = await this.#simulateUnconstrained(functionCall, scopes); - - // TODO - Return typed result based on the function artifact. - return executionResult; - }) - .catch(err => { - const stringifiedArgs = args.map(arg => arg.toString()).join(', '); - throw this.contextualizeError( - err, - `simulateUnconstrained ${to}:${functionName}(${stringifiedArgs})`, - `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`, - ); - }); + try { + await this.synchronizer.trigger(); + // TODO - Should check if `from` has the permission to call the view function. + const functionCall = await this.#getFunctionCall(functionName, args, to); + const executionResult = await this.#simulateUnconstrained(functionCall, scopes); + + // TODO - Return typed result based on the function artifact. + return executionResult; + } catch (err: any) { + const stringifiedArgs = args.map(arg => arg.toString()).join(', '); + throw this.contextualizeError( + err, + `simulateUnconstrained ${to}:${functionName}(${stringifiedArgs})`, + `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`, + ); + } } public getTxReceipt(txHash: TxHash): Promise { diff --git a/yarn-project/pxe/src/pxe_service/test/pxe_service.test.ts b/yarn-project/pxe/src/pxe_service/test/pxe_service.test.ts index 678f6c4bb761..d0dc0103bbfe 100644 --- a/yarn-project/pxe/src/pxe_service/test/pxe_service.test.ts +++ b/yarn-project/pxe/src/pxe_service/test/pxe_service.test.ts @@ -22,7 +22,6 @@ async function createPXEService(): Promise { const db = await KVPxeDatabase.create(kvStore); const tips = new L2TipsStore(kvStore, 'pxe'); const config: PXEServiceConfig = { - l2BlockPollingIntervalMS: 100, l2StartingBlock: INITIAL_L2_BLOCK_NUM, dataDirectory: undefined, dataStoreMapSizeKB: 1024 * 1024, @@ -67,7 +66,6 @@ describe('PXEService', () => { tips = new L2TipsStore(kvStore, 'pxe'); db = await KVPxeDatabase.create(kvStore); config = { - l2BlockPollingIntervalMS: 100, l2StartingBlock: INITIAL_L2_BLOCK_NUM, proverEnabled: false, dataDirectory: undefined, diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.ts b/yarn-project/pxe/src/synchronizer/synchronizer.ts index 382dc477e221..fa2143797aaa 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.ts @@ -27,16 +27,15 @@ export class Synchronizer implements L2BlockStreamEventHandler { private node: AztecNode, private db: PxeDatabase, private l2TipsStore: L2TipsStore, - config: Partial> = {}, + config: Partial> = {}, logSuffix?: string, ) { this.log = createLogger(logSuffix ? `pxe:synchronizer:${logSuffix}` : 'pxe:synchronizer'); this.blockStream = this.createBlockStream(config); } - protected createBlockStream(config: Partial>) { + protected createBlockStream(config: Partial>) { return new L2BlockStream(this.node, this.l2TipsStore, this, createLogger('pxe:block_stream'), { - pollIntervalMS: config.l2BlockPollingIntervalMS, startingBlock: config.l2StartingBlock, }); } @@ -93,6 +92,10 @@ export class Synchronizer implements L2BlockStreamEventHandler { this.running = false; } + public async stop() { + await this.blockStream.stop(); + } + public async getSynchedBlockNumber() { return (await this.db.getBlockNumber()) ?? this.initialSyncBlockNumber; } From f50c8e98619aae4de8b87f79da5430ae81507dab Mon Sep 17 00:00:00 2001 From: thunkar Date: Thu, 12 Dec 2024 08:32:24 +0000 Subject: [PATCH 14/18] fmt --- yarn-project/end-to-end/src/fixtures/utils.ts | 2 +- yarn-project/pxe/src/bin/index.ts | 2 +- yarn-project/pxe/src/pxe_service/pxe_service.ts | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index c343015cda2d..b8954d38cd15 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -42,7 +42,7 @@ import { FeeJuiceContract } from '@aztec/noir-contracts.js/FeeJuice'; import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types'; import { ProtocolContractAddress, protocolContractTreeRoot } from '@aztec/protocol-contracts'; import { type ProverNode, type ProverNodeConfig, createProverNode } from '@aztec/prover-node'; -import { PXEService, type PXEServiceConfig, createPXEService, getPXEServiceConfig } from '@aztec/pxe'; +import { type PXEService, type PXEServiceConfig, createPXEService, getPXEServiceConfig } from '@aztec/pxe'; import { type SequencerClient, TestL1Publisher } from '@aztec/sequencer-client'; import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { createAndStartTelemetryClient, getConfigEnvVars as getTelemetryConfig } from '@aztec/telemetry-client/start'; diff --git a/yarn-project/pxe/src/bin/index.ts b/yarn-project/pxe/src/bin/index.ts index 60a3d2da4cc4..66f451dae925 100644 --- a/yarn-project/pxe/src/bin/index.ts +++ b/yarn-project/pxe/src/bin/index.ts @@ -23,7 +23,7 @@ async function main() { const nodeRpcClient = createAztecNodeClient(AZTEC_NODE_URL); const pxeService = await createPXEService(nodeRpcClient, pxeConfig); - const shutdown = async () => { + const shutdown = () => { logger.info('Shutting down...'); process.exit(0); }; diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index c69cc9453256..3e52c79fa2f7 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -56,7 +56,6 @@ import { } from '@aztec/foundation/abi'; import { Fr, type Point } from '@aztec/foundation/fields'; import { type Logger, createLogger } from '@aztec/foundation/log'; -import { SerialQueue } from '@aztec/foundation/queue'; import { type KeyStore } from '@aztec/key-store'; import { type L2TipsStore } from '@aztec/kv-store/stores'; import { From 00fd955d0835386526819cb70c24348a7fe2220b Mon Sep 17 00:00:00 2001 From: thunkar Date: Thu, 12 Dec 2024 08:48:48 +0000 Subject: [PATCH 15/18] renaming --- yarn-project/pxe/src/pxe_service/pxe_service.ts | 2 +- yarn-project/pxe/src/synchronizer/synchronizer.ts | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 3e52c79fa2f7..6a1d557d783c 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -578,7 +578,7 @@ export class PXEService implements PXE { scopes?: AztecAddress[], ): Promise { try { - await this.synchronizer.trigger(); + await this.synchronizer.sync(); // TODO - Should check if `from` has the permission to call the view function. const functionCall = await this.#getFunctionCall(functionName, args, to); const executionResult = await this.#simulateUnconstrained(functionCall, scopes); diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.ts b/yarn-project/pxe/src/synchronizer/synchronizer.ts index fa2143797aaa..80a152dcf3a9 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.ts @@ -18,7 +18,6 @@ import { type PxeDatabase } from '../database/index.js'; * details, and fetch transactions by hash. */ export class Synchronizer implements L2BlockStreamEventHandler { - private running = false; private initialSyncBlockNumber = INITIAL_L2_BLOCK_NUM - 1; private log: Logger; protected readonly blockStream: L2BlockStream; @@ -74,9 +73,7 @@ export class Synchronizer implements L2BlockStreamEventHandler { * Syncs PXE and the node by dowloading the metadata of the latest blocks, allowing simulations to use * recent data (e.g. notes), and handling any reorgs that might have occurred. */ - public async trigger() { - this.running = true; - + public async sync() { let currentHeader; try { @@ -88,12 +85,7 @@ 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.blockStream.sync(); - this.running = false; - } - - public async stop() { - await this.blockStream.stop(); + await this.blockStream.triggerOnce(); } public async getSynchedBlockNumber() { From bc56c9ca527bec9f2fa247d6f64e68b1ab8b0c22 Mon Sep 17 00:00:00 2001 From: thunkar Date: Thu, 12 Dec 2024 08:54:52 +0000 Subject: [PATCH 16/18] fix --- yarn-project/pxe/src/pxe_service/pxe_service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 6a1d557d783c..dba22e806712 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -498,7 +498,7 @@ export class PXEService implements PXE { `Simulating transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`, txInfo, ); - await this.synchronizer.trigger(); + await this.synchronizer.sync(); const privateExecutionResult = await this.#executePrivate(txRequest, msgSender, scopes); let publicInputs: PrivateKernelTailCircuitPublicInputs; From ff200deda8ba2cb8480b4de3ede4466ba5e9d422 Mon Sep 17 00:00:00 2001 From: thunkar Date: Thu, 12 Dec 2024 09:00:27 +0000 Subject: [PATCH 17/18] typo --- yarn-project/pxe/src/synchronizer/synchronizer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.ts b/yarn-project/pxe/src/synchronizer/synchronizer.ts index 80a152dcf3a9..225787866df0 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.ts @@ -85,7 +85,7 @@ 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.blockStream.triggerOnce(); + await this.blockStream.sync(); } public async getSynchedBlockNumber() { From 77f8ddb2d1d464a84ffdcbb395c4aea0806a2666 Mon Sep 17 00:00:00 2001 From: thunkar Date: Thu, 12 Dec 2024 10:28:15 +0000 Subject: [PATCH 18/18] fmt --- yarn-project/cli-wallet/src/bin/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/yarn-project/cli-wallet/src/bin/index.ts b/yarn-project/cli-wallet/src/bin/index.ts index df08765c1005..1147134a56ff 100644 --- a/yarn-project/cli-wallet/src/bin/index.ts +++ b/yarn-project/cli-wallet/src/bin/index.ts @@ -2,7 +2,6 @@ import { Fr, computeSecretHash, fileURLToPath } from '@aztec/aztec.js'; import { LOCALHOST } from '@aztec/cli/cli-utils'; import { type LogFn, createConsoleLogger, createLogger } from '@aztec/foundation/log'; import { AztecLmdbStore } from '@aztec/kv-store/lmdb'; -import { type PXEService } from '@aztec/pxe'; import { Argument, Command, Option } from 'commander'; import { readFileSync } from 'fs';