From 1613373cea84b447a3a5971a3931fe1e157152ff Mon Sep 17 00:00:00 2001 From: 3shv Date: Mon, 3 Mar 2025 16:58:38 +0700 Subject: [PATCH 01/11] Bump price based on elapsed blocks for cancelling --- crates/refunder/src/refund_service.rs | 1 + crates/refunder/src/submitter.rs | 138 ++++++++++++++++++++++---- 2 files changed, 119 insertions(+), 20 deletions(-) diff --git a/crates/refunder/src/refund_service.rs b/crates/refunder/src/refund_service.rs index f238ed13d4..bcfde7ef96 100644 --- a/crates/refunder/src/refund_service.rs +++ b/crates/refunder/src/refund_service.rs @@ -58,6 +58,7 @@ impl RefundService { gas_estimator: Box::new(web3), gas_parameters_of_last_tx: None, nonce_of_last_submission: None, + block_of_last_submission: None, }, } } diff --git a/crates/refunder/src/submitter.rs b/crates/refunder/src/submitter.rs index 2bc8aab91a..8dc66ae2eb 100644 --- a/crates/refunder/src/submitter.rs +++ b/crates/refunder/src/submitter.rs @@ -8,15 +8,15 @@ // a higher gas price, in order to avoid: ErrReplaceUnderpriced erros // In the re-newed attempt for submission the same nonce is used as before. +use ethcontract::transaction::TransactionResult; +use ethcontract::web3::types::U64; use { super::ethflow_order::EncodedEthflowOrder, anyhow::{Result, anyhow}, contracts::CoWSwapEthFlow, database::OrderUid, ethcontract::{ - Account, - H160, - U256, + Account, H160, U256, transaction::{ResolveCondition, confirm::ConfirmParams}, }, gas_estimation::{GasPrice1559, GasPriceEstimating}, @@ -48,6 +48,7 @@ pub struct Submitter { pub gas_estimator: Box, pub gas_parameters_of_last_tx: Option, pub nonce_of_last_submission: Option, + pub block_of_last_submission: Option, } impl Submitter { @@ -74,15 +75,20 @@ impl Submitter { let resolve_conditions = ResolveCondition::Confirmed(confirm_params); let gas_price_estimation = self.gas_estimator.estimate().await?; let nonce = self.get_submission_nonce().await?; + let blocks_elapsed = self.get_blocks_elapsed().await?; let gas_price = calculate_submission_gas_price( self.gas_parameters_of_last_tx, gas_price_estimation, nonce, self.nonce_of_last_submission, + blocks_elapsed, )?; + let current_block = self.web3.eth().block_number().await?; + self.gas_parameters_of_last_tx = Some(gas_price); self.nonce_of_last_submission = Some(nonce); + self.block_of_last_submission = Some(current_block); let ethflow_contract = CoWSwapEthFlow::at(&self.web3, ethflow_contract); let tx_result = ethflow_contract .invalidate_orders_ignoring_not_allowed(encoded_ethflow_orders) @@ -95,11 +101,23 @@ impl Submitter { .await; match tx_result { Ok(handle) => { - tracing::debug!( - "Tx to refund the orderuids {:?} yielded following result {:?}", - uids, - handle - ); + // Extract the block number from the transaction receipt + if let TransactionResult::Receipt(receipt) = handle { + if let Some(block_number) = receipt.block_number { + self.block_of_last_submission = Some(block_number); // Store the block number + tracing::debug!( + "Tx to refund the orderuids {:?} was mined in block {:?}", + uids, + block_number + ); + } + } else { + tracing::debug!( + "Tx to refund the orderuids {:?} yielded following result {:?}", + uids, + handle + ); + } } Err(err) => { let err = err.to_string(); @@ -122,6 +140,18 @@ impl Submitter { } Ok(()) } + + async fn get_blocks_elapsed(&self) -> Result> { + let current_block: U64 = self.web3.eth().block_number().await?; + let blocks_elapsed = match self.block_of_last_submission { + Some(submission_block) => { + let elapsed = current_block.saturating_sub(submission_block); + Some(elapsed.as_u64()) + } + None => None, + }; + Ok(blocks_elapsed) + } } fn calculate_submission_gas_price( @@ -129,11 +159,13 @@ fn calculate_submission_gas_price( web3_gas_estimation: GasPrice1559, newest_nonce: U256, nonce_of_last_submission: Option, + blocks_elapsed: Option, ) -> Result { // The gas price of the refund tx is the current prevailing gas price // of the web3 gas estimation plus a buffer. let mut new_gas_price = web3_gas_estimation.bump(GAS_PRICE_BUFFER_FACTOR); - // limit the prio_fee to max_fee_per_gas as otherwise tx is invalid + + // Limit the priority fee to max_fee_per_gas to avoid invalid transactions. new_gas_price.max_priority_fee_per_gas = (START_PRIORITY_FEE_TIP as f64).min(new_gas_price.max_fee_per_gas); @@ -142,13 +174,16 @@ fn calculate_submission_gas_price( // in order to avoid "tx underpriced errors" if Some(newest_nonce) == nonce_of_last_submission { if let Some(gas_price_of_last_submission) = gas_price_of_last_submission { - let gas_price_of_last_submission = gas_price_of_last_submission.bump(GAS_PRICE_BUMP); + let blocks_elapsed = blocks_elapsed.unwrap_or(1); + let bump_factor = GAS_PRICE_BUMP.powf(blocks_elapsed as f64); + let bumped_gas_price = gas_price_of_last_submission.bump(bump_factor); + new_gas_price.max_fee_per_gas = new_gas_price .max_fee_per_gas - .max(gas_price_of_last_submission.max_fee_per_gas); + .max(bumped_gas_price.max_fee_per_gas); new_gas_price.max_priority_fee_per_gas = new_gas_price .max_priority_fee_per_gas - .max(gas_price_of_last_submission.max_priority_fee_per_gas); + .max(bumped_gas_price.max_priority_fee_per_gas); } } @@ -161,11 +196,14 @@ fn calculate_submission_gas_price( ); new_gas_price.max_fee_per_gas = f64::min(MAX_GAS_PRICE as f64, new_gas_price.max_fee_per_gas); + + // Adjust the max_priority_fee_per_gas proportionally. + new_gas_price.max_priority_fee_per_gas = f64::min( + new_gas_price.max_priority_fee_per_gas, + new_gas_price.max_fee_per_gas, + ); } - new_gas_price.max_priority_fee_per_gas = f64::min( - new_gas_price.max_priority_fee_per_gas, - new_gas_price.max_fee_per_gas, - ); + Ok(new_gas_price) } @@ -174,8 +212,8 @@ mod tests { use super::*; #[test] - fn test_calculate_submission_gas_price() { - // First case: previous tx was successful + fn test_calculate_submission_gas_price_initial_submission() { + // Case 1: Previous tx was successful let max_fee_per_gas = 4_000_000_000f64; let web3_gas_estimation = GasPrice1559 { base_fee_per_gas: 2_000_000_000f64, @@ -185,20 +223,34 @@ mod tests { let newest_nonce = U256::one(); let nonce_of_last_submission = None; let gas_price_of_last_submission = None; + let result = calculate_submission_gas_price( gas_price_of_last_submission, web3_gas_estimation, newest_nonce, nonce_of_last_submission, + None, ) .unwrap(); + let expected_result = GasPrice1559 { max_fee_per_gas: max_fee_per_gas * GAS_PRICE_BUFFER_FACTOR, max_priority_fee_per_gas: START_PRIORITY_FEE_TIP as f64, base_fee_per_gas: 2_000_000_000f64, }; assert_eq!(result, expected_result); - // Second case: Previous tx was not successful + } + + #[test] + fn test_calculate_submission_gas_price_resubmission_blocks_elapsed_1() { + // Case 2: Resubmission with blocks_elapsed = 1 + let max_fee_per_gas = 4_000_000_000f64; + let web3_gas_estimation = GasPrice1559 { + base_fee_per_gas: 2_000_000_000f64, + max_fee_per_gas, + max_priority_fee_per_gas: 3_000_000_000f64, + }; + let newest_nonce = U256::one(); let nonce_of_last_submission = Some(newest_nonce); let max_fee_per_gas_of_last_tx = max_fee_per_gas * 2f64; let gas_price_of_last_submission = GasPrice1559 { @@ -206,35 +258,81 @@ mod tests { max_priority_fee_per_gas: START_PRIORITY_FEE_TIP as f64, base_fee_per_gas: 2_000_000_000f64, }; + let result = calculate_submission_gas_price( Some(gas_price_of_last_submission), web3_gas_estimation, newest_nonce, nonce_of_last_submission, + Some(1), ) .unwrap(); + let expected_result = GasPrice1559 { max_fee_per_gas: max_fee_per_gas_of_last_tx * GAS_PRICE_BUMP, max_priority_fee_per_gas: START_PRIORITY_FEE_TIP as f64 * GAS_PRICE_BUMP, base_fee_per_gas: 2_000_000_000f64, }; assert_eq!(result, expected_result); - // Thrid case: MAX_GAS_PRICE is not exceeded + } + + #[test] + fn test_calculate_submission_gas_price_resubmission_blocks_elapsed_2() { + // Case 3: Resubmission with blocks_elapsed = 2 + let max_fee_per_gas = 4_000_000_000f64; + let web3_gas_estimation = GasPrice1559 { + base_fee_per_gas: 2_000_000_000f64, + max_fee_per_gas, + max_priority_fee_per_gas: 3_000_000_000f64, + }; + let newest_nonce = U256::one(); + let nonce_of_last_submission = Some(newest_nonce); + let max_fee_per_gas_of_last_tx = max_fee_per_gas * 2f64; + let gas_price_of_last_submission = GasPrice1559 { + max_fee_per_gas: max_fee_per_gas_of_last_tx, + max_priority_fee_per_gas: START_PRIORITY_FEE_TIP as f64, + base_fee_per_gas: 2_000_000_000f64, + }; + + let result = calculate_submission_gas_price( + Some(gas_price_of_last_submission), + web3_gas_estimation, + newest_nonce, + nonce_of_last_submission, + Some(2), + ) + .unwrap(); + + let expected_result = GasPrice1559 { + max_fee_per_gas: max_fee_per_gas_of_last_tx * GAS_PRICE_BUMP.powi(2), + max_priority_fee_per_gas: START_PRIORITY_FEE_TIP as f64 * GAS_PRICE_BUMP.powi(2), + base_fee_per_gas: 2_000_000_000f64, + }; + assert_eq!(result, expected_result); + } + + #[test] + fn test_calculate_submission_gas_price_max_gas_price_cap() { + // Case 4: Gas price exceeds MAX_GAS_PRICE and is capped let max_fee_per_gas = MAX_GAS_PRICE as f64 + 1000f64; let web3_gas_estimation = GasPrice1559 { base_fee_per_gas: 2_000_000_000f64, max_fee_per_gas, max_priority_fee_per_gas: 3_000_000_000f64, }; + let newest_nonce = U256::one(); let nonce_of_last_submission = None; let gas_price_of_last_submission = None; + let result = calculate_submission_gas_price( gas_price_of_last_submission, web3_gas_estimation, newest_nonce, nonce_of_last_submission, + Some(1), ) .unwrap(); + let expected_result = GasPrice1559 { base_fee_per_gas: 2_000_000_000f64, max_fee_per_gas: MAX_GAS_PRICE as f64, From a999a6f6b6223dc15447e29e8404eddf3fcc16d0 Mon Sep 17 00:00:00 2001 From: 3shv Date: Tue, 4 Mar 2025 16:09:26 +0700 Subject: [PATCH 02/11] Revert "Bump price based on elapsed blocks for cancelling" This reverts commit 1613373cea84b447a3a5971a3931fe1e157152ff. --- crates/refunder/src/refund_service.rs | 1 - crates/refunder/src/submitter.rs | 138 ++++---------------------- 2 files changed, 20 insertions(+), 119 deletions(-) diff --git a/crates/refunder/src/refund_service.rs b/crates/refunder/src/refund_service.rs index bcfde7ef96..f238ed13d4 100644 --- a/crates/refunder/src/refund_service.rs +++ b/crates/refunder/src/refund_service.rs @@ -58,7 +58,6 @@ impl RefundService { gas_estimator: Box::new(web3), gas_parameters_of_last_tx: None, nonce_of_last_submission: None, - block_of_last_submission: None, }, } } diff --git a/crates/refunder/src/submitter.rs b/crates/refunder/src/submitter.rs index 8dc66ae2eb..2bc8aab91a 100644 --- a/crates/refunder/src/submitter.rs +++ b/crates/refunder/src/submitter.rs @@ -8,15 +8,15 @@ // a higher gas price, in order to avoid: ErrReplaceUnderpriced erros // In the re-newed attempt for submission the same nonce is used as before. -use ethcontract::transaction::TransactionResult; -use ethcontract::web3::types::U64; use { super::ethflow_order::EncodedEthflowOrder, anyhow::{Result, anyhow}, contracts::CoWSwapEthFlow, database::OrderUid, ethcontract::{ - Account, H160, U256, + Account, + H160, + U256, transaction::{ResolveCondition, confirm::ConfirmParams}, }, gas_estimation::{GasPrice1559, GasPriceEstimating}, @@ -48,7 +48,6 @@ pub struct Submitter { pub gas_estimator: Box, pub gas_parameters_of_last_tx: Option, pub nonce_of_last_submission: Option, - pub block_of_last_submission: Option, } impl Submitter { @@ -75,20 +74,15 @@ impl Submitter { let resolve_conditions = ResolveCondition::Confirmed(confirm_params); let gas_price_estimation = self.gas_estimator.estimate().await?; let nonce = self.get_submission_nonce().await?; - let blocks_elapsed = self.get_blocks_elapsed().await?; let gas_price = calculate_submission_gas_price( self.gas_parameters_of_last_tx, gas_price_estimation, nonce, self.nonce_of_last_submission, - blocks_elapsed, )?; - let current_block = self.web3.eth().block_number().await?; - self.gas_parameters_of_last_tx = Some(gas_price); self.nonce_of_last_submission = Some(nonce); - self.block_of_last_submission = Some(current_block); let ethflow_contract = CoWSwapEthFlow::at(&self.web3, ethflow_contract); let tx_result = ethflow_contract .invalidate_orders_ignoring_not_allowed(encoded_ethflow_orders) @@ -101,23 +95,11 @@ impl Submitter { .await; match tx_result { Ok(handle) => { - // Extract the block number from the transaction receipt - if let TransactionResult::Receipt(receipt) = handle { - if let Some(block_number) = receipt.block_number { - self.block_of_last_submission = Some(block_number); // Store the block number - tracing::debug!( - "Tx to refund the orderuids {:?} was mined in block {:?}", - uids, - block_number - ); - } - } else { - tracing::debug!( - "Tx to refund the orderuids {:?} yielded following result {:?}", - uids, - handle - ); - } + tracing::debug!( + "Tx to refund the orderuids {:?} yielded following result {:?}", + uids, + handle + ); } Err(err) => { let err = err.to_string(); @@ -140,18 +122,6 @@ impl Submitter { } Ok(()) } - - async fn get_blocks_elapsed(&self) -> Result> { - let current_block: U64 = self.web3.eth().block_number().await?; - let blocks_elapsed = match self.block_of_last_submission { - Some(submission_block) => { - let elapsed = current_block.saturating_sub(submission_block); - Some(elapsed.as_u64()) - } - None => None, - }; - Ok(blocks_elapsed) - } } fn calculate_submission_gas_price( @@ -159,13 +129,11 @@ fn calculate_submission_gas_price( web3_gas_estimation: GasPrice1559, newest_nonce: U256, nonce_of_last_submission: Option, - blocks_elapsed: Option, ) -> Result { // The gas price of the refund tx is the current prevailing gas price // of the web3 gas estimation plus a buffer. let mut new_gas_price = web3_gas_estimation.bump(GAS_PRICE_BUFFER_FACTOR); - - // Limit the priority fee to max_fee_per_gas to avoid invalid transactions. + // limit the prio_fee to max_fee_per_gas as otherwise tx is invalid new_gas_price.max_priority_fee_per_gas = (START_PRIORITY_FEE_TIP as f64).min(new_gas_price.max_fee_per_gas); @@ -174,16 +142,13 @@ fn calculate_submission_gas_price( // in order to avoid "tx underpriced errors" if Some(newest_nonce) == nonce_of_last_submission { if let Some(gas_price_of_last_submission) = gas_price_of_last_submission { - let blocks_elapsed = blocks_elapsed.unwrap_or(1); - let bump_factor = GAS_PRICE_BUMP.powf(blocks_elapsed as f64); - let bumped_gas_price = gas_price_of_last_submission.bump(bump_factor); - + let gas_price_of_last_submission = gas_price_of_last_submission.bump(GAS_PRICE_BUMP); new_gas_price.max_fee_per_gas = new_gas_price .max_fee_per_gas - .max(bumped_gas_price.max_fee_per_gas); + .max(gas_price_of_last_submission.max_fee_per_gas); new_gas_price.max_priority_fee_per_gas = new_gas_price .max_priority_fee_per_gas - .max(bumped_gas_price.max_priority_fee_per_gas); + .max(gas_price_of_last_submission.max_priority_fee_per_gas); } } @@ -196,14 +161,11 @@ fn calculate_submission_gas_price( ); new_gas_price.max_fee_per_gas = f64::min(MAX_GAS_PRICE as f64, new_gas_price.max_fee_per_gas); - - // Adjust the max_priority_fee_per_gas proportionally. - new_gas_price.max_priority_fee_per_gas = f64::min( - new_gas_price.max_priority_fee_per_gas, - new_gas_price.max_fee_per_gas, - ); } - + new_gas_price.max_priority_fee_per_gas = f64::min( + new_gas_price.max_priority_fee_per_gas, + new_gas_price.max_fee_per_gas, + ); Ok(new_gas_price) } @@ -212,8 +174,8 @@ mod tests { use super::*; #[test] - fn test_calculate_submission_gas_price_initial_submission() { - // Case 1: Previous tx was successful + fn test_calculate_submission_gas_price() { + // First case: previous tx was successful let max_fee_per_gas = 4_000_000_000f64; let web3_gas_estimation = GasPrice1559 { base_fee_per_gas: 2_000_000_000f64, @@ -223,34 +185,20 @@ mod tests { let newest_nonce = U256::one(); let nonce_of_last_submission = None; let gas_price_of_last_submission = None; - let result = calculate_submission_gas_price( gas_price_of_last_submission, web3_gas_estimation, newest_nonce, nonce_of_last_submission, - None, ) .unwrap(); - let expected_result = GasPrice1559 { max_fee_per_gas: max_fee_per_gas * GAS_PRICE_BUFFER_FACTOR, max_priority_fee_per_gas: START_PRIORITY_FEE_TIP as f64, base_fee_per_gas: 2_000_000_000f64, }; assert_eq!(result, expected_result); - } - - #[test] - fn test_calculate_submission_gas_price_resubmission_blocks_elapsed_1() { - // Case 2: Resubmission with blocks_elapsed = 1 - let max_fee_per_gas = 4_000_000_000f64; - let web3_gas_estimation = GasPrice1559 { - base_fee_per_gas: 2_000_000_000f64, - max_fee_per_gas, - max_priority_fee_per_gas: 3_000_000_000f64, - }; - let newest_nonce = U256::one(); + // Second case: Previous tx was not successful let nonce_of_last_submission = Some(newest_nonce); let max_fee_per_gas_of_last_tx = max_fee_per_gas * 2f64; let gas_price_of_last_submission = GasPrice1559 { @@ -258,81 +206,35 @@ mod tests { max_priority_fee_per_gas: START_PRIORITY_FEE_TIP as f64, base_fee_per_gas: 2_000_000_000f64, }; - let result = calculate_submission_gas_price( Some(gas_price_of_last_submission), web3_gas_estimation, newest_nonce, nonce_of_last_submission, - Some(1), ) .unwrap(); - let expected_result = GasPrice1559 { max_fee_per_gas: max_fee_per_gas_of_last_tx * GAS_PRICE_BUMP, max_priority_fee_per_gas: START_PRIORITY_FEE_TIP as f64 * GAS_PRICE_BUMP, base_fee_per_gas: 2_000_000_000f64, }; assert_eq!(result, expected_result); - } - - #[test] - fn test_calculate_submission_gas_price_resubmission_blocks_elapsed_2() { - // Case 3: Resubmission with blocks_elapsed = 2 - let max_fee_per_gas = 4_000_000_000f64; - let web3_gas_estimation = GasPrice1559 { - base_fee_per_gas: 2_000_000_000f64, - max_fee_per_gas, - max_priority_fee_per_gas: 3_000_000_000f64, - }; - let newest_nonce = U256::one(); - let nonce_of_last_submission = Some(newest_nonce); - let max_fee_per_gas_of_last_tx = max_fee_per_gas * 2f64; - let gas_price_of_last_submission = GasPrice1559 { - max_fee_per_gas: max_fee_per_gas_of_last_tx, - max_priority_fee_per_gas: START_PRIORITY_FEE_TIP as f64, - base_fee_per_gas: 2_000_000_000f64, - }; - - let result = calculate_submission_gas_price( - Some(gas_price_of_last_submission), - web3_gas_estimation, - newest_nonce, - nonce_of_last_submission, - Some(2), - ) - .unwrap(); - - let expected_result = GasPrice1559 { - max_fee_per_gas: max_fee_per_gas_of_last_tx * GAS_PRICE_BUMP.powi(2), - max_priority_fee_per_gas: START_PRIORITY_FEE_TIP as f64 * GAS_PRICE_BUMP.powi(2), - base_fee_per_gas: 2_000_000_000f64, - }; - assert_eq!(result, expected_result); - } - - #[test] - fn test_calculate_submission_gas_price_max_gas_price_cap() { - // Case 4: Gas price exceeds MAX_GAS_PRICE and is capped + // Thrid case: MAX_GAS_PRICE is not exceeded let max_fee_per_gas = MAX_GAS_PRICE as f64 + 1000f64; let web3_gas_estimation = GasPrice1559 { base_fee_per_gas: 2_000_000_000f64, max_fee_per_gas, max_priority_fee_per_gas: 3_000_000_000f64, }; - let newest_nonce = U256::one(); let nonce_of_last_submission = None; let gas_price_of_last_submission = None; - let result = calculate_submission_gas_price( gas_price_of_last_submission, web3_gas_estimation, newest_nonce, nonce_of_last_submission, - Some(1), ) .unwrap(); - let expected_result = GasPrice1559 { base_fee_per_gas: 2_000_000_000f64, max_fee_per_gas: MAX_GAS_PRICE as f64, From 59f16cea44fe2212c2cb7c36660f606a09cc12ec Mon Sep 17 00:00:00 2001 From: 3shv Date: Tue, 4 Mar 2025 23:25:59 +0700 Subject: [PATCH 03/11] Bump gas price based on blocks elapsed --- crates/driver/src/domain/mempools.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/crates/driver/src/domain/mempools.rs b/crates/driver/src/domain/mempools.rs index 01293b7472..8746633b02 100644 --- a/crates/driver/src/domain/mempools.rs +++ b/crates/driver/src/domain/mempools.rs @@ -14,8 +14,10 @@ use { anyhow::Context, ethrpc::block_stream::into_stream, futures::{FutureExt, StreamExt, future::select_ok}, + std::ops::Sub, thiserror::Error, tracing::Instrument, + web3::types::BlockNumber, }; /// Factor by how much a transaction fee needs to be increased to override a @@ -150,10 +152,12 @@ impl Mempools { }) } TxStatus::Pending => { + let blocks_elapsed = block.number.sub(submitted_at_block); + // Check if the current block reached the submission deadline block number if block.number >= submission_deadline { let cancellation_tx_hash = self - .cancel(mempool, settlement.gas.price, solver) + .cancel(mempool, settlement.gas.price, solver, blocks_elapsed) .await .context("cancellation tx due to deadline failed")?; tracing::info!( @@ -173,7 +177,7 @@ impl Mempools { if let Err(err) = self.ethereum.estimate_gas(tx).await { if err.is_revert() { let cancellation_tx_hash = self - .cancel(mempool, settlement.gas.price, solver) + .cancel(mempool, settlement.gas.price, solver, blocks_elapsed) .await .context("cancellation tx due to revert failed")?; tracing::info!( @@ -214,7 +218,9 @@ impl Mempools { mempool: &infra::mempool::Mempool, pending: eth::GasPrice, solver: &Solver, + blocks_elapsed: u64, ) -> Result { + let gas_price_bump_factor = GAS_PRICE_BUMP.powf(blocks_elapsed as f64); let cancellation = eth::Tx { from: solver.address(), to: solver.address(), @@ -225,8 +231,16 @@ impl Mempools { let gas = competition::solution::settlement::Gas { estimate: CANCELLATION_GAS_AMOUNT.into(), limit: CANCELLATION_GAS_AMOUNT.into(), - price: pending * GAS_PRICE_BUMP, + price: pending * gas_price_bump_factor, }; + tracing::debug!( + blocks_elapsed = ?blocks_elapsed, + original_gas_price = ?pending, + new_gas_price = ?(pending * gas_price_bump_factor), + bump_factor = ?gas_price_bump_factor, + "Cancelling transaction with adjusted gas price" + ); + mempool.submit(cancellation, gas, solver).await } } From b2b47a11fe89431dba2732057bd806fbc1c18354 Mon Sep 17 00:00:00 2001 From: 3shv Date: Tue, 4 Mar 2025 23:33:43 +0700 Subject: [PATCH 04/11] max --- crates/driver/src/domain/mempools.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/driver/src/domain/mempools.rs b/crates/driver/src/domain/mempools.rs index 8746633b02..5875abde67 100644 --- a/crates/driver/src/domain/mempools.rs +++ b/crates/driver/src/domain/mempools.rs @@ -220,7 +220,7 @@ impl Mempools { solver: &Solver, blocks_elapsed: u64, ) -> Result { - let gas_price_bump_factor = GAS_PRICE_BUMP.powf(blocks_elapsed as f64); + let gas_price_bump_factor = GAS_PRICE_BUMP.powf(blocks_elapsed.max(1) as f64); let cancellation = eth::Tx { from: solver.address(), to: solver.address(), From 7013cc6f053b94f5a1cf77c0878ab32ba9a21115 Mon Sep 17 00:00:00 2001 From: 3shv Date: Wed, 5 Mar 2025 11:26:43 +0700 Subject: [PATCH 05/11] Multiply gas price with blocks_elapsed --- crates/driver/src/domain/mempools.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/driver/src/domain/mempools.rs b/crates/driver/src/domain/mempools.rs index 5875abde67..4d6b6eb9d9 100644 --- a/crates/driver/src/domain/mempools.rs +++ b/crates/driver/src/domain/mempools.rs @@ -220,7 +220,7 @@ impl Mempools { solver: &Solver, blocks_elapsed: u64, ) -> Result { - let gas_price_bump_factor = GAS_PRICE_BUMP.powf(blocks_elapsed.max(1) as f64); + let gas_price_bump_factor = GAS_PRICE_BUMP*(blocks_elapsed.max(1) as f64); let cancellation = eth::Tx { from: solver.address(), to: solver.address(), From e93f51fb34a4cdffdae7ad1ff2eeed4febd93aef Mon Sep 17 00:00:00 2001 From: 3shv Date: Thu, 6 Mar 2025 21:33:50 +0700 Subject: [PATCH 06/11] Use powi --- crates/driver/src/domain/mempools.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/driver/src/domain/mempools.rs b/crates/driver/src/domain/mempools.rs index 4d6b6eb9d9..c81df0bfd4 100644 --- a/crates/driver/src/domain/mempools.rs +++ b/crates/driver/src/domain/mempools.rs @@ -220,7 +220,7 @@ impl Mempools { solver: &Solver, blocks_elapsed: u64, ) -> Result { - let gas_price_bump_factor = GAS_PRICE_BUMP*(blocks_elapsed.max(1) as f64); + let gas_price_bump_factor = GAS_PRICE_BUMP.powi(blocks_elapsed.max(1) as i32); let cancellation = eth::Tx { from: solver.address(), to: solver.address(), From 4de5adf967ca29a37e2858de211b3347e6fe38e9 Mon Sep 17 00:00:00 2001 From: 3shv Date: Fri, 7 Mar 2025 18:51:31 +0700 Subject: [PATCH 07/11] Introduce a new variable for new_gas_price --- crates/driver/src/domain/mempools.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/driver/src/domain/mempools.rs b/crates/driver/src/domain/mempools.rs index c81df0bfd4..7559aa39cd 100644 --- a/crates/driver/src/domain/mempools.rs +++ b/crates/driver/src/domain/mempools.rs @@ -228,15 +228,16 @@ impl Mempools { input: Default::default(), access_list: Default::default(), }; + let new_gas_price = pending * gas_price_bump_factor; let gas = competition::solution::settlement::Gas { estimate: CANCELLATION_GAS_AMOUNT.into(), limit: CANCELLATION_GAS_AMOUNT.into(), - price: pending * gas_price_bump_factor, + price: new_gas_price, }; tracing::debug!( blocks_elapsed = ?blocks_elapsed, original_gas_price = ?pending, - new_gas_price = ?(pending * gas_price_bump_factor), + new_gas_price = ?new_gas_price, bump_factor = ?gas_price_bump_factor, "Cancelling transaction with adjusted gas price" ); From 9d687bcf15c8bdb16402d89ad9048df2f3f7cf8b Mon Sep 17 00:00:00 2001 From: 3shv Date: Fri, 7 Mar 2025 19:08:09 +0700 Subject: [PATCH 08/11] refactor --- crates/driver/src/domain/mempools.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/driver/src/domain/mempools.rs b/crates/driver/src/domain/mempools.rs index 7559aa39cd..0025f7f230 100644 --- a/crates/driver/src/domain/mempools.rs +++ b/crates/driver/src/domain/mempools.rs @@ -220,7 +220,6 @@ impl Mempools { solver: &Solver, blocks_elapsed: u64, ) -> Result { - let gas_price_bump_factor = GAS_PRICE_BUMP.powi(blocks_elapsed.max(1) as i32); let cancellation = eth::Tx { from: solver.address(), to: solver.address(), @@ -228,6 +227,7 @@ impl Mempools { input: Default::default(), access_list: Default::default(), }; + let gas_price_bump_factor = GAS_PRICE_BUMP.powi(blocks_elapsed.max(1) as i32); let new_gas_price = pending * gas_price_bump_factor; let gas = competition::solution::settlement::Gas { estimate: CANCELLATION_GAS_AMOUNT.into(), From 2c34707eaa08af21136db41b85e357c8614ee05e Mon Sep 17 00:00:00 2001 From: 3sh V Date: Sat, 8 Mar 2025 06:33:15 +0700 Subject: [PATCH 09/11] Update crates/driver/src/domain/mempools.rs Co-authored-by: ilya --- crates/driver/src/domain/mempools.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/driver/src/domain/mempools.rs b/crates/driver/src/domain/mempools.rs index 0025f7f230..fd8d6c66a3 100644 --- a/crates/driver/src/domain/mempools.rs +++ b/crates/driver/src/domain/mempools.rs @@ -235,9 +235,9 @@ impl Mempools { price: new_gas_price, }; tracing::debug!( - blocks_elapsed = ?blocks_elapsed, + ?blocks_elapsed, original_gas_price = ?pending, - new_gas_price = ?new_gas_price, + ?new_gas_price, bump_factor = ?gas_price_bump_factor, "Cancelling transaction with adjusted gas price" ); From 3457ffc05b46560c39be3c575fda8dd8e2c1af9d Mon Sep 17 00:00:00 2001 From: 3shv Date: Sat, 8 Mar 2025 16:41:18 +0700 Subject: [PATCH 10/11] remove unused import --- crates/driver/src/domain/mempools.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/driver/src/domain/mempools.rs b/crates/driver/src/domain/mempools.rs index fd8d6c66a3..2a26122849 100644 --- a/crates/driver/src/domain/mempools.rs +++ b/crates/driver/src/domain/mempools.rs @@ -16,8 +16,7 @@ use { futures::{FutureExt, StreamExt, future::select_ok}, std::ops::Sub, thiserror::Error, - tracing::Instrument, - web3::types::BlockNumber, + tracing::Instrument }; /// Factor by how much a transaction fee needs to be increased to override a From 2c4822810efb9d95ed9f154569780855edea58cc Mon Sep 17 00:00:00 2001 From: 3shv Date: Sat, 8 Mar 2025 16:42:33 +0700 Subject: [PATCH 11/11] format --- crates/driver/src/domain/mempools.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/driver/src/domain/mempools.rs b/crates/driver/src/domain/mempools.rs index 2a26122849..87a3f9fd9d 100644 --- a/crates/driver/src/domain/mempools.rs +++ b/crates/driver/src/domain/mempools.rs @@ -16,7 +16,7 @@ use { futures::{FutureExt, StreamExt, future::select_ok}, std::ops::Sub, thiserror::Error, - tracing::Instrument + tracing::Instrument, }; /// Factor by how much a transaction fee needs to be increased to override a