diff --git a/Code/itf/src/consensus.rs b/Code/itf/src/consensus.rs deleted file mode 100644 index 2bb430b6a..000000000 --- a/Code/itf/src/consensus.rs +++ /dev/null @@ -1,178 +0,0 @@ -use num_bigint::BigInt; -use serde::Deserialize; -use std::collections::HashMap; - -use crate::deserializers as de; - -pub type Address = String; -pub type Value = String; -pub type Step = String; -pub type Round = BigInt; -pub type Height = BigInt; - -#[derive(Clone, Debug, Deserialize)] -pub enum Timeout { - #[serde(rename = "timeoutPrevote")] - Prevote, - - #[serde(rename = "timeoutPrecommit")] - Precommit, - - #[serde(rename = "timeoutPropose")] - Propose, -} - -#[derive(Clone, Debug, Deserialize)] -pub struct State { - pub system: System, - - #[serde(rename = "_Event")] - pub event: Event, - - #[serde(rename = "_Result")] - pub result: Result, -} - -#[derive(Clone, Debug, Deserialize)] -pub struct System(HashMap); - -#[derive(Clone, Debug, Deserialize)] -#[serde(tag = "name")] -pub enum Event { - Initial, - NewRound { - height: Height, - round: Round, - }, - Proposal { - height: Height, - round: Round, - value: Value, - }, - ProposalAndPolkaAndValid { - height: Height, - round: Round, - value: Value, - }, - ProposalAndCommitAndValid { - height: Height, - round: Round, - value: Value, - }, - NewHeight { - height: Height, - round: Round, - }, - NewRoundProposer { - height: Height, - round: Round, - value: Value, - }, - PolkaNil { - height: Height, - round: Round, - value: Value, - }, - PolkaAny { - height: Height, - round: Round, - value: Value, - }, - PrecommitAny { - height: Height, - round: Round, - value: Value, - }, - TimeoutPrevote { - height: Height, - round: Round, - }, - TimeoutPrecommit { - height: Height, - round: Round, - value: Value, - }, - TimeoutPropose { - height: Height, - round: Round, - value: Value, - }, - ProposalInvalid { - height: Height, - round: Round, - }, -} - -#[derive(Clone, Debug, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct Result { - pub name: String, - #[serde(deserialize_with = "de::proposal_or_none")] - pub proposal: Option, - #[serde(deserialize_with = "de::vote_message_or_none")] - pub vote_message: Option, - #[serde(deserialize_with = "de::empty_string_as_none")] - pub timeout: Option, - #[serde(deserialize_with = "de::empty_string_as_none")] - pub decided: Option, - #[serde(deserialize_with = "de::minus_one_as_none")] - pub skip_round: Option, -} - -#[derive(Clone, Debug, Deserialize, PartialEq, Eq)] -#[serde(rename_all = "camelCase")] -pub struct Proposal { - pub src: Address, - pub height: Height, - pub round: Round, - pub proposal: Value, - pub valid_round: Round, -} - -impl Proposal { - pub fn is_empty(&self) -> bool { - self.src.is_empty() - && self.proposal.is_empty() - && self.height == BigInt::from(-1) - && self.round == BigInt::from(-1) - && self.valid_round == BigInt::from(-1) - } -} - -#[derive(Clone, Debug, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct VoteMessage { - pub src: Address, - pub height: Height, - pub round: Round, - pub step: Step, - pub id: Value, -} - -impl VoteMessage { - pub fn is_empty(&self) -> bool { - self.src.is_empty() - && self.id.is_empty() - && self.height == BigInt::from(-1) - && self.round == BigInt::from(-1) - && self.step.is_empty() - } -} - -#[derive(Clone, Debug, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct ConsensusState { - pub p: Address, - pub height: Height, - pub round: Round, - pub step: Step, - - #[serde(deserialize_with = "de::minus_one_as_none")] - pub locked_round: Option, - #[serde(deserialize_with = "de::empty_string_as_none")] - pub locked_value: Option, - #[serde(deserialize_with = "de::minus_one_as_none")] - pub valid_round: Option, - #[serde(deserialize_with = "de::empty_string_as_none")] - pub valid_value: Option, -} diff --git a/Code/itf/src/deserializers.rs b/Code/itf/src/deserializers.rs deleted file mode 100644 index 53231f40d..000000000 --- a/Code/itf/src/deserializers.rs +++ /dev/null @@ -1,53 +0,0 @@ -use num_bigint::BigInt; -use serde::de::IntoDeserializer; -use serde::Deserialize; - -use crate::consensus::{Proposal, VoteMessage}; - -pub(crate) fn empty_string_as_none<'de, D, T>(de: D) -> Result, D::Error> -where - D: serde::Deserializer<'de>, - T: serde::Deserialize<'de>, -{ - let opt = Option::::deserialize(de)?; - match opt.as_deref() { - None | Some("") => Ok(None), - Some(s) => T::deserialize(s.into_deserializer()).map(Some), - } -} - -pub(crate) fn minus_one_as_none<'de, D>(de: D) -> Result, D::Error> -where - D: serde::Deserializer<'de>, -{ - let opt = Option::::deserialize(de)?; - match opt { - None => Ok(None), - Some(i) if i == BigInt::from(-1) => Ok(None), - Some(i) => Ok(Some(i)), - } -} - -pub(crate) fn proposal_or_none<'de, D>(de: D) -> Result, D::Error> -where - D: serde::Deserializer<'de>, -{ - let proposal = Proposal::deserialize(de)?; - if proposal.is_empty() { - Ok(None) - } else { - Ok(Some(proposal)) - } -} - -pub(crate) fn vote_message_or_none<'de, D>(de: D) -> Result, D::Error> -where - D: serde::Deserializer<'de>, -{ - let vote_message = VoteMessage::deserialize(de)?; - if vote_message.is_empty() { - Ok(None) - } else { - Ok(Some(vote_message)) - } -} diff --git a/Code/itf/src/lib.rs b/Code/itf/src/lib.rs index d8bacfb93..be66ce483 100644 --- a/Code/itf/src/lib.rs +++ b/Code/itf/src/lib.rs @@ -1,5 +1,2 @@ -pub mod consensus; -pub mod votekeeper; - -mod deserializers; pub mod utils; +pub mod votekeeper;