diff --git a/typescript/sdk/src/ism/metadata/aggregation.ts b/typescript/sdk/src/ism/metadata/aggregation.ts index 8980c9a6e7..9c18b40d2f 100644 --- a/typescript/sdk/src/ism/metadata/aggregation.ts +++ b/typescript/sdk/src/ism/metadata/aggregation.ts @@ -5,6 +5,7 @@ import { assert, fromHexString, rootLogger, + runWithTimeout, toHexString, } from '@hyperlane-xyz/utils'; @@ -45,22 +46,22 @@ export class AggregationIsmMetadataBuilder dispatchTx: TransactionReceipt; }, maxDepth = 10, + timeout = maxDepth * 1000, ): Promise { assert(maxDepth > 0, 'Max depth reached'); const promises = await Promise.allSettled( - context.ism.modules.map((module) => - this.base.build( - message, - { - ...context, - ism: module as DerivedIsmConfigWithAddress, - }, - maxDepth - 1, - ), - ), + context.ism.modules.map((module) => { + const subContext = { + ...context, + ism: module as DerivedIsmConfigWithAddress, + }; + return runWithTimeout(timeout, () => + this.base.build(message, subContext, maxDepth - 1), + ); + }), ); const submoduleMetadata = promises.map((r) => - r.status === 'fulfilled' ? r.value : null, + r.status === 'fulfilled' ? r.value ?? null : null, ); const included = submoduleMetadata.filter((m) => m !== null).length; if (included < context.ism.threshold) { diff --git a/typescript/sdk/src/ism/metadata/builder.ts b/typescript/sdk/src/ism/metadata/builder.ts index dca5219b70..a52caabff3 100644 --- a/typescript/sdk/src/ism/metadata/builder.ts +++ b/typescript/sdk/src/ism/metadata/builder.ts @@ -12,6 +12,7 @@ import { HyperlaneCore } from '../../core/HyperlaneCore.js'; import { DispatchedMessage } from '../../core/types.js'; import { DerivedHookConfigWithAddress } from '../../hook/EvmHookReader.js'; import { HookType, MerkleTreeHookConfig } from '../../hook/types.js'; +import { MultiProvider } from '../../providers/MultiProvider.js'; import { DerivedIsmConfigWithAddress } from '../EvmIsmReader.js'; import { IsmType } from '../types.js'; @@ -54,13 +55,16 @@ export class BaseMetadataBuilder { private multisigMetadataBuilder: MultisigMetadataBuilder; private aggregationIsmMetadataBuilder: AggregationIsmMetadataBuilder; + + protected multiProvider: MultiProvider; protected logger = rootLogger.child({ module: 'BaseMetadataBuilder' }); - constructor(protected readonly core: HyperlaneCore) { + constructor(core: HyperlaneCore) { this.multisigMetadataBuilder = new MultisigMetadataBuilder(core); this.aggregationIsmMetadataBuilder = new AggregationIsmMetadataBuilder( this, ); + this.multiProvider = core.multiProvider; } // assumes that all post dispatch hooks are included in dispatchTx logs @@ -79,20 +83,19 @@ export class BaseMetadataBuilder `Building ${context.ism.type} metadata`, ); - if (context.ism.type === IsmType.TRUSTED_RELAYER) { - const destinationSigner = await this.core.multiProvider.getSignerAddress( - message.parsed.destination, - ); - assert( - eqAddress(destinationSigner, context.ism.relayer), - `Destination signer ${destinationSigner} does not match trusted relayer ${context.ism.relayer}`, - ); - } - const { ism, hook, dispatchTx } = context; + /* eslint-disable no-case-declarations */ switch (ism.type) { // Null case IsmType.TRUSTED_RELAYER: + const destinationSigner = await this.multiProvider.getSignerAddress( + message.parsed.destination, + ); + assert( + eqAddress(destinationSigner, ism.relayer), + `Destination signer ${destinationSigner} does not match trusted relayer ${ism.relayer}`, + ); + /* eslint-disable-next-line no-fallthrough */ case IsmType.PAUSABLE: case IsmType.TEST_ISM: case IsmType.OP_STACK: @@ -101,7 +104,6 @@ export class BaseMetadataBuilder // Multisig case IsmType.MERKLE_ROOT_MULTISIG: case IsmType.MESSAGE_ID_MULTISIG: - // eslint-disable-next-line no-case-declarations const merkleTreeHook = deepFind( hook, (v): v is WithAddress => @@ -122,7 +124,7 @@ export class BaseMetadataBuilder { ...context, ism: ism.domains[ - this.core.multiProvider.getChainName(message.parsed.origin) + this.multiProvider.getChainName(message.parsed.origin) ] as DerivedIsmConfigWithAddress, }, maxDepth - 1, @@ -136,5 +138,6 @@ export class BaseMetadataBuilder maxDepth - 1, ); } + /* eslint-enable no-case-declarations */ } } diff --git a/typescript/sdk/src/ism/metadata/multisig.ts b/typescript/sdk/src/ism/metadata/multisig.ts index b91cd89795..4db8ab257c 100644 --- a/typescript/sdk/src/ism/metadata/multisig.ts +++ b/typescript/sdk/src/ism/metadata/multisig.ts @@ -76,9 +76,10 @@ export class MultisigMetadataBuilder ); if (toFetch.length > 0) { - const storageLocations = await this.core - .getContracts(originChain) - .validatorAnnounce.getAnnouncedStorageLocations(toFetch); + const validatorAnnounce = + this.core.getContracts(originChain).validatorAnnounce; + const storageLocations = + await validatorAnnounce.getAnnouncedStorageLocations(toFetch); this.logger.debug({ storageLocations }, 'Fetched storage locations'); diff --git a/typescript/sdk/tsconfig.json b/typescript/sdk/tsconfig.json index 8b20eb5f5b..178bfaa026 100644 --- a/typescript/sdk/tsconfig.json +++ b/typescript/sdk/tsconfig.json @@ -3,6 +3,7 @@ "compilerOptions": { "outDir": "./dist/", "rootDir": "./src/", + "noFallthroughCasesInSwitch": false, }, "include": ["./src/**/*.ts", "./src/*.d.ts"] }