Skip to content

Commit 19894f6

Browse files
committed
check expected number of keys
1 parent a371ce8 commit 19894f6

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

  • crates/common/src/config

crates/common/src/config/mux.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ async fn fetch_ssv_pubkeys_from_public_api(
461461

462462
let mut pubkeys: Vec<BlsPublicKey> = vec![];
463463
let mut page = 1;
464+
let mut expected_total: Option<usize> = None;
464465

465466
loop {
466467
let route = format!(
@@ -470,26 +471,22 @@ async fn fetch_ssv_pubkeys_from_public_api(
470471

471472
let response = request_ssv_pubkeys_from_public_api(url, http_timeout).await?;
472473
let fetched = response.validators.len();
474+
if expected_total.is_none() && fetched > 0 {
475+
expected_total = Some(response.pagination.total);
476+
}
473477
pubkeys.extend(
474478
response.validators.into_iter().map(|v| v.pubkey).collect::<Vec<BlsPublicKey>>(),
475479
);
476480
page += 1;
477481

478482
if fetched < MAX_PER_PAGE {
479-
// Past-end page (fetched == 0) returns pagination.total == 0 from the SSV
480-
// public API; only assert the total when the page actually carried
481-
// data.
482-
if fetched > 0 {
483-
ensure!(
484-
pubkeys.len() == response.pagination.total,
485-
"expected {} keys, got {}",
486-
response.pagination.total,
487-
pubkeys.len()
488-
);
489-
}
490483
break;
491484
}
492485
}
493486

487+
if let Some(expected) = expected_total {
488+
ensure!(pubkeys.len() == expected, "expected {expected} keys, got {}", pubkeys.len());
489+
}
490+
494491
Ok(pubkeys)
495492
}

0 commit comments

Comments
 (0)