From 27d9a82f8942951be5e980c0ed88050f05dc7163 Mon Sep 17 00:00:00 2001 From: Gus Gutoski Date: Tue, 12 Sep 2023 16:30:10 -0400 Subject: [PATCH] fix #1717 --- crates/task-impls/src/da.rs | 32 ++++++++++------------------- crates/testing/tests/da_task.rs | 19 +++++------------ crates/types/src/traits/election.rs | 18 ++++++++-------- 3 files changed, 25 insertions(+), 44 deletions(-) diff --git a/crates/task-impls/src/da.rs b/crates/task-impls/src/da.rs index 0528ad85cd..d05588f1c8 100644 --- a/crates/task-impls/src/da.rs +++ b/crates/task-impls/src/da.rs @@ -19,7 +19,7 @@ use hotshot_types::{ certificate::DACertificate, consensus::{Consensus, View}, data::{DAProposal, ProposalType, SequencingLeaf, VidDisperse, VidScheme, VidSchemeTrait}, - message::{CommitteeConsensusMessage, Message, Proposal, SequencingMessage}, + message::{Message, Proposal, SequencingMessage}, traits::{ consensus_api::SequencingConsensusApi, election::{CommitteeExchangeType, ConsensusExchange, Membership}, @@ -353,7 +353,7 @@ where } Ok(Some(vote_token)) => { // Generate and send vote - let message = self.committee_exchange.create_da_message( + let vote = self.committee_exchange.create_da_message( block_commitment, view, vote_token, @@ -362,15 +362,10 @@ where // ED Don't think this is necessary? // self.cur_view = view; - if let CommitteeConsensusMessage::DAVote(vote) = message { - debug!("Sending vote to the DA leader {:?}", vote.current_view); - self.event_stream - .publish(SequencingHotShotEvent::DAVoteSend(vote)) - .await; - } else { - // TODO use the type system to make this check unnecessary https://github.com/EspressoSystems/HotShot/issues/1717 - error!("create_da_message did not return a DA message!"); - } + debug!("Sending vote to the DA leader {:?}", vote.current_view); + self.event_stream + .publish(SequencingHotShotEvent::DAVoteSend(vote)) + .await; let mut consensus = self.consensus.write().await; // Ensure this view is in the view map for garbage collection, but do not overwrite if @@ -604,7 +599,7 @@ where } Ok(Some(vote_token)) => { // Generate and send vote - let message = self.committee_exchange.create_vid_message( + let vote = self.committee_exchange.create_vid_message( block_commitment, view, vote_token, @@ -613,15 +608,10 @@ where // ED Don't think this is necessary? // self.cur_view = view; - if let CommitteeConsensusMessage::VidVote(vote) = message { - debug!("Sending vote to the VID leader {:?}", vote.current_view); - self.event_stream - .publish(SequencingHotShotEvent::VidVoteSend(vote)) - .await; - } else { - // TODO use the type system to make this check unnecessary https://github.com/EspressoSystems/HotShot/issues/1717 - error!("create_vid_message did not return a vid message!"); - } + debug!("Sending vote to the VID leader {:?}", vote.current_view); + self.event_stream + .publish(SequencingHotShotEvent::VidVoteSend(vote)) + .await; let mut consensus = self.consensus.write().await; // Ensure this view is in the view map for garbage collection, but do not overwrite if diff --git a/crates/testing/tests/da_task.rs b/crates/testing/tests/da_task.rs index ebd737a5dd..64b70ef40c 100644 --- a/crates/testing/tests/da_task.rs +++ b/crates/testing/tests/da_task.rs @@ -26,10 +26,7 @@ async fn test_da_task() { }; use hotshot_task_impls::harness::run_harness; use hotshot_testing::task_helpers::build_system_handle; - use hotshot_types::{ - message::{CommitteeConsensusMessage, Proposal}, - traits::election::CommitteeExchangeType, - }; + use hotshot_types::{message::Proposal, traits::election::CommitteeExchangeType}; async_compatibility_layer::logging::setup_logging(); async_compatibility_layer::logging::setup_backtrace(); @@ -98,11 +95,9 @@ async fn test_da_task() { .make_vote_token(ViewNumber::new(2)) .unwrap() .unwrap(); - let da_message = + let da_vote = committee_exchange.create_da_message(block_commitment, ViewNumber::new(2), vote_token); - if let CommitteeConsensusMessage::DAVote(vote) = da_message { - output.insert(SequencingHotShotEvent::DAVoteSend(vote), 1); - } + output.insert(SequencingHotShotEvent::DAVoteSend(da_vote), 1); output.insert( SequencingHotShotEvent::VidDisperseSend(vid_proposal.clone(), pub_key), 1, @@ -112,13 +107,9 @@ async fn test_da_task() { .make_vote_token(ViewNumber::new(2)) .unwrap() .unwrap(); - let vid_message = + let vid_vote = committee_exchange.create_vid_message(block_commitment, ViewNumber::new(2), vote_token); - if let CommitteeConsensusMessage::VidVote(vote) = vid_message { - output.insert(SequencingHotShotEvent::VidVoteSend(vote), 1); - } else { - panic!("wtf"); - } + output.insert(SequencingHotShotEvent::VidVoteSend(vid_vote), 1); output.insert(SequencingHotShotEvent::DAProposalRecv(message, pub_key), 1); output.insert( diff --git a/crates/types/src/traits/election.rs b/crates/types/src/traits/election.rs index c91df4687f..c24f90b99b 100644 --- a/crates/types/src/traits/election.rs +++ b/crates/types/src/traits/election.rs @@ -15,7 +15,7 @@ use crate::{ }; use crate::{ - message::{CommitteeConsensusMessage, GeneralConsensusMessage, Message}, + message::{GeneralConsensusMessage, Message}, vote::ViewSyncVoteInternal, }; @@ -517,7 +517,7 @@ pub trait CommitteeExchangeType: block_commitment: Commitment, current_view: TYPES::Time, vote_token: TYPES::VoteTokenType, - ) -> CommitteeConsensusMessage; + ) -> DAVote; // TODO temporary vid methods, move to quorum https://github.com/EspressoSystems/HotShot/issues/1696 @@ -527,7 +527,7 @@ pub trait CommitteeExchangeType: block_commitment: Commitment, current_view: TYPES::Time, vote_token: TYPES::VoteTokenType, - ) -> CommitteeConsensusMessage; + ) -> DAVote; /// Sign a vote on VID proposal. fn sign_vid_vote( @@ -597,15 +597,15 @@ impl< block_commitment: Commitment, current_view: TYPES::Time, vote_token: TYPES::VoteTokenType, - ) -> CommitteeConsensusMessage { + ) -> DAVote { let signature = self.sign_da_vote(block_commitment); - CommitteeConsensusMessage::::DAVote(DAVote { + DAVote { signature, block_commitment, current_view, vote_token, vote_data: VoteData::DA(block_commitment), - }) + } } fn create_vid_message( @@ -613,15 +613,15 @@ impl< block_commitment: Commitment, current_view: ::Time, vote_token: ::VoteTokenType, - ) -> CommitteeConsensusMessage { + ) -> DAVote { let signature = self.sign_vid_vote(block_commitment); - CommitteeConsensusMessage::::VidVote(DAVote { + DAVote { signature, block_commitment, current_view, vote_token, vote_data: VoteData::DA(block_commitment), - }) + } } fn sign_vid_vote(