forked from hyperlane-xyz/hyperlane-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Gas Policy Minimum Handling to Prevent Unexpected Behavior (hype…
…rlane-xyz#5517) ### Description Prior to this change, configuring the `gaspaymentenforcement` parameter in the config to a minimum of 0 resulted in unexpected behavior. With this configuration, the relayer would relay any message from the designated relay chains, whether or not the message paid the specified IGP, resulting in the same behavior as `gaspaymentenforcement` of None. This is due to `fn message_meets_gas_payment_requirement` in `rust/main/agents/relayer/src/msg/gas_payment/mod.rs`. ```rs let current_payment_option = self .db .retrieve_gas_payment_by_gas_payment_key(gas_payment_key)?; let current_payment = match current_payment_option { Some(payment) => payment, None => InterchainGasPayment::from_gas_payment_key(gas_payment_key), }; ``` If the payment does not exist (because it was not indexed on the specified IGP), `current_payment` is set to `InterchainGasPayment::from_gas_payment_key(gas_payment_key)` which creates an InterchainGasPayment with a default payment value of 0. As a result, payments to *other* IGPs appeared to be 0 payments to the specified IGP. Therefore, in the loop later in the function, the message matches with `GasPolicyStatus::PolicyMet(gas_limit)` and the relayer relays it. ```rs return policy .message_meets_gas_payment_requirement( message, ¤t_payment, ¤t_expenditure, tx_cost_estimate, ) .await .map(|result| { if let Some(gas_limit) = result { GasPolicyStatus::PolicyMet(gas_limit) } else if current_payment_option.is_some() { // There is a gas payment but it didn't meet the policy GasPolicyStatus::PolicyNotMet } else { // No payment was found and it didn't meet the policy GasPolicyStatus::NoPaymentFound } }); ``` These changes create the desired behavior, namely, that setting `gaspaymentenforcement` to a minimum of 0 should only relay messages that hooked / emitted from the specified IGP. ### Changes The desired functionality is implemented by modifying the `message_meets_gas_payment_requirement` function in `rust/main/agents/relayer/src/msg/gas_payment/mod.rs`. The change adds a check in that function to ensure that the `self.db.retrieve_gas_payment_by_gas_payment_key(gas_payment_key)?;` did in fact return a payment on the IGP from the database. ```rs if policy.requires_payment_found() && !payment_found { return Ok(GasPolicyStatus::NoPaymentFound); } ``` The check also calls a new function added to the `GasPaymentPolicy` trait called `requires_payment_found`. By default, this is set to return `false`, which allows the `none.rs` gas policy to skip this logic and continue relaying all messages. For the `minimum.rs` and `on_chain_fee_quoting.rs` gas policies, this is set to return `true` which requires a gas payment event to have been found on the specified IGP to continue. ### Related issues N/A ### Backward compatibility Unsure, as I am not as familiar with the history associated with this codebase. ### Testing Added unit tests and am currently running manual tests to ensure only messages that were emitted from the specified IGP were relayed.
- Loading branch information
1 parent
e861535
commit 9fc5e66
Showing
4 changed files
with
319 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters