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

Check for Genesis before Clearing payload_commitment_and_metadata #2276

Merged
merged 5 commits into from
Dec 22, 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
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
27 changes: 21 additions & 6 deletions crates/task-impls/src/consensus.rs
Original file line number Diff line number Diff line change
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 @@ -225,7 +232,6 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, A: ConsensusApi<TYPES, I> +
&self.private_key,
);

self.payload_commitment_and_metadata = None;
let message = GeneralConsensusMessage::<TYPES>::Vote(vote);

if let GeneralConsensusMessage::Vote(vote) = message {
Expand All @@ -236,6 +242,11 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, A: ConsensusApi<TYPES, I> +
self.event_stream
.publish(HotShotEvent::QuorumVoteSend(vote))
.await;
if let Some(commit_and_metadata) = &self.payload_commitment_and_metadata {
if commit_and_metadata.is_genesis {
self.payload_commitment_and_metadata = None;
}
}
return true;
}
}
Expand Down Expand Up @@ -1038,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 @@ -1129,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
Loading