Skip to content

Commit

Permalink
chore: log instead of panicking if gas price isn't set
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-savu committed Nov 8, 2024
1 parent eab0225 commit 0773c2a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 5 additions & 6 deletions ethers-middleware/src/gas_escalator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl<M, E> EscalationTask<M, E> {

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 {
Expand All @@ -271,7 +271,10 @@ impl<M, E> EscalationTask<M, E> {
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(
Expand All @@ -289,10 +292,6 @@ impl<M, E> EscalationTask<M, E> {
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,
Expand Down
2 changes: 2 additions & 0 deletions ethers-middleware/tests/gas_escalator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Http>::try_from(anvil.endpoint()).unwrap();
Expand Down

0 comments on commit 0773c2a

Please sign in to comment.