mirror of
https://github.com/serai-dex/serai.git
synced 2025-01-22 10:44:53 +00:00
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:
parent
22371a6585
commit
1a0b4198ba
3 changed files with 35 additions and 8 deletions
|
@ -253,15 +253,32 @@ 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!(
|
||||||
"couldn't connect to Serai node to publish set_keys TX: {:?}",
|
"couldn't connect to Serai node to publish set_keys TX: {:?}",
|
||||||
e
|
e
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue