fix: add gas buffer when sending message through HyperlaneCore (#4677)

### Description

estimates gas + adds gas limit buffer when sending a message through
HyperlaneCore

### Drive-by changes

also sets tx overrides

### Related issues

> incremental merkle tree insertions have inconsistent gas usage so if
there are multiple dispatch transactions in the mempool the gas
estimation can become too low depending on the tx ordering

bumping up the gas limit helps

[more
context](https://discord.com/channels/935678348330434570/1295388159407947859/1295393090181267558)

### Backward compatibility

yes

### Testing

manual
pull/4689/head
Paul Balaji 1 month ago committed by GitHub
parent 5f4540ed4e
commit 2317eca3cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      .changeset/wise-camels-repair.md
  2. 30
      typescript/sdk/src/core/HyperlaneCore.ts

@ -0,0 +1,5 @@
---
'@hyperlane-xyz/sdk': patch
---
Set transaction overrides and add 10% gas limit buffer when sending message through HyperlaneCore.

@ -12,6 +12,7 @@ import {
Address,
AddressBytes32,
ProtocolType,
addBufferToGasLimit,
addressToBytes32,
bytes32ToAddress,
isZeroishAddress,
@ -153,17 +154,31 @@ export class HyperlaneCore extends HyperlaneApp<CoreFactories> {
metadata,
hook,
);
const dispatchParams = [
destinationDomain,
recipientBytes32,
body,
metadata || '0x',
hook || ethers.constants.AddressZero,
] as const;
const estimateGas = await mailbox.estimateGas[
'dispatch(uint32,bytes32,bytes,bytes,address)'
](...dispatchParams, { value: quote });
const dispatchTx = await this.multiProvider.handleTx(
origin,
mailbox['dispatch(uint32,bytes32,bytes,bytes,address)'](
destinationDomain,
recipientBytes32,
body,
metadata || '0x',
hook || ethers.constants.AddressZero,
{ value: quote },
...dispatchParams,
{
...this.multiProvider.getTransactionOverrides(origin),
value: quote,
gasLimit: addBufferToGasLimit(estimateGas),
},
),
);
return {
dispatchTx,
message: this.getDispatchedMessages(dispatchTx)[0],
@ -241,11 +256,14 @@ export class HyperlaneCore extends HyperlaneApp<CoreFactories> {
ismMetadata: string,
): Promise<ethers.ContractReceipt> {
const destinationChain = this.getDestination(message);
const txOverrides =
this.multiProvider.getTransactionOverrides(destinationChain);
return this.multiProvider.handleTx(
destinationChain,
this.getContracts(destinationChain).mailbox.process(
ismMetadata,
message.message,
{ ...txOverrides },
),
);
}

Loading…
Cancel
Save