Skip to content

Commit

Permalink
Touchups
Browse files Browse the repository at this point in the history
  • Loading branch information
tkporter committed Oct 30, 2023
1 parent d211dc2 commit ce5fecb
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
{{- range .Values.hyperlane.relayerChains }}
{{- if or (eq .signer.type "hexKey") (eq .signer.type "cosmosKey") }}
HYP_CHAINS_{{ .name | upper }}_SIGNER_KEY: {{ printf "'{{ .%s_signer_key | toString }}'" .name }}
{{- include "agent-common.config-env-vars" (dict "config" . "format" "config_map" "key_name_prefix" (printf "CHAINS_%s_SIGNER_" (.name | upper))) | nindent 8 }}
{{- include "agent-common.config-env-vars" (dict "config" .signer "format" "config_map" "key_name_prefix" (printf "CHAINS_%s_SIGNER_" (.name | upper))) | nindent 8 }}
{{- end }}
{{- if and (eq .signer.type "aws") $.Values.hyperlane.relayer.aws }}
HYP_CHAINS_{{ .name | upper }}_SIGNER_TYPE: aws
Expand Down
16 changes: 5 additions & 11 deletions typescript/infra/config/environments/mainnet3/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const ethereumMainnetConfigs: ChainMap<ChainMetadata> = {
},
moonbeam: chainMetadata.moonbeam,
gnosis: chainMetadata.gnosis,

mantapacific: chainMetadata.mantapacific,
};

Expand All @@ -66,16 +65,11 @@ export const ethereumChainNames = Object.keys(
ethereumMainnetConfigs,
) as MainnetChains[];

const validatorChainNames = [
...supportedChainNames,
// chainMetadata.solana.name,
// chainMetadata.nautilus.name,
];

const relayerChainNames = validatorChainNames;

