Skip to content

Commit

Permalink
remove validating/sequencing ambiguity for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-maron committed Oct 26, 2023
1 parent c95a63e commit a3dc6da
Show file tree
Hide file tree
Showing 21 changed files with 127 additions and 234 deletions.
30 changes: 15 additions & 15 deletions crates/hotshot/src/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use std::{fmt::Debug, marker::PhantomData};

/// sequencing demo entry state
#[derive(PartialEq, Eq, Hash, Serialize, Deserialize, Clone, Debug)]
pub struct SDemoState {
pub struct DemoState {
/// the block height
block_height: u64,
/// the view number
Expand All @@ -39,9 +39,9 @@ pub struct SDemoState {
prev_state_commitment: Commitment<Self>,
}

impl Committable for SDemoState {
impl Committable for DemoState {
fn commit(&self) -> Commitment<Self> {
commit::RawCommitmentBuilder::new("SDemo State Commit")
commit::RawCommitmentBuilder::new("Demo State Commit")
.u64_field("block_height", self.block_height)
.u64_field("view_number", *self.view_number)
.field("prev_state_commitment", self.prev_state_commitment)
Expand All @@ -53,7 +53,7 @@ impl Committable for SDemoState {
}
}

impl Default for SDemoState {
impl Default for DemoState {
fn default() -> Self {
Self {
block_height: 0,
Expand All @@ -63,7 +63,7 @@ impl Default for SDemoState {
}
}

impl State for SDemoState {
impl State for DemoState {
type Error = BlockPayloadError;

type BlockType = VIDBlockPayload;
Expand All @@ -87,7 +87,7 @@ impl State for SDemoState {
return Err(BlockPayloadError::InvalidBlock);
}

Ok(SDemoState {
Ok(DemoState {
block_height: self.block_height + 1,
view_number: *view_number,
prev_state_commitment: self.commit(),
Expand All @@ -97,7 +97,7 @@ impl State for SDemoState {
fn on_commit(&self) {}
}

impl TestableState for SDemoState {
impl TestableState for DemoState {
fn create_random_transaction(
_state: Option<&Self>,
_rng: &mut dyn rand::RngCore,
Expand Down Expand Up @@ -131,39 +131,39 @@ impl NodeType for DemoTypes {
type VoteTokenType = StaticVoteToken<Self::SignatureKey>;
type Transaction = VIDTransaction;
type ElectionConfigType = StaticElectionConfig;
type StateType = SDemoState;
type StateType = DemoState;
}

/// The node implementation for the sequencing demo
#[derive(Derivative)]
#[derivative(Clone(bound = ""))]
pub struct SDemoNode<MEMBERSHIP>(PhantomData<MEMBERSHIP>)
pub struct DemoNode<MEMBERSHIP>(PhantomData<MEMBERSHIP>)
where
MEMBERSHIP: Membership<DemoTypes> + std::fmt::Debug;

impl<MEMBERSHIP> SDemoNode<MEMBERSHIP>
impl<MEMBERSHIP> DemoNode<MEMBERSHIP>
where
MEMBERSHIP: Membership<DemoTypes> + std::fmt::Debug,
{
/// Create a new `SDemoNode`
/// Create a new `DemoNode`
#[must_use]
pub fn new() -> Self {
SDemoNode(PhantomData)
DemoNode(PhantomData)
}
}

impl<MEMBERSHIP> Debug for SDemoNode<MEMBERSHIP>
impl<MEMBERSHIP> Debug for DemoNode<MEMBERSHIP>
where
MEMBERSHIP: Membership<DemoTypes> + std::fmt::Debug,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("SDemoNode")
f.debug_struct("DemoNode")
.field("_phantom", &"phantom")
.finish()
}
}

impl<MEMBERSHIP> Default for SDemoNode<MEMBERSHIP>
impl<MEMBERSHIP> Default for DemoNode<MEMBERSHIP>
where
MEMBERSHIP: Membership<DemoTypes> + std::fmt::Debug,
{
Expand Down
78 changes: 4 additions & 74 deletions crates/hotshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ use hotshot_types::{
ProcessedGeneralConsensusMessage, SequencingMessage,
},
traits::{
consensus_api::{ConsensusSharedApi, SequencingConsensusApi},
consensus_api::{ConsensusApi, ConsensusSharedApi},
election::{ConsensusExchange, Membership, SignedCertificate},
network::{CommunicationChannel, NetworkError},
node_implementation::{
Expand Down Expand Up @@ -798,86 +798,16 @@ where
}
}

/// A handle that exposes the interface that hotstuff needs to interact with [`HotShot`]
#[derive(Clone)]
struct HotShotValidatingConsensusApi<TYPES: NodeType, I: NodeImplementation<TYPES>> {
/// Reference to the [`SystemContextInner`]
inner: Arc<SystemContextInner<TYPES, I>>,
}

#[async_trait]
impl<TYPES: NodeType, I: NodeImplementation<TYPES>> ConsensusSharedApi<TYPES, I::Leaf, I>
for HotShotValidatingConsensusApi<TYPES, I>
{
fn total_nodes(&self) -> NonZeroUsize {
self.inner.config.total_nodes
}

fn propose_min_round_time(&self) -> Duration {
self.inner.config.propose_min_round_time
}

fn propose_max_round_time(&self) -> Duration {
self.inner.config.propose_max_round_time
}

fn max_transactions(&self) -> NonZeroUsize {
self.inner.config.max_transactions
}

fn min_transactions(&self) -> usize {
self.inner.config.min_transactions
}

/// Generates and encodes a vote token
async fn should_start_round(&self, _: TYPES::Time) -> bool {
false
}

async fn send_event(&self, event: Event<TYPES, I::Leaf>) {
debug!(?event, "send_event");
let mut event_sender = self.inner.event_sender.write().await;
if let Some(sender) = &*event_sender {
if let Err(e) = sender.send_async(event).await {
error!(?e, "Could not send event to event_sender");
*event_sender = None;
}
}
}

fn public_key(&self) -> &TYPES::SignatureKey {
&self.inner.public_key
}

fn private_key(&self) -> &<TYPES::SignatureKey as SignatureKey>::PrivateKey {
&self.inner.private_key
}

async fn store_leaf(
&self,
old_anchor_view: TYPES::Time,
leaf: I::Leaf,
) -> std::result::Result<(), hotshot_types::traits::storage::StorageError> {
let view_to_insert = StoredView::from(leaf);
let storage = &self.inner.storage;
storage.append_single_view(view_to_insert).await?;
storage.cleanup_storage_up_to_view(old_anchor_view).await?;
storage.commit().await?;
Ok(())
}
}

/// A handle that exposes the interface that hotstuff needs to interact with [`HotShot`]
#[derive(Clone, Debug)]
pub struct HotShotSequencingConsensusApi<TYPES: NodeType, I: NodeImplementation<TYPES>> {
pub struct HotShotConsensusApi<TYPES: NodeType, I: NodeImplementation<TYPES>> {
/// Reference to the [`SystemContextInner`]
pub inner: Arc<SystemContextInner<TYPES, I>>,
}

#[async_trait]
impl<TYPES: NodeType, I: NodeImplementation<TYPES>> ConsensusSharedApi<TYPES, I::Leaf, I>
for HotShotSequencingConsensusApi<TYPES, I>
for HotShotConsensusApi<TYPES, I>
{
fn total_nodes(&self) -> NonZeroUsize {
self.inner.config.total_nodes
Expand Down Expand Up @@ -942,7 +872,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>> ConsensusSharedApi<TYPES, I:
impl<
TYPES: NodeType,
I: NodeImplementation<TYPES, ConsensusMessage = SequencingMessage<TYPES, I>>,
> SequencingConsensusApi<TYPES, I::Leaf, I> for HotShotSequencingConsensusApi<TYPES, I>
> ConsensusApi<TYPES, I::Leaf, I> for HotShotConsensusApi<TYPES, I>
{
async fn send_direct_message(
&self,
Expand Down
Loading

0 comments on commit a3dc6da

Please sign in to comment.