File tree Expand file tree Collapse file tree 3 files changed +11
-6
lines changed
Expand file tree Collapse file tree 3 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,9 @@ pub enum ScannerError {
3333
3434 #[ error( "Subscription closed" ) ]
3535 SubscriptionClosed ,
36+
37+ #[ error( "Subscriptions Lagged too often" ) ]
38+ SubscriptionLagged ,
3639}
3740
3841impl From < RobustProviderError > for ScannerError {
@@ -42,6 +45,7 @@ impl From<RobustProviderError> for ScannerError {
4245 RobustProviderError :: RpcError ( err) => ScannerError :: RpcError ( err) ,
4346 RobustProviderError :: BlockNotFound ( block) => ScannerError :: BlockNotFound ( block) ,
4447 RobustProviderError :: Closed => ScannerError :: SubscriptionClosed ,
48+ RobustProviderError :: SubscriptionLagged => ScannerError :: SubscriptionLagged ,
4549 }
4650 }
4751}
Original file line number Diff line number Diff line change 1+ use crate :: robust_provider:: subscription:: MAX_LAG_COUNT ;
12use std:: sync:: Arc ;
23
34use alloy:: {
@@ -17,6 +18,8 @@ pub enum Error {
1718 BlockNotFound ( BlockId ) ,
1819 #[ error( "Subscription closed" ) ]
1920 Closed ,
21+ #[ error( "Subscription lag exceeded maximum consecutive lag count: {MAX_LAG_COUNT:?}" ) ]
22+ SubscriptionLagged ,
2023}
2124
2225impl From < RpcError < TransportErrorKind > > for Error {
Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ use alloy::{
88 network:: Network ,
99 providers:: { Provider , RootProvider } ,
1010 pubsub:: Subscription ,
11- transports:: { RpcError , TransportErrorKind } ,
1211} ;
1312use tokio:: { sync:: broadcast:: error:: RecvError , time:: timeout} ;
1413use tokio_stream:: Stream ;
@@ -124,11 +123,7 @@ impl<N: Network> RobustSubscription<N> {
124123
125124 if self . consecutive_lags >= MAX_LAG_COUNT {
126125 warn ! ( "Too many consecutive lags, switching provider" ) ;
127- let error = RpcError :: Transport ( TransportErrorKind :: Custom (
128- "Encountered too much lag" . into ( ) ,
129- ) )
130- . into ( ) ;
131- self . switch_to_fallback ( error) . await ?;
126+ self . switch_to_fallback ( Error :: SubscriptionLagged ) . await ?;
132127 }
133128 }
134129 }
@@ -324,6 +319,9 @@ mod tests {
324319 Error :: Closed => {
325320 panic ! ( "Unexpected Closed error" ) ;
326321 }
322+ Error :: SubscriptionLagged => {
323+ panic ! ( "Unexpected SubscriptionLagged error" ) ;
324+ }
327325 }
328326 }
329327
You can’t perform that action at this time.
0 commit comments