diff --git a/crates/hotshot/examples/libp2p/multi-validator.rs b/crates/hotshot/examples/libp2p/multi-validator.rs index 8a0f53c1c9..3ed46fa979 100644 --- a/crates/hotshot/examples/libp2p/multi-validator.rs +++ b/crates/hotshot/examples/libp2p/multi-validator.rs @@ -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; @@ -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, diff --git a/crates/hotshot/examples/libp2p/orchestrator.rs b/crates/hotshot/examples/libp2p/orchestrator.rs index 772d3aa12e..594d004a93 100644 --- a/crates/hotshot/examples/libp2p/orchestrator.rs +++ b/crates/hotshot/examples/libp2p/orchestrator.rs @@ -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; @@ -29,7 +29,7 @@ async fn main() { let args = OrchestratorArgs::parse(); run_orchestrator_da::< - SDemoTypes, + DemoTypes, ThisMembership, DANetwork, QuorumNetwork, diff --git a/crates/hotshot/examples/libp2p/types.rs b/crates/hotshot/examples/libp2p/types.rs index 5289c9d6fe..79b1ea1419 100644 --- a/crates/hotshot/examples/libp2p/types.rs +++ b/crates/hotshot/examples/libp2p/types.rs @@ -1,6 +1,6 @@ use crate::infra_da::Libp2pDARun; use hotshot::{ - demos::sdemo::SDemoTypes, + demo::DemoTypes, traits::{ election::static_committee::GeneralStaticCommittee, implementations::{Libp2pCommChannel, MemoryStorage}, @@ -22,54 +22,54 @@ use std::fmt::Debug; #[derive(Clone, Debug, Deserialize, Serialize, Hash, PartialEq, Eq)] pub struct NodeImpl {} -pub type ThisLeaf = SequencingLeaf; +pub type ThisLeaf = SequencingLeaf; pub type ThisMembership = - GeneralStaticCommittee::SignatureKey>; -pub type DANetwork = Libp2pCommChannel; -pub type QuorumNetwork = Libp2pCommChannel; -pub type ViewSyncNetwork = Libp2pCommChannel; + GeneralStaticCommittee::SignatureKey>; +pub type DANetwork = Libp2pCommChannel; +pub type QuorumNetwork = Libp2pCommChannel; +pub type ViewSyncNetwork = Libp2pCommChannel; -pub type ThisDAProposal = DAProposal; -pub type ThisDAVote = DAVote; +pub type ThisDAProposal = DAProposal; +pub type ThisDAVote = DAVote; -pub type ThisQuorumProposal = QuorumProposal; -pub type ThisQuorumVote = QuorumVote; +pub type ThisQuorumProposal = QuorumProposal; +pub type ThisQuorumVote = QuorumVote; -pub type ThisViewSyncProposal = ViewSyncCertificate; -pub type ThisViewSyncVote = ViewSyncVote; +pub type ThisViewSyncProposal = ViewSyncCertificate; +pub type ThisViewSyncVote = ViewSyncVote; -impl NodeImplementation for NodeImpl { - type Storage = MemoryStorage; - type Leaf = SequencingLeaf; +impl NodeImplementation for NodeImpl { + type Storage = MemoryStorage; + type Leaf = SequencingLeaf; type Exchanges = SequencingExchanges< - SDemoTypes, - Message, + DemoTypes, + Message, QuorumExchange< - SDemoTypes, + DemoTypes, Self::Leaf, ThisQuorumProposal, ThisMembership, QuorumNetwork, - Message, + Message, >, - CommitteeExchange>, + CommitteeExchange>, ViewSyncExchange< - SDemoTypes, + DemoTypes, ThisViewSyncProposal, ThisMembership, ViewSyncNetwork, - Message, + Message, >, >; - type ConsensusMessage = SequencingMessage; + type ConsensusMessage = SequencingMessage; fn new_channel_maps( - start_view: ::Time, + start_view: ::Time, ) -> ( - ChannelMaps, - Option>, + ChannelMaps, + Option>, ) { (ChannelMaps::new(start_view), None) } } -pub type ThisRun = Libp2pDARun; +pub type ThisRun = Libp2pDARun; diff --git a/crates/hotshot/examples/libp2p/validator.rs b/crates/hotshot/examples/libp2p/validator.rs index ec2415fd65..ab44e02991 100644 --- a/crates/hotshot/examples/libp2p/validator.rs +++ b/crates/hotshot/examples/libp2p/validator.rs @@ -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}; @@ -29,7 +29,7 @@ async fn main() { args.host, args.port ); infra_da::main_entry_point::< - SDemoTypes, + DemoTypes, ThisMembership, DANetwork, QuorumNetwork, diff --git a/crates/types/src/certificate.rs b/crates/types/src/certificate.rs index 9792026dcf..5309729eb7 100644 --- a/crates/types/src/certificate.rs +++ b/crates/types/src/certificate.rs @@ -146,7 +146,7 @@ pub struct VoteMetaData, /// Data of the vote, yes, no, timeout, or DA - pub data: VoteData, + pub data: VoteData>, /// The votes's token pub vote_token: T, /// View number for the vote diff --git a/crates/types/src/traits/election.rs b/crates/types/src/traits/election.rs index 6ced8bebbc..3d152cc85e 100644 --- a/crates/types/src/traits/election.rs +++ b/crates/types/src/traits/election.rs @@ -74,38 +74,46 @@ pub enum Checked { /// Data to vote on for different types of votes. #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Hash)] #[serde(bound(deserialize = ""))] -pub enum VoteData { +pub enum VoteData +where + COMMITMENT: for<'a> Deserialize<'a>, +{ /// Vote to provide availability for a block. - DA(Commitment), + DA(COMMITMENT), /// Vote to append a leaf to the log. - Yes(Commitment), + Yes(COMMITMENT), /// Vote to reject a leaf from the log. - No(Commitment), + No(COMMITMENT), /// Vote to time out and proceed to the next view. - Timeout(Commitment), + Timeout(COMMITMENT), /// Vote to pre-commit the view sync. - ViewSyncPreCommit(Commitment), + ViewSyncPreCommit(COMMITMENT), /// Vote to commit the view sync. - ViewSyncCommit(Commitment), + ViewSyncCommit(COMMITMENT), /// Vote to finalize the view sync. - ViewSyncFinalize(Commitment), + ViewSyncFinalize(COMMITMENT), } -impl VoteData +impl VoteData where - COMMITTABLE: Committable + Serialize + Clone, + COMMITMENT: for<'a> Deserialize<'a> + Clone, { /// Return the underlying commitment. #[must_use] - pub fn get_commit(&self) -> Commitment { + 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 VoteData +where + COMMITMENT: Serialize + for<'a> Deserialize<'a>, +{ #[must_use] /// Convert vote data into bytes. /// @@ -269,7 +277,7 @@ pub trait ConsensusExchange: Send + Sync { /// Network used by [`Membership`](Self::Membership) to communicate. type Networking: CommunicationChannel; /// 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( @@ -322,7 +330,10 @@ pub trait ConsensusExchange: Send + Sync { } /// The contents of a vote on `commit`. - fn vote_data(&self, commit: Commitment) -> VoteData; + fn vote_data( + &self, + commit: Commitment, + ) -> VoteData>; /// Validate a QC. fn is_valid_cert(&self, qc: &Self::Certificate, commit: Commitment) -> bool { @@ -376,7 +387,7 @@ pub trait ConsensusExchange: Send + Sync { &self, encoded_key: &EncodedPublicKey, encoded_signature: &EncodedSignature, - data: VoteData, + data: VoteData>, vote_token: Checked, ) -> bool { let mut is_valid_vote_token = false; @@ -401,7 +412,7 @@ pub trait ConsensusExchange: Send + Sync { &self, key: &TYPES::SignatureKey, encoded_signature: &EncodedSignature, - data: &VoteData, + data: &VoteData>, vote_token: &Checked, ) -> bool { let is_valid_signature = key.validate(encoded_signature, data.get_commit().as_ref()); @@ -439,7 +450,7 @@ pub trait ConsensusExchange: Send + Sync { encoded_key: &EncodedPublicKey, encoded_signature: &EncodedSignature, leaf_commitment: Commitment, - vote_data: VoteData, + vote_data: VoteData>, vote_token: TYPES::VoteTokenType, view_number: TYPES::Time, accumlator: VoteAccumulator, @@ -613,9 +624,7 @@ impl< ) -> (EncodedPublicKey, EncodedSignature) { let signature = TYPES::SignatureKey::sign( &self.private_key, - VoteData::::DA(block_commitment) - .get_commit() - .as_ref(), + VoteData::DA(block_commitment).get_commit().as_ref(), ); (self.public_key.to_bytes(), signature) } @@ -658,9 +667,7 @@ impl< ) -> (EncodedPublicKey, EncodedSignature) { let signature = TYPES::SignatureKey::sign( &self.private_key, - VoteData::::DA(block_commitment) - .get_commit() - .as_ref(), + VoteData::DA(block_commitment).get_commit().as_ref(), ); (self.public_key.to_bytes(), signature) } @@ -710,7 +717,10 @@ impl< .make_vote_token(view_number, &self.private_key) } - fn vote_data(&self, commit: Commitment) -> VoteData { + fn vote_data( + &self, + commit: Commitment, + ) -> VoteData> { VoteData::DA(commit) } @@ -721,7 +731,7 @@ impl< encoded_key: &EncodedPublicKey, encoded_signature: &EncodedSignature, leaf_commitment: Commitment, - vote_data: VoteData, + vote_data: VoteData>, vote_token: TYPES::VoteTokenType, view_number: TYPES::Time, accumlator: VoteAccumulator, @@ -902,7 +912,7 @@ impl< ) -> (EncodedPublicKey, EncodedSignature) { let signature = TYPES::SignatureKey::sign( &self.private_key, - VoteData::::Yes(leaf_commitment).get_commit().as_ref(), + VoteData::Yes(leaf_commitment).get_commit().as_ref(), ); (self.public_key.to_bytes(), signature) } @@ -918,7 +928,7 @@ impl< ) -> (EncodedPublicKey, EncodedSignature) { let signature = TYPES::SignatureKey::sign( &self.private_key, - VoteData::::No(leaf_commitment).get_commit().as_ref(), + VoteData::No(leaf_commitment).get_commit().as_ref(), ); (self.public_key.to_bytes(), signature) } @@ -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::::Timeout(view_number.commit()) + VoteData::Timeout(view_number.commit()) .get_commit() .as_ref(), ); @@ -1023,7 +1033,10 @@ impl< &self.network } - fn vote_data(&self, commit: Commitment) -> VoteData { + fn vote_data( + &self, + commit: Commitment, + ) -> VoteData> { VoteData::Yes(commit) } @@ -1034,7 +1047,7 @@ impl< encoded_key: &EncodedPublicKey, encoded_signature: &EncodedSignature, leaf_commitment: Commitment, - vote_data: VoteData, + vote_data: VoteData>, vote_token: TYPES::VoteTokenType, view_number: TYPES::Time, accumlator: VoteAccumulator, @@ -1382,7 +1395,10 @@ impl< &self.network } - fn vote_data(&self, _commit: Commitment) -> VoteData { + fn vote_data( + &self, + _commit: Commitment, + ) -> VoteData> { unimplemented!() } @@ -1391,7 +1407,7 @@ impl< encoded_key: &EncodedPublicKey, encoded_signature: &EncodedSignature, leaf_commitment: Commitment>, - vote_data: VoteData, + vote_data: VoteData>, vote_token: TYPES::VoteTokenType, view_number: TYPES::Time, accumlator: VoteAccumulator, TYPES>, diff --git a/crates/types/src/vote.rs b/crates/types/src/vote.rs index d5dda8d825..ef53bc4018 100644 --- a/crates/types/src/vote.rs +++ b/crates/types/src/vote.rs @@ -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; } @@ -56,7 +56,7 @@ pub struct DAVote { /// The vote token generated by this replica pub vote_token: TYPES::VoteTokenType, /// The vote data this vote is signed over - pub vote_data: VoteData, + pub vote_data: VoteData>, } /// A positive or negative vote on validating or commitment proposal. @@ -76,7 +76,7 @@ pub struct YesOrNoVote> { /// The vote token generated by this replica pub vote_token: TYPES::VoteTokenType, /// The vote data this vote is signed over - pub vote_data: VoteData, + pub vote_data: VoteData>, } /// A timeout vote. @@ -92,7 +92,7 @@ pub struct TimeoutVote> { /// The vote token generated by this replica pub vote_token: TYPES::VoteTokenType, /// The vote data this vote is signed over - pub vote_data: VoteData, + pub vote_data: VoteData>, } /// The internals of a view sync vote @@ -110,7 +110,7 @@ pub struct ViewSyncVoteInternal { /// The vote token generated by this replica pub vote_token: TYPES::VoteTokenType, /// The vote data this vote is signed over - pub vote_data: VoteData>, + pub vote_data: VoteData>>, } /// The data View Sync votes are signed over @@ -206,7 +206,7 @@ impl VoteType for DAVote { fn get_signature(&self) -> EncodedSignature { self.signature.1.clone() } - fn get_data(&self) -> VoteData { + fn get_data(&self) -> VoteData> { self.vote_data.clone() } fn get_vote_token(&self) -> ::VoteTokenType { @@ -239,7 +239,7 @@ impl> VoteType fn get_signature(&self) -> EncodedSignature { self.signature() } - fn get_data(&self) -> VoteData { + fn get_data(&self) -> VoteData> { match self { QuorumVote::Yes(v) | QuorumVote::No(v) => v.vote_data.clone(), QuorumVote::Timeout(_) => unimplemented!(), @@ -290,7 +290,7 @@ impl VoteType> for ViewSyncVote EncodedSignature { self.signature() } - fn get_data(&self) -> VoteData> { + fn get_data(&self) -> VoteData>> { match self { ViewSyncVote::PreCommit(vote_internal) | ViewSyncVote::Commit(vote_internal) @@ -762,7 +762,7 @@ type VoteMap = HashMap< Commitment, ( u64, - BTreeMap, TOKEN)>, + BTreeMap>, TOKEN)>, ), >; @@ -803,7 +803,7 @@ impl EncodedSignature, Vec<::StakeTableEntry>, usize, - VoteData, + VoteData>, TOKEN, ), ), @@ -824,7 +824,7 @@ where EncodedSignature, Vec<::StakeTableEntry>, usize, - VoteData, + VoteData>, TOKEN, ), ),