Skip to content

Commit

Permalink
Merge branch 'main' of github.com:abacus-network/abacus-monorepo into…
Browse files Browse the repository at this point in the history
… trevor/addtl-igp-cmds
  • Loading branch information
tkporter committed Oct 5, 2023
2 parents fa45809 + 8687e56 commit c4387cf
Show file tree
Hide file tree
Showing 22 changed files with 202 additions and 153 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Hyperlane is an interchain messaging protocol that allows applications to commun

Developers can use Hyperlane to share state between blockchains, allowing them to build interchain applications that live natively across multiple chains.

To read more about interchain applications, how the protocol works, and how to integrate with Hyperlane, please see the [documentation](https://docs.hyperlane.xyz/).
To read more about interchain applications, how the protocol works, and how to integrate with Hyperlane, please see the [documentation](https://docs.hyperlane.xyz).

## Working on Hyperlane

Expand Down
4 changes: 2 additions & 2 deletions typescript/helloworld/src/app/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type StatCounts = {
sent: number | bigint;
received: number | bigint;
sent: number;
received: number;
};
16 changes: 2 additions & 14 deletions typescript/helloworld/src/multiProtocolApp/evmAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from '@hyperlane-xyz/sdk';
import { Address } from '@hyperlane-xyz/utils';

import { StatCounts } from '../app/types';
import { HelloWorld, HelloWorld__factory } from '../types';

import { IHelloWorldAdapter } from './types';
Expand Down Expand Up @@ -55,22 +54,11 @@ export class EvmHelloWorldAdapter
return { transaction: tx, type: ProviderType.EthersV5 };
}

async channelStats(
destination: ChainName,
destinationMailbox: Address,
): Promise<StatCounts> {
const originDomain = this.multiProvider.getDomainId(this.chainName);
async sentStat(destination: ChainName): Promise<number> {
const destinationDomain = this.multiProvider.getDomainId(destination);
const originContract = this.getConnectedContract();
const sent = await originContract.sentTo(destinationDomain);
const destinationProvider =
this.multiProvider.getEthersV5Provider(destination);
const destinationContract = HelloWorld__factory.connect(
destinationMailbox,
destinationProvider,
);
const received = await destinationContract.sentTo(originDomain);
return { sent: sent.toNumber(), received: received.toNumber() };
return sent.toNumber();
}

override getConnectedContract(): HelloWorld {
Expand Down
14 changes: 9 additions & 5 deletions typescript/helloworld/src/multiProtocolApp/multiProtocolApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@ export class HelloMultiProtocolApp extends MultiProtocolRouterApp<
);
}

channelStats(origin: ChainName, destination: ChainName): Promise<StatCounts> {
return this.adapter(origin).channelStats(
destination,
this.addresses[destination].mailbox,
);
async channelStats(
origin: ChainName,
destination: ChainName,
): Promise<StatCounts> {
const [sent, received] = await Promise.all([
this.adapter(origin).sentStat(destination),
this.adapter(destination).sentStat(origin),
]);
return { sent, received };
}

async stats(): Promise<ChainMap<ChainMap<StatCounts>>> {
Expand Down
15 changes: 6 additions & 9 deletions typescript/helloworld/src/multiProtocolApp/sealevelAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import {
} from '@hyperlane-xyz/sdk';
import { Address, Domain } from '@hyperlane-xyz/utils';

import { StatCounts } from '../app/types';

import { IHelloWorldAdapter } from './types';

export class SealevelHelloWorldAdapter
Expand Down Expand Up @@ -164,21 +162,20 @@ export class SealevelHelloWorldAdapter
);
}

async channelStats(_destination: ChainName): Promise<StatCounts> {
async sentStat(destination: ChainName): Promise<number> {
const destinationDomain = this.multiProvider.getDomainId(destination);
const data = await this.getAccountInfo();
return { sent: data.sent, received: data.received };
return Number(data.sent_to.get(destinationDomain) || 0);
}

async getAccountInfo(): Promise<HelloWorldData> {
const address = this.addresses.router;
const connection = this.getProvider();

const msgRecipientPda = this.deriveMessageRecipientPda(address);
const accountInfo = await connection.getAccountInfo(msgRecipientPda);
const pda = this.deriveProgramStoragePDA(address);
const accountInfo = await connection.getAccountInfo(pda);
if (!accountInfo)
throw new Error(
`No account info found for ${msgRecipientPda.toBase58()}}`,
);
throw new Error(`No account info found for ${pda.toBase58()}}`);

const accountData = deserializeUnchecked(
HelloWorldDataSchema,
Expand Down
9 changes: 1 addition & 8 deletions typescript/helloworld/src/multiProtocolApp/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
} from '@hyperlane-xyz/sdk';
import { Address } from '@hyperlane-xyz/utils';

import { StatCounts } from '../app/types';

export interface IHelloWorldAdapter extends IRouterAdapter {
populateSendHelloTx: (
destination: ChainName,
Expand All @@ -15,10 +13,5 @@ export interface IHelloWorldAdapter extends IRouterAdapter {
sender: Address,
) => Promise<TypedTransaction>;

// TODO break apart into separate origin + destination methods to
// handle case where origin/dest protocols differ
channelStats: (
destination: ChainName,
destinationMailbox: Address,
) => Promise<StatCounts>;
sentStat: (destination: ChainName) => Promise<number>;
}
6 changes: 3 additions & 3 deletions typescript/infra/config/environments/mainnet2/helloworld.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AgentConnectionType } from '@hyperlane-xyz/sdk';

import { HelloWorldConfig } from '../../../src/config';
import { HelloWorldKathyRunMode } from '../../../src/config/helloworld';
import { HelloWorldKathyRunMode } from '../../../src/config/helloworld/types';
import { Contexts } from '../../contexts';

import { environment } from './chains';
Expand All @@ -13,7 +13,7 @@ export const hyperlane: HelloWorldConfig = {
kathy: {
docker: {
repo: 'gcr.io/abacus-labs-dev/hyperlane-monorepo',
tag: '4c598b9-20230503-205323',
tag: '25da8e0-20231004-135818',
},
chainsToSkip: [],
runEnv: environment,
Expand All @@ -34,7 +34,7 @@ export const releaseCandidate: HelloWorldConfig = {
kathy: {
docker: {
repo: 'gcr.io/abacus-labs-dev/hyperlane-monorepo',
tag: '25f19b7-20230319-124624',
tag: '25da8e0-20231004-135818',
},
chainsToSkip: [],
runEnv: environment,
Expand Down
6 changes: 3 additions & 3 deletions typescript/infra/config/environments/testnet3/helloworld.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AgentConnectionType } from '@hyperlane-xyz/sdk';

import { HelloWorldConfig } from '../../../src/config';
import { HelloWorldKathyRunMode } from '../../../src/config/helloworld';
import { HelloWorldKathyRunMode } from '../../../src/config/helloworld/types';
import { Contexts } from '../../contexts';

import { environment } from './chains';
Expand All @@ -13,7 +13,7 @@ export const hyperlaneHelloworld: HelloWorldConfig = {
kathy: {
docker: {
repo: 'gcr.io/abacus-labs-dev/hyperlane-monorepo',
tag: '4c598b9-20230503-205323',
tag: '25da8e0-20231004-135818',
},
chainsToSkip: [],
runEnv: environment,
Expand All @@ -33,7 +33,7 @@ export const releaseCandidateHelloworld: HelloWorldConfig = {
kathy: {
docker: {
repo: 'gcr.io/abacus-labs-dev/hyperlane-monorepo',
tag: '25f19b7-20230319-124624',
tag: '25da8e0-20231004-135818',
},
chainsToSkip: [],
runEnv: environment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ spec:
data:
GCP_SECRET_OVERRIDES_ENABLED: "true"
GCP_SECRET_OVERRIDE_HYPERLANE_{{ .Values.hyperlane.runEnv | upper }}_KEY_DEPLOYER: {{ print "'{{ .deployer_key | toString }}'" }}
{{/*
{{/*
* Always get the GCP-based key, which is used for non-EVM chains.
*/}}
GCP_SECRET_OVERRIDE_{{ .Values.hyperlane.context | upper }}_{{ .Values.hyperlane.runEnv | upper }}_KEY_KATHY: {{ print "'{{ .gcp_private_key | toString }}'" }}
{{/*
* For each network, create an environment variable with the RPC endpoint.
* The templating of external-secrets will use the data section below to know how
* to replace the correct value in the created secret.
*/}}
{{- range .Values.hyperlane.chains }}
{{- range .Values.hyperlane.chains.relayer }}
{{- if or (eq $.Values.hyperlane.connectionType "httpQuorum") (eq $.Values.hyperlane.connectionType "httpFallback") }}
GCP_SECRET_OVERRIDE_{{ $.Values.hyperlane.runEnv | upper }}_RPC_ENDPOINTS_{{ . | upper }}: {{ printf "'{{ .%s_rpcs | toString }}'" . }}
{{- else }}
Expand All @@ -37,8 +41,6 @@ spec:
{{- if .Values.hyperlane.aws }}
AWS_ACCESS_KEY_ID: {{ print "'{{ .aws_access_key_id | toString }}'" }}
AWS_SECRET_ACCESS_KEY: {{ print "'{{ .aws_secret_access_key | toString }}'" }}
{{- else }}
GCP_SECRET_OVERRIDE_{{ .Values.hyperlane.context | upper }}_{{ .Values.hyperlane.runEnv | upper }}_KEY_KATHY: {{ print "'{{ .gcp_private_key | toString }}'" }}
{{- end }}
data:
- secretKey: deployer_key
Expand All @@ -48,7 +50,7 @@ spec:
* For each network, load the secret in GCP secret manager with the form: environment-rpc-endpoint-network,
* and associate it with the secret key networkname_rpc.
*/}}
{{- range .Values.hyperlane.chains }}
{{- range .Values.hyperlane.chains.relayer }}
{{- if or (eq $.Values.hyperlane.connectionType "httpQuorum") (eq $.Values.hyperlane.connectionType "httpFallback") }}
- secretKey: {{ printf "%s_rpcs" . }}
remoteRef:
Expand All @@ -66,9 +68,7 @@ spec:
- secretKey: aws_secret_access_key
remoteRef:
key: {{ printf "%s-%s-kathy-aws-secret-access-key" .Values.hyperlane.context .Values.hyperlane.runEnv }}
{{- else }}
{{- end }}
- secretKey: gcp_private_key
remoteRef:
key: {{ printf "%s-%s-key-kathy" $.Values.hyperlane.context $.Values.hyperlane.runEnv }}
property: privateKey
{{- end }}
2 changes: 1 addition & 1 deletion typescript/infra/scripts/check-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ProtocolType } from '@hyperlane-xyz/utils';

import { Contexts } from '../config/contexts';
import { deployEnvToSdkEnv } from '../src/config/environment';
import { helloWorldRouterConfig } from '../src/config/helloworld';
import { helloWorldRouterConfig } from '../src/config/helloworld/config';
import { HyperlaneAppGovernor } from '../src/govern/HyperlaneAppGovernor';
import { HyperlaneCoreGovernor } from '../src/govern/HyperlaneCoreGovernor';
import { HyperlaneIgpGovernor } from '../src/govern/HyperlaneIgpGovernor';
Expand Down
2 changes: 1 addition & 1 deletion typescript/infra/scripts/helloworld/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {

import { Contexts } from '../../config/contexts';
import { deployEnvToSdkEnv } from '../../src/config/environment';
import { helloWorldRouterConfig } from '../../src/config/helloworld';
import { helloWorldRouterConfig } from '../../src/config/helloworld/config';
import { Role } from '../../src/roles';
import { readJSON, writeJSON } from '../../src/utils/utils';
import {
Expand Down
18 changes: 12 additions & 6 deletions typescript/infra/scripts/helloworld/kathy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
error,
log,
retryAsync,
strip0x,
timeout,
warn,
} from '@hyperlane-xyz/utils';
Expand All @@ -37,7 +38,7 @@ import { DeployEnvironment } from '../../src/config/environment';
import { Role } from '../../src/roles';
import { startMetricsServer } from '../../src/utils/metrics';
import { assertChain, diagonalize, sleep } from '../../src/utils/utils';
import { getAddressesForKey, getArgs, withContext } from '../utils';
import { getArgs, getEnvironmentConfig, withContext } from '../utils';

import { getHelloWorldMultiProtocolApp } from './utils';

Expand Down Expand Up @@ -160,9 +161,8 @@ async function main(): Promise<boolean> {
startMetricsServer(metricsRegister);
debug('Starting up', { environment });

// TODO (Rossy) remove getCoreConfigStub and re-enable getEnvironmentConfig
// const coreConfig = getEnvironmentConfig(environment);
const coreConfig = getCoreConfigStub(environment);
const coreConfig = getEnvironmentConfig(environment);
// const coreConfig = getCoreConfigStub(environment);

const { app, core, igp, multiProvider, keys } =
await getHelloWorldMultiProtocolApp(
Expand Down Expand Up @@ -421,7 +421,13 @@ async function sendMessage(
});

const sendAndConfirmMsg = async () => {
const sender = getAddressesForKey(keys, origin, multiProvider);
const originProtocol = app.metadata(origin).protocol;
const sender = keys[origin].addressForProtocol(originProtocol);
if (!sender) {
throw new Error(
`No sender address found for chain ${origin} and protocol ${originProtocol}`,
);
}
const tx = await app.populateHelloWorldTx(
origin,
destination,
Expand All @@ -447,7 +453,7 @@ async function sendMessage(
// that have not yet been ported over
const connection = app.multiProvider.getSolanaWeb3Provider(origin);
const payer = Keypair.fromSeed(
Buffer.from(keys[origin].privateKey, 'hex'),
Buffer.from(strip0x(keys[origin].privateKey), 'hex'),
);
tx.transaction.partialSign(payer);
// Note, tx signature essentially tx means hash on sealevel
Expand Down
47 changes: 40 additions & 7 deletions typescript/infra/scripts/helloworld/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ import {
hyperlaneEnvironments,
igpFactories,
} from '@hyperlane-xyz/sdk';
import { ProtocolType, objMerge } from '@hyperlane-xyz/utils';
import { ProtocolType, objMap } from '@hyperlane-xyz/utils';

import { Contexts } from '../../config/contexts';
import { EnvironmentConfig } from '../../src/config';
import { deployEnvToSdkEnv } from '../../src/config/environment';
import { HelloWorldConfig } from '../../src/config/helloworld';
import { HelloWorldConfig } from '../../src/config/helloworld/types';
import { Role } from '../../src/roles';
import { getKeyForRole } from '../utils';

export async function getHelloWorldApp(
coreConfig: EnvironmentConfig,
Expand Down Expand Up @@ -71,27 +72,60 @@ export async function getHelloWorldMultiProtocolApp(
connectionType,
);
const sdkEnvName = deployEnvToSdkEnv[coreConfig.environment];
const envAddresses = hyperlaneEnvironments[sdkEnvName];
const keys = await coreConfig.getKeys(keyContext, keyRole);

// Fetch all the keys, which is required to get the address for
// certain cloud keys
await Promise.all(Object.values(keys).map((key) => key.fetch()));

const helloworldConfig = getHelloWorldConfig(coreConfig, context);

const multiProtocolProvider =
MultiProtocolProvider.fromMultiProvider(multiProvider);
// Hacking around infra code limitations, we may need to add solana manually
// because the it's not in typescript/infra/config/environments/testnet3/chains.ts
// Adding it there breaks many things
if (!multiProtocolProvider.getKnownChainNames().includes('solanadevnet')) {
if (
coreConfig.environment === 'testnet3' &&
!multiProtocolProvider.getKnownChainNames().includes('solanadevnet')
) {
multiProvider.addChain(chainMetadata.solanadevnet);
multiProtocolProvider.addChain(chainMetadata.solanadevnet);
keys['solanadevnet'] = getKeyForRole(
coreConfig.environment,
context,
'solanadevnet',
keyRole,
);
await keys['solanadevnet'].fetch();
} else if (
coreConfig.environment === 'mainnet2' &&
!multiProtocolProvider.getKnownChainNames().includes('solana')
) {
multiProvider.addChain(chainMetadata.solana);
multiProtocolProvider.addChain(chainMetadata.solana);
keys['solana'] = getKeyForRole(
coreConfig.environment,
context,
'solana',
keyRole,
);
await keys['solana'].fetch();
}

const core = MultiProtocolCore.fromAddressesMap(
hyperlaneEnvironments[sdkEnvName],
envAddresses,
multiProtocolProvider,
);

const routersAndMailboxes = objMerge(
core.chainMap,
const routersAndMailboxes = objMap(
helloworldConfig.addresses,
(chain, addresses) => ({
router: addresses.router,
// @ts-ignore allow loosely typed chain name to index env addresses
mailbox: envAddresses[chain].mailbox,
}),
);
const app = new HelloMultiProtocolApp(
multiProtocolProvider,
Expand All @@ -101,7 +135,6 @@ export async function getHelloWorldMultiProtocolApp(
// TODO we need a MultiProtocolIgp
// Using an standard IGP for just evm chains for now
// Unfortunately this requires hacking surgically around certain addresses
const envAddresses = hyperlaneEnvironments[sdkEnvName];
const filteredAddresses = filterChainMapToProtocol(
envAddresses,
ProtocolType.Ethereum,
Expand Down
Loading

0 comments on commit c4387cf

Please sign in to comment.