mirror of
https://github.com/serai-dex/serai.git
synced 2024-11-16 17:07:35 +00:00
Route KeyPair so Tributary can construct SignId as needed
This commit is contained in:
parent
3745f8b6af
commit
f249e20028
3 changed files with 43 additions and 5 deletions
|
@ -23,7 +23,11 @@ use processor_messages::{SubstrateContext, key_gen::KeyGenId, CoordinatorMessage
|
|||
|
||||
use tokio::time::sleep;
|
||||
|
||||
use crate::{Db, processors::Processors, tributary::TributarySpec};
|
||||
use crate::{
|
||||
Db,
|
||||
processors::Processors,
|
||||
tributary::{TributarySpec, TributaryDb},
|
||||
};
|
||||
|
||||
mod db;
|
||||
pub use db::*;
|
||||
|
@ -298,6 +302,12 @@ async fn handle_block<
|
|||
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();
|
||||
TributaryDb::<D>::set_key_pair(&mut txn, set, &key_pair);
|
||||
txn.commit();
|
||||
|
||||
handle_key_gen(key, processors, serai, &block, set, key_pair).await?;
|
||||
} else {
|
||||
panic!("KeyGen event wasn't KeyGen: {key_gen:?}");
|
||||
|
|
|
@ -4,7 +4,7 @@ use scale::{Encode, Decode};
|
|||
|
||||
use ciphersuite::{group::GroupEncoding, Ciphersuite, Ristretto};
|
||||
|
||||
use serai_client::validator_sets::primitives::KeyPair;
|
||||
use serai_client::validator_sets::primitives::{ValidatorSet, KeyPair};
|
||||
|
||||
pub use serai_db::*;
|
||||
|
||||
|
@ -87,6 +87,16 @@ impl<D: Db> TributaryDb<D> {
|
|||
.map(|bytes| KeyPair::decode(&mut bytes.as_slice()).unwrap())
|
||||
}
|
||||
|
||||
pub fn key_pair_key(set: ValidatorSet) -> Vec<u8> {
|
||||
Self::tributary_key(b"key_pair", set.encode())
|
||||
}
|
||||
pub fn set_key_pair(txn: &mut D::Transaction<'_>, set: ValidatorSet, key_pair: &KeyPair) {
|
||||
txn.put(Self::key_pair_key(set), key_pair.encode());
|
||||
}
|
||||
pub fn key_pair<G: Get>(getter: &G, set: ValidatorSet) -> Option<KeyPair> {
|
||||
Some(KeyPair::decode(&mut getter.get(Self::key_pair_key(set))?.as_slice()).unwrap())
|
||||
}
|
||||
|
||||
fn recognized_id_key(label: &'static str, genesis: [u8; 32], id: [u8; 32]) -> Vec<u8> {
|
||||
Self::tributary_key(b"recognized", [label.as_bytes(), genesis.as_ref(), id.as_ref()].concat())
|
||||
}
|
||||
|
|
|
@ -522,6 +522,7 @@ pub async fn handle_application_tx<
|
|||
}
|
||||
|
||||
Transaction::SignPreprocess(data) => {
|
||||
let key_pair = TributaryDb::<D>::key_pair(txn, spec.set());
|
||||
match handle(
|
||||
txn,
|
||||
Zone::Sign,
|
||||
|
@ -537,7 +538,14 @@ pub async fn handle_application_tx<
|
|||
.send(
|
||||
spec.set().network,
|
||||
CoordinatorMessage::Sign(sign::CoordinatorMessage::Preprocesses {
|
||||
id: SignId { key: todo!(), id: data.plan, attempt: data.attempt },
|
||||
id: SignId {
|
||||
key: key_pair
|
||||
.expect("completed SignPreprocess despite not setting the key pair")
|
||||
.1
|
||||
.into(),
|
||||
id: data.plan,
|
||||
attempt: data.attempt,
|
||||
},
|
||||
preprocesses,
|
||||
}),
|
||||
)
|
||||
|
@ -548,6 +556,7 @@ pub async fn handle_application_tx<
|
|||
}
|
||||
}
|
||||
Transaction::SignShare(data) => {
|
||||
let key_pair = TributaryDb::<D>::key_pair(txn, spec.set());
|
||||
match handle(
|
||||
txn,
|
||||
Zone::Sign,
|
||||
|
@ -563,7 +572,14 @@ pub async fn handle_application_tx<
|
|||
.send(
|
||||
spec.set().network,
|
||||
CoordinatorMessage::Sign(sign::CoordinatorMessage::Shares {
|
||||
id: SignId { key: todo!(), id: data.plan, attempt: data.attempt },
|
||||
id: SignId {
|
||||
key: key_pair
|
||||
.expect("completed SignShares despite not setting the key pair")
|
||||
.1
|
||||
.into(),
|
||||
id: data.plan,
|
||||
attempt: data.attempt,
|
||||
},
|
||||
shares,
|
||||
}),
|
||||
)
|
||||
|
@ -573,6 +589,8 @@ pub async fn handle_application_tx<
|
|||
None => {}
|
||||
}
|
||||
}
|
||||
Transaction::SignCompleted(_, _, _) => todo!(),
|
||||
Transaction::SignCompleted(_, _, _) => {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue