From 0773c2af5eeec3394c24f8271d7680b7a5855e98 Mon Sep 17 00:00:00 2001 From: Daniel Savu <23065004+daniel-savu@users.noreply.github.com> Date: Fri, 8 Nov 2024 14:02:59 +0000 Subject: [PATCH] chore: log instead of panicking if gas price isn't set --- ethers-middleware/src/gas_escalator/mod.rs | 11 +++++------ ethers-middleware/tests/gas_escalator.rs | 2 ++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ethers-middleware/src/gas_escalator/mod.rs b/ethers-middleware/src/gas_escalator/mod.rs index 02b30162e..434a68690 100644 --- a/ethers-middleware/src/gas_escalator/mod.rs +++ b/ethers-middleware/src/gas_escalator/mod.rs @@ -254,7 +254,7 @@ impl EscalationTask { let len = txs.len(); if len > 0 { - println!("In the escalator watcher loop. Monitored txs: {:?}", txs); + tracing::debug!(?txs, "In the escalator watcher loop. Monitoring txs"); } // Pop all transactions and re-insert those that have not been included yet for _ in 0..len { @@ -271,7 +271,10 @@ impl EscalationTask { tracing::trace!(tx_hash = ?old_tx_hash, "checking if exists"); if receipt.is_none() { - let old_gas_price = replacement_tx.gas_price.expect("gas price must be set"); + let Some(old_gas_price) = replacement_tx.gas_price else { + tracing::error!(tx=?old_tx_hash, "gas price is not set for transaction, dropping from escalator"); + continue; + }; // Get the new gas price based on how much time passed since the // tx was last broadcast let new_gas_price = self.escalator.get_gas_price( @@ -289,10 +292,6 @@ impl EscalationTask { match self.inner.send_transaction(replacement_tx.clone(), priority).await { Ok(new_tx_hash) => { let new_tx_hash = *new_tx_hash; - println!( - "escalated gas price for tx hash: {:?}. New tx hash: {:?}. Old gas price: {:?}. New gas price: {:?}", - old_tx_hash, new_tx_hash, old_gas_price, new_gas_price - ); tracing::debug!( old_tx_hash = ?old_tx_hash, new_tx_hash = ?new_tx_hash, diff --git a/ethers-middleware/tests/gas_escalator.rs b/ethers-middleware/tests/gas_escalator.rs index fff88bf8a..827af9865 100644 --- a/ethers-middleware/tests/gas_escalator.rs +++ b/ethers-middleware/tests/gas_escalator.rs @@ -13,6 +13,8 @@ use tokio::time::sleep; #[tokio::test] async fn gas_escalator_live() { + // TODO: show tracing logs in the test + let anvil = Anvil::new().port(8545u16).block_time(10u64).spawn(); let chain_id = anvil.chain_id(); let provider = Provider::::try_from(anvil.endpoint()).unwrap();