Skip to content

Commit

Permalink
@pls148 better test misconfiguration reporting,
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-maron committed Feb 10, 2025
1 parent 1c74e88 commit d3d0f8c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
4 changes: 4 additions & 0 deletions hotshot/src/traits/election/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ impl RandomOverlapQuorumIterator {
count / 2 > overlap_max,
"Overlap cannot be greater than the entire set size"
);
assert!(
count / 2 >= members_max - overlap_min,
"members_max must be greater or equal to half of the count plus overlap_min"
);

let (mut prev_rng, mut this_rng) = make_rngs(seed, round);

Expand Down
39 changes: 37 additions & 2 deletions hotshot/src/traits/election/randomized_committee_members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use hotshot_types::{
use hotshot_utils::anytrace::Result;
use primitive_types::U256;
use rand::{rngs::StdRng, Rng};
use tracing::error;

use crate::traits::election::helpers::QuorumFilterConfig;

Expand Down Expand Up @@ -61,6 +62,36 @@ impl<TYPES: NodeType, CONFIG: QuorumFilterConfig> RandomizedCommitteeMembers<TYP
fn make_da_quorum_filter(&self, epoch: <TYPES as NodeType>::Epoch) -> BTreeSet<usize> {
CONFIG::execute(epoch.u64(), self.da_stake_table.len())
}

/// Writes the offsets used for the quorum filter and da_quorum filter to stdout
fn debug_display_offsets(&self) {
/// Ensures that the quorum filters are only displayed once
static START: std::sync::Once = std::sync::Once::new();

START.call_once(|| {
error!(
"{} offsets for Quorum filter:",
std::any::type_name::<CONFIG>()
);
for epoch in 1..=10 {
error!(
" epoch {epoch}: {:?}",
self.make_quorum_filter(<TYPES as NodeType>::Epoch::new(epoch))
);
}

error!(
"{} offsets for DA Quorum filter:",
std::any::type_name::<CONFIG>()
);
for epoch in 1..=10 {
error!(
" epoch {epoch}: {:?}",
self.make_da_quorum_filter(<TYPES as NodeType>::Epoch::new(epoch))
);
}
});
}
}

impl<TYPES: NodeType, CONFIG: QuorumFilterConfig> Membership<TYPES>
Expand Down Expand Up @@ -114,14 +145,18 @@ impl<TYPES: NodeType, CONFIG: QuorumFilterConfig> Membership<TYPES>
.map(|entry| (TYPES::SignatureKey::public_key(entry), entry.clone()))
.collect();

Self {
let s = Self {
eligible_leaders,
stake_table: members,
da_stake_table: da_members,
indexed_stake_table,
indexed_da_stake_table,
_pd: PhantomData,
}
};

s.debug_display_offsets();

s
}

/// Get the stake table for the current view
Expand Down

0 comments on commit d3d0f8c

Please sign in to comment.