Skip to content

Commit

Permalink
fix #1717
Browse files Browse the repository at this point in the history
  • Loading branch information
ggutoski committed Sep 12, 2023
1 parent b22f50a commit 27d9a82
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 44 deletions.
32 changes: 11 additions & 21 deletions crates/task-impls/src/da.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
19 changes: 5 additions & 14 deletions crates/testing/tests/da_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down
18 changes: 9 additions & 9 deletions crates/types/src/traits/election.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
};

use crate::{
message::{CommitteeConsensusMessage, GeneralConsensusMessage, Message},
message::{GeneralConsensusMessage, Message},
vote::ViewSyncVoteInternal,
};

Expand Down Expand Up @@ -517,7 +517,7 @@ pub trait CommitteeExchangeType<TYPES: NodeType, M: NetworkMsg>:
block_commitment: Commitment<TYPES::BlockType>,
current_view: TYPES::Time,
vote_token: TYPES::VoteTokenType,
) -> CommitteeConsensusMessage<TYPES>;
) -> DAVote<TYPES>;

// TODO temporary vid methods, move to quorum https://github.com/EspressoSystems/HotShot/issues/1696

Expand All @@ -527,7 +527,7 @@ pub trait CommitteeExchangeType<TYPES: NodeType, M: NetworkMsg>:
block_commitment: Commitment<TYPES::BlockType>,
current_view: TYPES::Time,
vote_token: TYPES::VoteTokenType,
) -> CommitteeConsensusMessage<TYPES>;
) -> DAVote<TYPES>;

/// Sign a vote on VID proposal.
fn sign_vid_vote(
Expand Down Expand Up @@ -597,31 +597,31 @@ impl<
block_commitment: Commitment<TYPES::BlockType>,
current_view: TYPES::Time,
vote_token: TYPES::VoteTokenType,
) -> CommitteeConsensusMessage<TYPES> {
) -> DAVote<TYPES> {
let signature = self.sign_da_vote(block_commitment);
CommitteeConsensusMessage::<TYPES>::DAVote(DAVote {
DAVote {
signature,
block_commitment,
current_view,
vote_token,
vote_data: VoteData::DA(block_commitment),
})
}
}

fn create_vid_message(
&self,
block_commitment: Commitment<TYPES::BlockType>,
current_view: <TYPES as NodeType>::Time,
vote_token: <TYPES as NodeType>::VoteTokenType,
) -> CommitteeConsensusMessage<TYPES> {
) -> DAVote<TYPES> {
let signature = self.sign_vid_vote(block_commitment);
CommitteeConsensusMessage::<TYPES>::VidVote(DAVote {
DAVote {
signature,
block_commitment,
current_view,
vote_token,
vote_data: VoteData::DA(block_commitment),
})
}
}

fn sign_vid_vote(
Expand Down

0 comments on commit 27d9a82

Please sign in to comment.