Skip to content

Commit

Permalink
refactor: simplify registry override (#5271)
Browse files Browse the repository at this point in the history
### Description

This PR includes two main improvements to the CLI's registry and
parameter handling:

1. Removes the unused `--overrides` parameter from all warp command
functions, which was previously only used for local testing purposes but
is no longer needed.

2. Enhances the registry handling by:
- Converting the registry parameter from a single URI to an array
structure
- Adding support for multiple registry sources, later registry takes
priority over previous
- Including default values in the registry array (GitHub and local
registry)

These changes simplify the codebase and make the registry configuration
more flexible and explicit.

### Related issues

#5267

### Backward compatibility

Yes - These changes are backward compatible. The removal of the unused
`--overrides` parameter doesn't affect functionality since it was not
being actively used. The registry array structure maintains
compatibility with existing registry configurations while adding support
for multiple sources.

### Testing

Manual testing

---------

Co-authored-by: Morteza Shojaei <[email protected]>
  • Loading branch information
mshojaei-txfusion and mortezashojaei authored Feb 9, 2025
1 parent 370e39d commit db832b8
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 42 deletions.
6 changes: 6 additions & 0 deletions .changeset/orange-planes-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@hyperlane-xyz/infra': minor
'@hyperlane-xyz/cli': minor
---

Added support for multiple registries in CLI with prioritization.
4 changes: 2 additions & 2 deletions typescript/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
logFormatCommandOption,
logLevelCommandOption,
overrideRegistryUriCommandOption,
registryUriCommandOption,
registryUrisCommandOption,
skipConfirmationOption,
strategyCommandOption,
} from './src/commands/options.js';
Expand All @@ -43,7 +43,7 @@ try {
.scriptName('hyperlane')
.option('log', logFormatCommandOption)
.option('verbosity', logLevelCommandOption)
.option('registry', registryUriCommandOption)
.option('registry', registryUrisCommandOption)
.option('overrides', overrideRegistryUriCommandOption)
.option('key', keyCommandOption)
.option('disableProxy', disableProxyCommandOption)
Expand Down
15 changes: 10 additions & 5 deletions typescript/cli/src/commands/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { ENV } from '../utils/env.js';

/* Global options */

export const DEFAULT_LOCAL_REGISTRY = `${os.homedir()}/.hyperlane`;

export const demandOption = (option: Options): Options => ({
...option,
demandOption: true,
Expand All @@ -25,17 +27,20 @@ export const logLevelCommandOption: Options = {
choices: Object.values(LogLevel),
};

export const registryUriCommandOption: Options = {
type: 'string',
description: 'Registry URI, such as a Github repo URL or a local file path',
export const registryUrisCommandOption: Options = {
type: 'array',
string: true,
description:
'List of Github or local path registries, later registry takes priority over previous',
alias: 'r',
default: DEFAULT_GITHUB_REGISTRY,
default: [DEFAULT_GITHUB_REGISTRY, DEFAULT_LOCAL_REGISTRY],
};

export const overrideRegistryUriCommandOption: Options = {
type: 'string',
description: 'Path to a local registry to override the default registry',
default: `${os.homedir()}/.hyperlane`,
default: '',
hidden: true,
};

export const skipConfirmationOption: Options = {
Expand Down
4 changes: 2 additions & 2 deletions typescript/cli/src/commands/relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import { tryReadJson, writeJson } from '../utils/files.js';
import { getWarpCoreConfigOrExit } from '../utils/warp.js';

import {
DEFAULT_LOCAL_REGISTRY,
agentTargetsCommandOption,
overrideRegistryUriCommandOption,
symbolCommandOption,
warpCoreConfigCommandOption,
} from './options.js';
import { MessageOptionsArgTypes } from './send.js';

const DEFAULT_RELAYER_CACHE = `${overrideRegistryUriCommandOption.default}/relayer-cache.json`;
const DEFAULT_RELAYER_CACHE = `${DEFAULT_LOCAL_REGISTRY}/relayer-cache.json`;

export const relayerCommand: CommandModuleWithContext<
MessageOptionsArgTypes & {
Expand Down
21 changes: 10 additions & 11 deletions typescript/cli/src/context/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ export async function contextMiddleware(argv: Record<string, any>) {
const isDryRun = !isNullish(argv.dryRun);
const requiresKey = isSignCommand(argv);
const settings: ContextSettings = {
registryUri: argv.registry,
registryOverrideUri: argv.overrides,
registryUris: [
...argv.registry,
...(argv.overrides ? [argv.overrides] : []),
],
key: argv.key,
fromAddress: argv.fromAddress,
requiresKey,
Expand Down Expand Up @@ -99,15 +101,14 @@ export async function signerMiddleware(argv: Record<string, any>) {
* @returns context for the current command
*/
export async function getContext({
registryUri,
registryOverrideUri,
registryUris,
key,
requiresKey,
skipConfirmation,
disableProxy = false,
strategyPath,
}: ContextSettings): Promise<CommandContext> {
const registry = getRegistry(registryUri, registryOverrideUri, !disableProxy);
const registry = getRegistry(registryUris, !disableProxy);

//Just for backward compatibility
let signerAddress: string | undefined = undefined;
Expand Down Expand Up @@ -137,16 +138,15 @@ export async function getContext({
*/
export async function getDryRunContext(
{
registryUri,
registryOverrideUri,
registryUris,
key,
fromAddress,
skipConfirmation,
disableProxy = false,
}: ContextSettings,
chain?: ChainName,
): Promise<CommandContext> {
const registry = getRegistry(registryUri, registryOverrideUri, !disableProxy);
const registry = getRegistry(registryUris, !disableProxy);
const chainMetadata = await registry.getMetadata();

if (!chain) {
Expand Down Expand Up @@ -189,12 +189,11 @@ export async function getDryRunContext(
* @returns a new MergedRegistry
*/
export function getRegistry(
primaryRegistryUri: string,
overrideRegistryUri: string,
registryUris: string[],
enableProxy: boolean,
): IRegistry {
const logger = rootLogger.child({ module: 'MergedRegistry' });
const registries = [primaryRegistryUri, overrideRegistryUri]
const registries = registryUris
.map((uri) => uri.trim())
.filter((uri) => !!uri)
.map((uri, index) => {
Expand Down
3 changes: 1 addition & 2 deletions typescript/cli/src/context/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import type {
} from '@hyperlane-xyz/sdk';

export interface ContextSettings {
registryUri: string;
registryOverrideUri: string;
registryUris: string[];
key?: string;
fromAddress?: string;
requiresKey?: boolean;
Expand Down
12 changes: 4 additions & 8 deletions typescript/cli/src/tests/commands/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ export async function deployOrUseExistingCore(
key: string,
) {
const { registry } = await getContext({
registryUri: REGISTRY_PATH,
registryOverrideUri: '',
registryUris: [REGISTRY_PATH],
key,
});
const addresses = (await registry.getChainAddresses(chain)) as ChainAddresses;
Expand All @@ -264,8 +263,7 @@ export async function getDomainId(
key: string,
): Promise<string> {
const { registry } = await getContext({
registryUri: REGISTRY_PATH,
registryOverrideUri: '',
registryUris: [REGISTRY_PATH],
key,
});
const chainMetadata = await registry.getChainMetadata(chainName);
Expand All @@ -279,8 +277,7 @@ export async function deployToken(
symbol = 'TOKEN',
): Promise<ERC20Test> {
const { multiProvider } = await getContext({
registryUri: REGISTRY_PATH,
registryOverrideUri: '',
registryUris: [REGISTRY_PATH],
key: privateKey,
});

Expand All @@ -306,8 +303,7 @@ export async function deploy4626Vault(
tokenAddress: string,
) {
const { multiProvider } = await getContext({
registryUri: REGISTRY_PATH,
registryOverrideUri: '',
registryUris: [REGISTRY_PATH],
key: privateKey,
});

Expand Down
7 changes: 0 additions & 7 deletions typescript/cli/src/tests/commands/warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ $.verbose = true;
* Deploys the Warp route to the specified chain using the provided config.
*/
export function hyperlaneWarpInit(warpCorePath: string): ProcessPromise {
// --overrides is " " to allow local testing to work
return $`yarn workspace @hyperlane-xyz/cli run hyperlane warp init \
--registry ${REGISTRY_PATH} \
--overrides " " \
--out ${warpCorePath} \
--key ${ANVIL_KEY} \
--verbosity debug \
Expand All @@ -47,7 +45,6 @@ export function hyperlaneWarpDeployRaw({
hypKey ? ['HYP_KEY=' + hypKey] : ''
} yarn workspace @hyperlane-xyz/cli run hyperlane warp deploy \
--registry ${REGISTRY_PATH} \
--overrides " " \
${warpCorePath ? ['--config', warpCorePath] : ''} \
${privateKey ? ['--key', privateKey] : ''} \
--verbosity debug \
Expand Down Expand Up @@ -75,7 +72,6 @@ export async function hyperlaneWarpApply(
) {
return $`yarn workspace @hyperlane-xyz/cli run hyperlane warp apply \
--registry ${REGISTRY_PATH} \
--overrides " " \
--config ${warpDeployPath} \
--warp ${warpCorePath} \
--key ${ANVIL_KEY} \
Expand All @@ -99,7 +95,6 @@ export function hyperlaneWarpReadRaw({
}): ProcessPromise {
return $`yarn workspace @hyperlane-xyz/cli run hyperlane warp read \
--registry ${REGISTRY_PATH} \
--overrides " " \
${warpAddress ? ['--address', warpAddress] : ''} \
${chain ? ['--chain', chain] : ''} \
${symbol ? ['--symbol', symbol] : ''} \
Expand Down Expand Up @@ -136,7 +131,6 @@ export function hyperlaneWarpCheckRaw({
hypKey && !privateKey ? ['HYP_KEY=' + hypKey] : ''
} yarn workspace @hyperlane-xyz/cli run hyperlane warp check \
--registry ${REGISTRY_PATH} \
--overrides " " \
${symbol ? ['--symbol', symbol] : ''} \
${privateKey && !hypKey ? ['--key', privateKey] : ''} \
--verbosity debug \
Expand Down Expand Up @@ -164,7 +158,6 @@ export function hyperlaneWarpSendRelay(
return $`yarn workspace @hyperlane-xyz/cli run hyperlane warp send \
${relay ? '--relay' : ''} \
--registry ${REGISTRY_PATH} \
--overrides " " \
--origin ${origin} \
--destination ${destination} \
--warp ${warpCorePath} \
Expand Down
3 changes: 1 addition & 2 deletions typescript/infra/config/warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ async function getConfigFromMergedRegistry(
warpRouteId: string,
): Promise<ChainMap<HypTokenRouterConfig>> {
const warpRoute = await getRegistry(
DEFAULT_REGISTRY_URI,
'',
[DEFAULT_REGISTRY_URI],
true,
).getWarpDeployConfig(warpRouteId);
assert(warpRoute, `Warp route Config not found for ${warpRouteId}`);
Expand Down
3 changes: 1 addition & 2 deletions typescript/infra/test/warp-configs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ describe('Warp Configs', async function () {
before(async function () {
multiProvider = (await getHyperlaneCore(ENV)).multiProvider;
configsFromGithub = await getRegistry(
DEFAULT_GITHUB_REGISTRY,
'',
[DEFAULT_GITHUB_REGISTRY],
true,
).getWarpDeployConfigs();
});
Expand Down
2 changes: 1 addition & 1 deletion typescript/infra/test/warpIds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { WarpRouteIds } from '../config/environments/mainnet3/warp/warpIds.js';

describe('Warp IDs', () => {
it('Has all warp IDs in the registry', () => {
const registry = getRegistry(DEFAULT_GITHUB_REGISTRY, '', true);
const registry = getRegistry([DEFAULT_GITHUB_REGISTRY], true);
for (const warpId of Object.values(WarpRouteIds)) {
// That's a long sentence!
expect(
Expand Down

0 comments on commit db832b8

Please sign in to comment.