Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove Committable from 3 more types #1789

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/hotshot/src/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -66,7 +66,7 @@ pub async fn add_network_message_task<
>,
COMMITTABLE: Committable + Serialize + Clone,
PROPOSAL: ProposalType<NodeType = TYPES>,
VOTE: VoteType<TYPES, COMMITTABLE>,
VOTE: VoteType<TYPES, Commitment<COMMITTABLE>>,
MEMBERSHIP: Membership<TYPES>,
EXCHANGE: ConsensusExchange<
TYPES,
Expand Down Expand Up @@ -176,7 +176,7 @@ pub async fn add_network_event_task<
>,
COMMITTABLE: Committable + Serialize + Clone,
PROPOSAL: ProposalType<NodeType = TYPES>,
VOTE: VoteType<TYPES, COMMITTABLE>,
VOTE: VoteType<TYPES, Commitment<COMMITTABLE>>,
MEMBERSHIP: Membership<TYPES>,
EXCHANGE: ConsensusExchange<
TYPES,
Expand Down
4 changes: 2 additions & 2 deletions crates/types/src/traits/election.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ where
TOKEN: VoteToken,
{
/// `VoteType` that is used in this certificate
type Vote: VoteType<TYPES, COMMITTABLE>;
type Vote: VoteType<TYPES, Commitment<COMMITTABLE>>;

/// `Accumulator` type to accumulate votes.
type VoteAccumulator: Accumulator2<TYPES, COMMITTABLE, Self::Vote>;
Expand Down Expand Up @@ -267,7 +267,7 @@ pub trait ConsensusExchange<TYPES: NodeType, M: NetworkMsg>: Send + Sync {
type Proposal: ProposalType<NodeType = TYPES>;
/// A vote on a [`Proposal`](Self::Proposal).
// TODO ED Make this equal Certificate vote (if possible?)
type Vote: VoteType<TYPES, Self::Commitment>;
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>
+ Hash
Expand Down
58 changes: 32 additions & 26 deletions crates/types/src/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use std::{
use tracing::error;

/// The vote sent by consensus messages.
pub trait VoteType<TYPES: NodeType, COMMITTABLE: Committable + Serialize + Clone>:
pub trait VoteType<TYPES: NodeType, COMMITMENT: for<'a> Deserialize<'a> + Serialize + Clone>:
Debug + Clone + 'static + Serialize + for<'a> Deserialize<'a> + Send + Sync + PartialEq
{
/// Get the view this vote was cast for
Expand All @@ -38,7 +38,7 @@ pub trait VoteType<TYPES: NodeType, COMMITTABLE: Committable + Serialize + Clone
/// Get the signature associated with this vote
fn get_signature(&self) -> EncodedSignature;
/// Get the data this vote was signed over
fn get_data(&self) -> VoteData<Commitment<COMMITTABLE>>;
fn get_data(&self) -> VoteData<COMMITMENT>;
/// Get the vote token of this vote
fn get_vote_token(&self) -> TYPES::VoteTokenType;
}
Expand Down Expand Up @@ -196,7 +196,7 @@ pub enum QuorumVote<TYPES: NodeType, LEAF: LeafType<NodeType = TYPES>> {
Timeout(TimeoutVote<TYPES, LEAF>),
}

impl<TYPES: NodeType> VoteType<TYPES, TYPES::BlockType> for DAVote<TYPES> {
impl<TYPES: NodeType> VoteType<TYPES, Commitment<TYPES::BlockType>> for DAVote<TYPES> {
fn get_view(&self) -> TYPES::Time {
self.current_view
}
Expand All @@ -223,7 +223,7 @@ impl<TYPES: NodeType> DAVote<TYPES> {
}
}

impl<TYPES: NodeType, LEAF: LeafType<NodeType = TYPES>> VoteType<TYPES, LEAF>
impl<TYPES: NodeType, LEAF: LeafType<NodeType = TYPES>> VoteType<TYPES, Commitment<LEAF>>
for QuorumVote<TYPES, LEAF>
{
fn get_view(&self) -> TYPES::Time {
Expand Down Expand Up @@ -275,7 +275,7 @@ impl<TYPES: NodeType, LEAF: LeafType<NodeType = TYPES>> QuorumVote<TYPES, LEAF>
}
}

impl<TYPES: NodeType> VoteType<TYPES, ViewSyncData<TYPES>> for ViewSyncVote<TYPES> {
impl<TYPES: NodeType> VoteType<TYPES, Commitment<ViewSyncData<TYPES>>> for ViewSyncVote<TYPES> {
fn get_view(&self) -> TYPES::Time {
match self {
ViewSyncVote::PreCommit(v) | ViewSyncVote::Commit(v) | ViewSyncVote::Finalize(v) => {
Expand Down Expand Up @@ -320,7 +320,7 @@ pub trait Accumulator<T, U>: Sized {
pub trait Accumulator2<
TYPES: NodeType,
COMMITTABLE: Committable + Serialize + Clone,
VOTE: VoteType<TYPES, COMMITTABLE>,
VOTE: VoteType<TYPES, Commitment<COMMITTABLE>>,
>: Sized
{
/// Append 1 vote to the accumulator. If the threshold is not reached, return
Expand All @@ -338,10 +338,10 @@ pub trait Accumulator2<
pub struct DAVoteAccumulator<
TYPES: NodeType,
COMMITTABLE: Committable + Serialize + Clone,
VOTE: VoteType<TYPES, COMMITTABLE>,
VOTE: VoteType<TYPES, Commitment<COMMITTABLE>>,
> {
/// Map of all da signatures accumlated so far
pub da_vote_outcomes: VoteMap<COMMITTABLE, TYPES::VoteTokenType>,
pub da_vote_outcomes: VoteMap<Commitment<COMMITTABLE>, 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 @@ -355,7 +355,7 @@ pub struct DAVoteAccumulator<
impl<
TYPES: NodeType,
COMMITTABLE: Committable + Serialize + Clone,
VOTE: VoteType<TYPES, COMMITTABLE>,
VOTE: VoteType<TYPES, Commitment<COMMITTABLE>>,
> Accumulator2<TYPES, COMMITTABLE, VOTE> for DAVoteAccumulator<TYPES, COMMITTABLE, VOTE>
{
fn append(
Expand Down Expand Up @@ -429,14 +429,14 @@ impl<
pub struct QuorumVoteAccumulator<
TYPES: NodeType,
COMMITTABLE: Committable + Serialize + Clone,
VOTE: VoteType<TYPES, COMMITTABLE>,
VOTE: VoteType<TYPES, Commitment<COMMITTABLE>>,
> {
/// Map of all signatures accumlated so far
pub total_vote_outcomes: VoteMap<COMMITTABLE, TYPES::VoteTokenType>,
pub total_vote_outcomes: VoteMap<Commitment<COMMITTABLE>, TYPES::VoteTokenType>,
/// Map of all yes signatures accumlated so far
pub yes_vote_outcomes: VoteMap<COMMITTABLE, TYPES::VoteTokenType>,
pub yes_vote_outcomes: VoteMap<Commitment<COMMITTABLE>, TYPES::VoteTokenType>,
/// Map of all no signatures accumlated so far
pub no_vote_outcomes: VoteMap<COMMITTABLE, TYPES::VoteTokenType>,
pub no_vote_outcomes: VoteMap<Commitment<COMMITTABLE>, TYPES::VoteTokenType>,

/// A quorum's worth of stake, generally 2f + 1
pub success_threshold: NonZeroU64,
Expand All @@ -453,7 +453,7 @@ pub struct QuorumVoteAccumulator<
impl<
TYPES: NodeType,
COMMITTABLE: Committable + Serialize + Clone,
VOTE: VoteType<TYPES, COMMITTABLE>,
VOTE: VoteType<TYPES, Commitment<COMMITTABLE>>,
> Accumulator2<TYPES, COMMITTABLE, VOTE> for QuorumVoteAccumulator<TYPES, COMMITTABLE, VOTE>
{
fn append(
Expand Down Expand Up @@ -560,14 +560,14 @@ impl<
pub struct ViewSyncVoteAccumulator<
TYPES: NodeType,
COMMITTABLE: Committable + Serialize + Clone,
VOTE: VoteType<TYPES, COMMITTABLE>,
VOTE: VoteType<TYPES, Commitment<COMMITTABLE>>,
> {
/// Map of all pre_commit signatures accumlated so far
pub pre_commit_vote_outcomes: VoteMap<COMMITTABLE, TYPES::VoteTokenType>,
pub pre_commit_vote_outcomes: VoteMap<Commitment<COMMITTABLE>, TYPES::VoteTokenType>,
/// Map of all ommit signatures accumlated so far
pub commit_vote_outcomes: VoteMap<COMMITTABLE, TYPES::VoteTokenType>,
pub commit_vote_outcomes: VoteMap<Commitment<COMMITTABLE>, TYPES::VoteTokenType>,
/// Map of all finalize signatures accumlated so far
pub finalize_vote_outcomes: VoteMap<COMMITTABLE, TYPES::VoteTokenType>,
pub finalize_vote_outcomes: VoteMap<Commitment<COMMITTABLE>, TYPES::VoteTokenType>,

/// A quorum's worth of stake, generally 2f + 1
pub success_threshold: NonZeroU64,
Expand All @@ -584,7 +584,7 @@ pub struct ViewSyncVoteAccumulator<
impl<
TYPES: NodeType,
COMMITTABLE: Committable + Serialize + Clone,
VOTE: VoteType<TYPES, COMMITTABLE>,
VOTE: VoteType<TYPES, Commitment<COMMITTABLE>>,
> Accumulator2<TYPES, COMMITTABLE, VOTE> for ViewSyncVoteAccumulator<TYPES, COMMITTABLE, VOTE>
{
#[allow(clippy::too_many_lines)]
Expand Down Expand Up @@ -734,7 +734,7 @@ impl<
pub struct AccumulatorPlaceholder<
TYPES: NodeType,
COMMITTABLE: Committable + Serialize + Clone,
VOTE: VoteType<TYPES, COMMITTABLE>,
VOTE: VoteType<TYPES, Commitment<COMMITTABLE>>,
> {
/// Phantom data to make compiler happy
pub phantom: PhantomData<(TYPES, VOTE, COMMITTABLE)>,
Expand All @@ -743,7 +743,7 @@ pub struct AccumulatorPlaceholder<
impl<
TYPES: NodeType,
COMMITTABLE: Committable + Serialize + Clone,
VOTE: VoteType<TYPES, COMMITTABLE>,
VOTE: VoteType<TYPES, Commitment<COMMITTABLE>>,
> Accumulator2<TYPES, COMMITTABLE, VOTE> for AccumulatorPlaceholder<TYPES, COMMITTABLE, VOTE>
{
fn append(
Expand All @@ -758,17 +758,23 @@ impl<

/// Mapping of commitments to vote tokens by key.
// TODO ED Remove this whole token generic
type VoteMap<C, TOKEN> = HashMap<
Commitment<C>,
type VoteMap<COMMITMENT, TOKEN> = HashMap<
COMMITMENT,
(
u64,
BTreeMap<EncodedPublicKey, (EncodedSignature, VoteData<Commitment<C>>, TOKEN)>,
BTreeMap<EncodedPublicKey, (EncodedSignature, VoteData<COMMITMENT>, TOKEN)>,
),
>;

/// Describe the process of collecting signatures on block or leaf commitment, to form a DAC or QC,
/// respectively.
pub struct VoteAccumulator<TOKEN, COMMITMENT: Committable + Serialize + Clone, TYPES: NodeType> {
///
/// 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<COMMITMENT, TOKEN>,
/// Map of all da signatures accumlated so far
Expand Down Expand Up @@ -809,7 +815,7 @@ impl<TOKEN, LEAF: Committable + Serialize + Clone, TYPES: NodeType>
),
),
AssembledSignature<TYPES>,
> for VoteAccumulator<TOKEN, LEAF, TYPES>
> for VoteAccumulator<TOKEN, Commitment<LEAF>, TYPES>
where
TOKEN: Clone + VoteToken,
{
Expand Down