Correct the check for if we still need to set keys

The prior check had an edge case where once keys were pruned, it'd believe the
keys needed to be set ad infinitum.
This commit is contained in:
Luke Parker 2023-10-10 22:53:15 -04:00
parent 22371a6585
commit 1a0b4198ba
No known key found for this signature in database
3 changed files with 35 additions and 8 deletions

View file

@ -253,13 +253,30 @@ pub(crate) async fn scan_tributaries<
// creation // creation
// TODO2: Differentiate connection errors from invariants // TODO2: Differentiate connection errors from invariants
Err(e) => { Err(e) => {
// Check if this failed because the keys were already set by someone else if let Ok(latest) = serai.get_latest_block_hash().await {
// TODO: hash_with_keys is latest, yet we'll remove old keys from storage // Check if this failed because the keys were already set by someone
let hash_with_keys = serai.get_latest_block_hash().await.unwrap(); // else
if matches!(serai.get_keys(spec.set(), hash_with_keys).await, Ok(Some(_))) if matches!(serai.get_keys(spec.set(), latest).await, Ok(Some(_))) {
{ log::info!("another coordinator set key pair for {:?}", set);
log::info!("another coordinator set key pair for {:?}", set); break;
break; }
// The above block may return false if the keys have been pruned from
// the state
// Check if this session is no longer the latest session, meaning it at
// some point did set keys, and we're just operating off very
// historical data
if let Ok(Some(current_session)) =
serai.get_session(spec.set().network, latest).await
{
if current_session.0 > spec.set().session.0 {
log::warn!(
"trying to set keys for a set which isn't the latest {:?}",
set
);
break;
}
}
} }
log::error!( log::error!(

View file

@ -243,6 +243,8 @@ async fn handle_block<D: Db, CNT: Clone + Fn(&mut D, TributarySpec), Pro: Proces
panic!("NewSet event wasn't NewSet: {new_set:?}"); panic!("NewSet event wasn't NewSet: {new_set:?}");
}; };
// If this is Serai, do nothing
// We only coordinate/process external networks
if set.network == NetworkId::Serai { if set.network == NetworkId::Serai {
continue; continue;
} }

View file

@ -2,7 +2,7 @@ use sp_core::sr25519::{Public, Signature};
use serai_runtime::{validator_sets, ValidatorSets, Runtime}; use serai_runtime::{validator_sets, ValidatorSets, Runtime};
pub use validator_sets::primitives; pub use validator_sets::primitives;
use primitives::{ValidatorSet, KeyPair}; use primitives::{Session, ValidatorSet, KeyPair};
use subxt::utils::Encoded; use subxt::utils::Encoded;
@ -31,6 +31,14 @@ impl Serai {
.await .await
} }
pub async fn get_session(
&self,
network: NetworkId,
at_hash: [u8; 32],
) -> Result<Option<Session>, SeraiError> {
self.storage(PALLET, "CurrentSession", Some(vec![scale_value(network)]), at_hash).await
}
pub async fn get_validator_set_participants( pub async fn get_validator_set_participants(
&self, &self,
network: NetworkId, network: NetworkId,