| 76 | |
| 77 | impl OrderSimulator { |
| 78 | pub async fn simulate_with_timeout( |
| 79 | &self, |
| 80 | order: &Order, |
| 81 | full_app_data: &str, |
| 82 | full_balance_check: bool, |
| 83 | ) -> Result<SimulationSuccess, OrderSimulationError> { |
| 84 | let start = Instant::now(); |
| 85 | let (outcome, result) = match tokio::time::timeout( |
| 86 | self.timeout, |
| 87 | self.simulator |
| 88 | .simulate(order, full_app_data, full_balance_check), |
| 89 | ) |
| 90 | .await |
| 91 | { |
| 92 | Ok(Ok(r)) => ("ok", Ok(r)), |
| 93 | Ok(r @ Err(OrderSimulationError::Reverted { .. })) => ("reverted", r), |
| 94 | Ok(r @ Err(OrderSimulationError::Infra(_))) => ("infra", r), |
| 95 | Err(_) => ( |
| 96 | "timeout", |
| 97 | Err(OrderSimulationError::Infra(anyhow!( |
| 98 | "order simulation timeout" |
| 99 | ))), |
| 100 | ), |
| 101 | }; |
| 102 | |
| 103 | Metrics::get() |
| 104 | .duration_seconds |
| 105 | .with_label_values(&[outcome]) |
| 106 | .observe(start.elapsed().as_secs_f64()); |
| 107 | |
| 108 | result |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | /// Logs disagreements (signature pass + simulation revert, or vice versa) |