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 VoteData type param #1779

Merged
merged 2 commits into from
Sep 19, 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
4 changes: 2 additions & 2 deletions crates/hotshot/examples/libp2p/multi-validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use async_compatibility_layer::{
logging::{setup_backtrace, setup_logging},
};
use clap::Parser;
use hotshot::demos::sdemo::SDemoTypes;
use hotshot::demo::DemoTypes;
use hotshot_orchestrator::client::ValidatorArgs;
use std::net::IpAddr;
use tracing::instrument;
Expand Down Expand Up @@ -49,7 +49,7 @@ async fn main() {
for _ in 0..args.num_nodes {
let node = async_spawn(async move {
infra_da::main_entry_point::<
SDemoTypes,
DemoTypes,
ThisMembership,
DANetwork,
QuorumNetwork,
Expand Down
4 changes: 2 additions & 2 deletions crates/hotshot/examples/libp2p/orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub mod types;

use async_compatibility_layer::logging::{setup_backtrace, setup_logging};
use clap::Parser;
use hotshot::demos::sdemo::SDemoTypes;
use hotshot::demo::DemoTypes;
use tracing::instrument;
use types::ThisMembership;

Expand All @@ -29,7 +29,7 @@ async fn main() {
let args = OrchestratorArgs::parse();

run_orchestrator_da::<
SDemoTypes,
DemoTypes,
ThisMembership,
DANetwork,
QuorumNetwork,
Expand Down
54 changes: 27 additions & 27 deletions crates/hotshot/examples/libp2p/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::infra_da::Libp2pDARun;
use hotshot::{
demos::sdemo::SDemoTypes,
demo::DemoTypes,
traits::{
election::static_committee::GeneralStaticCommittee,
implementations::{Libp2pCommChannel, MemoryStorage},
Expand All @@ -22,54 +22,54 @@ use std::fmt::Debug;
#[derive(Clone, Debug, Deserialize, Serialize, Hash, PartialEq, Eq)]
pub struct NodeImpl {}

pub type ThisLeaf = SequencingLeaf<SDemoTypes>;
pub type ThisLeaf = SequencingLeaf<DemoTypes>;
pub type ThisMembership =
GeneralStaticCommittee<SDemoTypes, ThisLeaf, <SDemoTypes as NodeType>::SignatureKey>;
pub type DANetwork = Libp2pCommChannel<SDemoTypes, NodeImpl, ThisMembership>;
pub type QuorumNetwork = Libp2pCommChannel<SDemoTypes, NodeImpl, ThisMembership>;
pub type ViewSyncNetwork = Libp2pCommChannel<SDemoTypes, NodeImpl, ThisMembership>;
GeneralStaticCommittee<DemoTypes, ThisLeaf, <DemoTypes as NodeType>::SignatureKey>;
pub type DANetwork = Libp2pCommChannel<DemoTypes, NodeImpl, ThisMembership>;
pub type QuorumNetwork = Libp2pCommChannel<DemoTypes, NodeImpl, ThisMembership>;
pub type ViewSyncNetwork = Libp2pCommChannel<DemoTypes, NodeImpl, ThisMembership>;

pub type ThisDAProposal = DAProposal<SDemoTypes>;
pub type ThisDAVote = DAVote<SDemoTypes>;
pub type ThisDAProposal = DAProposal<DemoTypes>;
pub type ThisDAVote = DAVote<DemoTypes>;

pub type ThisQuorumProposal = QuorumProposal<SDemoTypes, ThisLeaf>;
pub type ThisQuorumVote = QuorumVote<SDemoTypes, ThisLeaf>;
pub type ThisQuorumProposal = QuorumProposal<DemoTypes, ThisLeaf>;
pub type ThisQuorumVote = QuorumVote<DemoTypes, ThisLeaf>;

pub type ThisViewSyncProposal = ViewSyncCertificate<SDemoTypes>;
pub type ThisViewSyncVote = ViewSyncVote<SDemoTypes>;
pub type ThisViewSyncProposal = ViewSyncCertificate<DemoTypes>;
pub type ThisViewSyncVote = ViewSyncVote<DemoTypes>;

impl NodeImplementation<SDemoTypes> for NodeImpl {
type Storage = MemoryStorage<SDemoTypes, Self::Leaf>;
type Leaf = SequencingLeaf<SDemoTypes>;
impl NodeImplementation<DemoTypes> for NodeImpl {
type Storage = MemoryStorage<DemoTypes, Self::Leaf>;
type Leaf = SequencingLeaf<DemoTypes>;
type Exchanges = SequencingExchanges<
SDemoTypes,
Message<SDemoTypes, Self>,
DemoTypes,
Message<DemoTypes, Self>,
QuorumExchange<
SDemoTypes,
DemoTypes,
Self::Leaf,
ThisQuorumProposal,
ThisMembership,
QuorumNetwork,
Message<SDemoTypes, Self>,
Message<DemoTypes, Self>,
>,
CommitteeExchange<SDemoTypes, ThisMembership, DANetwork, Message<SDemoTypes, Self>>,
CommitteeExchange<DemoTypes, ThisMembership, DANetwork, Message<DemoTypes, Self>>,
ViewSyncExchange<
SDemoTypes,
DemoTypes,
ThisViewSyncProposal,
ThisMembership,
ViewSyncNetwork,
Message<SDemoTypes, Self>,
Message<DemoTypes, Self>,
>,
>;
type ConsensusMessage = SequencingMessage<SDemoTypes, Self>;
type ConsensusMessage = SequencingMessage<DemoTypes, Self>;

fn new_channel_maps(
start_view: <SDemoTypes as NodeType>::Time,
start_view: <DemoTypes as NodeType>::Time,
) -> (
ChannelMaps<SDemoTypes, Self>,
Option<ChannelMaps<SDemoTypes, Self>>,
ChannelMaps<DemoTypes, Self>,
Option<ChannelMaps<DemoTypes, Self>>,
) {
(ChannelMaps::new(start_view), None)
}
}
pub type ThisRun = Libp2pDARun<SDemoTypes, NodeImpl, ThisMembership>;
pub type ThisRun = Libp2pDARun<DemoTypes, NodeImpl, ThisMembership>;
4 changes: 2 additions & 2 deletions crates/hotshot/examples/libp2p/validator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use async_compatibility_layer::logging::{setup_backtrace, setup_logging};
use clap::Parser;
use hotshot::demos::sdemo::SDemoTypes;
use hotshot::demo::DemoTypes;
use tracing::{info, instrument};

use crate::types::{DANetwork, NodeImpl, QuorumNetwork, ThisMembership, ThisRun, ViewSyncNetwork};
Expand Down Expand Up @@ -29,7 +29,7 @@ async fn main() {
args.host, args.port
);
infra_da::main_entry_point::<
SDemoTypes,
DemoTypes,
ThisMembership,
DANetwork,
QuorumNetwork,
Expand Down
2 changes: 1 addition & 1 deletion crates/types/src/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub struct VoteMetaData<COMMITTABLE: Committable + Serialize + Clone, T: VoteTok
/// Commitment to what's voted on. E.g. the leaf for a `QuorumCertificate`
pub commitment: Commitment<COMMITTABLE>,
/// Data of the vote, yes, no, timeout, or DA
pub data: VoteData<COMMITTABLE>,
pub data: VoteData<Commitment<COMMITTABLE>>,
/// The votes's token
pub vote_token: T,
/// View number for the vote
Expand Down
80 changes: 48 additions & 32 deletions crates/types/src/traits/election.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,38 +74,46 @@ pub enum Checked<T> {
/// Data to vote on for different types of votes.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Hash)]
#[serde(bound(deserialize = ""))]
pub enum VoteData<COMMITTABLE: Committable + Serialize + Clone> {
pub enum VoteData<COMMITMENT>
where
COMMITMENT: for<'a> Deserialize<'a>,
{
/// Vote to provide availability for a block.
DA(Commitment<COMMITTABLE>),
DA(COMMITMENT),
/// Vote to append a leaf to the log.
Yes(Commitment<COMMITTABLE>),
Yes(COMMITMENT),
/// Vote to reject a leaf from the log.
No(Commitment<COMMITTABLE>),
No(COMMITMENT),
/// Vote to time out and proceed to the next view.
Timeout(Commitment<COMMITTABLE>),
Timeout(COMMITMENT),
/// Vote to pre-commit the view sync.
ViewSyncPreCommit(Commitment<COMMITTABLE>),
ViewSyncPreCommit(COMMITMENT),
/// Vote to commit the view sync.
ViewSyncCommit(Commitment<COMMITTABLE>),
ViewSyncCommit(COMMITMENT),
/// Vote to finalize the view sync.
ViewSyncFinalize(Commitment<COMMITTABLE>),
ViewSyncFinalize(COMMITMENT),
}

impl<COMMITTABLE> VoteData<COMMITTABLE>
impl<COMMITMENT> VoteData<COMMITMENT>
where
COMMITTABLE: Committable + Serialize + Clone,
COMMITMENT: for<'a> Deserialize<'a> + Clone,
{
/// Return the underlying commitment.
#[must_use]
pub fn get_commit(&self) -> Commitment<COMMITTABLE> {
pub fn get_commit(&self) -> COMMITMENT {
#[allow(clippy::enum_glob_use)]
use VoteData::*;
match self {
DA(c) | Yes(c) | No(c) | Timeout(c) | ViewSyncPreCommit(c) | ViewSyncCommit(c)
| ViewSyncFinalize(c) => *c,
| ViewSyncFinalize(c) => c.clone(),
}
}
}

impl<COMMITMENT> VoteData<COMMITMENT>
where
COMMITMENT: Serialize + for<'a> Deserialize<'a>,
{
#[must_use]
/// Convert vote data into bytes.
///
Expand Down Expand Up @@ -269,7 +277,7 @@ pub trait ConsensusExchange<TYPES: NodeType, M: NetworkMsg>: Send + Sync {
/// Network used by [`Membership`](Self::Membership) to communicate.
type Networking: CommunicationChannel<TYPES, M, Self::Membership>;
/// Commitments to items which are the subject of proposals and decisions.
type Commitment: Committable + Serialize + Clone;
type Commitment: Committable + Serialize + for<'a> Deserialize<'a> + Clone;

/// Join a [`ConsensusExchange`] with the given identity (`pk` and `sk`).
fn create(
Expand Down Expand Up @@ -322,7 +330,10 @@ pub trait ConsensusExchange<TYPES: NodeType, M: NetworkMsg>: Send + Sync {
}

/// The contents of a vote on `commit`.
fn vote_data(&self, commit: Commitment<Self::Commitment>) -> VoteData<Self::Commitment>;
fn vote_data(
&self,
commit: Commitment<Self::Commitment>,
) -> VoteData<Commitment<Self::Commitment>>;

/// Validate a QC.
fn is_valid_cert(&self, qc: &Self::Certificate, commit: Commitment<Self::Commitment>) -> bool {
Expand Down Expand Up @@ -376,7 +387,7 @@ pub trait ConsensusExchange<TYPES: NodeType, M: NetworkMsg>: Send + Sync {
&self,
encoded_key: &EncodedPublicKey,
encoded_signature: &EncodedSignature,
data: VoteData<Self::Commitment>,
data: VoteData<Commitment<Self::Commitment>>,
vote_token: Checked<TYPES::VoteTokenType>,
) -> bool {
let mut is_valid_vote_token = false;
Expand All @@ -401,7 +412,7 @@ pub trait ConsensusExchange<TYPES: NodeType, M: NetworkMsg>: Send + Sync {
&self,
key: &TYPES::SignatureKey,
encoded_signature: &EncodedSignature,
data: &VoteData<Self::Commitment>,
data: &VoteData<Commitment<Self::Commitment>>,
vote_token: &Checked<TYPES::VoteTokenType>,
) -> bool {
let is_valid_signature = key.validate(encoded_signature, data.get_commit().as_ref());
Expand Down Expand Up @@ -439,7 +450,7 @@ pub trait ConsensusExchange<TYPES: NodeType, M: NetworkMsg>: Send + Sync {
encoded_key: &EncodedPublicKey,
encoded_signature: &EncodedSignature,
leaf_commitment: Commitment<Self::Commitment>,
vote_data: VoteData<Self::Commitment>,
vote_data: VoteData<Commitment<Self::Commitment>>,
vote_token: TYPES::VoteTokenType,
view_number: TYPES::Time,
accumlator: VoteAccumulator<TYPES::VoteTokenType, Self::Commitment, TYPES>,
Expand Down Expand Up @@ -613,9 +624,7 @@ impl<
) -> (EncodedPublicKey, EncodedSignature) {
let signature = TYPES::SignatureKey::sign(
&self.private_key,
VoteData::<TYPES::BlockType>::DA(block_commitment)
.get_commit()
.as_ref(),
VoteData::DA(block_commitment).get_commit().as_ref(),
);
(self.public_key.to_bytes(), signature)
}
Expand Down Expand Up @@ -658,9 +667,7 @@ impl<
) -> (EncodedPublicKey, EncodedSignature) {
let signature = TYPES::SignatureKey::sign(
&self.private_key,
VoteData::<TYPES::BlockType>::DA(block_commitment)
.get_commit()
.as_ref(),
VoteData::DA(block_commitment).get_commit().as_ref(),
);
(self.public_key.to_bytes(), signature)
}
Expand Down Expand Up @@ -710,7 +717,10 @@ impl<
.make_vote_token(view_number, &self.private_key)
}

fn vote_data(&self, commit: Commitment<Self::Commitment>) -> VoteData<Self::Commitment> {
fn vote_data(
&self,
commit: Commitment<Self::Commitment>,
) -> VoteData<Commitment<Self::Commitment>> {
VoteData::DA(commit)
}

Expand All @@ -721,7 +731,7 @@ impl<
encoded_key: &EncodedPublicKey,
encoded_signature: &EncodedSignature,
leaf_commitment: Commitment<Self::Commitment>,
vote_data: VoteData<Self::Commitment>,
vote_data: VoteData<Commitment<Self::Commitment>>,
vote_token: TYPES::VoteTokenType,
view_number: TYPES::Time,
accumlator: VoteAccumulator<TYPES::VoteTokenType, Self::Commitment, TYPES>,
Expand Down Expand Up @@ -902,7 +912,7 @@ impl<
) -> (EncodedPublicKey, EncodedSignature) {
let signature = TYPES::SignatureKey::sign(
&self.private_key,
VoteData::<LEAF>::Yes(leaf_commitment).get_commit().as_ref(),
VoteData::Yes(leaf_commitment).get_commit().as_ref(),
);
(self.public_key.to_bytes(), signature)
}
Expand All @@ -918,7 +928,7 @@ impl<
) -> (EncodedPublicKey, EncodedSignature) {
let signature = TYPES::SignatureKey::sign(
&self.private_key,
VoteData::<LEAF>::No(leaf_commitment).get_commit().as_ref(),
VoteData::No(leaf_commitment).get_commit().as_ref(),
);
(self.public_key.to_bytes(), signature)
}
Expand All @@ -933,7 +943,7 @@ impl<
fn sign_timeout_vote(&self, view_number: TYPES::Time) -> (EncodedPublicKey, EncodedSignature) {
let signature = TYPES::SignatureKey::sign(
&self.private_key,
VoteData::<TYPES::Time>::Timeout(view_number.commit())
VoteData::Timeout(view_number.commit())
.get_commit()
.as_ref(),
);
Expand Down Expand Up @@ -1023,7 +1033,10 @@ impl<
&self.network
}

fn vote_data(&self, commit: Commitment<Self::Commitment>) -> VoteData<Self::Commitment> {
fn vote_data(
&self,
commit: Commitment<Self::Commitment>,
) -> VoteData<Commitment<Self::Commitment>> {
VoteData::Yes(commit)
}

Expand All @@ -1034,7 +1047,7 @@ impl<
encoded_key: &EncodedPublicKey,
encoded_signature: &EncodedSignature,
leaf_commitment: Commitment<LEAF>,
vote_data: VoteData<Self::Commitment>,
vote_data: VoteData<Commitment<Self::Commitment>>,
vote_token: TYPES::VoteTokenType,
view_number: TYPES::Time,
accumlator: VoteAccumulator<TYPES::VoteTokenType, LEAF, TYPES>,
Expand Down Expand Up @@ -1382,7 +1395,10 @@ impl<
&self.network
}

fn vote_data(&self, _commit: Commitment<Self::Commitment>) -> VoteData<Self::Commitment> {
fn vote_data(
&self,
_commit: Commitment<Self::Commitment>,
) -> VoteData<Commitment<Self::Commitment>> {
unimplemented!()
}

Expand All @@ -1391,7 +1407,7 @@ impl<
encoded_key: &EncodedPublicKey,
encoded_signature: &EncodedSignature,
leaf_commitment: Commitment<ViewSyncData<TYPES>>,
vote_data: VoteData<Self::Commitment>,
vote_data: VoteData<Commitment<Self::Commitment>>,
vote_token: TYPES::VoteTokenType,
view_number: TYPES::Time,
accumlator: VoteAccumulator<TYPES::VoteTokenType, ViewSyncData<TYPES>, TYPES>,
Expand Down
Loading
Loading