Skip to content

Commit

Permalink
add is_genesis flag to CommitmentAndMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
bfish713 committed Dec 22, 2023
1 parent 9f85fa3 commit d609e38
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
10 changes: 8 additions & 2 deletions crates/hotshot/src/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use hotshot_task::{
GeneratedStream, Merge,
};
use hotshot_task_impls::{
consensus::{consensus_event_filter, ConsensusTaskState, ConsensusTaskTypes},
consensus::{
consensus_event_filter, CommitmentAndMetadata, ConsensusTaskState, ConsensusTaskTypes,
},
da::{DATaskState, DATaskTypes},
events::HotShotEvent,
network::{
Expand Down Expand Up @@ -222,7 +224,11 @@ pub async fn add_consensus_task<TYPES: NodeType, I: NodeImplementation<TYPES>>(
consensus,
timeout: handle.hotshot.inner.config.next_view_timeout,
cur_view: TYPES::Time::new(0),
payload_commitment_and_metadata: Some((payload_commitment, metadata)),
payload_commitment_and_metadata: Some(CommitmentAndMetadata {
commitment: payload_commitment,
metadata,
is_genesis: true,
}),
api: c_api.clone(),
_pd: PhantomData,
vote_collector: None.into(),
Expand Down
33 changes: 19 additions & 14 deletions crates/task-impls/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use hotshot_types::{
simple_certificate::{QuorumCertificate, TimeoutCertificate},
simple_vote::{QuorumData, QuorumVote, TimeoutData, TimeoutVote},
traits::{
block_contents::{vid_commitment, BlockHeader},
block_contents::BlockHeader,
consensus_api::ConsensusApi,
election::Membership,
network::{CommunicationChannel, ConsensusIntentEvent},
Expand Down Expand Up @@ -54,7 +54,14 @@ use tracing::{debug, error, info, instrument};
pub struct ConsensusTaskError {}

/// Alias for the block payload commitment and the associated metadata.
type CommitmentAndMetadata<PAYLOAD> = (VidCommitment, <PAYLOAD as BlockPayload>::Metadata);
pub struct CommitmentAndMetadata<PAYLOAD: BlockPayload> {
/// Vid Commitment
pub commitment: VidCommitment,
/// Metadata for the block payload
pub metadata: <PAYLOAD as BlockPayload>::Metadata,
/// Flag for if this data represents the genesis block
pub is_genesis: bool,
}

/// Alias for Optional type for Vote Collectors
type VoteCollectorOption<TYPES, VOTE, CERT> = Option<VoteCollectionTaskState<TYPES, VOTE, CERT>>;
Expand Down Expand Up @@ -235,14 +242,8 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, A: ConsensusApi<TYPES, I> +
self.event_stream
.publish(HotShotEvent::QuorumVoteSend(vote))
.await;
if let Some((payload_commit, meta)) = &self.payload_commitment_and_metadata {
let (genesis_payload, genesis_meta) =
<TYPES::BlockPayload as BlockPayload>::genesis();
let genesis_commitment = vid_commitment(
&genesis_payload.encode().unwrap().collect(),
self.quorum_membership.total_nodes(),
);
if meta == &genesis_meta && payload_commit == &genesis_commitment {
if let Some(commit_and_metadata) = &self.payload_commitment_and_metadata {
if commit_and_metadata.is_genesis {
self.payload_commitment_and_metadata = None;
}
}
Expand Down Expand Up @@ -1048,7 +1049,11 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, A: ConsensusApi<TYPES, I> +
}
HotShotEvent::SendPayloadCommitmentAndMetadata(payload_commitment, metadata, view) => {
debug!("got commit and meta {:?}", payload_commitment);
self.payload_commitment_and_metadata = Some((payload_commitment, metadata));
self.payload_commitment_and_metadata = Some(CommitmentAndMetadata {
commitment: payload_commitment,
metadata,
is_genesis: false,
});
if self.quorum_membership.get_leader(view) == self.public_key
&& self.consensus.read().await.high_qc.get_view_number() == view
{
Expand Down Expand Up @@ -1139,14 +1144,14 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, A: ConsensusApi<TYPES, I> +
// TODO do some sort of sanity check on the view number that it matches decided
}

if let Some((payload_commitment, metadata)) = &self.payload_commitment_and_metadata {
if let Some(commit_and_metadata) = &self.payload_commitment_and_metadata {
let leaf = Leaf {
view_number: view,
justify_qc: consensus.high_qc.clone(),
parent_commitment: parent_leaf.commit(),
block_header: TYPES::BlockHeader::new(
*payload_commitment,
metadata.clone(),
commit_and_metadata.commitment,
commit_and_metadata.metadata.clone(),
&parent_header,
),
block_payload: None,
Expand Down

0 comments on commit d609e38

Please sign in to comment.