setting threshold value upon entering dealing exchange
This commit is contained in:
@@ -270,4 +270,8 @@ impl EpochState {
|
||||
pub fn is_in_progress(&self) -> bool {
|
||||
matches!(self, EpochState::InProgress)
|
||||
}
|
||||
|
||||
pub fn is_dealing_exchange(&self) -> bool {
|
||||
matches!(self, EpochState::DealingExchange { .. })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,15 @@ pub fn try_advance_epoch_state(deps: DepsMut<'_>, env: Env) -> Result<Response,
|
||||
}
|
||||
};
|
||||
|
||||
// if we're advancing into dealing exchange, we need to set the threshold value based on the number of registered dealers
|
||||
if next_state.is_dealing_exchange() {
|
||||
// note: ceiling in integer division can be achieved via q = (x + y - 1) / y;
|
||||
let registered_dealers = current_epoch.state_progress.registered_dealers as u64;
|
||||
// set the threshold to 2/3 amount of registered dealers
|
||||
let threshold = (2 * registered_dealers + 3 - 1) / 3;
|
||||
THRESHOLD.save(deps.storage, &threshold)?;
|
||||
}
|
||||
|
||||
// edge case: we have completed DKG with fewer than threshold number of verified keys.
|
||||
// we have no choice but to reset since no credentials can be issued anyway
|
||||
if next_state.is_in_progress() {
|
||||
|
||||
Reference in New Issue
Block a user