Skip to content

Commit

Permalink
fix(hyperlane-ethereum): only apply gas overrides when submitting
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-savu committed Dec 20, 2024
1 parent 5467c65 commit 02c74ee
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 8 deletions.
4 changes: 2 additions & 2 deletions rust/main/agents/relayer/src/msg/pending_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ impl PendingOperation for PendingMessage {
let tx_cost_estimate = match self
.ctx
.destination_mailbox
.process_estimate_costs(&self.message, &metadata)
.process_estimate_costs(&self.message, &metadata, false)
.await
{
Ok(tx_cost_estimate) => tx_cost_estimate,
Expand Down Expand Up @@ -355,7 +355,7 @@ impl PendingOperation for PendingMessage {
if self
.ctx
.destination_mailbox
.process_estimate_costs(&self.message, metadata)
.process_estimate_costs(&self.message, metadata, true)
.await
.is_err()
{
Expand Down
1 change: 1 addition & 0 deletions rust/main/chains/hyperlane-cosmos/src/mailbox/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ impl Mailbox for CosmosMailbox {
&self,
message: &HyperlaneMessage,
metadata: &[u8],
_apply_gas_overrides: bool,
) -> ChainResult<TxCostEstimate> {
let process_message = ProcessMessageRequest {
process: ProcessMessageRequestInner {
Expand Down
20 changes: 15 additions & 5 deletions rust/main/chains/hyperlane-ethereum/src/contracts/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ where
&self,
message: &HyperlaneMessage,
metadata: &[u8],
apply_gas_overrides: bool,
tx_gas_estimate: Option<U256>,
) -> ChainResult<ContractCall<M, ()>> {
let mut tx = self.contract.process(
Expand All @@ -324,7 +325,12 @@ where
if let Some(gas_estimate) = tx_gas_estimate {
tx = tx.gas(gas_estimate);
}
self.add_gas_overrides(tx).await

if apply_gas_overrides {
self.add_gas_overrides(tx).await
} else {
Ok(tx)
}
}

async fn add_gas_overrides<D: Detokenize>(
Expand Down Expand Up @@ -504,7 +510,7 @@ where
tx_gas_limit: Option<U256>,
) -> ChainResult<TxOutcome> {
let contract_call = self
.process_contract_call(message, metadata, tx_gas_limit)
.process_contract_call(message, metadata, true, tx_gas_limit)
.await?;
let receipt = report_tx(contract_call).await?;
Ok(receipt.into())
Expand All @@ -528,6 +534,7 @@ where
self.process_contract_call(
&batch_item.data,
&batch_item.submission_data.metadata,
true,
Some(batch_item.submission_data.gas_limit),
)
.await
Expand All @@ -547,8 +554,11 @@ where
&self,
message: &HyperlaneMessage,
metadata: &[u8],
apply_gas_overrides: bool,
) -> ChainResult<TxCostEstimate> {
let contract_call = self.process_contract_call(message, metadata, None).await?;
let contract_call = self
.process_contract_call(message, metadata, apply_gas_overrides, None)
.await?;
let gas_limit = contract_call
.tx
.gas()
Expand Down Expand Up @@ -701,7 +711,7 @@ mod test {
mock_provider.push(gas_limit).unwrap();

let tx_cost_estimate = mailbox
.process_estimate_costs(&message, &metadata)
.process_estimate_costs(&message, &metadata, true)
.await
.unwrap();

Expand Down Expand Up @@ -751,7 +761,7 @@ mod test {
mock_provider.push(gas_limit).unwrap();

let tx_cost_estimate = mailbox
.process_estimate_costs(&message, &metadata)
.process_estimate_costs(&message, &metadata, true)
.await
.unwrap();

Expand Down
1 change: 1 addition & 0 deletions rust/main/chains/hyperlane-fuel/src/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ impl Mailbox for FuelMailbox {
&self,
message: &HyperlaneMessage,
metadata: &[u8],
_apply_gas_overrides: bool,
) -> ChainResult<TxCostEstimate> {
let call_res = self
.contract
Expand Down
1 change: 1 addition & 0 deletions rust/main/chains/hyperlane-sealevel/src/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ impl Mailbox for SealevelMailbox {
&self,
_message: &HyperlaneMessage,
_metadata: &[u8],
_apply_gas_overrides: bool,
) -> ChainResult<TxCostEstimate> {
// TODO use correct data upon integrating IGP support
Ok(TxCostEstimate {
Expand Down
6 changes: 6 additions & 0 deletions rust/main/hyperlane-core/src/traits/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,16 @@ pub trait Mailbox: HyperlaneContract + Send + Sync + Debug {
}

/// Estimate transaction costs to process a message.
/// Arguments:
/// - `message`: The message to be processed
/// - `metadata`: The metadata needed to process the message
/// - `apply_gas_overrides`: Whether to apply gas overrides to the transaction. Use `false` if
/// just checking that it doesn't revert, and `true` when looking to submit the transaction.
async fn process_estimate_costs(
&self,
message: &HyperlaneMessage,
metadata: &[u8],
apply_gas_overrides: bool,
) -> ChainResult<TxCostEstimate>;

/// Get the calldata for a transaction to process a message with a proof
Expand Down
4 changes: 3 additions & 1 deletion rust/main/hyperlane-test/src/mocks/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ mock! {
&self,
message: &HyperlaneMessage,
metadata: &[u8],
apply_gas_overrides: bool,
) -> ChainResult<TxCostEstimate> {}

pub fn process_calldata(
Expand Down Expand Up @@ -102,8 +103,9 @@ impl Mailbox for MockMailboxContract {
&self,
message: &HyperlaneMessage,
metadata: &[u8],
apply_gas_overrides: bool,
) -> ChainResult<TxCostEstimate> {
self.process_estimate_costs(message, metadata)
self.process_estimate_costs(message, metadata, apply_gas_overrides)
}

fn process_calldata(&self, message: &HyperlaneMessage, metadata: &[u8]) -> Vec<u8> {
Expand Down

0 comments on commit 02c74ee

Please sign in to comment.