From 0d963aeb1fef8ac5b94487300ef4e0f30bd8a830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Wed, 20 Apr 2022 11:27:13 +0100 Subject: [PATCH] Advancing epoch state --- .../coconut-dkg-contract/src/types.rs | 71 +++++++++++++++++-- 1 file changed, 66 insertions(+), 5 deletions(-) diff --git a/common/cosmwasm-smart-contracts/coconut-dkg-contract/src/types.rs b/common/cosmwasm-smart-contracts/coconut-dkg-contract/src/types.rs index 91483f5cbc..8d208cdccf 100644 --- a/common/cosmwasm-smart-contracts/coconut-dkg-contract/src/types.rs +++ b/common/cosmwasm-smart-contracts/coconut-dkg-contract/src/types.rs @@ -96,14 +96,70 @@ pub struct Epoch { pub state: EpochState, } +impl Epoch { + pub fn next_state( + &self, + current_time: Option, + end_time: Option, + ) -> Option { + let state = match self.state { + EpochState::PublicKeySubmission { finish_by, .. } => EpochState::DealingExchange { + begun_at: finish_by, + finish_by: end_time?, + }, + EpochState::DealingExchange { finish_by, .. } => EpochState::ComplaintSubmission { + begun_at: finish_by, + finish_by: end_time?, + }, + EpochState::ComplaintSubmission { finish_by, .. } => EpochState::ComplaintVoting { + begun_at: finish_by, + finish_by: end_time?, + }, + EpochState::ComplaintVoting { finish_by, .. } => { + EpochState::VerificationKeySubmission { + begun_at: finish_by, + finish_by: end_time?, + } + } + EpochState::VerificationKeySubmission { finish_by, .. } => { + EpochState::VerificationKeyMismatchSubmission { + begun_at: finish_by, + finish_by: end_time?, + } + } + EpochState::VerificationKeyMismatchSubmission { finish_by, .. } => { + EpochState::VerificationKeyMismatchVoting { + begun_at: finish_by, + finish_by: end_time?, + } + } + EpochState::VerificationKeyMismatchVoting { finish_by, .. } => EpochState::InProgress { + begun_at: finish_by, + finish_by: end_time, + }, + EpochState::InProgress { .. } => EpochState::PublicKeySubmission { + begun_at: current_time?, + finish_by: end_time?, + }, + }; + + Some(Epoch { id: self.id, state }) + } +} + +// currently (it is still extremely likely to change, we might be able to get rid of verification key-related complaints), +// the epoch can be in the following states (in order): +// 1. PublicKeySubmission -> potential dealers are submitting their BTE and ed25519 public keys to participate in dealing exchange +// 2. DealingExchange -> the actual (off-chain) dealing exchange is happening +// 3. ComplaintSubmission -> receivers submitting evidence of other dealers sending malformed data +// 4. ComplaintVoting -> (if any complaints were submitted) receivers voting on the validity of the evidence provided +// 5. VerificationKeySubmission -> receivers submitting their partial (and master) verification keys +// 6. VerificationKeyMismatchSubmission -> receivers / watchers raising issue that the submitted VK are mismatched with their local derivations +// 7. VerificationKeyMismatchVoting -> (if any complaints were submitted) receivers voting on received mismatches +// 8. InProgress -> all receivers have all their secrets derived and all is good #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] #[serde(rename_all = "snake_case")] pub enum EpochState { - InProgress { - begun_at: BlockHeight, - // not entirely sure about that one yet. we'll see how it works out when we get to epoch transition - finish_by: Option, - }, PublicKeySubmission { begun_at: BlockHeight, finish_by: BlockHeight, @@ -132,4 +188,9 @@ pub enum EpochState { begun_at: BlockHeight, finish_by: BlockHeight, }, + InProgress { + begun_at: BlockHeight, + // not entirely sure about that one yet. we'll see how it works out when we get to epoch transition + finish_by: Option, + }, }