@@ -5,7 +5,7 @@ use std::time::Duration;
55use dapi_grpc:: mock:: Mockable ;
66use dpp:: version:: PlatformVersionError ;
77use dpp:: ProtocolError ;
8- use rs_dapi_client:: DapiClientError ;
8+ use rs_dapi_client:: { CanRetry , DapiClientError } ;
99
1010pub use drive_proof_verifier:: error:: ContextProviderError ;
1111
@@ -67,6 +67,10 @@ pub enum Error {
6767 /// Operation cancelled - cancel token was triggered, timeout, etc.
6868 #[ error( "Operation cancelled: {0}" ) ]
6969 Cancelled ( String ) ,
70+
71+ /// Remote node is stale; try another server
72+ #[ error( transparent) ]
73+ StaleNode ( #[ from] StaleNodeError ) ,
7074}
7175
7276impl < T : Debug + Mockable > From < DapiClientError < T > > for Error {
@@ -80,3 +84,36 @@ impl From<PlatformVersionError> for Error {
8084 Self :: Protocol ( value. into ( ) )
8185 }
8286}
87+
88+ impl CanRetry for Error {
89+ fn can_retry ( & self ) -> bool {
90+ matches ! ( self , Error :: StaleNode ( ..) | Error :: TimeoutReached ( _, _) )
91+ }
92+ }
93+
94+ /// Server returned stale metadata
95+ #[ derive( Debug , thiserror:: Error ) ]
96+ pub enum StaleNodeError {
97+ /// Server returned metadata with outdated height
98+ #[ error( "received height is outdated: expected {expected_height}, received {received_height}, tolerance {tolerance_blocks}; try another server" ) ]
99+ Height {
100+ /// Expected height - last block height seen by the Sdk
101+ expected_height : u64 ,
102+ /// Block height received from the server
103+ received_height : u64 ,
104+ /// Tolerance - how many blocks can be behind the expected height
105+ tolerance_blocks : u64 ,
106+ } ,
107+ /// Server returned metadata with time outside of the tolerance
108+ #[ error(
109+ "received invalid time: expected {expected_timestamp_ms}ms, received {received_timestamp_ms} ms, tolerance {tolerance_ms} ms; try another server"
110+ ) ]
111+ Time {
112+ /// Expected time in milliseconds - is local time when the message was received
113+ expected_timestamp_ms : u64 ,
114+ /// Time received from the server in the message, in milliseconds
115+ received_timestamp_ms : u64 ,
116+ /// Tolerance in milliseconds
117+ tolerance_ms : u64 ,
118+ } ,
119+ }
0 commit comments