Skip to content

Commit

Permalink
fix: register account contract before recipient (#6855)
Browse files Browse the repository at this point in the history
Fix potential race condition where the note processor catches up to the
tip of the chain before the PXE knows of the account contract at that
address
  • Loading branch information
alexghr authored Jun 4, 2024
1 parent d4dfdaf commit dfea1c7
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions yarn-project/aztec.js/src/account_manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ export class AccountManager {
* @returns A Wallet instance.
*/
public async register(opts: WaitOpts = DefaultWaitOpts): Promise<AccountWalletWithSecretKey> {
await this.#register();
await this.pxe.registerContract({
artifact: this.accountContract.getContractArtifact(),
instance: this.getInstance(),
});

await this.pxe.registerAccount(this.secretKey, this.getCompleteAddress().partialAddress);

await waitForAccountSynch(this.pxe, this.getCompleteAddress(), opts);
return this.getWallet();
}
Expand All @@ -127,7 +128,9 @@ export class AccountManager {
`Account contract ${this.accountContract.getContractArtifact().name} does not require deployment.`,
);
}
await this.#register();

await this.pxe.registerAccount(this.secretKey, this.getCompleteAddress().partialAddress);

const { chainId, protocolVersion } = await this.pxe.getNodeInfo();
const deployWallet = new SignerlessWallet(this.pxe, new DefaultMultiCallEntrypoint(chainId, protocolVersion));

Expand Down Expand Up @@ -191,9 +194,4 @@ export class AccountManager {
public isDeployable() {
return this.accountContract.getDeploymentArgs() !== undefined;
}

async #register(): Promise<void> {
const completeAddress = this.getCompleteAddress();
await this.pxe.registerAccount(this.secretKey, completeAddress.partialAddress);
}
}

0 comments on commit dfea1c7

Please sign in to comment.