mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-10 05:09:22 +00:00
* Remove NetworkId from processor-messages Because intent binds to the sender/receiver, it's not needed for intent. The processor knows what the network is. The coordinator knows which to use because it's sending this message to the processor for that network. Also removes the unused zeroize. * ProcessorMessage::Completed use Session instead of key * Move SubstrateSignId to Session * Finish replacing key with session
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
use scale::{Encode, Decode};
|
||||
|
||||
pub use serai_db::*;
|
||||
use scale::Encode;
|
||||
|
||||
use serai_client::{
|
||||
primitives::NetworkId,
|
||||
validator_sets::primitives::{Session, ValidatorSet, KeyPair},
|
||||
validator_sets::primitives::{Session, ValidatorSet},
|
||||
};
|
||||
|
||||
pub use serai_db::*;
|
||||
|
||||
create_db! {
|
||||
SubstrateDb {
|
||||
CosignTriggered: () -> (),
|
||||
@@ -86,24 +86,6 @@ impl<D: Db> SubstrateDb<D> {
|
||||
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);
|
||||
}
|
||||
|
||||
fn batch_instructions_key(network: NetworkId, id: u32) -> Vec<u8> {
|
||||
Self::substrate_key(b"batch", (network, id).encode())
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ use tokio::{sync::mpsc, time::sleep};
|
||||
use crate::{
|
||||
Db,
|
||||
processors::Processors,
|
||||
tributary::{TributarySpec, SeraiBlockNumber, KeyPairDb},
|
||||
tributary::{TributarySpec, SeraiBlockNumber},
|
||||
};
|
||||
|
||||
mod db;
|
||||
@@ -116,19 +116,13 @@ async fn handle_new_set<D: Db>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_key_gen<D: Db, Pro: Processors>(
|
||||
db: &mut D,
|
||||
async fn handle_key_gen<Pro: Processors>(
|
||||
processors: &Pro,
|
||||
serai: &Serai,
|
||||
block: &Block,
|
||||
set: ValidatorSet,
|
||||
key_pair: KeyPair,
|
||||
) -> Result<(), SeraiError> {
|
||||
// This has to be saved *before* we send ConfirmKeyPair
|
||||
let mut txn = db.txn();
|
||||
SubstrateDb::<D>::save_session_for_keys(&mut txn, &key_pair, set.session);
|
||||
txn.commit();
|
||||
|
||||
processors
|
||||
.send(
|
||||
set.network,
|
||||
@@ -144,7 +138,7 @@ async fn handle_key_gen<D: Db, Pro: Processors>(
|
||||
// block which has a time greater than or equal to the Serai time
|
||||
.unwrap_or(BlockHash([0; 32])),
|
||||
},
|
||||
set,
|
||||
session: set.session,
|
||||
key_pair,
|
||||
},
|
||||
)
|
||||
@@ -232,7 +226,6 @@ async fn handle_batch_and_burns<D: Db, Pro: Processors>(
|
||||
serai_time: block.time().unwrap() / 1000,
|
||||
network_latest_finalized_block,
|
||||
},
|
||||
network,
|
||||
block: block.number(),
|
||||
burns: burns.remove(&network).unwrap(),
|
||||
batches: batches.remove(&network).unwrap(),
|
||||
@@ -291,13 +284,7 @@ async fn handle_block<D: Db, Pro: Processors>(
|
||||
if !SubstrateDb::<D>::handled_event(&db.0, hash, event_id) {
|
||||
log::info!("found fresh key gen event {:?}", key_gen);
|
||||
if let ValidatorSetsEvent::KeyGen { set, key_pair } = key_gen {
|
||||
// Immediately ensure this key pair is accessible to the tributary, before we fire any
|
||||
// events off of it
|
||||
let mut txn = db.0.txn();
|
||||
KeyPairDb::set(&mut txn, set, &key_pair);
|
||||
txn.commit();
|
||||
|
||||
handle_key_gen(&mut db.0, processors, serai, &block, set, key_pair).await?;
|
||||
handle_key_gen(processors, serai, &block, set, key_pair).await?;
|
||||
} else {
|
||||
panic!("KeyGen event wasn't KeyGen: {key_gen:?}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user