@@ -133,22 +133,36 @@ impl<R: Retrieve + Send + Sync, C: Check, P: Persist> CheckPersistRunner<R, C, P
133
133
. await
134
134
. context ( "failed to check node" ) ;
135
135
136
- // Update the `checks` entry
137
- let mut entry = checks
138
- . entry ( ( subnet_id. to_string ( ) , node. node_id . clone ( ) ) )
139
- . or_default ( ) ;
140
- entry. last_updated = current_run_id;
141
- entry. ok_count = if check_result. is_err ( ) {
142
- 0
143
- } else {
144
- min_ok_count. min ( entry. ok_count + 1 )
136
+ let k = (
137
+ subnet_id. to_string ( ) , // subnet
138
+ node. node_id . clone ( ) , // node
139
+ ) ;
140
+
141
+ let ok_count = match ( checks. get ( & k) , & check_result) {
142
+ // If check failed, reset OK count to 0
143
+ ( _, Err ( _) ) => 0 ,
144
+
145
+ // If check succeeded, but is also the first check, set OK count to max-value
146
+ ( None , Ok ( _) ) => min_ok_count,
147
+
148
+ // Otherwise, increment OK count
149
+ ( Some ( entry) , Ok ( _) ) => min_ok_count. min ( entry. ok_count + 1 ) ,
145
150
} ;
146
151
152
+ // Update the `checks` entry
153
+ checks. insert (
154
+ k,
155
+ CheckState {
156
+ ok_count,
157
+ last_updated : current_run_id,
158
+ } ,
159
+ ) ;
160
+
147
161
// Return the node
148
162
check_result. map ( |check_result| NodeCheck {
149
163
node,
150
164
height : check_result. height ,
151
- ok_count : entry . ok_count ,
165
+ ok_count,
152
166
} )
153
167
}
154
168
0 commit comments