Write agent config for core and IGP deploys (#2051)

### Description

This PR fixes the broken E2E tests by writing agent config after core
*or* IGP deploys.

Rather than reading contract addresses from the deployed contracts,
agent configs are built from the cached contract addresses in the SDK.
Therefore, we must write (but not read) contract addresses when
deploying to the test environment.
test-sol-fixes
Asa Oines 2 years ago committed by GitHub
parent 9a373d0ec9
commit 08f3b9b32b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      typescript/infra/scripts/deploy.ts
  2. 43
      typescript/infra/src/core/deploy.ts
  3. 60
      typescript/infra/src/deploy.ts

@ -115,11 +115,21 @@ async function main() {
const verification = path.join(modulePath, 'verification.json');
// do not cache for test environment
const cache =
environment === 'test' ? undefined : { addresses, verification };
const cache = {
addresses,
verification,
read: environment !== 'test',
write: true,
};
const agentConfig = ['core', 'igp'].includes(module)
? {
addresses,
environment,
multiProvider,
}
: undefined;
await deployWithArtifacts(deployer, cache, fork);
await deployWithArtifacts(deployer, cache, fork, agentConfig);
}
main()

@ -5,24 +5,15 @@ import {
ChainMap,
ChainName,
CoreConfig,
CoreContracts,
HyperlaneAgentAddresses,
HyperlaneCoreDeployer,
MultiProvider,
ProxiedContract,
TransparentProxyAddresses,
buildAgentConfig,
objMap,
promiseObjAll,
serializeContracts,
} from '@hyperlane-xyz/sdk';
import { DeployOptions } from '@hyperlane-xyz/sdk/dist/deploy/HyperlaneDeployer';
import { types } from '@hyperlane-xyz/utils';
import { getAgentConfigDirectory } from '../../scripts/utils';
import { DeployEnvironment } from '../config';
import { deployEnvToSdkEnv } from '../config/environment';
import { writeJSON } from '../utils/utils';
export class HyperlaneCoreInfraDeployer extends HyperlaneCoreDeployer {
environment: DeployEnvironment;
@ -36,40 +27,6 @@ export class HyperlaneCoreInfraDeployer extends HyperlaneCoreDeployer {
this.environment = environment;
}
protected async writeAgentConfig() {
// Write agent config indexing from the deployed or latest block numbers.
// For non-net-new deployments, these changes will need to be
// reverted manually.
const startBlocks = await promiseObjAll(
objMap(this.deployedContracts, async (chain, contracts) => {
const latest = await this.multiProvider
.getProvider(chain)
.getBlockNumber();
const deployedBlocks = Object.values(contracts).map(
(c) => c.deployTransaction?.blockNumber ?? latest,
);
return Math.min(...deployedBlocks);
}),
);
const addresses = serializeContracts(
this.deployedContracts,
) as ChainMap<HyperlaneAgentAddresses>;
const agentConfig = buildAgentConfig(
this.multiProvider.getKnownChainNames(),
this.multiProvider,
addresses,
startBlocks,
);
const sdkEnv = deployEnvToSdkEnv[this.environment];
writeJSON(getAgentConfigDirectory(), `${sdkEnv}_config.json`, agentConfig);
}
async deploy(): Promise<ChainMap<CoreContracts>> {
const result = await super.deploy();
await this.writeAgentConfig();
return result;
}
async deployMailbox(
chain: ChainName,
defaultIsmAddress: types.Address,

@ -1,25 +1,72 @@
import {
ChainMap,
ChainName,
HyperlaneAddresses,
HyperlaneAgentAddresses,
HyperlaneDeployer,
MultiProvider,
buildAgentConfig,
buildContracts,
objMap,
promiseObjAll,
serializeContracts,
} from '@hyperlane-xyz/sdk';
import { getAgentConfigDirectory } from '../scripts/utils';
import { DeployEnvironment, deployEnvToSdkEnv } from './config/environment';
import {
readJSONAtPath,
writeJSON,
writeJsonAtPath,
writeMergedJSONAtPath,
} from './utils/utils';
export async function writeAgentConfig(
addressesPath: string,
multiProvider: MultiProvider,
environment: DeployEnvironment,
) {
let addresses: ChainMap<HyperlaneAddresses> = {};
try {
addresses = readJSONAtPath(addressesPath);
} catch (e) {
console.error('Failed to load cached addresses');
}
// Write agent config indexing from the deployed or latest block numbers.
// For non-net-new deployments, these changes will need to be
// reverted manually.
const startBlocks = await promiseObjAll(
objMap(addresses, (chain, _) =>
multiProvider.getProvider(chain).getBlockNumber(),
),
);
const agentConfig = buildAgentConfig(
multiProvider.getKnownChainNames(),
multiProvider,
addresses as ChainMap<HyperlaneAgentAddresses>,
startBlocks,
);
const sdkEnv = deployEnvToSdkEnv[environment];
writeJSON(getAgentConfigDirectory(), `${sdkEnv}_config.json`, agentConfig);
}
export async function deployWithArtifacts(
deployer: HyperlaneDeployer<any, any, any>,
cache?: {
cache: {
addresses: string;
verification: string;
read: boolean;
write: boolean;
},
fork?: ChainName,
agentConfig?: {
multiProvider: MultiProvider;
addresses: string;
environment: DeployEnvironment;
},
) {
if (cache) {
if (cache.read) {
let addresses = {};
try {
addresses = readJSONAtPath(cache.addresses);
@ -41,7 +88,7 @@ export async function deployWithArtifacts(
console.error('Failed to deploy contracts', e);
}
if (cache) {
if (cache.write) {
// cache addresses of deployed contracts
writeMergedJSONAtPath(
cache.addresses,
@ -60,4 +107,11 @@ export async function deployWithArtifacts(
deployer.mergeWithExistingVerificationInputs(savedVerification);
writeJsonAtPath(cache.verification, inputs);
}
if (agentConfig) {
await writeAgentConfig(
agentConfig.addresses,
agentConfig.multiProvider,
agentConfig.environment,
);
}
}

Loading…
Cancel
Save