diff --git a/crates/hotshot/src/tasks/mod.rs b/crates/hotshot/src/tasks/mod.rs index 619fdb6d59..3f342b68f7 100644 --- a/crates/hotshot/src/tasks/mod.rs +++ b/crates/hotshot/src/tasks/mod.rs @@ -5,7 +5,7 @@ use crate::{ QuorumCertificate, SequencingQuorumEx, }; use async_compatibility_layer::art::async_sleep; -use commit::Committable; +use commit::{Commitment, Committable}; use futures::FutureExt; use hotshot_task::{ boxed_sync, @@ -66,7 +66,7 @@ pub async fn add_network_message_task< >, COMMITTABLE: Committable + Serialize + Clone, PROPOSAL: ProposalType, - VOTE: VoteType, + VOTE: VoteType>, MEMBERSHIP: Membership, EXCHANGE: ConsensusExchange< TYPES, @@ -176,7 +176,7 @@ pub async fn add_network_event_task< >, COMMITTABLE: Committable + Serialize + Clone, PROPOSAL: ProposalType, - VOTE: VoteType, + VOTE: VoteType>, MEMBERSHIP: Membership, EXCHANGE: ConsensusExchange< TYPES, diff --git a/crates/types/src/traits/election.rs b/crates/types/src/traits/election.rs index 3d152cc85e..fb1ff72a58 100644 --- a/crates/types/src/traits/election.rs +++ b/crates/types/src/traits/election.rs @@ -165,7 +165,7 @@ where TOKEN: VoteToken, { /// `VoteType` that is used in this certificate - type Vote: VoteType; + type Vote: VoteType>; /// `Accumulator` type to accumulate votes. type VoteAccumulator: Accumulator2; @@ -267,7 +267,7 @@ pub trait ConsensusExchange: Send + Sync { type Proposal: ProposalType; /// A vote on a [`Proposal`](Self::Proposal). // TODO ED Make this equal Certificate vote (if possible?) - type Vote: VoteType; + type Vote: VoteType>; /// A [`SignedCertificate`] attesting to a decision taken by the committee. type Certificate: SignedCertificate + Hash diff --git a/crates/types/src/vote.rs b/crates/types/src/vote.rs index ef53bc4018..c470925b54 100644 --- a/crates/types/src/vote.rs +++ b/crates/types/src/vote.rs @@ -28,7 +28,7 @@ use std::{ use tracing::error; /// The vote sent by consensus messages. -pub trait VoteType: +pub trait VoteType Deserialize<'a> + Serialize + Clone>: Debug + Clone + 'static + Serialize + for<'a> Deserialize<'a> + Send + Sync + PartialEq { /// Get the view this vote was cast for @@ -38,7 +38,7 @@ pub trait VoteType EncodedSignature; /// Get the data this vote was signed over - fn get_data(&self) -> VoteData>; + fn get_data(&self) -> VoteData; /// Get the vote token of this vote fn get_vote_token(&self) -> TYPES::VoteTokenType; } @@ -196,7 +196,7 @@ pub enum QuorumVote> { Timeout(TimeoutVote), } -impl VoteType for DAVote { +impl VoteType> for DAVote { fn get_view(&self) -> TYPES::Time { self.current_view } @@ -223,7 +223,7 @@ impl DAVote { } } -impl> VoteType +impl> VoteType> for QuorumVote { fn get_view(&self) -> TYPES::Time { @@ -275,7 +275,7 @@ impl> QuorumVote } } -impl VoteType> for ViewSyncVote { +impl VoteType>> for ViewSyncVote { fn get_view(&self) -> TYPES::Time { match self { ViewSyncVote::PreCommit(v) | ViewSyncVote::Commit(v) | ViewSyncVote::Finalize(v) => { @@ -320,7 +320,7 @@ pub trait Accumulator: Sized { pub trait Accumulator2< TYPES: NodeType, COMMITTABLE: Committable + Serialize + Clone, - VOTE: VoteType, + VOTE: VoteType>, >: Sized { /// Append 1 vote to the accumulator. If the threshold is not reached, return @@ -338,10 +338,10 @@ pub trait Accumulator2< pub struct DAVoteAccumulator< TYPES: NodeType, COMMITTABLE: Committable + Serialize + Clone, - VOTE: VoteType, + VOTE: VoteType>, > { /// Map of all da signatures accumlated so far - pub da_vote_outcomes: VoteMap, + pub da_vote_outcomes: VoteMap, TYPES::VoteTokenType>, /// A quorum's worth of stake, generally 2f + 1 pub success_threshold: NonZeroU64, /// A list of valid signatures for certificate aggregation @@ -355,7 +355,7 @@ pub struct DAVoteAccumulator< impl< TYPES: NodeType, COMMITTABLE: Committable + Serialize + Clone, - VOTE: VoteType, + VOTE: VoteType>, > Accumulator2 for DAVoteAccumulator { fn append( @@ -429,14 +429,14 @@ impl< pub struct QuorumVoteAccumulator< TYPES: NodeType, COMMITTABLE: Committable + Serialize + Clone, - VOTE: VoteType, + VOTE: VoteType>, > { /// Map of all signatures accumlated so far - pub total_vote_outcomes: VoteMap, + pub total_vote_outcomes: VoteMap, TYPES::VoteTokenType>, /// Map of all yes signatures accumlated so far - pub yes_vote_outcomes: VoteMap, + pub yes_vote_outcomes: VoteMap, TYPES::VoteTokenType>, /// Map of all no signatures accumlated so far - pub no_vote_outcomes: VoteMap, + pub no_vote_outcomes: VoteMap, TYPES::VoteTokenType>, /// A quorum's worth of stake, generally 2f + 1 pub success_threshold: NonZeroU64, @@ -453,7 +453,7 @@ pub struct QuorumVoteAccumulator< impl< TYPES: NodeType, COMMITTABLE: Committable + Serialize + Clone, - VOTE: VoteType, + VOTE: VoteType>, > Accumulator2 for QuorumVoteAccumulator { fn append( @@ -560,14 +560,14 @@ impl< pub struct ViewSyncVoteAccumulator< TYPES: NodeType, COMMITTABLE: Committable + Serialize + Clone, - VOTE: VoteType, + VOTE: VoteType>, > { /// Map of all pre_commit signatures accumlated so far - pub pre_commit_vote_outcomes: VoteMap, + pub pre_commit_vote_outcomes: VoteMap, TYPES::VoteTokenType>, /// Map of all ommit signatures accumlated so far - pub commit_vote_outcomes: VoteMap, + pub commit_vote_outcomes: VoteMap, TYPES::VoteTokenType>, /// Map of all finalize signatures accumlated so far - pub finalize_vote_outcomes: VoteMap, + pub finalize_vote_outcomes: VoteMap, TYPES::VoteTokenType>, /// A quorum's worth of stake, generally 2f + 1 pub success_threshold: NonZeroU64, @@ -584,7 +584,7 @@ pub struct ViewSyncVoteAccumulator< impl< TYPES: NodeType, COMMITTABLE: Committable + Serialize + Clone, - VOTE: VoteType, + VOTE: VoteType>, > Accumulator2 for ViewSyncVoteAccumulator { #[allow(clippy::too_many_lines)] @@ -734,7 +734,7 @@ impl< pub struct AccumulatorPlaceholder< TYPES: NodeType, COMMITTABLE: Committable + Serialize + Clone, - VOTE: VoteType, + VOTE: VoteType>, > { /// Phantom data to make compiler happy pub phantom: PhantomData<(TYPES, VOTE, COMMITTABLE)>, @@ -743,7 +743,7 @@ pub struct AccumulatorPlaceholder< impl< TYPES: NodeType, COMMITTABLE: Committable + Serialize + Clone, - VOTE: VoteType, + VOTE: VoteType>, > Accumulator2 for AccumulatorPlaceholder { fn append( @@ -758,17 +758,23 @@ impl< /// Mapping of commitments to vote tokens by key. // TODO ED Remove this whole token generic -type VoteMap = HashMap< - Commitment, +type VoteMap = HashMap< + COMMITMENT, ( u64, - BTreeMap>, TOKEN)>, + BTreeMap, TOKEN)>, ), >; /// Describe the process of collecting signatures on block or leaf commitment, to form a DAC or QC, /// respectively. -pub struct VoteAccumulator { +/// +/// TODO GG used only in election.rs; move this to there and make it private? +pub struct VoteAccumulator< + TOKEN, + COMMITMENT: Serialize + for<'a> Deserialize<'a> + Clone, + TYPES: NodeType, +> { /// Map of all signatures accumlated so far pub total_vote_outcomes: VoteMap, /// Map of all da signatures accumlated so far @@ -809,7 +815,7 @@ impl ), ), AssembledSignature, - > for VoteAccumulator + > for VoteAccumulator, TYPES> where TOKEN: Clone + VoteToken, {