Skip to content

Commit

Permalink
Specify per-agent chains to deploy to in deploy-agents (#2669)
Browse files Browse the repository at this point in the history
### Description

In addition to the context, also configure the **chains** that an agent
is deployable to.

### Drive-by changes

<!--
Are there any minor or drive-by changes also included?
-->

### Related issues

- Fixes #2664

### Backward compatibility

<!--
Are these changes backward compatible? Are there any infrastructure
implications, e.g. changes that would prohibit deploying older commits
using this infra tooling?

Yes/No
-->

### Testing
Dry-ran the script for the three agents. Output for the validator looks
wrong though:
```
% npx ts-node typescript/infra/scripts/agents/deploy-agents.ts -e mainnet2 -r validator --dry-run
undefined
```
  • Loading branch information
daniel-savu authored Aug 17, 2023
1 parent bd02b8d commit 4a59af3
Show file tree
Hide file tree
Showing 19 changed files with 105 additions and 51 deletions.
4 changes: 2 additions & 2 deletions typescript/infra/config/aggregationIsm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import { objFilter, objMap } from '@hyperlane-xyz/utils';
import { DeployEnvironment } from '../src/config';

import { Contexts } from './contexts';
import { chainNames as mainnet2Chains } from './environments/mainnet2/chains';
import { supportedChainNames as mainnet2Chains } from './environments/mainnet2/chains';
import { owners as mainnet2Owners } from './environments/mainnet2/owners';
import { chainNames as testChains } from './environments/test/chains';
import { owners as testOwners } from './environments/test/owners';
import { chainNames as testnet3Chains } from './environments/testnet3/chains';
import { supportedChainNames as testnet3Chains } from './environments/testnet3/chains';
import { owners as testnet3Owners } from './environments/testnet3/owners';
import { rcMultisigIsmConfigs } from './multisigIsm';

Expand Down
4 changes: 2 additions & 2 deletions typescript/infra/config/environments/mainnet2/agent.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
AgentConnectionType,
chainMetadata,
getDomainId,
hyperlaneEnvironments,
} from '@hyperlane-xyz/sdk';
import { objMap } from '@hyperlane-xyz/utils';

import {
GasPaymentEnforcementPolicyType,
RootAgentConfig,
allAgentChainNames,
routerMatchingList,
} from '../../../src/config';
import { GasPaymentEnforcementConfig } from '../../../src/config/agent/relayer';
Expand Down Expand Up @@ -42,7 +42,7 @@ const contextBase = {
namespace: environment,
runEnv: environment,
contextChainNames: agentChainNames,
environmentChainNames: agentChainNames,
environmentChainNames: allAgentChainNames(agentChainNames),
aws: {
region: 'us-east-1',
},
Expand Down
19 changes: 15 additions & 4 deletions typescript/infra/config/environments/mainnet2/chains.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ChainMap, ChainMetadata, chainMetadata } from '@hyperlane-xyz/sdk';

import { AgentChainNames, Role } from '../../../src/roles';

