mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Move where we trigger DKGs for safety reasons
This commit is contained in:
@@ -64,10 +64,11 @@ pub struct ActiveTributary<D: Db, P: P2p> {
|
|||||||
|
|
||||||
type Tributaries<D, P> = HashMap<[u8; 32], ActiveTributary<D, P>>;
|
type Tributaries<D, P> = HashMap<[u8; 32], ActiveTributary<D, P>>;
|
||||||
|
|
||||||
// Adds a tributary into the specified HahMap
|
// Adds a tributary into the specified HashMap
|
||||||
async fn add_tributary<D: Db, P: P2p>(
|
async fn add_tributary<D: Db, Pro: Processors, P: P2p>(
|
||||||
db: D,
|
db: D,
|
||||||
key: Zeroizing<<Ristretto as Ciphersuite>::F>,
|
key: Zeroizing<<Ristretto as Ciphersuite>::F>,
|
||||||
|
processors: &Pro,
|
||||||
p2p: P,
|
p2p: P,
|
||||||
tributaries: &mut Tributaries<D, P>,
|
tributaries: &mut Tributaries<D, P>,
|
||||||
spec: TributarySpec,
|
spec: TributarySpec,
|
||||||
@@ -79,13 +80,36 @@ async fn add_tributary<D: Db, P: P2p>(
|
|||||||
db,
|
db,
|
||||||
spec.genesis(),
|
spec.genesis(),
|
||||||
spec.start_time(),
|
spec.start_time(),
|
||||||
key,
|
key.clone(),
|
||||||
spec.validators(),
|
spec.validators(),
|
||||||
p2p,
|
p2p,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
// Trigger a DKG for the newly added Tributary
|
||||||
|
// If we're rebooting, we'll re-fire this message
|
||||||
|
// This is safe due to the message-queue deduplicating based off the intent system
|
||||||
|
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;
|
||||||
|
|
||||||
let reader = tributary.reader();
|
let reader = tributary.reader();
|
||||||
|
|
||||||
tributaries.insert(
|
tributaries.insert(
|
||||||
@@ -214,6 +238,7 @@ pub async fn scan_tributaries<
|
|||||||
let reader = add_tributary(
|
let reader = add_tributary(
|
||||||
raw_db.clone(),
|
raw_db.clone(),
|
||||||
key.clone(),
|
key.clone(),
|
||||||
|
&processors,
|
||||||
p2p.clone(),
|
p2p.clone(),
|
||||||
// This is a short-lived write acquisition, which is why it should be fine
|
// This is a short-lived write acquisition, which is why it should be fine
|
||||||
&mut *tributaries.write().await,
|
&mut *tributaries.write().await,
|
||||||
@@ -221,28 +246,6 @@ pub async fn scan_tributaries<
|
|||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
// Trigger a DKG for the newly added Tributary
|
|
||||||
// TODO: This needs to moved into add_tributary, or else we may never emit GenerateKey
|
|
||||||
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));
|
tributary_readers.push((spec, reader));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -819,6 +822,7 @@ pub async fn run<D: Db, Pro: Processors, P: P2p>(
|
|||||||
let _ = add_tributary(
|
let _ = add_tributary(
|
||||||
raw_db.clone(),
|
raw_db.clone(),
|
||||||
key.clone(),
|
key.clone(),
|
||||||
|
&processors,
|
||||||
p2p.clone(),
|
p2p.clone(),
|
||||||
&mut *tributaries.write().await,
|
&mut *tributaries.write().await,
|
||||||
spec,
|
spec,
|
||||||
|
|||||||
Reference in New Issue
Block a user