use crate::error::ConversationError;
use crate::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,
},
}
pub trait StewardListPlugin {
fn config(&self) -> &StewardListConfig;
fn set_config(&mut self, config: StewardListConfig);
fn set_conversation_id(&mut self, _conversation_id: &[u8]) {}
fn current_list(&self) -> Option<&StewardList>;
fn election_epoch(&self) -> Option<u64>;
fn next_retry_round(&self) -> u32;
fn max_retries(&self) -> u32;
fn set_max_retries(&mut self, max: u32);
fn is_steward(&self, member_id: &[u8]) -> bool;
fn is_exhausted(&self, epoch: u64) -> bool;
fn election_required(&self, member_count: usize) -> bool {
member_count > self.config().sn_max
}
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<(), ConversationError>;
fn validate_proposed(
&self,
proposed: &[Vec<u8>],
epoch: u64,
candidate_pool: &[Vec<u8>],
retry_round: u32,
) -> Result<bool, ConversationError>;
fn propose_election<F: Fn(&[u8]) -> bool>(
&self,
epoch: u64,
candidate_pool: &[Vec<u8>],
self_member_id: &[u8],
eligible: F,
recovery: bool,
) -> Result<ElectionDecision, ConversationError>;
fn bump_retry(&mut self);
fn reset_retry(&mut self);
}