Skip to content

Commit

Permalink
fix: don't derive testnet domains in IGP config derivation on mainnet (
Browse files Browse the repository at this point in the history
…#5410)

### Description

Right now, because IGP's domains are not an enumerable set, we have to
query all known domains on it. That is becoming very expensive. This
change at least avoids querying for testnet domains when looking at a
mainnet IGP and vice versa.
  • Loading branch information
nambrot authored Feb 9, 2025
1 parent b92eb1b commit ede0cbc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/purple-geese-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hyperlane-xyz/sdk": minor
---

Don't derive testnet domains in IGP config derivation on mainnet
59 changes: 36 additions & 23 deletions typescript/sdk/src/hook/EvmHookReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,23 @@ export class EvmHookReader extends HyperlaneReader implements HookReader {
return config;
}

possibleDomainIds(): number[] {
const isTestnet = !!this.multiProvider.getChainMetadata(this.chain)
.isTestnet;

return this.messageContext
? [this.messageContext.parsed.destination]
: // filter to only domains that are the same testnet/mainnet
this.multiProvider
.getKnownChainNames()
.filter(
(chainName) =>
!!this.multiProvider.getChainMetadata(chainName).isTestnet ===
isTestnet,
)
.map((chainName) => this.multiProvider.getDomainId(chainName));
}

async deriveIgpConfig(address: Address): Promise<WithAddress<IgpHookConfig>> {
const hook = InterchainGasPaymaster__factory.connect(
address,
Expand All @@ -243,13 +260,9 @@ export class EvmHookReader extends HyperlaneReader implements HookReader {

let oracleKey: string | undefined;

const domainIds = this.messageContext
? [this.messageContext.parsed.destination]
: this.multiProvider.getKnownDomainIds();

const allKeys = await concurrentMap(
this.concurrency,
domainIds,
this.possibleDomainIds(),
async (domainId) => {
const { name: chainName, nativeToken } =
this.multiProvider.getChainMetadata(domainId);
Expand Down Expand Up @@ -441,26 +454,26 @@ export class EvmHookReader extends HyperlaneReader implements HookReader {
private async fetchDomainHooks(
hook: DomainRoutingHook | FallbackDomainRoutingHook,
): Promise<RoutingHookConfig['domains']> {
const domainIds = this.messageContext
? [this.messageContext.parsed.destination]
: this.multiProvider.getKnownDomainIds();

const domainHooks: RoutingHookConfig['domains'] = {};
await concurrentMap(this.concurrency, domainIds, async (domainId) => {
const chainName = this.multiProvider.getChainName(domainId);
try {
const domainHook = await hook.hooks(domainId);
if (domainHook !== ethers.constants.AddressZero) {
domainHooks[chainName] = await this.deriveHookConfig(domainHook);
await concurrentMap(
this.concurrency,
this.possibleDomainIds(),
async (domainId) => {
const chainName = this.multiProvider.getChainName(domainId);
try {
const domainHook = await hook.hooks(domainId);
if (domainHook !== ethers.constants.AddressZero) {
domainHooks[chainName] = await this.deriveHookConfig(domainHook);
}
} catch {
this.logger.debug(
`Domain not configured on ${hook.constructor.name}`,
domainId,
chainName,
);
}
} catch {
this.logger.debug(
`Domain not configured on ${hook.constructor.name}`,
domainId,
chainName,
);
}
});
},
);

return domainHooks;
}
Expand Down

0 comments on commit ede0cbc

Please sign in to comment.