@@ -9,7 +9,7 @@ use alloy::{
99} ;
1010use anyhow:: Result ;
1111use log:: { debug, info, warn} ;
12- use tokio:: time:: { timeout , Duration } ;
12+ use tokio:: time:: Duration ;
1313
1414use crate :: web3:: wallet:: WalletProvider ;
1515
@@ -30,13 +30,23 @@ where
3030 N : Network ,
3131 D : CallDecoder + Clone ,
3232{
33+ const PENDING_TRANSACTION_TIMEOUT : Duration = Duration :: from_secs ( 60 ) ;
34+
3335 let mut tries = 0 ;
3436 let retry_delay = retry_delay. unwrap_or ( 2 ) ;
37+ let mut tx_hash = None ;
3538
3639 while tries < max_tries {
3740 if tries > 0 {
3841 tokio:: time:: sleep ( Duration :: from_secs ( retry_delay) ) . await ;
3942
43+ if let Some ( tx_hash) = tx_hash {
44+ let receipt = provider. get_transaction_receipt ( tx_hash) . await ?;
45+ if receipt. is_some ( ) {
46+ return Ok ( tx_hash) ;
47+ }
48+ }
49+
4050 // On retry, always fetch fresh fee estimates from the provider.
4151 let priority_fee_res = provider. get_max_priority_fee_per_gas ( ) . await ;
4252 let gas_price_res = provider. get_gas_price ( ) . await ;
5464 call = call
5565 . clone ( )
5666 . max_fee_per_gas ( new_gas_price)
57- . max_priority_fee_per_gas ( new_priority_fee) ;
67+ . max_priority_fee_per_gas ( new_priority_fee)
5868 } else {
5969 warn ! ( "Could not get new gas fees, retrying with old settings." ) ;
6070 }
@@ -63,10 +73,15 @@ where
6373 match call. clone ( ) . send ( ) . await {
6474 Ok ( result) => {
6575 debug ! ( "Transaction sent, waiting for confirmation..." ) ;
66- match timeout ( Duration :: from_secs ( 30 ) , result. watch ( ) ) . await {
67- Ok ( Ok ( hash) ) => return Ok ( hash) ,
68- Ok ( Err ( err) ) => warn ! ( "Transaction watch failed: {err:?}" ) ,
69- Err ( _) => warn ! ( "Watch timed out, retrying transaction..." ) ,
76+ tx_hash = Some ( * result. tx_hash ( ) ) ;
77+
78+ match result
79+ . with_timeout ( Some ( PENDING_TRANSACTION_TIMEOUT ) )
80+ . watch ( )
81+ . await
82+ {
83+ Ok ( hash) => return Ok ( hash) ,
84+ Err ( err) => warn ! ( "Transaction watch failed: {err:?}" ) ,
7085 }
7186 }
7287 Err ( err) => {
0 commit comments