@@ -14,9 +14,6 @@ use std::collections::{HashMap, HashSet};
14
14
use std:: error:: Error ;
15
15
use std:: fmt;
16
16
17
- // TODO: remove this
18
- use crate :: kiprintln;
19
-
20
17
/// Subscription kind. Pulled directly from alloy (https://github.com/alloy-rs/alloy).
21
18
/// Why? Because alloy is not yet 1.0 and the types in this interface must be stable.
22
19
/// If alloy SubscriptionKind changes, we can implement a transition function in runtime
@@ -338,9 +335,6 @@ impl Provider {
338
335
. unwrap ( )
339
336
. map_err ( |_| EthError :: RpcTimeout ) ?;
340
337
341
- //TODO: remove
342
- //kiprintln!("PROCESS_LIB::send_request_and_parse_response resp: {:#?}", resp);
343
-
344
338
match resp {
345
339
Message :: Response { body, .. } => match serde_json:: from_slice :: < EthResponse > ( & body) {
346
340
Ok ( EthResponse :: Response ( value) ) => {
@@ -705,8 +699,6 @@ impl Provider {
705
699
// NOTE: tx must be encased by a tuple to be serialized correctly
706
700
params : serde_json:: to_value ( ( tx, ) ) . unwrap ( ) ,
707
701
} ;
708
- //TODO: remove
709
- kiprintln ! ( "PROCESS_LIB::send_raw_transaction action: {:#?}" , action) ;
710
702
711
703
self . send_request_and_parse_response :: < TxHash > ( action)
712
704
}
@@ -764,21 +756,54 @@ impl Provider {
764
756
print_verbosity_success : u8 ,
765
757
print_verbosity_error : u8 ,
766
758
) {
759
+ let mut delay_secs = 5 ; // Initial delay
760
+ const MAX_DELAY_SECS : u64 = 60 ; // Maximum delay
761
+
767
762
loop {
768
763
match self . subscribe ( sub_id, filter. clone ( ) ) {
769
- Ok ( ( ) ) => break ,
770
- Err ( _ ) => {
764
+ Ok ( ( ) ) => break , // Success, exit loop
765
+ Err ( e ) => { // Log the actual error
771
766
crate :: print_to_terminal (
772
767
print_verbosity_error,
773
- "failed to subscribe to chain! trying again in 5s..." ,
768
+ & format ! (
769
+ "Failed to subscribe to chain (sub_id {}): {:?}. Retrying in {}s..." ,
770
+ sub_id, e, delay_secs
771
+ ) ,
774
772
) ;
775
- std:: thread:: sleep ( std:: time:: Duration :: from_secs ( 5 ) ) ;
776
- continue ;
773
+ std:: thread:: sleep ( std:: time:: Duration :: from_secs ( delay_secs) ) ;
774
+ // Increase delay for next attempt, capped at maximum
775
+ delay_secs = ( delay_secs * 2 ) . min ( MAX_DELAY_SECS ) ;
776
+ continue ; // Retry
777
777
}
778
778
}
779
779
}
780
- crate :: print_to_terminal ( print_verbosity_success, "subscribed to logs successfully" ) ;
780
+ crate :: print_to_terminal (
781
+ print_verbosity_success,
782
+ & format ! ( "Subscribed successfully (sub_id {})" , sub_id) ,
783
+ ) ;
781
784
}
785
+ //pub fn subscribe_loop(
786
+ // &self,
787
+ // sub_id: u64,
788
+ // filter: Filter,
789
+ // print_verbosity_success: u8,
790
+ // print_verbosity_error: u8,
791
+ //) {
792
+ // loop {
793
+ // match self.subscribe(sub_id, filter.clone()) {
794
+ // Ok(()) => break,
795
+ // Err(_) => {
796
+ // crate::print_to_terminal(
797
+ // print_verbosity_error,
798
+ // "failed to subscribe to chain! trying again in 5s...",
799
+ // );
800
+ // std::thread::sleep(std::time::Duration::from_secs(5));
801
+ // continue;
802
+ // }
803
+ // }
804
+ // }
805
+ // crate::print_to_terminal(print_verbosity_success, "subscribed to logs successfully");
806
+ //}
782
807
783
808
/// Unsubscribes from a previously created subscription.
784
809
///
0 commit comments