Skip to content

Commit

Permalink
fix: add gas buffer when sending message through HyperlaneCore (#4677)
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
paulbalaji authored Oct 14, 2024
1 parent 0301055 commit d419f43
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/wise-camels-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/sdk': patch
---

Set transaction overrides and add 10% gas limit buffer when sending message through HyperlaneCore.
30 changes: 24 additions & 6 deletions typescript/sdk/src/core/HyperlaneCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Address,
AddressBytes32,
ProtocolType,
addBufferToGasLimit,
addressToBytes32,
bytes32ToAddress,
isZeroishAddress,
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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 },
),
);
}
Expand Down

0 comments on commit d419f43

Please sign in to comment.