From 956ea8d9b16c8767a8fd6c980a4f461ce83ac538 Mon Sep 17 00:00:00 2001 From: Dzejkop Date: Mon, 11 Dec 2023 11:02:16 +0100 Subject: [PATCH] Fix escalation fee logic --- src/tasks/escalate.rs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/tasks/escalate.rs b/src/tasks/escalate.rs index 9725842..59797eb 100644 --- a/src/tasks/escalate.rs +++ b/src/tasks/escalate.rs @@ -37,22 +37,19 @@ pub async fn escalate_txs(app: Arc) -> eyre::Result<()> { .context("Missing block")?; // Min increase of 20% on the priority fee required for a replacement tx + let factor = U256::from(100); let increased_gas_price_percentage = - U256::from(100 + (10 * (1 + escalation))); + factor + U256::from(10 * (1 + escalation)); - let factor = U256::from(100); + let max_fee_per_gas_increase = tx.initial_max_fee_per_gas.0 + * increased_gas_price_percentage + / factor; - let max_priority_fee_per_gas_increase = - tx.initial_max_priority_fee_per_gas.0 - * increased_gas_price_percentage - / factor; + let max_fee_per_gas = + tx.initial_max_fee_per_gas.0 + max_fee_per_gas_increase; let max_priority_fee_per_gas = - tx.initial_max_priority_fee_per_gas.0 - + max_priority_fee_per_gas_increase; - - let max_fee_per_gas = - fees.fee_estimates.base_fee_per_gas + max_priority_fee_per_gas; + max_fee_per_gas - fees.fee_estimates.base_fee_per_gas; let eip1559_tx = Eip1559TransactionRequest { from: None, @@ -84,8 +81,6 @@ pub async fn escalate_txs(app: Arc) -> eyre::Result<()> { let tx_hash = pending_tx.tx_hash(); - tracing::info!(?tx.id, ?tx_hash, "Tx escalated"); - app.db .escalate_tx( &tx.id, @@ -94,6 +89,8 @@ pub async fn escalate_txs(app: Arc) -> eyre::Result<()> { max_priority_fee_per_gas, ) .await?; + + tracing::info!(?tx.id, ?tx_hash, "Tx escalated"); } tokio::time::sleep(app.config.service.escalation_interval).await;