feat: improve mailbox initialized check (#4371)

resolves https://github.com/hyperlane-xyz/hyperlane-monorepo/issues/4233

- feat: improve mailbox initialized check
- drive-by: update pinned registry + agent config
pull/4375/head
Paul Balaji 3 months ago committed by GitHub
parent feb1d390c4
commit 2ffb78f5c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      .changeset/warm-grapes-talk.md
  2. 2
      .registryrc
  3. 37
      typescript/sdk/src/core/HyperlaneCoreDeployer.ts

@ -0,0 +1,5 @@
---
'@hyperlane-xyz/sdk': patch
---
Improved check for mailbox initialization

@ -1 +1 @@
06faae6fd81eec5584f830a18ae0355d7da63144
488c6eb828e46821e3858275c1e6f53bc5721db3

@ -5,7 +5,7 @@ import {
TestRecipient,
ValidatorAnnounce,
} from '@hyperlane-xyz/core';
import { Address, rootLogger } from '@hyperlane-xyz/utils';
import { Address, isZeroishAddress, rootLogger } from '@hyperlane-xyz/utils';
import { HyperlaneContracts } from '../contracts/types.js';
import { HyperlaneDeployer } from '../deploy/HyperlaneDeployer.js';
@ -107,9 +107,14 @@ export class HyperlaneCoreDeployer extends HyperlaneDeployer<
hookAddresses,
);
// configure mailbox
try {
const txOverrides = this.multiProvider.getTransactionOverrides(chain);
// Check if the mailbox has already been initialized
const currentDefaultIsm = await mailbox.defaultIsm();
if (isZeroishAddress(currentDefaultIsm)) {
// If the default ISM is the zero address, the mailbox hasn't been initialized
this.logger.debug('Initializing mailbox');
try {
await this.multiProvider.handleTx(
chain,
mailbox.initialize(
@ -117,33 +122,26 @@ export class HyperlaneCoreDeployer extends HyperlaneDeployer<
defaultIsm,
defaultHook.address,
requiredHook.address,
this.multiProvider.getTransactionOverrides(chain),
txOverrides,
),
);
} catch (e: any) {
if (
!e.message.includes('already initialized') &&
// Some RPC providers dont return the revert reason (nor allow ethers to parse it), so we have to check the message
!e.message.includes('Reverted 0x08c379a') &&
// Handle situation where the gas estimation fails on the call function,
// then the real error reason is not available in `e.message`, but rather in `e.error.reason`
!e.error?.reason?.includes('already initialized') &&
// Some providers, like on Viction, return a generic error message for all revert reasons
!e.message.includes('always failing transaction')
) {
// If we still get an error here, it's likely a genuine error
this.logger.error('Failed to initialize mailbox:', e);
throw e;
}
} else {
// If the default ISM is not the zero address, the mailbox has likely been initialized
this.logger.debug('Mailbox appears to be already initialized');
}
this.logger.debug('Mailbox already initialized');
const overrides = this.multiProvider.getTransactionOverrides(chain);
await this.configureHook(
chain,
mailbox,
defaultHook.address,
(_mailbox) => _mailbox.defaultHook(),
(_mailbox, _hook) =>
_mailbox.populateTransaction.setDefaultHook(_hook, { ...overrides }),
_mailbox.populateTransaction.setDefaultHook(_hook, { ...txOverrides }),
);
await this.configureHook(
@ -152,7 +150,7 @@ export class HyperlaneCoreDeployer extends HyperlaneDeployer<
requiredHook.address,
(_mailbox) => _mailbox.requiredHook(),
(_mailbox, _hook) =>
_mailbox.populateTransaction.setRequiredHook(_hook, { ...overrides }),
_mailbox.populateTransaction.setRequiredHook(_hook, { ...txOverrides }),
);
await this.configureIsm(
@ -163,7 +161,6 @@ export class HyperlaneCoreDeployer extends HyperlaneDeployer<
(_mailbox, _module) =>
_mailbox.populateTransaction.setDefaultIsm(_module),
);
}
return mailbox;
}

Loading…
Cancel
Save