Skip to content

Commit

Permalink
Add da_total_nodes to Membership
Browse files Browse the repository at this point in the history
And proxy fn to Certificate
  • Loading branch information
tbro committed Nov 19, 2024
1 parent 6f54c3e commit 0368dc6
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 7 deletions.
6 changes: 4 additions & 2 deletions crates/hotshot/src/traits/election/randomized_committee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use ethereum_types::U256;
use hotshot_types::{
traits::{
election::Membership,
network::Topic,
node_implementation::NodeType,
signature_key::{SignatureKey, StakeTableEntryType},
},
Expand Down Expand Up @@ -250,7 +249,10 @@ impl<TYPES: NodeType> Membership<TYPES> for RandomizedCommittee<TYPES> {
fn total_nodes(&self, _epoch: <TYPES as NodeType>::Epoch) -> usize {
self.stake_table.len()
}

/// Get the total number of nodes in the committee
fn da_total_nodes(&self, _epoch: <TYPES as NodeType>::Epoch) -> usize {
self.da_stake_table.len()
}
/// Get the voting success threshold for the committee
fn success_threshold(&self) -> NonZeroU64 {
NonZeroU64::new(((self.stake_table.len() as u64 * 2) / 3) + 1).unwrap()
Expand Down
6 changes: 5 additions & 1 deletion crates/hotshot/src/traits/election/static_committee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use ethereum_types::U256;
use hotshot_types::{
traits::{
election::Membership,
network::Topic,
node_implementation::NodeType,
signature_key::{SignatureKey, StakeTableEntryType},
},
Expand Down Expand Up @@ -237,6 +236,11 @@ impl<TYPES: NodeType> Membership<TYPES> for StaticCommittee<TYPES> {
self.stake_table.len()
}

/// Get the total number of DA nodes in the committee
fn da_total_nodes(&self, _epoch: <TYPES as NodeType>::Epoch) -> usize {
self.da_stake_table.len()
}

/// Get the voting success threshold for the committee
fn success_threshold(&self) -> NonZeroU64 {
NonZeroU64::new(((self.stake_table.len() as u64 * 2) / 3) + 1).unwrap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ impl<TYPES: NodeType> Membership<TYPES> for StaticCommitteeLeaderForTwoViews<TYP
self.stake_table.len()
}

/// Get the total number of DA nodes in the committee
fn da_total_nodes(&self, _epoch: <TYPES as NodeType>::Epoch) -> usize {
self.da_stake_table.len()
}

/// Get the voting success threshold for the committee
fn success_threshold(&self) -> NonZeroU64 {
NonZeroU64::new(((self.stake_table.len() as u64 * 2) / 3) + 1).unwrap()
Expand Down
2 changes: 1 addition & 1 deletion crates/testing/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ pub async fn build_assembled_sig<
epoch: TYPES::Epoch,
upgrade_lock: &UpgradeLock<TYPES, V>,
) -> <TYPES::SignatureKey as SignatureKey>::QcType {
let stake_table = membership.stake_table(epoch);
let stake_table = CERT::stake_table(membership, epoch);
let real_qc_pp: <TYPES::SignatureKey as SignatureKey>::QcParams =
<TYPES::SignatureKey as SignatureKey>::public_parameter(
stake_table.clone(),
Expand Down
22 changes: 20 additions & 2 deletions crates/types/src/simple_certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,26 @@ impl<TYPES: NodeType, THRESHOLD: Threshold<TYPES>> Certificate<TYPES, DaData>
pub_key: &TYPES::SignatureKey,
epoch: TYPES::Epoch,
) -> Option<<TYPES::SignatureKey as SignatureKey>::StakeTableEntry> {
dbg!("XXX DA CERT `stake_table_entry`");
membership.da_stake(pub_key, epoch)
}

/// Proxy's to `Membership.stake_table`
/// Proxy's to `Membership.da_stake_table`
fn stake_table<MEMBERSHIP: Membership<TYPES>>(
membership: &MEMBERSHIP,
epoch: TYPES::Epoch,
) -> Vec<<TYPES::SignatureKey as SignatureKey>::StakeTableEntry> {
dbg!("XXX DA CERT `stake_table`");
membership.da_stake_table(epoch)
}

/// Proxy's to `Membership.da_total_nodes`
fn total_nodes<MEMBERSHIP: Membership<TYPES>>(
membership: &MEMBERSHIP,
epoch: TYPES::Epoch,
) -> usize {
dbg!("XXX DA CERT `stake_table`");
membership.da_total_nodes(epoch)
}
fn threshold<MEMBERSHIP: Membership<TYPES>>(membership: &MEMBERSHIP) -> u64 {
THRESHOLD::threshold(membership)
}
Expand Down Expand Up @@ -266,6 +275,15 @@ impl<TYPES: NodeType, VOTEABLE: Voteable + 'static + QuorumMaker, THRESHOLD: Thr
membership.stake_table(epoch)
}

/// Proxy's to `Membership.total_nodes`
fn total_nodes<MEMBERSHIP: Membership<TYPES>>(
membership: &MEMBERSHIP,
epoch: TYPES::Epoch,
) -> usize {
dbg!("XXX Quorum CERT `total_nodes`");
membership.total_nodes(epoch)
}

fn data(&self) -> &Self::Voteable {
&self.data
}
Expand Down
3 changes: 3 additions & 0 deletions crates/types/src/traits/election.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ pub trait Membership<TYPES: NodeType>: Clone + Debug + Send + Sync {
/// Returns the number of total nodes in the committee in an epoch `epoch`
fn total_nodes(&self, epoch: TYPES::Epoch) -> usize;

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

/// Returns the threshold for a specific `Membership` implementation
fn success_threshold(&self) -> NonZeroU64;

Expand Down
8 changes: 7 additions & 1 deletion crates/types/src/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ pub trait Certificate<TYPES: NodeType, T>: HasViewNumber<TYPES> {
epoch: TYPES::Epoch,
) -> Vec<<TYPES::SignatureKey as SignatureKey>::StakeTableEntry>;

/// Get Total Nodes from Membership implementation.
fn total_nodes<MEMBERSHIP: Membership<TYPES>>(
membership: &MEMBERSHIP,
epoch: TYPES::Epoch,
) -> usize;

/// Get `StakeTableEntry` from Membership implementation.
fn stake_table_entry<MEMBERSHIP: Membership<TYPES>>(
membership: &MEMBERSHIP,
Expand Down Expand Up @@ -203,7 +209,7 @@ impl<
let (signers, sig_list) = self
.signers
.entry(vote_commitment)
.or_insert((bitvec![0; membership.total_nodes(epoch)], Vec::new()));
.or_insert((bitvec![0; CERT::total_nodes(membership, epoch)], Vec::new()));
if signers.get(vote_node_id).as_deref() == Some(&true) {
error!("Node id is already in signers list");
return Either::Left(());
Expand Down

0 comments on commit 0368dc6

Please sign in to comment.