mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Start moving Coordinator to a multi-Tributary model
Prior, we only supported a single Tributary per network, and spawned a task to handled Processor messages per Tributary. Now, we handle Processor messages per network, yet we still only supported a single Tributary in that handling function. Now, when we handle a message, we load the Tributary which is relevant. Once we know it, we ensure we have it (preventing race conditions), and then proceed. We do need work to check if we should have a Tributary, or if we're not participating. We also need to check if a Tributary has been retired, meaning we shouldn't handle any transactions related to them, and to clean up retired Tributaries.
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
use scale::{Encode, Decode};
|
||||
|
||||
pub use serai_db::*;
|
||||
|
||||
use serai_client::validator_sets::primitives::{Session, KeyPair};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SubstrateDb<D: Db>(pub D);
|
||||
impl<D: Db> SubstrateDb<D> {
|
||||
@@ -33,4 +37,22 @@ impl<D: Db> SubstrateDb<D> {
|
||||
assert!(!Self::handled_event(txn, id, index));
|
||||
txn.put(Self::event_key(&id, index), []);
|
||||
}
|
||||
|
||||
fn session_key(key: &[u8]) -> Vec<u8> {
|
||||
Self::substrate_key(b"session", key)
|
||||
}
|
||||
pub fn session_for_key<G: Get>(getter: &G, key: &[u8]) -> Option<Session> {
|
||||
getter.get(Self::session_key(key)).map(|bytes| Session::decode(&mut bytes.as_ref()).unwrap())
|
||||
}
|
||||
pub fn save_session_for_keys(txn: &mut D::Transaction<'_>, key_pair: &KeyPair, session: Session) {
|
||||
let session = session.encode();
|
||||
let key_0 = Self::session_key(&key_pair.0);
|
||||
let existing = txn.get(&key_0);
|
||||
// This may trigger if 100% of a DKG are malicious, and they create a key equivalent to a prior
|
||||
// key. Since it requires 100% maliciousness, not just 67% maliciousness, this will only assert
|
||||
// in a modified-to-be-malicious stack, making it safe
|
||||
assert!(existing.is_none() || (existing.as_ref() == Some(&session)));
|
||||
txn.put(key_0, session.clone());
|
||||
txn.put(Self::session_key(&key_pair.1), session);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user