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:
Luke Parker
2023-08-27 18:23:45 -04:00
parent 1bd14163a0
commit a3649b2062
2 changed files with 23 additions and 25 deletions

View File

@@ -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();