Skip to content

Commit

Permalink
merge conflict round 2
Browse files Browse the repository at this point in the history
  • Loading branch information
jparr721 committed Jan 31, 2025
2 parents 63d433a + 0f75108 commit 59c2393
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 28 deletions.
4 changes: 2 additions & 2 deletions sequencer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ pub async fn init_node<P: SequencerPersistence, V: Versions>(
// Create the HotShot membership
let membership = EpochCommittees::new_stake(
network_config.config.known_nodes_with_stake.clone(),
network_config.config.known_nodes_with_stake.clone(),
network_config.config.known_da_nodes.clone(),
&instance_state,
network_config.config.epoch_height,
);
Expand Down Expand Up @@ -972,7 +972,7 @@ pub mod testing {
// Create the HotShot membership
let membership = EpochCommittees::new_stake(
config.known_nodes_with_stake.clone(),
config.known_nodes_with_stake.clone(),
config.known_da_nodes.clone(),
&node_state,
100,
);
Expand Down
68 changes: 42 additions & 26 deletions types/src/v0/impls/stake_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use hotshot_types::{
use itertools::Itertools;
use std::{
cmp::max,
collections::{BTreeMap, BTreeSet, HashMap},
collections::{BTreeSet, HashMap},
num::NonZeroU64,
str::FromStr,
};
Expand Down Expand Up @@ -129,11 +129,17 @@ struct Committee {
/// leader but without voting rights.
eligible_leaders: Vec<StakeTableEntry<PubKey>>,

/// TODO: add comment
indexed_stake_table: BTreeMap<PubKey, StakeTableEntry<PubKey>>,
/// Keys for nodes participating in the network
stake_table: Vec<StakeTableEntry<PubKey>>,

/// TODO: comment
indexed_da_members: BTreeMap<PubKey, StakeTableEntry<PubKey>>,
/// Keys for DA members
da_members: Vec<StakeTableEntry<PubKey>>,

/// Stake entries indexed by public key, for efficient lookup.
indexed_stake_table: HashMap<PubKey, StakeTableEntry<PubKey>>,

/// DA entries indexed by public key, for efficient lookup.
indexed_da_members: HashMap<PubKey, StakeTableEntry<PubKey>>,
}

impl EpochCommittees {
Expand All @@ -147,14 +153,18 @@ impl EpochCommittees {
// update events and building the table for us. We will need
// more subtlety when start fetching only the events since last update.

let indexed_stake_table: BTreeMap<PubKey, _> = st
let stake_table = st.stake_table.0.clone();

let da_members = st.da_members.0.clone();

let indexed_stake_table: HashMap<PubKey, _> = st
.stake_table
.0
.iter()
.map(|entry| (PubKey::public_key(entry), entry.clone()))
.collect();

let indexed_da_members: BTreeMap<PubKey, _> = st
let indexed_da_members: HashMap<PubKey, _> = st
.da_members
.0
.iter()
Expand All @@ -170,6 +180,8 @@ impl EpochCommittees {

let committee = Committee {
eligible_leaders,
stake_table,
da_members,
indexed_stake_table,
indexed_da_members,
};
Expand All @@ -195,7 +207,7 @@ impl EpochCommittees {
.collect();

// For each member, get the stake table entry
let members: Vec<_> = committee_members
let stake_table: Vec<_> = committee_members
.iter()
.map(|member| member.stake_table_entry.clone())
.filter(|entry| entry.stake() > U256::zero())
Expand All @@ -209,19 +221,21 @@ impl EpochCommittees {
.collect();

// Index the stake table by public key
let indexed_stake_table: BTreeMap<PubKey, _> = members
let indexed_stake_table: HashMap<PubKey, _> = stake_table
.iter()
.map(|entry| (PubKey::public_key(entry), entry.clone()))
.collect();

// Index the stake table by public key
let indexed_da_members: BTreeMap<PubKey, _> = da_members
let indexed_da_members: HashMap<PubKey, _> = da_members
.iter()
.map(|entry| (PubKey::public_key(entry), entry.clone()))
.collect();

let members = Committee {
eligible_leaders,
stake_table,
da_members,
indexed_stake_table,
indexed_da_members,
};
Expand Down Expand Up @@ -272,7 +286,7 @@ impl Membership<SeqTypes> for EpochCommittees {
.collect();

// For each member, get the stake table entry
let members: Vec<_> = committee_members
let stake_table: Vec<_> = committee_members
.iter()
.map(|member| member.stake_table_entry.clone())
.filter(|entry| entry.stake() > U256::zero())
Expand All @@ -286,19 +300,21 @@ impl Membership<SeqTypes> for EpochCommittees {
.collect();

// Index the stake table by public key
let indexed_stake_table: BTreeMap<PubKey, _> = members
let indexed_stake_table: HashMap<PubKey, _> = stake_table
.iter()
.map(|entry| (PubKey::public_key(entry), entry.clone()))
.collect();

// Index the stake table by public key
let indexed_da_members: BTreeMap<PubKey, _> = da_members
let indexed_da_members: HashMap<PubKey, _> = da_members
.iter()
.map(|entry| (PubKey::public_key(entry), entry.clone()))
.collect();

let members = Committee {
eligible_leaders,
stake_table,
da_members,
indexed_stake_table,
indexed_da_members,
};
Expand All @@ -320,15 +336,15 @@ impl Membership<SeqTypes> for EpochCommittees {
/// Get the stake table for the current view
fn stake_table(&self, epoch: Option<Epoch>) -> Vec<StakeTableEntry<PubKey>> {
if let Some(st) = self.state(&epoch) {
st.indexed_stake_table.clone().into_values().collect()
st.stake_table.clone()
} else {
vec![]
}
}
/// Get the stake table for the current view
fn da_stake_table(&self, epoch: Option<Epoch>) -> Vec<StakeTableEntry<PubKey>> {
if let Some(sc) = self.state(&epoch) {
sc.indexed_da_members.clone().into_values().collect()
sc.da_members.clone()
} else {
vec![]
}
Expand Down Expand Up @@ -422,43 +438,43 @@ impl Membership<SeqTypes> for EpochCommittees {
/// Get the total number of nodes in the committee
fn total_nodes(&self, epoch: Option<Epoch>) -> usize {
self.state(&epoch)
.map(|sc| sc.indexed_stake_table.len())
.map(|sc| sc.stake_table.len())
.unwrap_or_default()
}

/// Get the total number of DA nodes in the committee
fn da_total_nodes(&self, epoch: Option<Epoch>) -> usize {
self.state(&epoch)
.map(|sc: &Committee| sc.indexed_da_members.len())
.map(|sc: &Committee| sc.da_members.len())
.unwrap_or_default()
}

/// Get the voting success threshold for the committee
fn success_threshold(&self, epoch: Option<Epoch>) -> NonZeroU64 {
let quorum = self.state(&epoch).unwrap().indexed_stake_table.clone();
NonZeroU64::new(((quorum.len() as u64 * 2) / 3) + 1).unwrap()
let quorum_len = self.state(&epoch).unwrap().stake_table.len();
NonZeroU64::new(((quorum_len as u64 * 2) / 3) + 1).unwrap()
}

/// Get the voting success threshold for the committee
fn da_success_threshold(&self, epoch: Option<Epoch>) -> NonZeroU64 {
let da = self.state(&epoch).unwrap().indexed_da_members.clone();
NonZeroU64::new(((da.len() as u64 * 2) / 3) + 1).unwrap()
let da_len = self.state(&epoch).unwrap().da_members.len();
NonZeroU64::new(((da_len as u64 * 2) / 3) + 1).unwrap()
}

/// Get the voting failure threshold for the committee
fn failure_threshold(&self, epoch: Option<Epoch>) -> NonZeroU64 {
let quorum = self.state(&epoch).unwrap().indexed_stake_table.clone();
let quorum_len = self.state(&epoch).unwrap().stake_table.len();

NonZeroU64::new(((quorum.len() as u64) / 3) + 1).unwrap()
NonZeroU64::new(((quorum_len as u64) / 3) + 1).unwrap()
}

/// Get the voting upgrade threshold for the committee
fn upgrade_threshold(&self, epoch: Option<Epoch>) -> NonZeroU64 {
let quorum = self.state(&epoch).unwrap().indexed_stake_table.clone();
let quorum_len = self.state(&epoch).unwrap().indexed_stake_table.len();

NonZeroU64::new(max(
(quorum.len() as u64 * 9) / 10,
((quorum.len() as u64 * 2) / 3) + 1,
(quorum_len as u64 * 9) / 10,
((quorum_len as u64 * 2) / 3) + 1,
))
.unwrap()
}
Expand Down

0 comments on commit 59c2393

Please sign in to comment.