2020-06-11 12:16:04 -07:00
|
|
|
use crate::{
|
2021-04-21 14:40:35 -07:00
|
|
|
consensus::{SwitchForkDecision, Tower},
|
|
|
|
latest_validator_votes_for_frozen_banks::LatestValidatorVotesForFrozenBanks,
|
2020-06-11 12:16:04 -07:00
|
|
|
progress_map::ProgressMap,
|
|
|
|
replay_stage::HeaviestForkFailures,
|
|
|
|
};
|
2020-06-17 09:27:03 -06:00
|
|
|
use solana_runtime::{bank::Bank, bank_forks::BankForks};
|
2020-06-11 12:16:04 -07:00
|
|
|
use std::{
|
|
|
|
collections::{HashMap, HashSet},
|
|
|
|
sync::{Arc, RwLock},
|
|
|
|
};
|
|
|
|
|
|
|
|
pub(crate) struct SelectVoteAndResetForkResult {
|
|
|
|
pub vote_bank: Option<(Arc<Bank>, SwitchForkDecision)>,
|
|
|
|
pub reset_bank: Option<Arc<Bank>>,
|
|
|
|
pub heaviest_fork_failures: Vec<HeaviestForkFailures>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) trait ForkChoice {
|
2021-04-12 01:00:59 -07:00
|
|
|
type ForkChoiceKey;
|
2020-06-11 12:16:04 -07:00
|
|
|
fn compute_bank_stats(
|
|
|
|
&mut self,
|
|
|
|
bank: &Bank,
|
|
|
|
tower: &Tower,
|
2021-04-21 14:40:35 -07:00
|
|
|
latest_validator_votes_for_frozen_banks: &mut LatestValidatorVotesForFrozenBanks,
|
2020-06-11 12:16:04 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
// Returns:
|
2020-06-17 21:59:08 -06:00
|
|
|
// 1) The heaviest overall bank
|
|
|
|
// 2) The heaviest bank on the same fork as the last vote (doesn't require a
|
2020-06-11 12:16:04 -07:00
|
|
|
// switching proof to vote for)
|
|
|
|
fn select_forks(
|
|
|
|
&self,
|
|
|
|
frozen_banks: &[Arc<Bank>],
|
|
|
|
tower: &Tower,
|
|
|
|
progress: &ProgressMap,
|
|
|
|
ancestors: &HashMap<u64, HashSet<u64>>,
|
|
|
|
bank_forks: &RwLock<BankForks>,
|
|
|
|
) -> (Arc<Bank>, Option<Arc<Bank>>);
|
2021-03-24 23:41:52 -07:00
|
|
|
|
2021-04-12 01:00:59 -07:00
|
|
|
fn mark_fork_invalid_candidate(&mut self, invalid_slot: &Self::ForkChoiceKey);
|
2021-03-24 23:41:52 -07:00
|
|
|
|
2021-04-12 01:00:59 -07:00
|
|
|
fn mark_fork_valid_candidate(&mut self, valid_slot: &Self::ForkChoiceKey);
|
2020-06-11 12:16:04 -07:00
|
|
|
}
|