Skip to content

Commit

Permalink
Address pr comments on metadata builders
Browse files Browse the repository at this point in the history
  • Loading branch information
yorhodes committed May 12, 2024
1 parent 5a72ad5 commit d83b325
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
23 changes: 12 additions & 11 deletions typescript/sdk/src/ism/metadata/aggregation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
assert,
fromHexString,
rootLogger,
runWithTimeout,
toHexString,
} from '@hyperlane-xyz/utils';

Expand Down Expand Up @@ -45,22 +46,22 @@ export class AggregationIsmMetadataBuilder
dispatchTx: TransactionReceipt;
},
maxDepth = 10,
timeout = maxDepth * 1000,
): Promise<string> {
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) {
Expand Down
29 changes: 16 additions & 13 deletions typescript/sdk/src/ism/metadata/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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<MerkleTreeHookConfig> =>
Expand All @@ -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,
Expand All @@ -136,5 +138,6 @@ export class BaseMetadataBuilder
maxDepth - 1,
);
}
/* eslint-enable no-case-declarations */
}
}
7 changes: 4 additions & 3 deletions typescript/sdk/src/ism/metadata/multisig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
1 change: 1 addition & 0 deletions typescript/sdk/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"outDir": "./dist/",
"rootDir": "./src/",
"noFallthroughCasesInSwitch": false,
},
"include": ["./src/**/*.ts", "./src/*.d.ts"]
}

0 comments on commit d83b325

Please sign in to comment.