Tidy Serai use in coordinator to new API

This commit is contained in:
Luke Parker 2023-10-14 02:59:22 -04:00
parent 530fba51dd
commit e3e9939eaf
2 changed files with 7 additions and 7 deletions

View file

@ -451,19 +451,19 @@ pub async fn scan_task<D: Db, Pro: Processors>(
pub async fn is_active_set(serai: &Serai, set: ValidatorSet) -> bool { pub async fn is_active_set(serai: &Serai, set: ValidatorSet) -> bool {
// TODO: Track this from the Substrate scanner to reduce our overhead? We'd only have a DB // TODO: Track this from the Substrate scanner to reduce our overhead? We'd only have a DB
// call, instead of a series of network requests // call, instead of a series of network requests
let latest = loop { let serai = loop {
let Ok(res) = serai.latest_block_hash().await else { let Ok(serai) = serai.with_current_latest_block().await else {
log::error!( log::error!(
"couldn't get the latest block hash from serai when checking tributary relevancy" "couldn't get the latest block hash from serai when checking tributary relevancy"
); );
sleep(Duration::from_secs(5)).await; sleep(Duration::from_secs(5)).await;
continue; continue;
}; };
break res; break serai.validator_sets();
}; };
let latest_session = loop { let latest_session = loop {
let Ok(res) = serai.as_of(latest).validator_sets().session(set.network).await else { let Ok(res) = serai.session(set.network).await else {
log::error!("couldn't get the latest session from serai when checking tributary relevancy"); log::error!("couldn't get the latest session from serai when checking tributary relevancy");
sleep(Duration::from_secs(5)).await; sleep(Duration::from_secs(5)).await;
continue; continue;
@ -482,7 +482,7 @@ pub async fn is_active_set(serai: &Serai, set: ValidatorSet) -> bool {
} else { } else {
// Since the next session has started, check its handover status // Since the next session has started, check its handover status
let keys = loop { let keys = loop {
let Ok(res) = serai.as_of(latest).validator_sets().keys(set).await else { let Ok(res) = serai.keys(set).await else {
log::error!( log::error!(
"couldn't get the keys for a session from serai when checking tributary relevancy" "couldn't get the keys for a session from serai when checking tributary relevancy"
); );

View file

@ -216,8 +216,8 @@ pub(crate) async fn scan_tributaries_task<
// creation // creation
// TODO2: Differentiate connection errors from invariants // TODO2: Differentiate connection errors from invariants
Err(e) => { Err(e) => {
if let Ok(latest) = serai.latest_block_hash().await { if let Ok(serai) = serai.with_current_latest_block().await {
let serai = serai.as_of(latest).validator_sets(); let serai = serai.validator_sets();
// Check if this failed because the keys were already set by someone // Check if this failed because the keys were already set by someone
// else // else
if matches!(serai.keys(spec.set()).await, Ok(Some(_))) { if matches!(serai.keys(spec.set()).await, Ok(Some(_))) {