Skip to content

Commit

Permalink
Merge pull request #1967 from EspressoSystems/bf/quorum-vote-cert
Browse files Browse the repository at this point in the history
Create new Certificate and Vote types and use them for Quorum
  • Loading branch information
bfish713 authored Nov 3, 2023
2 parents 6ebf036 + d68a874 commit b071638
Show file tree
Hide file tree
Showing 23 changed files with 727 additions and 533 deletions.
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
16 changes: 11 additions & 5 deletions crates/hotshot/src/traits/storage/memory_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ mod test {
use hotshot_signature_key::bn254::BLSPubKey;
use hotshot_types::{
block_impl::{VIDBlockHeader, VIDBlockPayload, VIDTransaction},
certificate::{AssembledSignature, QuorumCertificate},
data::{fake_commitment, genesis_proposer_id, ValidatingLeaf, ViewNumber},
simple_certificate::QuorumCertificate2,
traits::{node_implementation::NodeType, state::dummy::DummyState, state::ConsensusTime},
};
use std::{fmt::Debug, hash::Hash};
use std::{fmt::Debug, hash::Hash, marker::PhantomData};
use tracing::instrument;

#[derive(
Expand Down Expand Up @@ -165,12 +165,18 @@ mod test {
payload_commitment: payload.commit(),
};
let dummy_leaf_commit = fake_commitment::<ValidatingLeaf<DummyTypes>>();
let data = hotshot_types::simple_vote::QuorumData {
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(),
data,
vote_commitment: commit,
signatures: None,
view_number,
_pd: PhantomData,
},
header,
Some(payload),
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::QuorumData;
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.data = QuorumData {
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

0 comments on commit b071638

Please sign in to comment.