// Hyperlane & RC context agent chain names.
export const agentChainNames: AgentChainNames = {
[Role.Validator]: validatorChainNames,
[Role.Relayer]: relayerChainNames,
// Run validators for all chains.
[Role.Validator]: supportedChainNames,
// Only run relayers for Ethereum chains at the moment.
[Role.Relayer]: ethereumChainNames,
[Role.Scraper]: ethereumChainNames,
};
4 changes: 2 additions & 2 deletions typescript/infra/config/environments/testnet4/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const hyperlane: RootAgentConfig = {
},
chainDockerOverrides: {
neutrontestnet: {
tag: 'eea130c-20231027-115055',
tag: '31822d0-20231030-003417',
},
},
chains: validatorChainConfig(Contexts.Hyperlane),
Expand Down Expand Up @@ -125,7 +125,7 @@ const neutron: RootAgentConfig = {
rpcConsensusType: RpcConsensusType.Fallback,
docker: {
repo,
tag: 'eea130c-20231027-115055',
tag: '31822d0-20231030-003417',
},
gasPaymentEnforcement,
transactionGasLimit: 750000,
Expand Down
9 changes: 5 additions & 4 deletions typescript/infra/config/environments/testnet4/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ export const environment = 'testnet4';
export const ethereumChainNames = Object.keys(
ethereumTestnetConfigs,
) as TestnetChains[];
const validatorChainNames = supportedChainNames;
const relayerChainNames = validatorChainNames;

// Hyperlane & RC context agent chain names.
export const agentChainNames: AgentChainNames = {
[Role.Validator]: validatorChainNames,
[Role.Relayer]: relayerChainNames,
// Run validators for all chains.
[Role.Validator]: supportedChainNames,
// Only run relayers for Ethereum chains at the moment.
[Role.Relayer]: ethereumChainNames,
[Role.Scraper]: ethereumChainNames,
};
24 changes: 10 additions & 14 deletions typescript/infra/scripts/agents/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export class AgentCli {
agentConfig!: RootAgentConfig;
initialized = false;
dryRun = false;
// Whether to run deployments in parallel
parallel = false;

public async runHelmCommand(command: HelmCommand) {
await this.init();
Expand All @@ -34,12 +36,6 @@ export class AgentCli {
switch (role) {
case Role.Validator:
for (const chain of this.agentConfig.contextChainNames[role]) {
if (
chain !== 'neutrontestnet' &&
chain !== 'neutron' &&
chain !== 'mantapacific'
)
continue;
const key = `${role}-${chain}`;
managers[key] = new ValidatorHelmManager(this.agentConfig, chain);
}
Expand Down Expand Up @@ -67,21 +63,21 @@ export class AgentCli {
}
}

protected async init(
argv?: GetConfigsArgv & { role: Role[]; 'dry-run'?: boolean },
) {
protected async init() {
if (this.initialized) return;
if (!argv)
argv = await withAgentRole(withContext(getArgs()))
.describe('dry-run', 'Run through the steps without making any changes')
.boolean('dry-run').argv;
const argv = await withAgentRole(withContext(getArgs()))
.describe('dry-run', 'Run through the steps without making any changes')
.boolean('dry-run')
.describe('parallel', 'Whether to run deployments in parallel')
.boolean('parallel').argv;

const { envConfig, agentConfig } = await getConfigsBasedOnArgs(argv);
await assertCorrectKubeContext(envConfig);
this.roles = argv.role;
this.envConfig = envConfig;
this.agentConfig = agentConfig;
this.dryRun = argv['dry-run'] || false;
this.dryRun = argv.dryRun || false;
this.parallel = argv.parallel || false;
this.initialized = true;
}
}
21 changes: 21 additions & 0 deletions typescript/infra/src/config/agent/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
AgentSignerKeyType,
ChainName,
RpcConsensusType,
chainMetadata,
} from '@hyperlane-xyz/sdk';
import { ProtocolType } from '@hyperlane-xyz/utils';

import { Contexts } from '../../../config/contexts';
import { AgentChainNames, Role } from '../../roles';
Expand Down Expand Up @@ -186,3 +188,22 @@ export abstract class AgentConfigHelper<R = unknown>
export const allAgentChainNames = (agentChainNames: AgentChainNames) => [
...new Set(Object.values(agentChainNames).reduce((a, b) => a.concat(b), [])),
];

// Returns the default KeyConfig for the `chainName`'s chain signer.
// For Ethereum or Sealevel, this is a hexKey, for Cosmos, this is a cosmosKey.
export function defaultChainSignerKeyConfig(chainName: ChainName): KeyConfig {
const metadata = chainMetadata[chainName];

switch (metadata?.protocol) {
case ProtocolType.Cosmos:
if (metadata.bech32Prefix === undefined) {
throw new Error(`Bech32 prefix for cosmos chain ${name} is undefined`);
}
return { type: AgentSignerKeyType.Cosmos, prefix: metadata.bech32Prefix };
// For Ethereum and Sealevel, use a hex key
case ProtocolType.Ethereum:
case ProtocolType.Sealevel:
default:
return { type: AgentSignerKeyType.Hex };
}
}
44 changes: 25 additions & 19 deletions typescript/infra/src/config/agent/relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import { AgentAwsUser } from '../../agents/aws';
import { Role } from '../../roles';
import { HelmStatefulSetValues } from '../infrastructure';

import { AgentConfigHelper, KeyConfig, RootAgentConfig } from './agent';
import {
AgentConfigHelper,
KeyConfig,
RootAgentConfig,
defaultChainSignerKeyConfig,
} from './agent';

export { GasPaymentEnforcement as GasPaymentEnforcementConfig } from '@hyperlane-xyz/sdk';

Expand Down Expand Up @@ -83,6 +88,8 @@ export class RelayerConfigHelper extends AgentConfigHelper<RelayerConfig> {

// Get the signer configuration for each chain by the chain name.
async signers(): Promise<ChainMap<KeyConfig>> {
let chainSigners: ChainMap<KeyConfig> = {};

if (this.aws) {
const awsUser = new AgentAwsUser(
this.runEnv,
Expand All @@ -92,25 +99,24 @@ export class RelayerConfigHelper extends AgentConfigHelper<RelayerConfig> {
);
await awsUser.createIfNotExists();
const awsKey = (await awsUser.createKeyIfNotExists(this)).keyConfig;
return Object.fromEntries(
this.contextChainNames[Role.Relayer].map((name) => {
const chain = chainMetadata[name];
if (chain?.protocol === ProtocolType.Ethereum) {
return [name, awsKey];
} else {
// Non-ethereum chains always use hex keys
return [name, { type: AgentSignerKeyType.Hex }];
}
}),
);
} else {
return Object.fromEntries(
this.contextChainNames[Role.Relayer].map((name) => [
name,
{ type: AgentSignerKeyType.Hex },
]),
);

// AWS keys only work for Ethereum chains
for (const chainName of this.relayChains) {
if (chainMetadata[chainName].protocol === ProtocolType.Ethereum) {
chainSigners[chainName] = awsKey;
}
}
}

// For any chains that were not configured with AWS keys, fill in the defaults
for (const chainName of this.relayChains) {
if (chainSigners[chainName] !== undefined) {
continue;
}
chainSigners[chainName] = defaultChainSignerKeyConfig(chainName);
}

return chainSigners;
}

// Returns whether the relayer requires AWS credentials
Expand Down
14 changes: 13 additions & 1 deletion typescript/infra/src/config/agent/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import { AgentAwsUser, ValidatorAgentAwsUser } from '../../agents/aws';
import { Role } from '../../roles';
import { HelmStatefulSetValues } from '../infrastructure';

import { AgentConfigHelper, KeyConfig, RootAgentConfig } from './agent';
import {
AgentConfigHelper,
KeyConfig,
RootAgentConfig,
defaultChainSignerKeyConfig,
} from './agent';

// Validator agents for each chain.
export type ValidatorBaseChainConfigMap = ChainMap<ValidatorBaseChainConfig>;
Expand Down Expand Up @@ -162,6 +167,13 @@ export class ValidatorConfigHelper extends AgentConfigHelper<ValidatorConfig> {
);
}

// If the chainSigner isn't set to the AWS-based key above, then set the default.
// There is no self-announcement on Sealevel, so in that case we just skip the
// chain signer altogether
if (chainSigner === undefined && protocol !== ProtocolType.Sealevel) {
chainSigner = defaultChainSignerKeyConfig(this.chainName);
}

return {
checkpointSyncer: cfg.checkpointSyncer,
validator,
Expand Down

0 comments on commit ce5fecb

Please sign in to comment.