Skip to content

Commit

Permalink
chore: Remove Committable from more types (#1792)
Browse files Browse the repository at this point in the history
* remove Committable from Accumulator2

* remove Committable from AccumulatorPlaceholder

* remove Committable from DAVoteAccumulator type param

* remove Committable from QuorumVoteAccumulator type param

* remove Committable from ViewSyncVoteAccumulator type param

* remove Committable from SignedCertificate type param (that's a big one)
  • Loading branch information
ggutoski authored Sep 21, 2023
1 parent 4a29f8f commit 6f85c10
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 52 deletions.
4 changes: 2 additions & 2 deletions crates/task-impls/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use async_lock::{RwLock, RwLockUpgradableReadGuard};
#[cfg(async_executor_impl = "async-std")]
use async_std::task::JoinHandle;
use bitvec::prelude::*;
use commit::Committable;
use commit::{Commitment, Committable};
use core::time::Duration;
use either::{Either, Left, Right};
use futures::FutureExt;
Expand Down Expand Up @@ -151,7 +151,7 @@ pub struct VoteCollectionTaskState<
TYPES,
TYPES::Time,
TYPES::VoteTokenType,
SequencingLeaf<TYPES>,
Commitment<SequencingLeaf<TYPES>>,
>>::VoteAccumulator,
QuorumCertificate<TYPES, SequencingLeaf<TYPES>>,
>,
Expand Down
4 changes: 2 additions & 2 deletions crates/task-impls/src/da.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use async_compatibility_layer::art::async_spawn;
use async_lock::RwLock;

use bitvec::prelude::*;
use commit::Committable;
use commit::{Commitment, Committable};
use either::{Either, Left, Right};
use futures::FutureExt;
use hotshot_task::{
Expand Down Expand Up @@ -103,7 +103,7 @@ pub struct DAVoteCollectionTaskState<
TYPES,
TYPES::Time,
TYPES::VoteTokenType,
TYPES::BlockType,
Commitment<TYPES::BlockType>,
>>::VoteAccumulator,
DACertificate<TYPES>,
>,
Expand Down
4 changes: 2 additions & 2 deletions crates/task-impls/src/view_sync.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(clippy::module_name_repetitions)]
use crate::events::SequencingHotShotEvent;
use async_compatibility_layer::art::{async_sleep, async_spawn};
use commit::Committable;
use commit::{Commitment, Committable};
use either::Either::{self, Left, Right};
use futures::FutureExt;
use hotshot_task::{
Expand Down Expand Up @@ -228,7 +228,7 @@ pub struct ViewSyncRelayTaskState<
TYPES,
TYPES::Time,
TYPES::VoteTokenType,
ViewSyncData<TYPES>,
Commitment<ViewSyncData<TYPES>>,
>>::VoteAccumulator,
ViewSyncCertificate<TYPES>,
>,
Expand Down
14 changes: 8 additions & 6 deletions crates/types/src/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ pub struct VoteMetaData<COMMITTABLE: Committable + Serialize + Clone, T: VoteTok
}

impl<TYPES: NodeType, LEAF: LeafType<NodeType = TYPES>>
SignedCertificate<TYPES, TYPES::Time, TYPES::VoteTokenType, LEAF>
SignedCertificate<TYPES, TYPES::Time, TYPES::VoteTokenType, Commitment<LEAF>>
for QuorumCertificate<TYPES, LEAF>
{
type Vote = QuorumVote<TYPES, LEAF>;
type VoteAccumulator = QuorumVoteAccumulator<TYPES, LEAF, Self::Vote>;
type VoteAccumulator = QuorumVoteAccumulator<TYPES, Commitment<LEAF>, Self::Vote>;

fn from_signatures_and_commitment(
signatures: AssembledSignature<TYPES>,
Expand Down Expand Up @@ -234,11 +234,12 @@ impl<TYPES: NodeType, LEAF: LeafType<NodeType = TYPES>> Committable
}
}

impl<TYPES: NodeType> SignedCertificate<TYPES, TYPES::Time, TYPES::VoteTokenType, TYPES::BlockType>
impl<TYPES: NodeType>
SignedCertificate<TYPES, TYPES::Time, TYPES::VoteTokenType, Commitment<TYPES::BlockType>>
for DACertificate<TYPES>
{
type Vote = DAVote<TYPES>;
type VoteAccumulator = DAVoteAccumulator<TYPES, TYPES::BlockType, Self::Vote>;
type VoteAccumulator = DAVoteAccumulator<TYPES, Commitment<TYPES::BlockType>, Self::Vote>;

fn from_signatures_and_commitment(
signatures: AssembledSignature<TYPES>,
Expand Down Expand Up @@ -323,11 +324,12 @@ impl<TYPES: NodeType> Committable for ViewSyncCertificate<TYPES> {
}

impl<TYPES: NodeType>
SignedCertificate<TYPES, TYPES::Time, TYPES::VoteTokenType, ViewSyncData<TYPES>>
SignedCertificate<TYPES, TYPES::Time, TYPES::VoteTokenType, Commitment<ViewSyncData<TYPES>>>
for ViewSyncCertificate<TYPES>
{
type Vote = ViewSyncVote<TYPES>;
type VoteAccumulator = ViewSyncVoteAccumulator<TYPES, ViewSyncData<TYPES>, Self::Vote>;
type VoteAccumulator =
ViewSyncVoteAccumulator<TYPES, Commitment<ViewSyncData<TYPES>>, Self::Vote>;
/// Build a QC from the threshold signature and commitment
fn from_signatures_and_commitment(
signatures: AssembledSignature<TYPES>,
Expand Down
20 changes: 10 additions & 10 deletions crates/types/src/traits/election.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,17 @@ pub trait ElectionConfig:
}

/// A certificate of some property which has been signed by a quroum of nodes.
pub trait SignedCertificate<TYPES: NodeType, TIME, TOKEN, COMMITTABLE>
pub trait SignedCertificate<TYPES: NodeType, TIME, TOKEN, COMMITMENT>
where
Self: Send + Sync + Clone + Serialize + for<'a> Deserialize<'a>,
COMMITTABLE: Committable + Serialize + Clone,
COMMITMENT: for<'a> Deserialize<'a> + Serialize + Clone,
TOKEN: VoteToken,
{
/// `VoteType` that is used in this certificate
type Vote: VoteType<TYPES, Commitment<COMMITTABLE>>;
type Vote: VoteType<TYPES, COMMITMENT>;

/// `Accumulator` type to accumulate votes.
type VoteAccumulator: Accumulator2<TYPES, COMMITTABLE, Self::Vote>;
type VoteAccumulator: Accumulator2<TYPES, COMMITMENT, Self::Vote>;

/// Build a QC from the threshold signature and commitment
// TODO ED Rename this function and rework this function parameters
Expand All @@ -189,10 +189,10 @@ where
// TODO ED Make an issue for this

/// Get the leaf commitment.
fn leaf_commitment(&self) -> Commitment<COMMITTABLE>;
fn leaf_commitment(&self) -> COMMITMENT;

/// Set the leaf commitment.
fn set_leaf_commitment(&mut self, commitment: Commitment<COMMITTABLE>);
fn set_leaf_commitment(&mut self, commitment: COMMITMENT);

/// Get whether the certificate is for the genesis block.
fn is_genesis(&self) -> bool;
Expand Down Expand Up @@ -269,7 +269,7 @@ pub trait ConsensusExchange<TYPES: NodeType, M: NetworkMsg>: Send + Sync {
// TODO ED Make this equal Certificate vote (if possible?)
type Vote: VoteType<TYPES, Commitment<Self::Commitment>>;
/// A [`SignedCertificate`] attesting to a decision taken by the committee.
type Certificate: SignedCertificate<TYPES, TYPES::Time, TYPES::VoteTokenType, Self::Commitment>
type Certificate: SignedCertificate<TYPES, TYPES::Time, TYPES::VoteTokenType, Commitment<Self::Commitment>>
+ Hash
+ Eq;
/// The committee eligible to make decisions.
Expand Down Expand Up @@ -468,21 +468,21 @@ pub trait ConsensusExchange<TYPES: NodeType, M: NetworkMsg>: Send + Sync {
TYPES,
TYPES::Time,
TYPES::VoteTokenType,
Self::Commitment,
Commitment<Self::Commitment>,
>>::VoteAccumulator,
vote: &<<Self as ConsensusExchange<TYPES, M>>::Certificate as SignedCertificate<
TYPES,
TYPES::Time,
TYPES::VoteTokenType,
Self::Commitment,
Commitment<Self::Commitment>,
>>::Vote,
_commit: &Commitment<Self::Commitment>,
) -> Either<
<<Self as ConsensusExchange<TYPES, M>>::Certificate as SignedCertificate<
TYPES,
TYPES::Time,
TYPES::VoteTokenType,
Self::Commitment,
Commitment<Self::Commitment>,
>>::VoteAccumulator,
Self::Certificate,
> {
Expand Down
61 changes: 31 additions & 30 deletions crates/types/src/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use serde::{Deserialize, Serialize};
use std::{
collections::{BTreeMap, HashMap},
fmt::Debug,
hash::Hash,
marker::PhantomData,
num::NonZeroU64,
};
Expand Down Expand Up @@ -319,8 +320,8 @@ pub trait Accumulator<T, U>: Sized {
/// Accumulator trait used to accumulate votes into an `AssembledSignature`
pub trait Accumulator2<
TYPES: NodeType,
COMMITTABLE: Committable + Serialize + Clone,
VOTE: VoteType<TYPES, Commitment<COMMITTABLE>>,
COMMITMENT: for<'a> Deserialize<'a> + Serialize + Clone,
VOTE: VoteType<TYPES, COMMITMENT>,
>: Sized
{
/// Append 1 vote to the accumulator. If the threshold is not reached, return
Expand All @@ -337,11 +338,11 @@ pub trait Accumulator2<
/// Accumulates DA votes
pub struct DAVoteAccumulator<
TYPES: NodeType,
COMMITTABLE: Committable + Serialize + Clone,
VOTE: VoteType<TYPES, Commitment<COMMITTABLE>>,
COMMITMENT: for<'a> Deserialize<'a> + Serialize + Clone,
VOTE: VoteType<TYPES, COMMITMENT>,
> {
/// Map of all da signatures accumlated so far
pub da_vote_outcomes: VoteMap<Commitment<COMMITTABLE>, TYPES::VoteTokenType>,
pub da_vote_outcomes: VoteMap<COMMITMENT, TYPES::VoteTokenType>,
/// A quorum's worth of stake, generally 2f + 1
pub success_threshold: NonZeroU64,
/// A list of valid signatures for certificate aggregation
Expand All @@ -354,9 +355,9 @@ pub struct DAVoteAccumulator<

impl<
TYPES: NodeType,
COMMITTABLE: Committable + Serialize + Clone,
VOTE: VoteType<TYPES, Commitment<COMMITTABLE>>,
> Accumulator2<TYPES, COMMITTABLE, VOTE> for DAVoteAccumulator<TYPES, COMMITTABLE, VOTE>
COMMITMENT: for<'a> Deserialize<'a> + Serialize + Clone + Copy + PartialEq + Eq + Hash,
VOTE: VoteType<TYPES, COMMITMENT>,
> Accumulator2<TYPES, COMMITMENT, VOTE> for DAVoteAccumulator<TYPES, COMMITMENT, VOTE>
{
fn append(
mut self,
Expand Down Expand Up @@ -428,15 +429,15 @@ impl<
/// Accumulate quorum votes
pub struct QuorumVoteAccumulator<
TYPES: NodeType,
COMMITTABLE: Committable + Serialize + Clone,
VOTE: VoteType<TYPES, Commitment<COMMITTABLE>>,
COMMITMENT: for<'a> Deserialize<'a> + Serialize + Clone,
VOTE: VoteType<TYPES, COMMITMENT>,
> {
/// Map of all signatures accumlated so far
pub total_vote_outcomes: VoteMap<Commitment<COMMITTABLE>, TYPES::VoteTokenType>,
pub total_vote_outcomes: VoteMap<COMMITMENT, TYPES::VoteTokenType>,
/// Map of all yes signatures accumlated so far
pub yes_vote_outcomes: VoteMap<Commitment<COMMITTABLE>, TYPES::VoteTokenType>,
pub yes_vote_outcomes: VoteMap<COMMITMENT, TYPES::VoteTokenType>,
/// Map of all no signatures accumlated so far
pub no_vote_outcomes: VoteMap<Commitment<COMMITTABLE>, TYPES::VoteTokenType>,
pub no_vote_outcomes: VoteMap<COMMITMENT, TYPES::VoteTokenType>,

/// A quorum's worth of stake, generally 2f + 1
pub success_threshold: NonZeroU64,
Expand All @@ -452,9 +453,9 @@ pub struct QuorumVoteAccumulator<

impl<
TYPES: NodeType,
COMMITTABLE: Committable + Serialize + Clone,
VOTE: VoteType<TYPES, Commitment<COMMITTABLE>>,
> Accumulator2<TYPES, COMMITTABLE, VOTE> for QuorumVoteAccumulator<TYPES, COMMITTABLE, VOTE>
COMMITMENT: for<'a> Deserialize<'a> + Serialize + Clone + Copy + PartialEq + Eq + Hash,
VOTE: VoteType<TYPES, COMMITMENT>,
> Accumulator2<TYPES, COMMITMENT, VOTE> for QuorumVoteAccumulator<TYPES, COMMITMENT, VOTE>
{
fn append(
mut self,
Expand Down Expand Up @@ -559,15 +560,15 @@ impl<
/// Accumulates view sync votes
pub struct ViewSyncVoteAccumulator<
TYPES: NodeType,
COMMITTABLE: Committable + Serialize + Clone,
VOTE: VoteType<TYPES, Commitment<COMMITTABLE>>,
COMMITMENT: for<'a> Deserialize<'a> + Serialize + Clone,
VOTE: VoteType<TYPES, COMMITMENT>,
> {
/// Map of all pre_commit signatures accumlated so far
pub pre_commit_vote_outcomes: VoteMap<Commitment<COMMITTABLE>, TYPES::VoteTokenType>,
pub pre_commit_vote_outcomes: VoteMap<COMMITMENT, TYPES::VoteTokenType>,
/// Map of all ommit signatures accumlated so far
pub commit_vote_outcomes: VoteMap<Commitment<COMMITTABLE>, TYPES::VoteTokenType>,
pub commit_vote_outcomes: VoteMap<COMMITMENT, TYPES::VoteTokenType>,
/// Map of all finalize signatures accumlated so far
pub finalize_vote_outcomes: VoteMap<Commitment<COMMITTABLE>, TYPES::VoteTokenType>,
pub finalize_vote_outcomes: VoteMap<COMMITMENT, TYPES::VoteTokenType>,

/// A quorum's worth of stake, generally 2f + 1
pub success_threshold: NonZeroU64,
Expand All @@ -583,9 +584,9 @@ pub struct ViewSyncVoteAccumulator<

impl<
TYPES: NodeType,
COMMITTABLE: Committable + Serialize + Clone,
VOTE: VoteType<TYPES, Commitment<COMMITTABLE>>,
> Accumulator2<TYPES, COMMITTABLE, VOTE> for ViewSyncVoteAccumulator<TYPES, COMMITTABLE, VOTE>
COMMITMENT: for<'a> Deserialize<'a> + Serialize + Clone + Copy + PartialEq + Eq + Hash,
VOTE: VoteType<TYPES, COMMITMENT>,
> Accumulator2<TYPES, COMMITMENT, VOTE> for ViewSyncVoteAccumulator<TYPES, COMMITMENT, VOTE>
{
#[allow(clippy::too_many_lines)]
fn append(
Expand Down Expand Up @@ -733,18 +734,18 @@ impl<
/// Placeholder accumulator; will be replaced by accumulator for each certificate type
pub struct AccumulatorPlaceholder<
TYPES: NodeType,
COMMITTABLE: Committable + Serialize + Clone,
VOTE: VoteType<TYPES, Commitment<COMMITTABLE>>,
COMMITMENT: for<'a> Deserialize<'a> + Serialize + Clone,
VOTE: VoteType<TYPES, COMMITMENT>,
> {
/// Phantom data to make compiler happy
pub phantom: PhantomData<(TYPES, VOTE, COMMITTABLE)>,
pub phantom: PhantomData<(TYPES, VOTE, COMMITMENT)>,
}

impl<
TYPES: NodeType,
COMMITTABLE: Committable + Serialize + Clone,
VOTE: VoteType<TYPES, Commitment<COMMITTABLE>>,
> Accumulator2<TYPES, COMMITTABLE, VOTE> for AccumulatorPlaceholder<TYPES, COMMITTABLE, VOTE>
COMMITMENT: for<'a> Deserialize<'a> + Serialize + Clone,
VOTE: VoteType<TYPES, COMMITMENT>,
> Accumulator2<TYPES, COMMITMENT, VOTE> for AccumulatorPlaceholder<TYPES, COMMITMENT, VOTE>
{
fn append(
self,
Expand Down

0 comments on commit 6f85c10

Please sign in to comment.