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

Create new Certificate and Vote types and use them for Quorum #1967

Merged
merged 18 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 11 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
18 changes: 3 additions & 15 deletions crates/hotshot/src/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
use crate::traits::election::static_committee::{StaticElectionConfig, StaticVoteToken};
use commit::{Commitment, Committable};
use derivative::Derivative;

use hotshot_signature_key::bn254::BLSPubKey;
use hotshot_types::{
block_impl::{BlockPayloadError, VIDBlockHeader, VIDBlockPayload, VIDTransaction},
certificate::{AssembledSignature, QuorumCertificate},
data::{fake_commitment, random_commitment, LeafType, ViewNumber},
data::{fake_commitment, ViewNumber},
traits::{
election::Membership,
node_implementation::NodeType,
state::{ConsensusTime, TestableState},
BlockPayload, State,
},
};
use rand::Rng;

use serde::{Deserialize, Serialize};
use std::{fmt::Debug, marker::PhantomData};

Expand Down Expand Up @@ -176,15 +176,3 @@ where
Self::new()
}
}

/// Provides a random [`QuorumCertificate`]
pub fn random_quorum_certificate<TYPES: NodeType, LEAF: LeafType<NodeType = TYPES>>(
rng: &mut dyn rand::RngCore,
) -> QuorumCertificate<TYPES, Commitment<LEAF>> {
QuorumCertificate {
leaf_commitment: random_commitment(rng),
view_number: TYPES::Time::new(rng.gen()),
signatures: AssembledSignature::Genesis(),
is_genesis: rng.gen(),
}
}
7 changes: 4 additions & 3 deletions crates/hotshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ use hotshot_task_impls::{events::HotShotEvent, network::NetworkTaskKind};
use hotshot_types::{
certificate::{TimeoutCertificate, VIDCertificate},
data::VidDisperse,
simple_certificate::QuorumCertificate2,
traits::node_implementation::TimeoutEx,
};

