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

make membership functions async #3968

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions crates/examples/infra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ pub trait RunDa<
.hotshot
.memberships
.committee_leaders(TYPES::View::genesis(), TYPES::Epoch::genesis())
.await
.len();
let total_num_views = usize::try_from(consensus.locked_view().u64()).unwrap();
// `failed_num_views` could include uncommitted views
Expand Down
2 changes: 1 addition & 1 deletion crates/hotshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> SystemContext<T
api
.network.da_broadcast_message(
serialized_message,
api.memberships.da_committee_members(view_number, TYPES::Epoch::new(1)).iter().cloned().collect(),
api.memberships.da_committee_members(view_number, TYPES::Epoch::new(1)).await.iter().cloned().collect(),
BroadcastDelay::None,
),
api
Expand Down
32 changes: 16 additions & 16 deletions crates/hotshot/src/traits/election/randomized_committee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,23 @@ impl<TYPES: NodeType> Membership<TYPES> for RandomizedCommittee<TYPES> {
}

/// Get the stake table for the current view
fn stake_table(
async fn stake_table(
&self,
_epoch: <TYPES as NodeType>::Epoch,
) -> Vec<<<TYPES as NodeType>::SignatureKey as SignatureKey>::StakeTableEntry> {
self.stake_table.clone()
}

/// Get the stake table for the current view
fn da_stake_table(
async fn da_stake_table(
&self,
_epoch: <TYPES as NodeType>::Epoch,
) -> Vec<<<TYPES as NodeType>::SignatureKey as SignatureKey>::StakeTableEntry> {
self.da_stake_table.clone()
}

/// Get all members of the committee for the current view
fn committee_members(
async fn committee_members(
&self,
_view_number: <TYPES as NodeType>::View,
_epoch: <TYPES as NodeType>::Epoch,
Expand All @@ -130,7 +130,7 @@ impl<TYPES: NodeType> Membership<TYPES> for RandomizedCommittee<TYPES> {
}

/// Get all members of the committee for the current view
fn da_committee_members(
async fn da_committee_members(
&self,
_view_number: <TYPES as NodeType>::View,
_epoch: <TYPES as NodeType>::Epoch,
Expand All @@ -142,7 +142,7 @@ impl<TYPES: NodeType> Membership<TYPES> for RandomizedCommittee<TYPES> {
}

/// Get all eligible leaders of the committee for the current view
fn committee_leaders(
async fn committee_leaders(
&self,
_view_number: <TYPES as NodeType>::View,
_epoch: <TYPES as NodeType>::Epoch,
Expand All @@ -154,7 +154,7 @@ impl<TYPES: NodeType> Membership<TYPES> for RandomizedCommittee<TYPES> {
}

/// Get the stake table entry for a public key
fn stake(
async fn stake(
&self,
pub_key: &<TYPES as NodeType>::SignatureKey,
_epoch: <TYPES as NodeType>::Epoch,
Expand All @@ -164,7 +164,7 @@ impl<TYPES: NodeType> Membership<TYPES> for RandomizedCommittee<TYPES> {
}

/// Get the stake table entry for a public key
fn da_stake(
async fn da_stake(
&self,
pub_key: &<TYPES as NodeType>::SignatureKey,
_epoch: <TYPES as NodeType>::Epoch,
Expand All @@ -174,7 +174,7 @@ impl<TYPES: NodeType> Membership<TYPES> for RandomizedCommittee<TYPES> {
}

/// Check if a node has stake in the committee
fn has_stake(
async fn has_stake(
&self,
pub_key: &<TYPES as NodeType>::SignatureKey,
_epoch: <TYPES as NodeType>::Epoch,
Expand All @@ -185,7 +185,7 @@ impl<TYPES: NodeType> Membership<TYPES> for RandomizedCommittee<TYPES> {
}

/// Check if a node has stake in the committee
fn has_da_stake(
async fn has_da_stake(
&self,
pub_key: &<TYPES as NodeType>::SignatureKey,
_epoch: <TYPES as NodeType>::Epoch,
Expand All @@ -201,7 +201,7 @@ impl<TYPES: NodeType> Membership<TYPES> for RandomizedCommittee<TYPES> {
// }

/// Index the vector of public keys with the current view number
fn lookup_leader(
async fn lookup_leader(
&self,
view_number: TYPES::View,
_epoch: <TYPES as NodeType>::Epoch,
Expand All @@ -218,30 +218,30 @@ impl<TYPES: NodeType> Membership<TYPES> for RandomizedCommittee<TYPES> {
}

/// Get the total number of nodes in the committee
fn total_nodes(&self, _epoch: <TYPES as NodeType>::Epoch) -> usize {
async 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 {
async 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, _epoch: <TYPES as NodeType>::Epoch) -> NonZeroU64 {
async fn success_threshold(&self, _epoch: <TYPES as NodeType>::Epoch) -> NonZeroU64 {
NonZeroU64::new(((self.stake_table.len() as u64 * 2) / 3) + 1).unwrap()
}

/// Get the voting success threshold for the committee
fn da_success_threshold(&self, _epoch: <TYPES as NodeType>::Epoch) -> NonZeroU64 {
async fn da_success_threshold(&self, _epoch: <TYPES as NodeType>::Epoch) -> NonZeroU64 {
NonZeroU64::new(((self.da_stake_table.len() as u64 * 2) / 3) + 1).unwrap()
}

/// Get the voting failure threshold for the committee
fn failure_threshold(&self, _epoch: <TYPES as NodeType>::Epoch) -> NonZeroU64 {
async fn failure_threshold(&self, _epoch: <TYPES as NodeType>::Epoch) -> NonZeroU64 {
NonZeroU64::new(((self.stake_table.len() as u64) / 3) + 1).unwrap()
}

/// Get the voting upgrade threshold for the committee
fn upgrade_threshold(&self, _epoch: <TYPES as NodeType>::Epoch) -> NonZeroU64 {
async fn upgrade_threshold(&self, _epoch: <TYPES as NodeType>::Epoch) -> NonZeroU64 {
NonZeroU64::new(max(
(self.stake_table.len() as u64 * 9) / 10,
((self.stake_table.len() as u64 * 2) / 3) + 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl<TYPES: NodeType, CONFIG: QuorumFilterConfig> Membership<TYPES>
}

/// Get the stake table for the current view
fn stake_table(
async fn stake_table(
&self,
epoch: <TYPES as NodeType>::Epoch,
) -> Vec<<<TYPES as NodeType>::SignatureKey as SignatureKey>::StakeTableEntry> {
Expand All @@ -140,7 +140,7 @@ impl<TYPES: NodeType, CONFIG: QuorumFilterConfig> Membership<TYPES>
}

/// Get the da stake table for the current view
fn da_stake_table(
async fn da_stake_table(
&self,
epoch: <TYPES as NodeType>::Epoch,
) -> Vec<<<TYPES as NodeType>::SignatureKey as SignatureKey>::StakeTableEntry> {
Expand All @@ -155,11 +155,11 @@ impl<TYPES: NodeType, CONFIG: QuorumFilterConfig> Membership<TYPES>
}

/// Get all members of the committee for the current view
fn committee_members(
async fn committee_members(
&self,
_view_number: <TYPES as NodeType>::View,
epoch: <TYPES as NodeType>::Epoch,
) -> BTreeSet<<TYPES as NodeType>::SignatureKey> {
) -> BTreeSet<TYPES::SignatureKey> {
let filter = self.make_quorum_filter(epoch);
self.stake_table
.iter()
Expand All @@ -170,7 +170,7 @@ impl<TYPES: NodeType, CONFIG: QuorumFilterConfig> Membership<TYPES>
}

/// Get all members of the committee for the current view
fn da_committee_members(
async fn da_committee_members(
&self,
_view_number: <TYPES as NodeType>::View,
epoch: <TYPES as NodeType>::Epoch,
Expand All @@ -189,12 +189,12 @@ impl<TYPES: NodeType, CONFIG: QuorumFilterConfig> Membership<TYPES>
&self,
view_number: <TYPES as NodeType>::View,
epoch: <TYPES as NodeType>::Epoch,
) -> BTreeSet<<TYPES as NodeType>::SignatureKey> {
) -> impl futures::Future<Output = BTreeSet<TYPES::SignatureKey>> + Send {
self.committee_members(view_number, epoch)
}

/// Get the stake table entry for a public key
fn stake(
async fn stake(
&self,
pub_key: &<TYPES as NodeType>::SignatureKey,
epoch: <TYPES as NodeType>::Epoch,
Expand All @@ -218,7 +218,7 @@ impl<TYPES: NodeType, CONFIG: QuorumFilterConfig> Membership<TYPES>
}

/// Get the da stake table entry for a public key
fn da_stake(
async fn da_stake(
&self,
pub_key: &<TYPES as NodeType>::SignatureKey,
epoch: <TYPES as NodeType>::Epoch,
Expand All @@ -242,7 +242,7 @@ impl<TYPES: NodeType, CONFIG: QuorumFilterConfig> Membership<TYPES>
}

/// Check if a node has stake in the committee
fn has_stake(
async fn has_stake(
&self,
pub_key: &<TYPES as NodeType>::SignatureKey,
epoch: <TYPES as NodeType>::Epoch,
Expand All @@ -267,7 +267,7 @@ impl<TYPES: NodeType, CONFIG: QuorumFilterConfig> Membership<TYPES>
}

/// Check if a node has stake in the committee
fn has_da_stake(
async fn has_da_stake(
&self,
pub_key: &<TYPES as NodeType>::SignatureKey,
epoch: <TYPES as NodeType>::Epoch,
Expand All @@ -292,7 +292,7 @@ impl<TYPES: NodeType, CONFIG: QuorumFilterConfig> Membership<TYPES>
}

/// Index the vector of public keys with the current view number
fn lookup_leader(
async fn lookup_leader(
&self,
view_number: TYPES::View,
epoch: <TYPES as NodeType>::Epoch,
Expand All @@ -318,36 +318,36 @@ impl<TYPES: NodeType, CONFIG: QuorumFilterConfig> Membership<TYPES>
}

/// Get the total number of nodes in the committee
fn total_nodes(&self, epoch: <TYPES as NodeType>::Epoch) -> usize {
async fn total_nodes(&self, epoch: <TYPES as NodeType>::Epoch) -> usize {
self.make_quorum_filter(epoch).len()
}

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

/// Get the voting success threshold for the committee
fn success_threshold(&self, epoch: <TYPES as NodeType>::Epoch) -> NonZeroU64 {
let len = self.total_nodes(epoch);
async fn success_threshold(&self, epoch: <TYPES as NodeType>::Epoch) -> NonZeroU64 {
let len = self.total_nodes(epoch).await;
NonZeroU64::new(((len as u64 * 2) / 3) + 1).unwrap()
}

/// Get the voting success threshold for the committee
fn da_success_threshold(&self, epoch: <TYPES as NodeType>::Epoch) -> NonZeroU64 {
let len = self.da_total_nodes(epoch);
async fn da_success_threshold(&self, epoch: <TYPES as NodeType>::Epoch) -> NonZeroU64 {
let len = self.da_total_nodes(epoch).await;
NonZeroU64::new(((len as u64 * 2) / 3) + 1).unwrap()
}

/// Get the voting failure threshold for the committee
fn failure_threshold(&self, epoch: <TYPES as NodeType>::Epoch) -> NonZeroU64 {
let len = self.total_nodes(epoch);
async fn failure_threshold(&self, epoch: <TYPES as NodeType>::Epoch) -> NonZeroU64 {
let len = self.total_nodes(epoch).await;
NonZeroU64::new(((len as u64) / 3) + 1).unwrap()
}

/// Get the voting upgrade threshold for the committee
fn upgrade_threshold(&self, epoch: <TYPES as NodeType>::Epoch) -> NonZeroU64 {
let len = self.total_nodes(epoch);
async fn upgrade_threshold(&self, epoch: <TYPES as NodeType>::Epoch) -> NonZeroU64 {
let len = self.total_nodes(epoch).await;
NonZeroU64::new(max((len as u64 * 9) / 10, ((len as u64 * 2) / 3) + 1)).unwrap()
}
}
Loading
Loading