From ebd41651f5912fc2e0d1aa5d0df154620341c755 Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Sun, 1 Dec 2024 20:30:42 +0000 Subject: [PATCH] fix: bot waits for pxe synch (#10316) Fix for bot failing to start back up in rough-rhino. Thanks to @Thunkar for help identifying this. --- yarn-project/bot/src/factory.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/yarn-project/bot/src/factory.ts b/yarn-project/bot/src/factory.ts index 2a72653005a..d41ddf174ff 100644 --- a/yarn-project/bot/src/factory.ts +++ b/yarn-project/bot/src/factory.ts @@ -6,6 +6,7 @@ import { type DeployOptions, createDebugLogger, createPXEClient, + retryUntil, } from '@aztec/aztec.js'; import { type AztecNode, type FunctionCall, type PXE } from '@aztec/circuit-types'; import { Fr, deriveSigningKey } from '@aztec/circuits.js'; @@ -65,7 +66,18 @@ export class BotFactory { const isInit = await this.pxe.isContractInitialized(account.getAddress()); if (isInit) { this.log.info(`Account at ${account.getAddress().toString()} already initialized`); - return account.register(); + 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()}`); const sentTx = account.deploy();