From 2b0c76c569afaafc0915b1de498c5847ef4c33b1 Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Wed, 16 Apr 2025 12:44:00 -0300 Subject: [PATCH] chore: Fetch rollup address using version as index --- yarn-project/ethereum/src/contracts/registry.test.ts | 4 ++++ yarn-project/ethereum/src/contracts/registry.ts | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/yarn-project/ethereum/src/contracts/registry.test.ts b/yarn-project/ethereum/src/contracts/registry.test.ts index f7f0bb39faaf..70d5a30e115a 100644 --- a/yarn-project/ethereum/src/contracts/registry.test.ts +++ b/yarn-project/ethereum/src/contracts/registry.test.ts @@ -81,6 +81,10 @@ describe('Registry', () => { const address = await registry.getRollupAddress(deployedVersion); expect(address).toEqual(rollupAddress); } + { + const address = await registry.getRollupAddress(0); + expect(address).toEqual(rollupAddress); + } }); it('handles non-existent versions', async () => { diff --git a/yarn-project/ethereum/src/contracts/registry.ts b/yarn-project/ethereum/src/contracts/registry.ts index 7fd30fb26caa..21b5f9f58331 100644 --- a/yarn-project/ethereum/src/contracts/registry.ts +++ b/yarn-project/ethereum/src/contracts/registry.ts @@ -1,4 +1,5 @@ import { EthAddress } from '@aztec/foundation/eth-address'; +import { createLogger } from '@aztec/foundation/log'; import { RegistryAbi } from '@aztec/l1-artifacts/RegistryAbi'; import { TestERC20Abi } from '@aztec/l1-artifacts/TestERC20Abi'; @@ -18,6 +19,8 @@ import { RollupContract } from './rollup.js'; export class RegistryContract { public address: EthAddress; + + private readonly log = createLogger('ethereum:contracts:registry'); private readonly registry: GetContractReturnType>; constructor(public readonly client: L1Clients['publicClient'], address: Hex | EthAddress) { @@ -44,6 +47,14 @@ export class RegistryContract { try { return EthAddress.fromString(await this.registry.read.getRollup([version])); + } catch (e) { + this.log.warn(`Failed fetching rollup address for version ${version}. Retrying as index.`); + } + + try { + const actualVersion = await this.registry.read.getVersion([version]); + const rollupAddress = await this.registry.read.getRollup([actualVersion]); + return EthAddress.fromString(rollupAddress); } catch (e) { throw new Error('Rollup address is undefined'); }