agave-votor 4.2.1

Blockchain, Rebuilt for Scale
Documentation
use {
    agave_votor_messages::{
        certificate::CertificateType,
        fraction::Fraction,
        vote::{Vote, VoteType},
    },
    std::time::Duration,
};

// Core consensus types and constants
pub type Stake = u64;

pub(crate) const fn conflicting_types(vote_type: VoteType) -> &'static [VoteType] {
    match vote_type {
        VoteType::Finalize => &[
            VoteType::NotarizeFallback,
            VoteType::Skip,
            VoteType::SkipFallback,
            VoteType::Genesis,
        ],
        VoteType::Notarize => &[
            VoteType::Skip,
            VoteType::NotarizeFallback,
            VoteType::Genesis,
        ],
        VoteType::NotarizeFallback => &[VoteType::Finalize, VoteType::Notarize, VoteType::Genesis],
        VoteType::Skip => &[
            VoteType::Finalize,
            VoteType::Notarize,
            VoteType::SkipFallback,
            VoteType::Genesis,
        ],
        VoteType::SkipFallback => &[VoteType::Skip, VoteType::Finalize, VoteType::Genesis],
        VoteType::Genesis => &[
            VoteType::Finalize,
            VoteType::Notarize,
            VoteType::NotarizeFallback,
            VoteType::Skip,
            VoteType::SkipFallback,
        ],
    }
}

/// Lookup from `Vote` to the `CertificateId`s the vote accounts for
///
/// Must be in sync with `certificate_limits_and_vote_types` and `VoteType::get_type`
pub fn vote_to_cert_types(vote: &Vote) -> Vec<CertificateType> {
    match vote {
        Vote::Notarize(vote) => vec![
            CertificateType::Notarize(vote.block),
            CertificateType::NotarizeFallback(vote.block),
            CertificateType::FinalizeFast(vote.block),
        ],
        Vote::NotarizeFallback(vote) => {
            vec![CertificateType::NotarizeFallback(vote.block)]
        }
        Vote::Finalize(vote) => vec![CertificateType::Finalize(vote.slot)],
        Vote::Skip(vote) => vec![CertificateType::Skip(vote.slot)],
        Vote::SkipFallback(vote) => vec![CertificateType::Skip(vote.slot)],
        Vote::Genesis(vote) => vec![CertificateType::Genesis(vote.block)],
    }
}

pub const MAX_ENTRIES_PER_PUBKEY_FOR_OTHER_TYPES: usize = 1;
pub const MAX_ENTRIES_PER_PUBKEY_FOR_NOTARIZE_LITE: usize = 3;
pub const MAX_NOTAR_FALLBACK_BLOCKS: usize = 7;

pub const SAFE_TO_NOTAR_MIN_NOTARIZE_ONLY: Fraction = Fraction::from_percentage(40);
pub const SAFE_TO_NOTAR_MIN_NOTARIZE_FOR_NOTARIZE_OR_SKIP: Fraction = Fraction::from_percentage(20);
pub const SAFE_TO_NOTAR_MIN_NOTARIZE_AND_SKIP: Fraction = Fraction::from_percentage(60);

pub const SAFE_TO_SKIP_THRESHOLD: Fraction = Fraction::from_percentage(40);

/// Time bound assumed on network transmission delays during periods of synchrony.
pub const DELTA: Duration = Duration::from_millis(250);

/// Base leader handover timeout: Time after parent-ready that a validator would
/// see a leaders first fec set if that leader sent it at the very start of their
/// window.
///
/// With the current 400ms slot duration, this schedules both
/// `TimeoutCrashedLeader(s)` and `Timeout(s)` at 800ms after `ParentReady`.
pub(crate) const DELTA_TIMEOUT: Duration = Duration::from_millis(400);

/// Timeout for standstill detection mechanism.
pub(crate) const DELTA_STANDSTILL: Duration = Duration::from_millis(10_000);