alto_types/
consensus.rs

1use commonware_codec::Encode;
2use commonware_consensus::threshold_simplex::types::{
3    Activity as CActivity, Finalization as CFinalization, Notarization as CNotarization,
4    Seed as CSeed,
5};
6use commonware_cryptography::{
7    bls12381::primitives::variant::{MinSig, Variant},
8    sha256::Digest,
9};
10use commonware_utils::modulo;
11
12pub type Seed = CSeed<MinSig>;
13pub type Notarization = CNotarization<MinSig, Digest>;
14pub type Finalization = CFinalization<MinSig, Digest>;
15pub type Activity = CActivity<MinSig, Digest>;
16
17pub type Identity = <MinSig as Variant>::Public;
18pub type Evaluation = Identity;
19pub type Signature = <MinSig as Variant>::Signature;
20
21/// The leader for a given seed is determined by the modulo of the seed with the number of participants.
22pub fn leader_index(seed: &Seed, participants: usize) -> usize {
23    let signature = seed.signature.encode().freeze();
24    modulo(&signature, participants as u64) as usize
25}