Waits for correct chain identity and a new head on every referenced endpoint.
(
observer: &RpcObserver,
config: &ScenarioConfig,
endpoints: &EndpointMap,
deadline: Instant,
)
| 400 | |
| 401 | /// Waits for correct chain identity and a new head on every referenced endpoint. |
| 402 | pub async fn wait_ready( |
| 403 | observer: &RpcObserver, |
| 404 | config: &ScenarioConfig, |
| 405 | endpoints: &EndpointMap, |
| 406 | deadline: Instant, |
| 407 | ) -> Result<()> { |
| 408 | let roles = Self::required_roles(config); |
| 409 | let mut initial = BTreeMap::new(); |
| 410 | loop { |
| 411 | let mut all = true; |
| 412 | for role in &roles { |
| 413 | let url = RpcObserver::endpoint(endpoints, role)?; |
| 414 | match observer.chain_id(url, deadline).await { |
| 415 | Ok(chain) => { |
| 416 | let expected = if role == "l1" { |
| 417 | config.devnet.l1.chain_id |
| 418 | } else { |
| 419 | config.devnet.l2.chain_id |
| 420 | }; |
| 421 | if chain != expected { |
| 422 | bail!( |
| 423 | "{role} chain identity mismatch: expected {expected}, observed {chain}" |
| 424 | ); |
| 425 | } |
| 426 | } |
| 427 | Err(_) => { |
| 428 | all = false; |
| 429 | continue; |
| 430 | } |
| 431 | } |
| 432 | match observer.block(url, "latest", deadline).await { |
| 433 | Ok(block) => { |
| 434 | let first = initial.entry(role).or_insert(block.number); |
| 435 | all &= block.number > *first; |
| 436 | } |
| 437 | Err(_) => all = false, |
| 438 | } |
| 439 | } |
| 440 | if all { |
| 441 | return Ok(()); |
| 442 | } |
| 443 | if Instant::now() >= deadline { |
| 444 | bail!("readiness deadline elapsed"); |
| 445 | } |
| 446 | tokio::time::sleep_until( |
| 447 | (Instant::now() + config.readiness.poll_interval.0).min(deadline), |
| 448 | ) |
| 449 | .await; |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | /// Resolves dependencies from checks, including their fork observation role. |
| 454 | pub fn required_roles(config: &ScenarioConfig) -> BTreeSet<String> { |