11use {
2+ crate :: config:: EscalationPolicyConfig ,
3+ crate :: eth_utils:: nonce_manager:: NonceManaged ,
24 anyhow:: { anyhow, Result } ,
3- ethers:: { contract:: ContractCall , middleware:: Middleware } ,
4- ethers:: types:: U256 ,
5+ backoff:: ExponentialBackoff ,
56 ethers:: types:: TransactionReceipt ,
7+ ethers:: types:: U256 ,
8+ ethers:: { contract:: ContractCall , middleware:: Middleware } ,
9+ std:: sync:: atomic:: AtomicU64 ,
610 std:: sync:: Arc ,
7- tracing,
8- std:: sync:: atomic:: AtomicU64 ,
9- crate :: config:: EscalationPolicyConfig ,
1011 tokio:: time:: { timeout, Duration } ,
11- backoff :: ExponentialBackoff ,
12+ tracing ,
1213} ;
1314
1415const TX_CONFIRMATION_TIMEOUT_SECS : u64 = 30 ;
@@ -81,7 +82,7 @@ pub async fn estimate_tx_cost<T: Middleware + 'static>(
8182 Ok ( gas_price * gas_used)
8283}
8384
84- pub async fn submit_tx_with_backoff < T : Middleware + ' static > (
85+ pub async fn submit_tx_with_backoff < T : Middleware + NonceManaged + ' static > (
8586 middleware : Arc < T > ,
8687 call : ContractCall < T , ( ) > ,
8788 gas_limit : U256 ,
@@ -110,7 +111,8 @@ pub async fn submit_tx_with_backoff<T: Middleware + 'static>(
110111 gas_limit,
111112 gas_multiplier_pct,
112113 fee_multiplier_pct,
113- ) . await
114+ )
115+ . await
114116 } ,
115117 |e, dur| {
116118 let retry_number = num_retries. load ( std:: sync:: atomic:: Ordering :: Relaxed ) ;
@@ -125,11 +127,11 @@ pub async fn submit_tx_with_backoff<T: Middleware + 'static>(
125127 )
126128 . await ;
127129
128- let duration = start_time. elapsed ( ) ;
130+ let duration = start_time. elapsed ( ) ;
129131 let num_retries = num_retries. load ( std:: sync:: atomic:: Ordering :: Relaxed ) ;
130132
131133 Ok ( SubmitTxResult {
132- num_retries : num_retries ,
134+ num_retries,
133135 gas_multiplier : escalation_policy. get_gas_multiplier_pct ( num_retries) ,
134136 fee_multiplier : escalation_policy. get_fee_multiplier_pct ( num_retries) ,
135137 duration,
@@ -141,16 +143,15 @@ pub async fn submit_tx_with_backoff<T: Middleware + 'static>(
141143/// submits the transaction if the gas estimate is below the gas limit.
142144/// It will return a permanent or transient error depending on the error type and whether
143145/// retry is possible or not.
144- pub async fn submit_tx < T : Middleware + ' static > (
146+ pub async fn submit_tx < T : Middleware + NonceManaged + ' static > (
145147 client : Arc < T > ,
146148 call : & ContractCall < T , ( ) > ,
147149 gas_limit : U256 ,
148150 // A value of 100 submits the tx with the same gas/fee as the estimate.
149151 gas_estimate_multiplier_pct : u64 ,
150152 fee_estimate_multiplier_pct : u64 ,
151153) -> Result < TransactionReceipt , backoff:: Error < anyhow:: Error > > {
152-
153- let gas_estimate_res = call. estimate_gas ( ) . await ;
154+ let gas_estimate_res = call. estimate_gas ( ) . await ;
154155
155156 let gas_estimate = gas_estimate_res. map_err ( |e| {
156157 // we consider the error transient even if it is a contract revert since
@@ -173,7 +174,7 @@ pub async fn submit_tx<T: Middleware + 'static>(
173174 // the padded gas estimate doesn't exceed the maximum amount of gas we are willing to use.
174175 let gas_estimate = gas_estimate. saturating_mul ( gas_estimate_multiplier_pct. into ( ) ) / 100 ;
175176
176- let call = call. gas ( gas_estimate) ;
177+ let call = call. clone ( ) . gas ( gas_estimate) ;
177178
178179 let mut transaction = call. tx . clone ( ) ;
179180
@@ -207,8 +208,7 @@ pub async fn submit_tx<T: Middleware + 'static>(
207208 } ) ?;
208209
209210 let reset_nonce = || {
210- let nonce_manager = client. inner ( ) . inner ( ) ;
211- nonce_manager. reset ( ) ;
211+ client. reset ( ) ;
212212 } ;
213213
214214 let pending_receipt = timeout (
0 commit comments