Skip to content

Commit

Permalink
change stake table entry to peer config for epoch committees
Browse files Browse the repository at this point in the history
  • Loading branch information
imabdulbasit committed Feb 28, 2025
1 parent 06c7f62 commit 33fa6b7
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 132 deletions.
13 changes: 13 additions & 0 deletions contracts/rust/adapter/src/stake_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use hotshot_types::{
signature_key::BLSPubKey,
stake_table::StakeTableEntry,
traits::signature_key::SignatureKey as _,
PeerConfig,
};
use serde::{Deserialize, Serialize};
use std::str::FromStr;
Expand Down Expand Up @@ -216,6 +217,18 @@ impl From<NodeInfoJf> for StakeTableEntry<BLSPubKey> {
}
}

impl From<NodeInfoJf> for PeerConfig<BLSPubKey> {
fn from(value: NodeInfoJf) -> Self {
Self {
stake_table_entry: StakeTableEntry {
stake_key: value.stake_table_key,
stake_amount: U256::from(1), // dummy stake amount
},
state_ver_key: value.state_ver_key,
}
}
}

impl From<NodeInfo> for NodeInfoJf {
fn from(value: NodeInfo) -> Self {
let NodeInfo {
Expand Down
43 changes: 19 additions & 24 deletions hotshot-types/src/traits/election.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ use crate::{drb::DrbResult, traits::signature_key::SignatureKey, PeerConfig};
#[async_trait]
/// A protocol for determining membership in and participating in a committee.
pub trait Membership<TYPES: NodeType>: Debug + Send + Sync {
/// The error type returned by methods like `lookup_leader`.
type Error: std::fmt::Display;

/// Create a committee
fn new(
// Note: eligible_leaders is currently a hack because the DA leader == the quorum leader
Expand All @@ -31,34 +28,34 @@ pub trait Membership<TYPES: NodeType>: Debug + Send + Sync {
fn stake_table(
&self,
epoch: Option<TYPES::Epoch>,
) -> Vec<<TYPES::SignatureKey as SignatureKey>::StakeTableEntry>;
) -> Result<Vec<PeerConfig<TYPES::SignatureKey>>>;

/// Get all participants in the committee (including their stake) for a specific epoch
fn da_stake_table(
&self,
epoch: Option<TYPES::Epoch>,
) -> Vec<<TYPES::SignatureKey as SignatureKey>::StakeTableEntry>;
) -> Result<Vec<PeerConfig<TYPES::SignatureKey>>>;

/// Get all participants in the committee for a specific view for a specific epoch
fn committee_members(
&self,
view_number: TYPES::View,
epoch: Option<TYPES::Epoch>,
) -> BTreeSet<TYPES::SignatureKey>;
) -> Result<BTreeSet<TYPES::SignatureKey>>;

/// Get all participants in the committee for a specific view for a specific epoch
fn da_committee_members(
&self,
view_number: TYPES::View,
epoch: Option<TYPES::Epoch>,
) -> BTreeSet<TYPES::SignatureKey>;
) -> Result<BTreeSet<TYPES::SignatureKey>>;

/// Get all leaders in the committee for a specific view for a specific epoch
fn committee_leaders(
&self,
view_number: TYPES::View,
epoch: Option<TYPES::Epoch>,
) -> BTreeSet<TYPES::SignatureKey>;
) -> Result<BTreeSet<TYPES::SignatureKey>>;

/// Get the stake table entry for a public key, returns `None` if the
/// key is not in the table for a specific epoch
Expand All @@ -77,10 +74,15 @@ pub trait Membership<TYPES: NodeType>: Debug + Send + Sync {
) -> Option<<TYPES::SignatureKey as SignatureKey>::StakeTableEntry>;

/// See if a node has stake in the committee in a specific epoch
fn has_stake(&self, pub_key: &TYPES::SignatureKey, epoch: Option<TYPES::Epoch>) -> bool;
fn has_stake(&self, pub_key: &TYPES::SignatureKey, epoch: Option<TYPES::Epoch>)
-> Result<bool>;

/// See if a node has stake in the committee in a specific epoch
fn has_da_stake(&self, pub_key: &TYPES::SignatureKey, epoch: Option<TYPES::Epoch>) -> bool;
fn has_da_stake(
&self,
pub_key: &TYPES::SignatureKey,
epoch: Option<TYPES::Epoch>,
) -> Result<bool>;

/// The leader of the committee for view `view_number` in `epoch`.
///
Expand Down Expand Up @@ -112,25 +114,25 @@ pub trait Membership<TYPES: NodeType>: Debug + Send + Sync {
&self,
view: TYPES::View,
epoch: Option<TYPES::Epoch>,
) -> std::result::Result<TYPES::SignatureKey, Self::Error>;
) -> Result<TYPES::SignatureKey>;

/// Returns the number of total nodes in the committee in an epoch `epoch`
fn total_nodes(&self, epoch: Option<TYPES::Epoch>) -> usize;
fn total_nodes(&self, epoch: Option<TYPES::Epoch>) -> Result<usize>;

/// Returns the number of total DA nodes in the committee in an epoch `epoch`
fn da_total_nodes(&self, epoch: Option<TYPES::Epoch>) -> usize;
fn da_total_nodes(&self, epoch: Option<TYPES::Epoch>) -> Result<usize>;

/// Returns the threshold for a specific `Membership` implementation
fn success_threshold(&self, epoch: Option<TYPES::Epoch>) -> NonZeroU64;
fn success_threshold(&self, epoch: Option<TYPES::Epoch>) -> Result<NonZeroU64>;

/// Returns the DA threshold for a specific `Membership` implementation
fn da_success_threshold(&self, epoch: Option<TYPES::Epoch>) -> NonZeroU64;
fn da_success_threshold(&self, epoch: Option<TYPES::Epoch>) -> Result<NonZeroU64>;

/// Returns the threshold for a specific `Membership` implementation
fn failure_threshold(&self, epoch: Option<TYPES::Epoch>) -> NonZeroU64;
fn failure_threshold(&self, epoch: Option<TYPES::Epoch>) -> Result<NonZeroU64>;

/// Returns the threshold required to upgrade the network protocol
fn upgrade_threshold(&self, epoch: Option<TYPES::Epoch>) -> NonZeroU64;
fn upgrade_threshold(&self, epoch: Option<TYPES::Epoch>) -> Result<NonZeroU64>;

#[allow(clippy::type_complexity)]
/// Handles notifications that a new epoch root has been created
Expand All @@ -146,13 +148,6 @@ pub trait Membership<TYPES: NodeType>: Debug + Send + Sync {
None
}

#[allow(clippy::type_complexity)]
/// Called after add_epoch_root runs and any callback has been invoked.
/// Causes a read lock to be reacquired for this functionality.
async fn sync_l1(&self) -> Option<Box<dyn FnOnce(&mut Self) + Send>> {
None
}

/// Called to notify the Membership when a new DRB result has been calculated.
/// Observes the same semantics as add_epoch_root
fn add_drb_result(&mut self, _epoch: TYPES::Epoch, _drb_result: DrbResult);
Expand Down
Loading

0 comments on commit 33fa6b7

Please sign in to comment.