mirror of
https://github.com/serai-dex/serai.git
synced 2025-01-22 02:34:55 +00:00
Move where we trigger KeyGen to avoid a race condition
We only expect processor messages when we have the relevant Tributary. We queued Tributary creation, yet then kicked off processor messages. We need to wait until the Tributary is actually created to kick off processor messages.
This commit is contained in:
parent
1bd14163a0
commit
a3649b2062
2 changed files with 23 additions and 25 deletions
|
@ -179,6 +179,27 @@ pub async fn scan_tributaries<
|
|||
)
|
||||
.await;
|
||||
|
||||
// Trigger a DKG for the newly added Tributary
|
||||
let set = spec.set();
|
||||
processors
|
||||
.send(
|
||||
set.network,
|
||||
processor_messages::CoordinatorMessage::KeyGen(
|
||||
processor_messages::key_gen::CoordinatorMessage::GenerateKey {
|
||||
id: processor_messages::key_gen::KeyGenId { set, attempt: 0 },
|
||||
params: frost::ThresholdParams::new(
|
||||
spec.t(),
|
||||
spec.n(),
|
||||
spec
|
||||
.i(Ristretto::generator() * key.deref())
|
||||
.expect("adding a tribuary for a set we aren't in set for"),
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
)
|
||||
.await;
|
||||
|
||||
tributary_readers.push((spec, reader));
|
||||
}
|
||||
}
|
||||
|
@ -438,7 +459,7 @@ pub async fn handle_processors<D: Db, Pro: Processors, P: P2p>(
|
|||
break;
|
||||
}
|
||||
}
|
||||
spec.unwrap()
|
||||
spec.expect("received message from processor we don't have a tributary for")
|
||||
};
|
||||
|
||||
let genesis = spec.genesis();
|
||||
|
|
|
@ -4,7 +4,6 @@ use std::collections::{HashSet, HashMap};
|
|||
use zeroize::Zeroizing;
|
||||
|
||||
use ciphersuite::{group::GroupEncoding, Ciphersuite, Ristretto};
|
||||
use frost::ThresholdParams;
|
||||
|
||||
use serai_client::{
|
||||
SeraiError, Block, Serai,
|
||||
|
@ -19,7 +18,7 @@ use serai_client::{
|
|||
|
||||
use serai_db::DbTxn;
|
||||
|
||||
use processor_messages::{SubstrateContext, key_gen::KeyGenId, CoordinatorMessage};
|
||||
use processor_messages::{SubstrateContext, CoordinatorMessage};
|
||||
|
||||
use tokio::time::sleep;
|
||||
|
||||
|
@ -86,28 +85,6 @@ async fn handle_new_set<
|
|||
|
||||
let spec = TributarySpec::new(block.hash(), time, set, set_data);
|
||||
create_new_tributary(db, spec.clone()).await;
|
||||
|
||||
// Trigger a DKG
|
||||
// TODO: Check how the processor handles this being fired multiple times
|
||||
// We already have a unique event ID based on block, event index (where event index is
|
||||
// the one generated in this handle_block function)
|
||||
// We could use that on this end and the processor end?
|
||||
processors
|
||||
.send(
|
||||
set.network,
|
||||
CoordinatorMessage::KeyGen(processor_messages::key_gen::CoordinatorMessage::GenerateKey {
|
||||
id: KeyGenId { set, attempt: 0 },
|
||||
params: ThresholdParams::new(
|
||||
spec.t(),
|
||||
spec.n(),
|
||||
spec
|
||||
.i(Ristretto::generator() * key.deref())
|
||||
.expect("In set for a set we aren't in set for"),
|
||||
)
|
||||
.unwrap(),
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
} else {
|
||||
log::info!("not present in set {:?}", set);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue