use crate::core::error::CoreError;
use crate::core::steward_list::list::{StewardList, StewardListConfig};
pub const DEFAULT_MAX_RETRIES: u32 = 1;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ElectionDecision {
Skip(&'static str),
Proposed {
proposed_stewards: Vec<Vec<u8>>,
election_epoch: u64,
retry_round: u32,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum StewardListEvent {
ListInstalled {
epoch: u64,
retry_round: u32,
len: usize,
},
RetryExhausted { round: u32, max: u32 },
}
pub trait StewardListPlugin {
fn config(&self) -> &StewardListConfig;
fn set_config(&mut self, config: StewardListConfig);
fn current_list(&self) -> Option<&StewardList>;
fn election_epoch(&self) -> Option<u64>;
fn retry_round(&self) -> u32;
fn max_retries(&self) -> u32;
fn set_max_retries(&mut self, max: u32);
fn is_steward(&self, identity: &[u8]) -> bool;
fn is_exhausted(&self, epoch: u64) -> bool;
fn epoch_steward<F: Fn(&[u8]) -> bool>(&self, epoch: u64, eligible: F) -> Option<&[u8]>;
fn epoch_and_backup<F: Fn(&[u8]) -> bool>(
&self,
epoch: u64,
eligible: F,
) -> (Option<&[u8]>, Option<&[u8]>);
fn steward_members<F: Fn(&[u8]) -> bool>(&self, eligible: F) -> Vec<Vec<u8>>;
fn election_proposer<F: Fn(&[u8]) -> bool>(&self, eligible: F) -> Option<&[u8]>;
fn install_list(
&mut self,
epoch: u64,
candidate_pool: &[Vec<u8>],
sn: usize,
retry_round: u32,
) -> Result<Vec<StewardListEvent>, CoreError>;
fn maybe_auto_fill(
&mut self,
epoch: u64,
members: &[Vec<u8>],
) -> Result<Vec<StewardListEvent>, CoreError>;
fn validate_proposed(
&self,
proposed: &[Vec<u8>],
epoch: u64,
candidate_pool: &[Vec<u8>],
retry_round: u32,
) -> Result<bool, CoreError>;
fn propose_election<F: Fn(&[u8]) -> bool>(
&self,
epoch: u64,
candidate_pool: &[Vec<u8>],
self_identity: &[u8],
eligible: F,
recovery: bool,
) -> Result<ElectionDecision, CoreError>;
fn bump_retry(&mut self) -> Vec<StewardListEvent>;
fn reset_retry(&mut self);
}