diff --git a/yarn-project/end-to-end/src/shared/submit-transactions.ts b/yarn-project/end-to-end/src/shared/submit-transactions.ts index ed3928d3ddea..02cacfe6f83e 100644 --- a/yarn-project/end-to-end/src/shared/submit-transactions.ts +++ b/yarn-project/end-to-end/src/shared/submit-transactions.ts @@ -1,5 +1,6 @@ import { getSchnorrAccount } from '@aztec/accounts/schnorr'; import { Fr, GrumpkinScalar, type Logger, type SentTx, TxStatus, type Wallet } from '@aztec/aztec.js'; +import { times } from '@aztec/foundation/collection'; import type { PXEService } from '@aztec/pxe'; // submits a set of transactions to the provided Private eXecution Environment (PXE) @@ -10,21 +11,23 @@ export const submitTxsTo = async ( logger: Logger, ): Promise => { const txs: SentTx[] = []; - for (let i = 0; i < numTxs; i++) { - const accountManager = await getSchnorrAccount(pxe, Fr.random(), GrumpkinScalar.random(), Fr.random()); - const tx = accountManager.deploy({ deployWallet: wallet }); - const txHash = await tx.getTxHash(); + await Promise.all( + times(numTxs, async () => { + const accountManager = await getSchnorrAccount(pxe, Fr.random(), GrumpkinScalar.random(), Fr.random()); + const tx = accountManager.deploy({ deployWallet: wallet }); + const txHash = await tx.getTxHash(); - logger.info(`Tx sent with hash ${txHash}`); - const receipt = await tx.getReceipt(); - expect(receipt).toEqual( - expect.objectContaining({ - status: TxStatus.PENDING, - error: '', - }), - ); - logger.info(`Receipt received for ${txHash}`); - txs.push(tx); - } + logger.info(`Tx sent with hash ${txHash}`); + const receipt = await tx.getReceipt(); + expect(receipt).toEqual( + expect.objectContaining({ + status: TxStatus.PENDING, + error: '', + }), + ); + logger.info(`Receipt received for ${txHash}`); + txs.push(tx); + }), + ); return txs; }; diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.ts b/yarn-project/pxe/src/synchronizer/synchronizer.ts index fbf17737dc27..ba89d5a4da11 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.ts @@ -16,6 +16,7 @@ import type { PxeDatabase } from '../database/index.js'; export class Synchronizer implements L2BlockStreamEventHandler { private initialSyncBlockNumber = INITIAL_L2_BLOCK_NUM - 1; private log: Logger; + private isSyncing: Promise | undefined; protected readonly blockStream: L2BlockStream; constructor( @@ -78,6 +79,23 @@ export class Synchronizer implements L2BlockStreamEventHandler { * recent data (e.g. notes), and handling any reorgs that might have occurred. */ public async sync() { + if (this.isSyncing !== undefined) { + this.log.debug(`Waiting for the ongoing sync to finish`); + await this.isSyncing; + return; + } + + this.log.debug(`Syncing PXE with the node`); + const isSyncing = this.doSync(); + this.isSyncing = isSyncing; + try { + await isSyncing; + } finally { + this.isSyncing = undefined; + } + } + + private async doSync() { let currentHeader; try {