@@ -10,6 +10,8 @@ use crate::{
1010// RPC retry and timeout settings
1111/// Default timeout used by `RobustProvider`
1212pub const DEFAULT_MAX_TIMEOUT : Duration = Duration :: from_secs ( 60 ) ;
13+ /// Default timeout for subscriptions (longer to accommodate slow block times)
14+ pub const DEFAULT_SUBSCRIPTION_TIMEOUT : Duration = Duration :: from_secs ( 120 ) ;
1315/// Default maximum number of retry attempts.
1416pub const DEFAULT_MAX_RETRIES : usize = 3 ;
1517/// Default base delay between retries.
@@ -19,27 +21,29 @@ pub const DEFAULT_MIN_DELAY: Duration = Duration::from_secs(1);
1921pub struct RobustProviderBuilder < N : Network , P : IntoProvider < N > > {
2022 providers : Vec < P > ,
2123 max_timeout : Duration ,
24+ subscription_timeout : Duration ,
2225 max_retries : usize ,
2326 min_delay : Duration ,
2427 _network : PhantomData < N > ,
2528}
2629
2730impl < N : Network , P : IntoProvider < N > > RobustProviderBuilder < N , P > {
28- /// Create a new `RobustProvider` with default settings.
31+ /// Create a new [ `RobustProvider`] with default settings.
2932 ///
3033 /// The provided provider is treated as the primary provider.
3134 #[ must_use]
3235 pub fn new ( provider : P ) -> Self {
3336 Self {
3437 providers : vec ! [ provider] ,
3538 max_timeout : DEFAULT_MAX_TIMEOUT ,
39+ subscription_timeout : DEFAULT_SUBSCRIPTION_TIMEOUT ,
3640 max_retries : DEFAULT_MAX_RETRIES ,
3741 min_delay : DEFAULT_MIN_DELAY ,
3842 _network : PhantomData ,
3943 }
4044 }
4145
42- /// Create a new `RobustProvider` with no retry attempts and only timeout set.
46+ /// Create a new [ `RobustProvider`] with no retry attempts and only timeout set.
4347 ///
4448 /// The provided provider is treated as the primary provider.
4549 #[ must_use]
@@ -63,6 +67,16 @@ impl<N: Network, P: IntoProvider<N>> RobustProviderBuilder<N, P> {
6367 self
6468 }
6569
70+ /// Set the timeout for subscription operations.
71+ ///
72+ /// This should be set higher than [`max_timeout`](Self::max_timeout) to accommodate chains with
73+ /// slow block times. Default is [`DEFAULT_SUBSCRIPTION_TIMEOUT`].
74+ #[ must_use]
75+ pub fn subscription_timeout ( mut self , timeout : Duration ) -> Self {
76+ self . subscription_timeout = timeout;
77+ self
78+ }
79+
6680 /// Set the maximum number of retry attempts.
6781 #[ must_use]
6882 pub fn max_retries ( mut self , max_retries : usize ) -> Self {
@@ -92,6 +106,7 @@ impl<N: Network, P: IntoProvider<N>> RobustProviderBuilder<N, P> {
92106 Ok ( RobustProvider {
93107 providers,
94108 max_timeout : self . max_timeout ,
109+ subscription_timeout : self . subscription_timeout ,
95110 max_retries : self . max_retries ,
96111 min_delay : self . min_delay ,
97112 } )
0 commit comments