Expand All @@ -71,7 +72,7 @@ use hotshot_types::{
},
traits::{
consensus_api::{ConsensusApi, ConsensusSharedApi},
election::{ConsensusExchange, Membership, SignedCertificate},
election::{ConsensusExchange, Membership},
network::{CommunicationChannel, NetworkError},
node_implementation::{
ChannelMaps, CommitteeEx, ExchangesType, NodeType, QuorumEx, SendToTasks, VIDEx,
Expand Down Expand Up @@ -249,7 +250,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>> SystemContext<TYPES, I> {
self.inner
.internal_event_stream
.publish(HotShotEvent::QCFormed(either::Left(
QuorumCertificate::genesis(),
QuorumCertificate2::genesis(),
)))
.await;
}
Expand Down Expand Up @@ -1020,7 +1021,7 @@ impl<TYPES: NodeType, LEAF: LeafType<NodeType = TYPES>> HotShotInitializer<TYPES
pub fn from_genesis(genesis_payload: TYPES::BlockPayload) -> Result<Self, HotShotError<TYPES>> {
let state = TYPES::StateType::initialize();
let time = TYPES::Time::genesis();
let justify_qc = QuorumCertificate::<TYPES, Commitment<LEAF>>::genesis();
let justify_qc = QuorumCertificate2::<TYPES, LEAF>::genesis();

Ok(Self {
inner: LEAF::new(time, justify_qc, genesis_payload, state),
Expand Down
2 changes: 1 addition & 1 deletion crates/hotshot/src/traits/election/static_committee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use tracing::debug;

/// Dummy implementation of [`Membership`]

#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct GeneralStaticCommittee<T, LEAF: LeafType<NodeType = T>, PUBKEY: SignatureKey> {
/// All the nodes participating and their stake
nodes_with_stake: Vec<PUBKEY::StakeTableEntry>,
Expand Down
17 changes: 12 additions & 5 deletions crates/hotshot/src/traits/storage/memory_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,19 @@ mod test {
use crate::traits::election::static_committee::{StaticElectionConfig, StaticVoteToken};

use super::*;
use commit::Committable;
use hotshot_signature_key::bn254::BLSPubKey;
use hotshot_types::{
certificate::{AssembledSignature, QuorumCertificate},
data::{fake_commitment, genesis_proposer_id, ValidatingLeaf, ViewNumber},
simple_certificate::QuorumCertificate2,
traits::{
block_contents::dummy::{DummyBlock, DummyState},
node_implementation::NodeType,
state::ConsensusTime,
BlockPayload,
},
};
use std::{fmt::Debug, hash::Hash};
use std::{fmt::Debug, hash::Hash, marker::PhantomData};
use tracing::instrument;

#[derive(
Expand Down Expand Up @@ -165,12 +166,18 @@ mod test {
// TODO is it okay to be using genesis here?
let _dummy_block_commit = fake_commitment::<DummyBlock>();
let dummy_leaf_commit = fake_commitment::<ValidatingLeaf<DummyTypes>>();
let data = hotshot_types::simple_vote::YesData {
bfish713 marked this conversation as resolved.
Show resolved Hide resolved
leaf_commit: dummy_leaf_commit,
};
let commit = data.commit();
StoredView::from_qc_block_and_state(
QuorumCertificate {
QuorumCertificate2 {
is_genesis: view_number == <DummyTypes as NodeType>::Time::genesis(),
leaf_commitment: dummy_leaf_commit,
signatures: AssembledSignature::Genesis(),
leaf_commitment: data,
vote_commitment: commit,
signatures: None,
view_number,
_pd: PhantomData,
},
DummyBlock::random(rng),
Some(DummyBlock::random(rng)),
Expand Down
42 changes: 10 additions & 32 deletions crates/hotshot/src/types/handle.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Provides an event-streaming handle for a [`HotShot`] running in the background

use crate::{traits::NodeImplementation, types::Event, Message, QuorumCertificate, SystemContext};
use crate::QuorumCertificate2;
use crate::{traits::NodeImplementation, types::Event, SystemContext};
use async_compatibility_layer::channel::UnboundedStream;
use async_lock::RwLock;
use commit::Committable;
Expand All @@ -13,20 +14,20 @@ use hotshot_task::{
BoxSyncFuture,
};
use hotshot_task_impls::events::HotShotEvent;
use hotshot_types::simple_vote::YesData;
use hotshot_types::{
consensus::Consensus,
data::LeafType,
error::HotShotError,
event::EventType,
message::{GeneralConsensusMessage, MessageKind},
message::MessageKind,
traits::{
election::{ConsensusExchange, QuorumExchangeType, SignedCertificate},
node_implementation::{ExchangesType, NodeType, QuorumEx},
election::{ConsensusExchange, QuorumExchangeType},
node_implementation::{ExchangesType, NodeType},
state::ConsensusTime,
storage::Storage,
},
};

use std::sync::Arc;
use tracing::error;

Expand Down Expand Up @@ -190,8 +191,10 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES> + 'static> SystemContextHandl
if let Ok(anchor_leaf) = self.storage().get_anchored_view().await {
if anchor_leaf.view_number == TYPES::Time::genesis() {
let leaf: I::Leaf = I::Leaf::from_stored_view(anchor_leaf);
let mut qc = QuorumCertificate::<TYPES, Commitment<I::Leaf>>::genesis();
qc.leaf_commitment = leaf.commit();
let mut qc = QuorumCertificate2::<TYPES, I::Leaf>::genesis();
qc.leaf_commitment = YesData {
leaf_commit: leaf.commit(),
};
let event = Event {
view_number: TYPES::Time::genesis(),
event: EventType::Decide {
Expand Down Expand Up @@ -329,31 +332,6 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES> + 'static> SystemContextHandl
.sign_validating_or_commitment_proposal::<I>(leaf_commitment)
}

/// create a yes message
#[cfg(feature = "hotshot-testing")]
pub fn create_yes_message(
&self,
justify_qc_commitment: Commitment<QuorumCertificate<TYPES, Commitment<I::Leaf>>>,
leaf_commitment: Commitment<I::Leaf>,
current_view: TYPES::Time,
vote_token: TYPES::VoteTokenType,
) -> GeneralConsensusMessage<TYPES, I>
where
QuorumEx<TYPES, I>: ConsensusExchange<
TYPES,
Message<TYPES, I>,
Certificate = QuorumCertificate<TYPES, Commitment<I::Leaf>>,
>,
{
let inner = self.hotshot.inner.clone();
inner.exchanges.quorum_exchange().create_yes_message(
justify_qc_commitment,
leaf_commitment,
current_view,
vote_token,
)
}

/// Wrapper around `HotShotConsensusApi`'s `send_broadcast_consensus_message` function
#[cfg(feature = "hotshot-testing")]
pub async fn send_broadcast_consensus_message(&self, msg: I::ConsensusMessage) {
Expand Down
Loading
Loading