@@ -11,7 +11,7 @@ use alloy::{
1111use backon:: { ExponentialBuilder , Retryable } ;
1212use thiserror:: Error ;
1313use tokio:: time:: { error as TokioError , timeout} ;
14- use tracing:: { error, info} ;
14+ use tracing:: { error, info, instrument , warn } ;
1515
1616use crate :: robust_provider:: RobustSubscription ;
1717
@@ -111,20 +111,17 @@ impl<N: Network> RobustProvider<N> {
111111 /// # Errors
112112 ///
113113 /// See [retry errors](#retry-errors).
114+ #[ instrument( level = "debug" , skip( self ) ) ]
114115 pub async fn get_block_by_number (
115116 & self ,
116117 number : BlockNumberOrTag ,
117118 ) -> Result < N :: BlockResponse , Error > {
118- info ! ( "eth_getBlockByNumber called" ) ;
119119 let result = self
120120 . try_operation_with_failover (
121121 move |provider| async move { provider. get_block_by_number ( number) . await } ,
122122 false ,
123123 )
124124 . await ;
125- if let Err ( e) = & result {
126- error ! ( error = %e, "eth_getByBlockNumber failed" ) ;
127- }
128125
129126 result?. ok_or_else ( || Error :: BlockNotFound ( number. into ( ) ) )
130127 }
@@ -136,17 +133,14 @@ impl<N: Network> RobustProvider<N> {
136133 /// # Errors
137134 ///
138135 /// See [retry errors](#retry-errors).
136+ #[ instrument( level = "debug" , skip( self ) ) ]
139137 pub async fn get_block ( & self , id : BlockId ) -> Result < N :: BlockResponse , Error > {
140- info ! ( "eth_getBlock called" ) ;
141138 let result = self
142139 . try_operation_with_failover (
143140 |provider| async move { provider. get_block ( id) . await } ,
144141 false ,
145142 )
146143 . await ;
147- if let Err ( e) = & result {
148- error ! ( error = %e, "eth_getByBlockNumber failed" ) ;
149- }
150144 result?. ok_or_else ( || Error :: BlockNotFound ( id) )
151145 }
152146
@@ -157,19 +151,14 @@ impl<N: Network> RobustProvider<N> {
157151 /// # Errors
158152 ///
159153 /// See [retry errors](#retry-errors).
154+ #[ instrument( level = "debug" , skip( self ) ) ]
160155 pub async fn get_block_number ( & self ) -> Result < BlockNumber , Error > {
161- info ! ( "eth_getBlockNumber called" ) ;
162- let result = self
163- . try_operation_with_failover (
164- move |provider| async move { provider. get_block_number ( ) . await } ,
165- false ,
166- )
167- . await
168- . map_err ( Error :: from) ;
169- if let Err ( e) = & result {
170- error ! ( error = %e, "eth_getBlockNumber failed" ) ;
171- }
172- result
156+ self . try_operation_with_failover (
157+ move |provider| async move { provider. get_block_number ( ) . await } ,
158+ false ,
159+ )
160+ . await
161+ . map_err ( Error :: from)
173162 }
174163
175164 /// Get the block number for a given block identifier.
@@ -183,17 +172,14 @@ impl<N: Network> RobustProvider<N> {
183172 /// # Errors
184173 ///
185174 /// See [retry errors](#retry-errors).
175+ #[ instrument( level = "debug" , skip( self ) ) ]
186176 pub async fn get_block_number_by_id ( & self , block_id : BlockId ) -> Result < BlockNumber , Error > {
187- info ! ( "get_block_number_by_id called" ) ;
188177 let result = self
189178 . try_operation_with_failover (
190179 move |provider| async move { provider. get_block_number_by_id ( block_id) . await } ,
191180 false ,
192181 )
193182 . await ;
194- if let Err ( e) = & result {
195- error ! ( error = %e, "get_block_number_by_id failed" ) ;
196- }
197183 result?. ok_or_else ( || Error :: BlockNotFound ( block_id) )
198184 }
199185
@@ -210,8 +196,8 @@ impl<N: Network> RobustProvider<N> {
210196 /// # Errors
211197 ///
212198 /// See [retry errors](#retry-errors).
199+ #[ instrument( level = "debug" , skip( self ) ) ]
213200 pub async fn get_latest_confirmed ( & self , confirmations : u64 ) -> Result < u64 , Error > {
214- info ! ( "get_latest_confirmed called with confirmations={}" , confirmations) ;
215201 let latest_block = self . get_block_number ( ) . await ?;
216202 let confirmed_block = latest_block. saturating_sub ( confirmations) ;
217203 Ok ( confirmed_block)
@@ -224,17 +210,14 @@ impl<N: Network> RobustProvider<N> {
224210 /// # Errors
225211 ///
226212 /// See [retry errors](#retry-errors).
213+ #[ instrument( level = "debug" , skip( self ) ) ]
227214 pub async fn get_block_by_hash ( & self , hash : BlockHash ) -> Result < N :: BlockResponse , Error > {
228- info ! ( "eth_getBlockByHash called" ) ;
229215 let result = self
230216 . try_operation_with_failover (
231217 move |provider| async move { provider. get_block_by_hash ( hash) . await } ,
232218 false ,
233219 )
234220 . await ;
235- if let Err ( e) = & result {
236- error ! ( error = %e, "eth_getBlockByHash failed" ) ;
237- }
238221
239222 result?. ok_or_else ( || Error :: BlockNotFound ( hash. into ( ) ) )
240223 }
@@ -246,19 +229,14 @@ impl<N: Network> RobustProvider<N> {
246229 /// # Errors
247230 ///
248231 /// See [retry errors](#retry-errors).
232+ #[ instrument( level = "debug" , skip( self , filter) ) ]
249233 pub async fn get_logs ( & self , filter : & Filter ) -> Result < Vec < Log > , Error > {
250- info ! ( "eth_getLogs called" ) ;
251- let result = self
252- . try_operation_with_failover (
253- move |provider| async move { provider. get_logs ( filter) . await } ,
254- false ,
255- )
256- . await
257- . map_err ( Error :: from) ;
258- if let Err ( e) = & result {
259- error ! ( error = %e, "eth_getLogs failed" ) ;
260- }
261- result
234+ self . try_operation_with_failover (
235+ move |provider| async move { provider. get_logs ( filter) . await } ,
236+ false ,
237+ )
238+ . await
239+ . map_err ( Error :: from)
262240 }
263241
264242 /// Subscribe to new block headers with automatic failover and reconnection.
@@ -273,24 +251,18 @@ impl<N: Network> RobustProvider<N> {
273251 /// # Errors
274252 ///
275253 /// see [retry errors](#retry-errors).
254+ #[ instrument( level = "debug" , skip( self ) ) ]
276255 pub async fn subscribe_blocks ( & self ) -> Result < RobustSubscription < N > , Error > {
277- info ! ( "eth_subscribe called" ) ;
278256 let subscription = self
279257 . try_operation_with_failover (
280258 move |provider| async move {
281259 provider. subscribe_blocks ( ) . channel_size ( MAX_CHANNEL_SIZE ) . await
282260 } ,
283261 true ,
284262 )
285- . await ;
263+ . await ? ;
286264
287- match subscription {
288- Ok ( sub) => Ok ( RobustSubscription :: new ( sub, self . clone ( ) ) ) ,
289- Err ( e) => {
290- error ! ( error = %e, "eth_subscribe failed" ) ;
291- Err ( e. into ( ) )
292- }
293- }
265+ Ok ( RobustSubscription :: new ( subscription, self . clone ( ) ) )
294266 }
295267
296268 /// Execute `operation` with exponential backoff and a total timeout.
@@ -361,31 +333,30 @@ impl<N: Network> RobustProvider<N> {
361333 Fut : Future < Output = Result < T , RpcError < TransportErrorKind > > > ,
362334 {
363335 let num_fallbacks = self . fallback_providers . len ( ) ;
364- if num_fallbacks > 0 && start_index == 0 {
365- info ! ( "Primary provider failed, trying fallback provider(s)" ) ;
366- }
367336
368337 let fallback_providers = self . fallback_providers . iter ( ) . enumerate ( ) . skip ( start_index) ;
369338 for ( fallback_idx, provider) in fallback_providers {
370339 if require_pubsub && !Self :: supports_pubsub ( provider) {
371- info ! ( "Fallback provider {} doesn't support pubsub, skipping" , fallback_idx + 1 ) ;
340+ warn ! ( provider_num = fallback_idx + 1 , "Fallback provider doesn't support pubsub, skipping" ) ;
372341 continue ;
373342 }
374- info ! ( "Attempting fallback provider {}/{}" , fallback_idx + 1 , num_fallbacks) ;
375343
376344 match self . try_provider_with_timeout ( provider, & operation) . await {
377345 Ok ( value) => {
378- info ! ( provider_num = fallback_idx + 1 , "Fallback provider succeeded" ) ;
346+ info ! (
347+ provider_num = fallback_idx + 1 ,
348+ total_fallbacks = num_fallbacks,
349+ "Switched to fallback provider"
350+ ) ;
379351 return Ok ( ( value, fallback_idx) ) ;
380352 }
381353 Err ( e) => {
382- error ! ( provider_num = fallback_idx + 1 , err = %e, "Fallback provider failed" ) ;
383354 last_error = e;
384355 }
385356 }
386357 }
387- // All fallbacks failed / skipped, return the last error
388- error ! ( "All providers failed or timed out - returning the last providers attempt's error " ) ;
358+
359+ error ! ( "All providers exhausted " ) ;
389360 Err ( last_error)
390361 }
391362
@@ -405,12 +376,7 @@ impl<N: Network> RobustProvider<N> {
405376
406377 timeout (
407378 self . call_timeout ,
408- ( || operation ( provider. clone ( ) ) )
409- . retry ( retry_strategy)
410- . notify ( |err : & RpcError < TransportErrorKind > , dur : Duration | {
411- info ! ( error = %err, "RPC error retrying after {:?}" , dur) ;
412- } )
413- . sleep ( tokio:: time:: sleep) ,
379+ ( || operation ( provider. clone ( ) ) ) . retry ( retry_strategy) . sleep ( tokio:: time:: sleep) ,
414380 )
415381 . await
416382 . map_err ( CoreError :: from) ?
0 commit comments