export const mainnetConfigs: ChainMap<ChainMetadata> = {
bsc: {
...chainMetadata.bsc,
Expand Down Expand Up @@ -39,12 +41,21 @@ export const mainnetConfigs: ChainMap<ChainMetadata> = {
};

export type MainnetChains = keyof typeof mainnetConfigs;
export const chainNames = Object.keys(mainnetConfigs) as MainnetChains[];
export const supportedChainNames = Object.keys(
mainnetConfigs,
) as MainnetChains[];
export const environment = 'mainnet2';

// Chains that we want to run agents for.
export const agentChainNames = [
...chainNames,
const validatorChainNames = [
...supportedChainNames,
chainMetadata.solana.name,
chainMetadata.nautilus.name,
];

const relayerChainNames = validatorChainNames;

export const agentChainNames: AgentChainNames = {
[Role.Validator]: validatorChainNames,
[Role.Relayer]: relayerChainNames,
[Role.Scraper]: supportedChainNames,
};
8 changes: 6 additions & 2 deletions typescript/infra/config/environments/mainnet2/gas-oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '../../../src/config';
import { TOKEN_EXCHANGE_RATE_DECIMALS } from '../../../src/config/gas-oracle';

import { chainNames } from './chains';
import { supportedChainNames } from './chains';

// Overcharge by 30% to account for market making risk
const TOKEN_EXCHANGE_RATE_MULTIPLIER = ethers.utils.parseUnits(
Expand Down Expand Up @@ -81,4 +81,8 @@ function getTokenExchangeRate(local: ChainName, remote: ChainName): BigNumber {
}

export const storageGasOracleConfig: AllStorageGasOracleConfigs =
getAllStorageGasOracleConfigs(chainNames, gasPrices, getTokenExchangeRate);
getAllStorageGasOracleConfigs(
supportedChainNames,
gasPrices,
getTokenExchangeRate,
);
6 changes: 3 additions & 3 deletions typescript/infra/config/environments/mainnet2/igp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '@hyperlane-xyz/sdk';
import { exclude, objMap } from '@hyperlane-xyz/utils';

import { MainnetChains, chainNames } from './chains';
import { MainnetChains, supportedChainNames } from './chains';
import { core } from './core';
import { owners } from './owners';

Expand All @@ -17,7 +17,7 @@ const DEPLOYER_ADDRESS = '0xa7ECcdb9Be08178f896c26b7BbD8C3D4E844d9Ba';

function getGasOracles(local: MainnetChains) {
return Object.fromEntries(
exclude(local, chainNames).map((name) => [
exclude(local, supportedChainNames).map((name) => [
name,
GasOracleContractType.StorageGasOracle,
]),
Expand All @@ -33,7 +33,7 @@ export const igp: ChainMap<OverheadIgpConfig> = objMap(
beneficiary: KEY_FUNDER_ADDRESS,
gasOracleType: getGasOracles(chain),
overhead: Object.fromEntries(
exclude(chain, chainNames).map((remote) => [
exclude(chain, supportedChainNames).map((remote) => [
remote,
multisigIsmVerificationCost(
defaultMultisigIsmConfigs[remote].threshold,
Expand Down
4 changes: 2 additions & 2 deletions typescript/infra/config/environments/test/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { ALL_KEY_ROLES } from '../../../src/roles';
import { Contexts } from '../../contexts';

import { chainNames } from './chains';
import { agentChainNames, chainNames } from './chains';
import { validators } from './validators';

const roleBase = {
Expand All @@ -23,7 +23,7 @@ const hyperlane: RootAgentConfig = {
runEnv: 'test',
context: Contexts.Hyperlane,
rolesWithKeys: ALL_KEY_ROLES,
contextChainNames: chainNames,
contextChainNames: agentChainNames,
environmentChainNames: chainNames,
relayer: {
...roleBase,
Expand Down
8 changes: 8 additions & 0 deletions typescript/infra/config/environments/test/chains.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ChainMap, ChainMetadata, chainMetadata } from '@hyperlane-xyz/sdk';

import { AgentChainNames, Role } from '../../../src/roles';

export const testConfigs: ChainMap<ChainMetadata> = {
test1: chainMetadata.test1,
test2: chainMetadata.test2,
Expand All @@ -8,3 +10,9 @@ export const testConfigs: ChainMap<ChainMetadata> = {

export type TestChains = keyof typeof testConfigs;
export const chainNames = Object.keys(testConfigs) as TestChains[];

export const agentChainNames: AgentChainNames = {
[Role.Validator]: chainNames,
[Role.Relayer]: chainNames,
[Role.Scraper]: chainNames,
};
6 changes: 3 additions & 3 deletions typescript/infra/config/environments/testnet3/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import { objMap } from '@hyperlane-xyz/utils';
import {
GasPaymentEnforcementPolicyType,
RootAgentConfig,
allAgentChainNames,
routerMatchingList,
} from '../../../src/config';
import { GasPaymentEnforcementConfig } from '../../../src/config/agent/relayer';
import { ALL_KEY_ROLES, Role } from '../../../src/roles';
import { Contexts } from '../../contexts';
import { chainNames } from '../mainnet2/chains';

import { agentChainNames, environment } from './chains';
import { helloWorld } from './helloworld';
Expand Down Expand Up @@ -44,7 +44,7 @@ const contextBase = {
namespace: environment,
runEnv: environment,
contextChainNames: agentChainNames,
environmentChainNames: agentChainNames,
environmentChainNames: allAgentChainNames(agentChainNames),
aws: {
region: 'us-east-1',
},
Expand All @@ -67,7 +67,7 @@ const gasPaymentEnforcement: GasPaymentEnforcementConfig[] = [

const hyperlane: RootAgentConfig = {
...contextBase,
contextChainNames: chainNames,
contextChainNames: agentChainNames,
context: Contexts.Hyperlane,
rolesWithKeys: ALL_KEY_ROLES,
relayer: {
Expand Down
23 changes: 17 additions & 6 deletions typescript/infra/config/environments/testnet3/chains.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ChainMap, ChainMetadata, chainMetadata } from '@hyperlane-xyz/sdk';

import { AgentChainNames, AgentRole, Role } from '../../../src/roles';

export const testnetConfigs: ChainMap<ChainMetadata> = {
alfajores: chainMetadata.alfajores,
fuji: chainMetadata.fuji,
Expand All @@ -20,12 +22,21 @@ export const testnetConfigs: ChainMap<ChainMetadata> = {

// "Blessed" chains that we want core contracts for.
export type TestnetChains = keyof typeof testnetConfigs;
export const chainNames = Object.keys(testnetConfigs) as TestnetChains[];
export const supportedChainNames = Object.keys(
testnetConfigs,
) as TestnetChains[];
export const environment = 'testnet3';

// Chains that we want to run agents for.
export const agentChainNames = [
...chainNames,
'solanadevnet',
'proteustestnet',
const validatorChainNames = [
...supportedChainNames,
chainMetadata.solanadevnet.name,
chainMetadata.proteustestnet.name,
];

const relayerChainNames = validatorChainNames;

export const agentChainNames: AgentChainNames = {
[Role.Validator]: validatorChainNames,
[Role.Relayer]: relayerChainNames,
[Role.Scraper]: supportedChainNames,
};
8 changes: 6 additions & 2 deletions typescript/infra/config/environments/testnet3/gas-oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '../../../src/config';
import { TOKEN_EXCHANGE_RATE_DECIMALS } from '../../../src/config/gas-oracle';

import { TestnetChains, chainNames } from './chains';
import { TestnetChains, supportedChainNames } from './chains';

// Overcharge by 30% to account for market making risk
const TOKEN_EXCHANGE_RATE_MULTIPLIER = ethers.utils.parseUnits(
Expand Down Expand Up @@ -73,4 +73,8 @@ function getTokenExchangeRate(local: ChainName, remote: ChainName): BigNumber {
}

export const storageGasOracleConfig: AllStorageGasOracleConfigs =
getAllStorageGasOracleConfigs(chainNames, gasPrices, getTokenExchangeRate);
getAllStorageGasOracleConfigs(
supportedChainNames,
gasPrices,
getTokenExchangeRate,
);
6 changes: 3 additions & 3 deletions typescript/infra/config/environments/testnet3/igp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import {
} from '@hyperlane-xyz/sdk';
import { exclude, objMap } from '@hyperlane-xyz/utils';

import { TestnetChains, chainNames } from './chains';
import { TestnetChains, supportedChainNames } from './chains';
import { owners } from './owners';

function getGasOracles(local: TestnetChains) {
return Object.fromEntries(
exclude(local, chainNames).map((name) => [
exclude(local, supportedChainNames).map((name) => [
name,
GasOracleContractType.StorageGasOracle,
]),
Expand All @@ -28,7 +28,7 @@ export const igp: ChainMap<OverheadIgpConfig> = objMap(
beneficiary: owner,
gasOracleType: getGasOracles(chain),
overhead: Object.fromEntries(
exclude(chain, chainNames).map((remote) => [
exclude(chain, supportedChainNames).map((remote) => [
remote,
multisigIsmVerificationCost(
defaultMultisigIsmConfigs[remote].threshold,
Expand Down
4 changes: 2 additions & 2 deletions typescript/infra/config/environments/testnet3/owners.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ChainMap } from '@hyperlane-xyz/sdk';
import { Address } from '@hyperlane-xyz/utils';

import { chainNames } from './chains';
import { supportedChainNames } from './chains';

const DEPLOYER_ADDRESS = '0xfaD1C94469700833717Fa8a3017278BC1cA8031C';

export const owners: ChainMap<Address> = Object.fromEntries(
chainNames.map((chain) => [chain, DEPLOYER_ADDRESS]),
supportedChainNames.map((chain) => [chain, DEPLOYER_ADDRESS]),
);
2 changes: 1 addition & 1 deletion typescript/infra/scripts/agents/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class AgentCli {
for (const role of this.roles) {
switch (role) {
case Role.Validator:
for (const chain of this.agentConfig.contextChainNames) {
for (const chain of this.agentConfig.contextChainNames[role]) {
if (chain !== 'solana' && chain !== 'nautilus') continue;
const key = `${role}-${chain}`;
managers[key] = new ValidatorHelmManager(this.agentConfig, chain);
Expand Down
4 changes: 2 additions & 2 deletions typescript/infra/scripts/funding/fund-keys-from-deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
import { DeployEnvironment } from '../../src/config';
import { deployEnvToSdkEnv } from '../../src/config/environment';
import { ContextAndRoles, ContextAndRolesMap } from '../../src/config/funding';
import { Role } from '../../src/roles';
import { AgentRole, Role } from '../../src/roles';
import { submitMetrics } from '../../src/utils/metrics';
import {
assertContext,
Expand Down Expand Up @@ -403,7 +403,7 @@ class ContextFunder {
key.context,
key.environment,
).contextChainNames;
for (const chain of chains) {
for (const chain of chains[role as AgentRole]) {
chainKeys[chain].push(key);
}
}
Expand Down
8 changes: 4 additions & 4 deletions typescript/infra/src/agents/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
ScraperConfigHelper,
ValidatorConfigHelper,
} from '../config';
import { Role } from '../roles';
import { AgentRole, Role } from '../roles';
import { fetchGCPSecret } from '../utils/gcloud';
import {
HelmCommand,
Expand All @@ -37,7 +37,7 @@ if (!fs.existsSync(HELM_CHART_PATH + 'Chart.yaml'))
);

export abstract class AgentHelmManager {
abstract readonly role: Role;
abstract readonly role: AgentRole;
abstract readonly helmReleaseName: string;
readonly helmChartPath: string = HELM_CHART_PATH;
protected abstract readonly config: AgentConfigHelper;
Expand Down Expand Up @@ -119,7 +119,7 @@ export abstract class AgentHelmManager {
aws: !!this.config.aws,
chains: this.config.environmentChainNames.map((name) => ({
name,
disabled: !this.config.contextChainNames.includes(name),
disabled: !this.config.contextChainNames[this.role].includes(name),
connection: { type: this.connectionType(name) },
})),
},
Expand Down Expand Up @@ -240,7 +240,7 @@ export class ValidatorHelmManager extends MultichainAgentHelmManager {
constructor(config: RootAgentConfig, chainName: ChainName) {
super(chainName);
this.config = new ValidatorConfigHelper(config, chainName);
if (!this.config.contextChainNames.includes(chainName))
if (!this.config.contextChainNames[this.role].includes(chainName))
throw Error('Context does not support chain');
if (!this.config.environmentChainNames.includes(chainName))
throw Error('Environment does not support chain');
Expand Down
14 changes: 8 additions & 6 deletions typescript/infra/src/agents/key-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function getRelayerCloudAgentKeys(

const keys = [];
keys.push(new AgentAwsKey(agentConfig, Role.Relayer));
const nonEthereumChains = agentConfig.contextChainNames.find(
const nonEthereumChains = agentConfig.contextChainNames[Role.Relayer].find(
(chainName) => chainMetadata[chainName].protocol !== ProtocolType.Ethereum,
);
// If there are any non-ethereum chains, we also want hex keys.
Expand Down Expand Up @@ -71,11 +71,13 @@ export function getValidatorCloudAgentKeys(
// For each chainName, create validatorCount keys
if (!agentConfig.validators) return [];
const validators = agentConfig.validators;
return agentConfig.contextChainNames.flatMap((chainName) =>
validators.chains[chainName].validators.map((_, index) =>
getCloudAgentKey(agentConfig, Role.Validator, chainName, index),
),
);
return agentConfig.contextChainNames[Role.Validator]
.filter((chainName) => !!validators.chains[chainName])
.flatMap((chainName) =>
validators.chains[chainName].validators.map((_, index) =>
getCloudAgentKey(agentConfig, Role.Validator, chainName, index),
),
);
}

export function getAllCloudAgentKeys(
Expand Down
Loading

0 comments on commit 4a59af3

Please sign in to comment.