Skip to content

Commit b798a97

Browse files
authored
fix: Add 100% percentile to fee history request and avoid resubmit if no gas price change (#7218)
Co-authored-by: Danil Nemirovsky <[email protected]>
1 parent f684196 commit b798a97

File tree

11 files changed

+321
-71
lines changed

11 files changed

+321
-71
lines changed

rust/main/lander/src/adapter/chains/ethereum.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub use metrics::EthereumAdapterMetrics;
33
pub use precursor::EthereumTxPrecursor;
44

55
mod adapter;
6+
mod gas_price;
67
mod metrics;
78
mod nonce;
89
mod payload;

rust/main/lander/src/adapter/chains/ethereum/adapter.rs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@ use crate::{
4242
};
4343

4444
use super::{
45-
metrics::EthereumAdapterMetrics, nonce::NonceManager, transaction::Precursor,
46-
EthereumTxPrecursor,
45+
gas_price::GasPrice, metrics::EthereumAdapterMetrics, nonce::NonceManager,
46+
transaction::Precursor, EthereumTxPrecursor,
4747
};
4848

49-
use gas_price::GasPrice;
50-
5149
mod gas_limit_estimator;
5250
mod gas_price;
5351
mod tx_status_checker;
@@ -135,7 +133,7 @@ impl EthereumAdapter {
135133
// to be resilient to gas spikes
136134
let old_tx_precursor = tx.precursor();
137135

138-
let old_gas_price = gas_price::extract_gas_price(old_tx_precursor);
136+
let old_gas_price = old_tx_precursor.extract_gas_price();
139137

140138
// first, estimate the gas price
141139
let estimated_gas_price = gas_price::estimate_gas_price(
@@ -162,6 +160,29 @@ impl EthereumAdapter {
162160
Ok(new_gas_price)
163161
}
164162

163+
fn check_if_resubmission_makes_sense(
164+
tx: &Transaction,
165+
gas_price: &GasPrice,
166+
) -> Result<(), LanderError> {
167+
let precursor = tx.precursor();
168+
let tx_gas_price = precursor.extract_gas_price();
169+
170+
if tx_gas_price == GasPrice::None {
171+
// If transaction has no gas price set, it is the first submission
172+
return Ok(());
173+
}
174+
175+
// Transaction has been submitted before, check if the new gas price has not
176+
// reached limit yet
177+
178+
if gas_price == &tx_gas_price {
179+
// If new gas price is the same as the old one, no point in resubmitting
180+
return Err(LanderError::TxAlreadyExists);
181+
}
182+
183+
Ok(())
184+
}
185+
165186
fn update_tx(&self, tx: &mut Transaction, nonce: U256, gas_price: GasPrice) {
166187
let precursor = tx.precursor_mut();
167188

@@ -579,6 +600,8 @@ impl AdaptsChain for EthereumAdapter {
579600
self.estimate_gas_price(&tx_for_gas_price)
580601
)?;
581602

603+
Self::check_if_resubmission_makes_sense(tx, &gas_price)?;
604+
582605
self.update_tx(tx, nonce, gas_price);
583606

584607
info!(?tx, "submitting transaction");
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
pub use escalator::escalate_gas_price_if_needed;
22
pub use estimator::estimate_gas_price;
3-
pub use price::{extract_gas_price, GasPrice};
43

54
mod escalator;
65
mod estimator;
7-
mod price;

rust/main/lander/src/adapter/chains/ethereum/adapter/gas_price/escalator.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use hyperlane_ethereum::TransactionOverrides;
77

88
use crate::adapter::EthereumTxPrecursor;
99

10-
use super::price::GasPrice;
10+
use super::super::super::gas_price::GasPrice;
1111

1212
const ESCALATION_MULTIPLIER_NUMERATOR: u32 = 110;
1313
const ESCALATION_MULTIPLIER_DENOMINATOR: u32 = 100;
@@ -153,7 +153,6 @@ fn apply_escalation_multiplier(gas_price: &U256) -> U256 {
153153
mod tests {
154154
use hyperlane_core::U256;
155155

156-
use crate::adapter::chains::ethereum::adapter::gas_price::GasPrice;
157156
use hyperlane_ethereum::TransactionOverrides;
158157

159158
use super::*;

rust/main/lander/src/adapter/chains/ethereum/adapter/gas_price/estimator.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
use std::{str::FromStr, sync::Arc};
1+
use std::{iter::once, str::FromStr, sync::Arc};
22

3-
use ethers::contract::Lazy;
43
use ethers::{
54
abi::Detokenize,
6-
contract::builders::ContractCall,
5+
contract::{builders::ContractCall, Lazy},
76
providers::{Middleware, ProviderError},
87
types::{
98
transaction::eip2718::TypedTransaction, Block, Eip1559TransactionRequest, H160,
109
H256 as TxHash,
1110
},
1211
};
13-
use futures_util::try_join;
14-
use hyperlane_core::{ChainCommunicationError, ChainResult, HyperlaneDomain, U256};
15-
use hyperlane_ethereum::{EvmProviderForLander, TransactionOverrides, ZksyncEstimateFeeResponse};
16-
use tracing::{debug, warn};
17-
18-
use crate::{adapter::EthereumTxPrecursor, LanderError};
19-
use ethers_core::types::FeeHistory;
2012
use ethers_core::{
21-
types::{BlockNumber, U256 as EthersU256},
13+
types::{BlockNumber, FeeHistory, U256 as EthersU256},
2214
utils::{
2315
eip1559_default_estimator, EIP1559_FEE_ESTIMATION_PAST_BLOCKS,
2416
EIP1559_FEE_ESTIMATION_REWARD_PERCENTILE,
2517
},
2618
};
27-
use futures_util::future::join_all;
19+
use futures_util::{future::join_all, try_join};
20+
use tracing::{debug, warn};
21+
22+
use hyperlane_core::{ChainCommunicationError, ChainResult, HyperlaneDomain, U256};
23+
use hyperlane_ethereum::{EvmProviderForLander, TransactionOverrides, ZksyncEstimateFeeResponse};
24+
25+
use crate::{adapter::EthereumTxPrecursor, LanderError};
2826

29-
use super::price::GasPrice;
27+
use super::super::super::gas_price::GasPrice;
3028

3129
type FeeEstimator = fn(EthersU256, Vec<Vec<EthersU256>>) -> (EthersU256, EthersU256);
3230

3331
const EVM_RELAYER_ADDRESS: &str = "0x74cae0ecc47b02ed9b9d32e000fd70b9417970c5";
3432

3533
// We have 2 to 4 multiples of the default percentile, and we limit it to 100% percentile.
34+
// We add 100% percentile so that we increase the chance to get fee history with non-zero rewards.
3635
static PERCENTILES: Lazy<Vec<f64>> = Lazy::new(|| {
3736
(2..5)
3837
.map(|m| EIP1559_FEE_ESTIMATION_REWARD_PERCENTILE * m as f64)
39-
.filter(|p| *p <= 100.0)
38+
.filter(|p| *p < 100.0)
39+
.chain(once(100.0))
4040
.collect::<Vec<_>>()
4141
});
4242

rust/main/lander/src/adapter/chains/ethereum/adapter/gas_price/price.rs

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)