Dispatches a configured check to its observation algorithm.
(
&self,
check: &AcceptanceCheck,
minimum_timestamp: u64,
endpoints: &BTreeMap<String, String>,
deadline: Instant,
state: &mut ObservationState<'_>,
| 193 | |
| 194 | /// Dispatches a configured check to its observation algorithm. |
| 195 | pub async fn evaluate( |
| 196 | &self, |
| 197 | check: &AcceptanceCheck, |
| 198 | minimum_timestamp: u64, |
| 199 | endpoints: &BTreeMap<String, String>, |
| 200 | deadline: Instant, |
| 201 | state: &mut ObservationState<'_>, |
| 202 | ) -> Result<String> { |
| 203 | match check { |
| 204 | AcceptanceCheck::ChainId { endpoint, expected, .. } => { |
| 205 | state.expected = json!(expected); |
| 206 | match self.chain_id(Self::endpoint(endpoints, endpoint)?, deadline).await { |
| 207 | Ok(actual) => { |
| 208 | state.count += 1; |
| 209 | state.observed = json!(actual); |
| 210 | if actual == *expected { |
| 211 | Ok("chain identity matched".into()) |
| 212 | } else { |
| 213 | bail!("chain id mismatch: expected {expected}, observed {actual}") |
| 214 | } |
| 215 | } |
| 216 | Err(error) => { |
| 217 | state.errors += 1; |
| 218 | state.infrastructure_error = true; |
| 219 | Err(error) |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | AcceptanceCheck::HeadProgress { endpoint, minimum_blocks, .. } |
| 224 | | AcceptanceCheck::SafeHeadProgress { endpoint, minimum_blocks, .. } => { |
| 225 | state.expected = json!({ "minimum_blocks": minimum_blocks }); |
| 226 | let tag = if matches!(check, AcceptanceCheck::SafeHeadProgress { .. }) { |
| 227 | "safe" |
| 228 | } else { |
| 229 | "latest" |
| 230 | }; |
| 231 | self.progress( |
| 232 | Self::endpoint(endpoints, endpoint)?, |
| 233 | endpoint, |
| 234 | tag, |
| 235 | *minimum_blocks, |
| 236 | deadline, |
| 237 | state, |
| 238 | ) |
| 239 | .await |
| 240 | } |
| 241 | AcceptanceCheck::HeadsConverge { endpoints: roles, head, max_lag_blocks, .. } => { |
| 242 | state.expected = json!({ |
| 243 | "max_lag_blocks": max_lag_blocks, |
| 244 | "common_height_hash": true, |
| 245 | }); |
| 246 | let bounds = |
| 247 | ConvergenceBounds { max_lag_blocks: *max_lag_blocks, minimum_timestamp }; |
| 248 | self.converge(endpoints, roles, head, bounds, deadline, state).await |
| 249 | } |
| 250 | AcceptanceCheck::HeadFresh { endpoint, maximum_age, duration, .. } => { |
| 251 | state.expected = json!({ |
| 252 | "maximum_age_seconds": maximum_age.0.as_secs(), |