Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
fix:don't prompt user for multisig config if chain is core (hyperlane…
Browse files Browse the repository at this point in the history
…-xyz#3021)

### Description

- don't restrict user to having two chains for ism config
- if the user accidentally picks two chains, we prompt them again to
confirm if they don't want to use the hyperlane validators for their
multisigconfig

### Drive-by changes

None

### Related issues

- fixes hyperlane-xyz/issues#811

### Backward compatibility

Yes

### Testing

Manual between arbitrumgoerli and anvil1
  • Loading branch information
aroralanuk committed Dec 5, 2023
1 parent c606b6a commit 2da6cce
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
8 changes: 8 additions & 0 deletions .changeset/ninety-seas-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@hyperlane-xyz/cli': patch
---

Allow users to only configure validators for their chain

- Don't restrict user to having two chains for ism config
- If the user accidentally picks two chains, we prompt them again to confirm if they don't want to use the hyperlane validators for their multisigConfig
6 changes: 5 additions & 1 deletion typescript/cli/src/config/ism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ export async function createIsmConfigMap({
}) {
logBlue('Creating a new ISM config');
const customChains = readChainConfigsIfExists(chainConfigPath);
const chains = await runMultiChainSelectionStep(customChains);
const chains = await runMultiChainSelectionStep(
customChains,
'Select chains to configure ISM for',
true,
);

const result: ZodIsmConfigMap = {};
for (const chain of chains) {
Expand Down
14 changes: 12 additions & 2 deletions typescript/cli/src/config/multisig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { input } from '@inquirer/prompts';
import { confirm, input } from '@inquirer/prompts';
import { z } from 'zod';

import { ChainMap, MultisigConfig } from '@hyperlane-xyz/sdk';
Expand All @@ -10,6 +10,7 @@ import {
} from '@hyperlane-xyz/utils';

import { errorRed, log, logBlue, logGreen } from '../../logger.js';
import { sdkContractAddressesMap } from '../context.js';
import { runMultiChainSelectionStep } from '../utils/chains.js';
import { FileFormat, mergeYamlOrJson, readYamlOrJson } from '../utils/files.js';

Expand Down Expand Up @@ -72,6 +73,9 @@ export async function createMultisigConfig({
chainConfigPath: string;
}) {
logBlue('Creating a new multisig config');
log(
'Select your own chain below to run your own validators. If you want to reuse existing Hyperlane validators instead of running your own, do not select additional mainnet or testnet chains.',
);
const customChains = readChainConfigsIfExists(chainConfigPath);
const chains = await runMultiChainSelectionStep(customChains);

Expand All @@ -84,6 +88,12 @@ export async function createMultisigConfig({
result[chain] = lastConfig;
continue;
}
if (Object.keys(sdkContractAddressesMap).includes(chain)) {
const reuseCoreConfig = await confirm({
message: 'Use existing Hyperlane validators for this chain?',
});
if (reuseCoreConfig) continue;
}

const thresholdInput = await input({
message: 'Enter threshold of signers (number)',
Expand Down Expand Up @@ -111,7 +121,7 @@ export async function createMultisigConfig({
mergeYamlOrJson(outPath, result, format);
} else {
errorRed(
`Multisig config is invalid, please see https://github.com/hyperlane-xyz/hyperlane-monorepo/blob/main/typescript/cli/examples/multisig-ism.yaml for an example`,
`Multisig config is invalid, please see https://github.com/hyperlane-xyz/hyperlane-monorepo/blob/main/typescript/cli/examples/ism.yaml for an example`,
);
throw new Error('Invalid multisig config');
}
Expand Down
1 change: 1 addition & 0 deletions typescript/cli/src/deploy/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export async function runKurtosisAgentDeploy({
const selectedRelayChains = await runMultiChainSelectionStep(
customChains,
'Select chains to relay between',
true,
);
relayChains = selectedRelayChains.join(',');
}
Expand Down
1 change: 1 addition & 0 deletions typescript/cli/src/deploy/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export async function runCoreDeploy({
chains = await runMultiChainSelectionStep(
customChains,
'Select chains to connect',
true,
);
}
const artifacts = await runArtifactStep(chains, artifactsPath);
Expand Down
21 changes: 9 additions & 12 deletions typescript/cli/src/utils/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import chalk from 'chalk';
import {
ChainMap,
ChainMetadata,
ChainName,
mainnetChainsMetadata,
testnetChainsMetadata,
} from '@hyperlane-xyz/sdk';
Expand Down Expand Up @@ -33,9 +32,9 @@ export async function runSingleChainSelectionStep(
export async function runMultiChainSelectionStep(
customChains: ChainMap<ChainMetadata>,
message = 'Select chains',
chainsToFilterOut: ChainName[] = [],
requireMultiple = false,
) {
const choices = getChainChoices(customChains, chainsToFilterOut);
const choices = getChainChoices(customChains);
while (true) {
logTip('Use SPACE key to select chains, then press ENTER');
const chains = (await checkbox({
Expand All @@ -44,19 +43,17 @@ export async function runMultiChainSelectionStep(
pageSize: 20,
})) as string[];
handleNewChain(chains);
if (chains?.length >= 2) return chains;
else logRed('Please select at least 2 chains');
if (requireMultiple && chains?.length < 2) {
logRed('Please select at least 2 chains');
continue;
}
return chains;
}
}

function getChainChoices(
customChains: ChainMap<ChainMetadata>,
chainsToFilterOut: ChainName[] = [],
) {
function getChainChoices(customChains: ChainMap<ChainMetadata>) {
const chainsToChoices = (chains: ChainMetadata[]) =>
chains
.filter((chain) => !chainsToFilterOut.includes(chain.name))
.map((c) => ({ name: c.name, value: c.name }));
chains.map((c) => ({ name: c.name, value: c.name }));
const choices: Parameters<typeof select>['0']['choices'] = [
new Separator('--Custom Chains--'),
...chainsToChoices(Object.values(customChains)),
Expand Down

0 comments on commit 2da6cce

Please sign in to comment.