fix:remove `agentStartBlock` and use `mailbox.deployedBlock()` instead (#3005)

### Description

- CLI was using a static start block numbers for core chains or getting
the latest block number from a PI chain for agent config which is
redundant and dangerous. Instead, I updated to using the
`mailbox.deployedBlock()` which should precede all other indexable
contract deployment and is hence safer.

### Drive-by changes

- filtering the agent configs in CLI is redundant since the
`HyperlaneDeploymentArtifactsSchema` requires all the specified entries
and if `writeAgentConfig` gets an artifacts which doesn't contain these,
we should throw an error and not filter them.

### Related issues

- related to https://github.com/hyperlane-xyz/issues/issues/736

### Backward compatibility

Yes

### Testing

Manual b/w anvil1 and anvil2
pull/3007/head
Kunal Arora 12 months ago committed by GitHub
parent 3501755816
commit 9f2c7ce7c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      .changeset/tall-shirts-accept.md
  2. 29
      typescript/cli/src/deploy/core.ts
  3. 20
      typescript/infra/src/deployment/deploy.ts
  4. 26
      typescript/sdk/src/consts/agentStartBlocks.ts
  5. 1
      typescript/sdk/src/index.ts

@ -0,0 +1,7 @@
---
'@hyperlane-xyz/infra': patch
'@hyperlane-xyz/cli': patch
'@hyperlane-xyz/sdk': patch
---
Removing agentStartBlocks and using mailbox.deployedBlock() instead

@ -8,9 +8,9 @@ import {
DeployedIsm,
GasOracleContractType,
HookType,
HyperlaneAddresses,
HyperlaneAddressesMap,
HyperlaneContractsMap,
HyperlaneCore,
HyperlaneCoreDeployer,
HyperlaneDeploymentArtifacts,
HyperlaneIsmFactory,
@ -21,7 +21,6 @@ import {
MultiProvider,
MultisigConfig,
RoutingIsmConfig,
agentStartBlocks,
buildAgentConfig,
buildAggregationIsmConfigs,
defaultMultisigConfigs,
@ -472,33 +471,21 @@ async function writeAgentConfig(
chains: ChainName[],
multiProvider: MultiProvider,
) {
// TODO: share with rust/config/*
const startBlocks: ChainMap<number> = { ...agentStartBlocks };
const startBlocks: ChainMap<number> = {};
for (const chain of chains) {
if (startBlocks[chain]) continue;
startBlocks[chain] = await multiProvider
.getProvider(chain)
.getBlockNumber();
const core = HyperlaneCore.fromAddressesMap(artifacts, multiProvider);
const mailbox = core.getContracts(chain).mailbox;
startBlocks[chain] = (await mailbox.deployedBlock()).toNumber();
}
const mergedAddressesMap: HyperlaneAddressesMap<any> = objMerge(
const mergedAddressesMap = objMerge(
sdkContractAddressesMap,
artifacts,
);
const filteredAddressesMap = objFilter(
mergedAddressesMap,
(chain, v): v is HyperlaneAddresses<any> =>
chains.includes(chain) &&
!!v.mailbox &&
!!v.interchainGasPaymaster &&
!!v.validatorAnnounce,
) as ChainMap<HyperlaneDeploymentArtifacts>;
const agentConfig = buildAgentConfig(
Object.keys(filteredAddressesMap),
Object.keys(mergedAddressesMap),
multiProvider,
filteredAddressesMap,
mergedAddressesMap,
startBlocks,
);
writeJson(filePath, agentConfig);

@ -2,6 +2,7 @@ import {
ChainMap,
ChainName,
HyperlaneAddresses,
HyperlaneCore,
HyperlaneDeployer,
HyperlaneDeploymentArtifacts,
MultiProvider,
@ -126,14 +127,19 @@ export async function writeAgentConfig(
} 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 core = HyperlaneCore.fromAddressesMap(addresses, multiProvider);
// Write agent config indexing from the deployed Mailbox which stores the block number at deployment
const startBlocksBigNumber = await promiseObjAll(
objMap(addresses, (chain, _) => {
const mailbox = core.getContracts(chain).mailbox;
return mailbox.deployedBlock();
}),
);
const startBlocks = objMap(startBlocksBigNumber, (_, blockNumber) =>
blockNumber.toNumber(),
);
const agentConfig = buildAgentConfig(
multiProvider.getKnownChainNames(),
multiProvider,

@ -1,26 +0,0 @@
import { ChainMap } from '../types';
// TODO this was previously in hyp-deploy, but ideally should be integrated
// into the ChainMetadata type and de-duped with agent consts
export const agentStartBlocks: ChainMap<number> = {
// --------------- Mainnets ---------------------
celo: 16884144,
ethereum: 16271503,
avalanche: 24145479,
polygon: 37313389,
bsc: 25063295,
arbitrum: 49073182,
optimism: 55698988,
moonbeam: 2595747,
gnosis: 25900000,
// --------------- Testnets ---------------------
alfajores: 14863532,
fuji: 16330615,
mumbai: 29390033,
bsctestnet: 25001629,
goerli: 8039005,
sepolia: 3082913,
moonbasealpha: 3310405,
optimismgoerli: 3055263,
arbitrumgoerli: 1941997,
};

@ -6,7 +6,6 @@ export {
BaseSealevelAdapter,
MultiProtocolApp,
} from './app/MultiProtocolApp';
export { agentStartBlocks } from './consts/agentStartBlocks';
export {
chainIdToMetadata,
chainMetadata,

Loading…
Cancel
Save