@@ -44,9 +44,9 @@ const WARNING_MSG: &str = "BLOCK PROPOSALS WILL FAIL WITHOUT VALID, SYNCED ETH1
44
44
/// A factor used to reduce the eth1 follow distance to account for discrepancies in the block time.
45
45
const ETH1_BLOCK_TIME_TOLERANCE_FACTOR : u64 = 4 ;
46
46
47
- #[ derive( Debug , PartialEq , Clone , Copy ) ]
47
+ #[ derive( Debug , PartialEq , Clone ) ]
48
48
pub enum EndpointError {
49
- NotReachable ,
49
+ RequestFailed ( String ) ,
50
50
WrongNetworkId ,
51
51
WrongChainId ,
52
52
FarBehind ,
@@ -73,7 +73,7 @@ async fn reset_endpoint_state(endpoint: &EndpointWithState) {
73
73
}
74
74
75
75
async fn get_state ( endpoint : & EndpointWithState ) -> Option < EndpointState > {
76
- * endpoint. state . read ( ) . await
76
+ endpoint. state . read ( ) . await . clone ( )
77
77
}
78
78
79
79
/// A cache structure to lazily check usability of endpoints. An endpoint is usable if it is
@@ -90,11 +90,11 @@ impl EndpointsCache {
90
90
/// Checks the usability of an endpoint. Results get cached and therefore only the first call
91
91
/// for each endpoint does the real check.
92
92
async fn state ( & self , endpoint : & EndpointWithState ) -> EndpointState {
93
- if let Some ( result) = * endpoint. state . read ( ) . await {
93
+ if let Some ( result) = endpoint. state . read ( ) . await . clone ( ) {
94
94
return result;
95
95
}
96
96
let mut value = endpoint. state . write ( ) . await ;
97
- if let Some ( result) = * value {
97
+ if let Some ( result) = value. clone ( ) {
98
98
return result;
99
99
}
100
100
crate :: metrics:: inc_counter_vec (
@@ -108,7 +108,7 @@ impl EndpointsCache {
108
108
& self . log ,
109
109
)
110
110
. await ;
111
- * value = Some ( state) ;
111
+ * value = Some ( state. clone ( ) ) ;
112
112
if state. is_err ( ) {
113
113
crate :: metrics:: inc_counter_vec (
114
114
& crate :: metrics:: ENDPOINT_ERRORS ,
@@ -147,7 +147,7 @@ impl EndpointsCache {
147
147
& [ endpoint_str] ,
148
148
) ;
149
149
if let SingleEndpointError :: EndpointError ( e) = & t {
150
- * endpoint. state . write ( ) . await = Some ( Err ( * e ) ) ;
150
+ * endpoint. state . write ( ) . await = Some ( Err ( e . clone ( ) ) ) ;
151
151
} else {
152
152
// A non-`EndpointError` error occurred, so reset the state.
153
153
reset_endpoint_state ( endpoint) . await ;
@@ -181,14 +181,14 @@ async fn endpoint_state(
181
181
config_chain_id : & Eth1Id ,
182
182
log : & Logger ,
183
183
) -> EndpointState {
184
- let error_connecting = |_ | {
184
+ let error_connecting = |e | {
185
185
warn ! (
186
186
log,
187
187
"Error connecting to eth1 node endpoint" ;
188
188
"endpoint" => %endpoint,
189
189
"action" => "trying fallbacks"
190
190
) ;
191
- EndpointError :: NotReachable
191
+ EndpointError :: RequestFailed ( e )
192
192
} ;
193
193
let network_id = get_network_id ( endpoint, Duration :: from_millis ( STANDARD_TIMEOUT_MILLIS ) )
194
194
. await
0 commit comments