Skip to content

Commit

Permalink
fix:remove agentStartBlock and use mailbox.deployedBlock() instead (
Browse files Browse the repository at this point in the history
#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 hyperlane-xyz/issues#736

### Backward compatibility

Yes

### Testing

Manual b/w anvil1 and anvil2
  • Loading branch information
aroralanuk authored Nov 30, 2023
1 parent 3501755 commit 9f2c7ce
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 55 deletions.
7 changes: 7 additions & 0 deletions .changeset/tall-shirts-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@hyperlane-xyz/infra': patch
'@hyperlane-xyz/cli': patch
'@hyperlane-xyz/sdk': patch
---

Removing agentStartBlocks and using mailbox.deployedBlock() instead
29 changes: 8 additions & 21 deletions typescript/cli/src/deploy/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
DeployedIsm,
GasOracleContractType,
HookType,
HyperlaneAddresses,
HyperlaneAddressesMap,
HyperlaneContractsMap,
HyperlaneCore,
HyperlaneCoreDeployer,
HyperlaneDeploymentArtifacts,
HyperlaneIsmFactory,
Expand All @@ -21,7 +21,6 @@ import {
MultiProvider,
MultisigConfig,
RoutingIsmConfig,
agentStartBlocks,
buildAgentConfig,
buildAggregationIsmConfigs,
defaultMultisigConfigs,
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 13 additions & 7 deletions typescript/infra/src/deployment/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
ChainMap,
ChainName,
HyperlaneAddresses,
HyperlaneCore,
HyperlaneDeployer,
HyperlaneDeploymentArtifacts,
MultiProvider,
Expand Down Expand Up @@ -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,
Expand Down
26 changes: 0 additions & 26 deletions typescript/sdk/src/consts/agentStartBlocks.ts

This file was deleted.

1 change: 0 additions & 1 deletion typescript/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export {
BaseSealevelAdapter,
MultiProtocolApp,
} from './app/MultiProtocolApp';
export { agentStartBlocks } from './consts/agentStartBlocks';
export {
chainIdToMetadata,
chainMetadata,
Expand Down

0 comments on commit 9f2c7ce

Please sign in to comment.