fix: minor change was breaking in registry export (#3821)

### Description

Fixes compat with with breaking changes in registry 1.3.0

---------

Co-authored-by: Yorke Rhodes <yorke@hyperlane.xyz>
Co-authored-by: J M Rossy <jm.rossy@gmail.com>
pull/3854/head
Connor McEwen 6 months ago committed by GitHub
parent 214f503e53
commit b6b26e2bb8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 7
      .changeset/many-rice-wave.md
  2. 2
      typescript/cli/package.json
  3. 35
      typescript/cli/src/context/context.ts
  4. 12
      typescript/cli/src/deploy/core.ts
  5. 6
      typescript/cli/src/deploy/warp.ts
  6. 156
      typescript/cli/src/registry/MergedRegistry.ts
  7. 2
      typescript/helloworld/package.json
  8. 22
      typescript/infra/config/registry.ts
  9. 2
      typescript/infra/package.json
  10. 14
      yarn.lock

@ -0,0 +1,7 @@
---
"@hyperlane-xyz/cli": patch
"@hyperlane-xyz/helloworld": patch
"@hyperlane-xyz/infra": patch
---
fix: minor change was breaking in registry export

@ -5,7 +5,7 @@
"dependencies": {
"@aws-sdk/client-kms": "^3.577.0",
"@aws-sdk/client-s3": "^3.577.0",
"@hyperlane-xyz/registry": "^1.0.7",
"@hyperlane-xyz/registry": "1.3.0",
"@hyperlane-xyz/sdk": "3.12.2",
"@hyperlane-xyz/utils": "3.12.2",
"@inquirer/prompts": "^3.0.0",

@ -1,13 +1,17 @@
import { ethers } from 'ethers';
import { IRegistry } from '@hyperlane-xyz/registry';
import {
GithubRegistry,
IRegistry,
MergedRegistry,
} from '@hyperlane-xyz/registry';
import { FileSystemRegistry } from '@hyperlane-xyz/registry/fs';
import { ChainName, MultiProvider } from '@hyperlane-xyz/sdk';
import { isNullish } from '@hyperlane-xyz/utils';
import { isHttpsUrl, isNullish, rootLogger } from '@hyperlane-xyz/utils';
import { isSignCommand } from '../commands/signCommands.js';
import { forkNetworkToMultiProvider, verifyAnvil } from '../deploy/dry-run.js';
import { logBlue } from '../logger.js';
import { MergedRegistry } from '../registry/MergedRegistry.js';
import { runSingleChainSelectionStep } from '../utils/chains.js';
import { getImpersonatedSigner, getSigner } from '../utils/keys.js';
@ -81,7 +85,7 @@ export async function getDryRunContext(
}: ContextSettings,
chain?: ChainName,
): Promise<CommandContext> {
const registry = getRegistry(registryUri, registryOverrideUri, true);
const registry = getRegistry(registryUri, registryOverrideUri);
const chainMetadata = await registry.getMetadata();
if (!chain) {
@ -127,14 +131,25 @@ export async function getDryRunContext(
function getRegistry(
primaryRegistryUri: string,
overrideRegistryUri: string,
isDryRun?: boolean,
): IRegistry {
const registryUris = [primaryRegistryUri, overrideRegistryUri]
.map((r) => r.trim())
.filter((r) => !!r);
const logger = rootLogger.child({ module: 'MergedRegistry' });
const registries = [primaryRegistryUri, overrideRegistryUri]
.map((uri) => uri.trim())
.filter((uri) => !!uri)
.map((uri, index) => {
const childLogger = logger.child({ uri, index });
if (isHttpsUrl(uri)) {
return new GithubRegistry({ uri, logger: childLogger });
} else {
return new FileSystemRegistry({
uri,
logger: childLogger,
});
}
});
return new MergedRegistry({
registryUris,
isDryRun,
registries,
logger,
});
}

@ -258,6 +258,7 @@ async function executeDeploy({
registry,
ismFactoryContracts,
artifacts,
context.isDryRun,
);
logGreen('ISM factory contracts deployed');
@ -297,7 +298,12 @@ async function executeDeploy({
};
}
artifacts = objMerge(artifacts, isms);
artifacts = await updateChainAddresses(registry, coreContracts, artifacts);
artifacts = await updateChainAddresses(
registry,
coreContracts,
artifacts,
context.isDryRun,
);
logGreen('✅ Core contracts deployed');
log(JSON.stringify(artifacts, null, 2));
@ -395,6 +401,7 @@ async function updateChainAddresses(
registry: IRegistry,
newContracts: HyperlaneContractsMap<any>,
otherAddresses: HyperlaneAddressesMap<any>,
isDryRun?: boolean,
) {
let newAddresses = serializeContractsMap(newContracts);
// The HyperlaneCoreDeployer is returning a nested object with ISM addresses
@ -407,6 +414,9 @@ async function updateChainAddresses(
);
});
const mergedAddresses = objMerge(otherAddresses, newAddresses);
if (isDryRun) return mergedAddresses;
for (const chainName of Object.keys(newContracts)) {
await registry.updateChain({
chainName,

@ -123,9 +123,11 @@ async function executeDeploy(params: DeployParams) {
logGreen('✅ Hyp token deployments complete');
if (!isDryRun) log('Writing deployment artifacts');
const warpCoreConfig = await getWarpCoreConfig(params, deployedContracts);
await registry.addWarpRoute(warpCoreConfig);
if (!isDryRun) {
log('Writing deployment artifacts');
await registry.addWarpRoute(warpCoreConfig);
}
log(JSON.stringify(warpCoreConfig, null, 2));
logBlue('Deployment is complete!');
}

@ -1,156 +0,0 @@
import { Logger } from 'pino';
import {
BaseRegistry,
ChainAddresses,
GithubRegistry,
IRegistry,
RegistryContent,
RegistryType,
} from '@hyperlane-xyz/registry';
import { LocalRegistry } from '@hyperlane-xyz/registry/local';
import {
ChainMap,
ChainMetadata,
ChainName,
WarpCoreConfig,
} from '@hyperlane-xyz/sdk';
import {
isHttpsUrl,
objKeys,
objMerge,
rootLogger,
} from '@hyperlane-xyz/utils';
export interface MergedRegistryOptions {
registryUris: Array<string>;
isDryRun?: boolean;
logger?: Logger;
}
export class MergedRegistry extends BaseRegistry implements IRegistry {
public readonly type = RegistryType.Local;
public readonly registries: Array<IRegistry>;
public readonly isDryRun: boolean;
constructor({ registryUris, logger, isDryRun }: MergedRegistryOptions) {
logger ||= rootLogger.child({ module: 'MergedRegistry' });
super({ uri: '__merged_registry__', logger });
if (!registryUris.length)
throw new Error('At least one registry URI is required');
this.registries = registryUris.map((uri, index) => {
if (isHttpsUrl(uri)) {
return new GithubRegistry({ uri, logger: logger!.child({ index }) });
} else {
return new LocalRegistry({ uri, logger: logger!.child({ index }) });
}
});
this.isDryRun = !!isDryRun;
}
async listRegistryContent(): Promise<RegistryContent> {
const results = await this.multiRegistryRead((r) =>
r.listRegistryContent(),
);
return results.reduce((acc, content) => objMerge(acc, content), {
chains: {},
deployments: {},
});
}
async getChains(): Promise<Array<ChainName>> {
return objKeys(await this.getMetadata);
}
async getMetadata(): Promise<ChainMap<ChainMetadata>> {
const results = await this.multiRegistryRead((r) => r.getMetadata());
return results.reduce((acc, content) => objMerge(acc, content), {});
}
async getChainMetadata(chainName: ChainName): Promise<ChainMetadata | null> {
return (await this.getMetadata())[chainName] || null;
}
async getAddresses(): Promise<ChainMap<ChainAddresses>> {
const results = await this.multiRegistryRead((r) => r.getAddresses());
return results.reduce((acc, content) => objMerge(acc, content), {});
}
async getChainAddresses(
chainName: ChainName,
): Promise<ChainAddresses | null> {
return (await this.getAddresses())[chainName] || null;
}
async addChain(chain: {
chainName: ChainName;
metadata?: ChainMetadata;
addresses?: ChainAddresses;
}): Promise<void> {
return this.multiRegistryWrite(
async (registry) => await registry.addChain(chain),
`adding chain ${chain.chainName}`,
);
}
async updateChain(chain: {
chainName: ChainName;
metadata?: ChainMetadata;
addresses?: ChainAddresses;
}): Promise<void> {
return this.multiRegistryWrite(
async (registry) => await registry.updateChain(chain),
`updating chain ${chain.chainName}`,
);
}
async removeChain(chain: ChainName): Promise<void> {
return this.multiRegistryWrite(
async (registry) => await registry.removeChain(chain),
`removing chain ${chain}`,
);
}
async addWarpRoute(config: WarpCoreConfig): Promise<void> {
return this.multiRegistryWrite(
async (registry) => await registry.addWarpRoute(config),
'adding warp route',
);
}
protected multiRegistryRead<R>(
readFn: (registry: IRegistry) => Promise<R> | R,
) {
return Promise.all(this.registries.map(readFn));
}
protected async multiRegistryWrite(
writeFn: (registry: IRegistry) => Promise<void>,
logMsg: string,
): Promise<void> {
if (this.isDryRun) return;
for (const registry of this.registries) {
// TODO remove this when GithubRegistry supports write methods
if (registry.type === RegistryType.Github) {
this.logger.warn(`skipping ${logMsg} at ${registry.type} registry`);
continue;
}
try {
this.logger.info(
`${logMsg} at ${registry.type} registry at ${registry.uri}`,
);
await writeFn(registry);
this.logger.info(`done ${logMsg} at ${registry.type} registry`);
} catch (error) {
// To prevent loss of artifacts, MergedRegistry write methods are failure tolerant
this.logger.error(
`failure ${logMsg} at ${registry.type} registry`,
error,
);
}
}
}
}

@ -4,7 +4,7 @@
"version": "3.12.2",
"dependencies": {
"@hyperlane-xyz/core": "3.12.2",
"@hyperlane-xyz/registry": "^1.0.7",
"@hyperlane-xyz/registry": "1.3.0",
"@hyperlane-xyz/sdk": "3.12.2",
"@openzeppelin/contracts-upgradeable": "^4.9.3",
"ethers": "^5.7.2"

@ -2,7 +2,7 @@ import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
import { ChainAddresses } from '@hyperlane-xyz/registry';
import { LocalRegistry } from '@hyperlane-xyz/registry/local';
import { FileSystemRegistry } from '@hyperlane-xyz/registry/fs';
import {
ChainMap,
ChainMetadata,
@ -10,7 +10,7 @@ import {
getDomainId as resolveDomainId,
getReorgPeriod as resolveReorgPeriod,
} from '@hyperlane-xyz/sdk';
import { objFilter, rootLogger } from '@hyperlane-xyz/utils';
import { assert, objFilter, rootLogger } from '@hyperlane-xyz/utils';
import type { DeployEnvironment } from '../src/config/environment.js';
@ -29,17 +29,17 @@ const DEFAULT_REGISTRY_URI = join(
// A global Registry singleton
// All uses of chain metadata or chain address artifacts should go through this registry.
let registry: LocalRegistry;
let registry: FileSystemRegistry;
export function setRegistry(reg: LocalRegistry) {
export function setRegistry(reg: FileSystemRegistry) {
registry = reg;
}
export function getRegistry(): LocalRegistry {
export function getRegistry(): FileSystemRegistry {
if (!registry) {
const registryUri = process.env.REGISTRY_URI || DEFAULT_REGISTRY_URI;
rootLogger.info('Using registry URI:', registryUri);
registry = new LocalRegistry({
registry = new FileSystemRegistry({
uri: registryUri,
logger: rootLogger.child({ module: 'infra-registry' }),
});
@ -55,15 +55,19 @@ export function getChain(chainName: ChainName): ChainMetadata {
if (testChains.includes(chainName)) {
return testChainMetadata[chainName];
}
return getRegistry().getChainMetadata(chainName);
const chain = getRegistry().getChainMetadata(chainName);
assert(chain, `Chain not found: ${chainName}`);
return chain;
}
export function getDomainId(chainName: ChainName): number {
return resolveDomainId(getChain(chainName));
const chain = getChain(chainName);
return resolveDomainId(chain);
}
export function getReorgPeriod(chainName: ChainName): number {
return resolveReorgPeriod(getChain(chainName));
const chain = getChain(chainName);
return resolveReorgPeriod(chain);
}
export function getChainMetadata(): ChainMap<ChainMetadata> {

@ -13,7 +13,7 @@
"@ethersproject/hardware-wallets": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@hyperlane-xyz/helloworld": "3.12.2",
"@hyperlane-xyz/registry": "^1.0.7",
"@hyperlane-xyz/registry": "1.3.0",
"@hyperlane-xyz/sdk": "3.12.2",
"@hyperlane-xyz/utils": "3.12.2",
"@nomiclabs/hardhat-etherscan": "^3.0.3",

@ -5690,7 +5690,7 @@ __metadata:
dependencies:
"@aws-sdk/client-kms": "npm:^3.577.0"
"@aws-sdk/client-s3": "npm:^3.577.0"
"@hyperlane-xyz/registry": "npm:^1.0.7"
"@hyperlane-xyz/registry": "npm:1.3.0"
"@hyperlane-xyz/sdk": "npm:3.12.2"
"@hyperlane-xyz/utils": "npm:3.12.2"
"@inquirer/prompts": "npm:^3.0.0"
@ -5778,7 +5778,7 @@ __metadata:
resolution: "@hyperlane-xyz/helloworld@workspace:typescript/helloworld"
dependencies:
"@hyperlane-xyz/core": "npm:3.12.2"
"@hyperlane-xyz/registry": "npm:^1.0.7"
"@hyperlane-xyz/registry": "npm:1.3.0"
"@hyperlane-xyz/sdk": "npm:3.12.2"
"@nomiclabs/hardhat-ethers": "npm:^2.2.3"
"@nomiclabs/hardhat-waffle": "npm:^2.0.6"
@ -5825,7 +5825,7 @@ __metadata:
"@ethersproject/hardware-wallets": "npm:^5.7.0"
"@ethersproject/providers": "npm:^5.7.2"
"@hyperlane-xyz/helloworld": "npm:3.12.2"
"@hyperlane-xyz/registry": "npm:^1.0.7"
"@hyperlane-xyz/registry": "npm:1.3.0"
"@hyperlane-xyz/sdk": "npm:3.12.2"
"@hyperlane-xyz/utils": "npm:3.12.2"
"@nomiclabs/hardhat-ethers": "npm:^2.2.3"
@ -5877,13 +5877,13 @@ __metadata:
languageName: unknown
linkType: soft
"@hyperlane-xyz/registry@npm:^1.0.7":
version: 1.0.7
resolution: "@hyperlane-xyz/registry@npm:1.0.7"
"@hyperlane-xyz/registry@npm:1.3.0":
version: 1.3.0
resolution: "@hyperlane-xyz/registry@npm:1.3.0"
dependencies:
yaml: "npm:^2"
zod: "npm:^3.21.2"
checksum: fb112e2a1fdec539c6ef457ab44b9b5a835b719f2d4cc5cb0efb4413e2647402ed826d597f4c63b552f86fcf91bf69d4d1e5934aee8498f83dac61007a9d5650
checksum: 2cbdfd9e8958d0babde7104dfb0c98def7edb5f87f5f4679b09467a6a9b531884f187fcbc16fd85b00e304ef8fa3beb0a0779555b2c3edc1936541a0e878a73d
languageName: node
linkType: hard

Loading…
Cancel
Save