fixes rust code formatting in core/src/consensus.rs (#29204)
This commit is contained in:
parent
7be57d661f
commit
4ee318b2b2
|
@ -651,8 +651,10 @@ impl Tower {
|
||||||
latest_validator_votes_for_frozen_banks: &LatestValidatorVotesForFrozenBanks,
|
latest_validator_votes_for_frozen_banks: &LatestValidatorVotesForFrozenBanks,
|
||||||
heaviest_subtree_fork_choice: &HeaviestSubtreeForkChoice,
|
heaviest_subtree_fork_choice: &HeaviestSubtreeForkChoice,
|
||||||
) -> SwitchForkDecision {
|
) -> SwitchForkDecision {
|
||||||
self.last_voted_slot_hash()
|
let (last_voted_slot, last_voted_hash) = match self.last_voted_slot_hash() {
|
||||||
.map(|(last_voted_slot, last_voted_hash)| {
|
None => return SwitchForkDecision::SameFork,
|
||||||
|
Some(slot_hash) => slot_hash,
|
||||||
|
};
|
||||||
let root = self.root();
|
let root = self.root();
|
||||||
let empty_ancestors = HashSet::default();
|
let empty_ancestors = HashSet::default();
|
||||||
let empty_ancestors_due_to_minor_unsynced_ledger = || {
|
let empty_ancestors_due_to_minor_unsynced_ledger = || {
|
||||||
|
@ -806,16 +808,33 @@ impl Tower {
|
||||||
// `last_vote`
|
// `last_vote`
|
||||||
// 5) Don't consider any banks before the root because
|
// 5) Don't consider any banks before the root because
|
||||||
// all lockouts must be ancestors of `last_vote`
|
// all lockouts must be ancestors of `last_vote`
|
||||||
if !progress.get_fork_stats(*candidate_slot).map(|stats| stats.computed).unwrap_or(false)
|
if !progress
|
||||||
|
.get_fork_stats(*candidate_slot)
|
||||||
|
.map(|stats| stats.computed)
|
||||||
|
.unwrap_or(false)
|
||||||
|
|| {
|
||||||
// If any of the descendants have the `computed` flag set, then there must be a more
|
// If any of the descendants have the `computed` flag set, then there must be a more
|
||||||
// recent frozen bank on this fork to use, so we can ignore this one. Otherwise,
|
// recent frozen bank on this fork to use, so we can ignore this one. Otherwise,
|
||||||
// even if this bank has descendants, if they have not yet been frozen / stats computed,
|
// even if this bank has descendants, if they have not yet been frozen / stats computed,
|
||||||
// then use this bank as a representative for the fork.
|
// then use this bank as a representative for the fork.
|
||||||
|| descendants.iter().any(|d| progress.get_fork_stats(*d).map(|stats| stats.computed).unwrap_or(false))
|
descendants.iter().any(|d| {
|
||||||
|
progress
|
||||||
|
.get_fork_stats(*d)
|
||||||
|
.map(|stats| stats.computed)
|
||||||
|
.unwrap_or(false)
|
||||||
|
})
|
||||||
|
}
|
||||||
|| *candidate_slot == last_voted_slot
|
|| *candidate_slot == last_voted_slot
|
||||||
|
|| {
|
||||||
// Ignore if the `candidate_slot` is a descendant of the `last_voted_slot`, since we do not
|
// Ignore if the `candidate_slot` is a descendant of the `last_voted_slot`, since we do not
|
||||||
// want to count votes on the same fork.
|
// want to count votes on the same fork.
|
||||||
|| Self::is_candidate_slot_descendant_of_last_vote(*candidate_slot, last_voted_slot, ancestors).expect("exists in descendants map, so must exist in ancestors map")
|
Self::is_candidate_slot_descendant_of_last_vote(
|
||||||
|
*candidate_slot,
|
||||||
|
last_voted_slot,
|
||||||
|
ancestors,
|
||||||
|
)
|
||||||
|
.expect("exists in descendants map, so must exist in ancestors map")
|
||||||
|
}
|
||||||
|| *candidate_slot <= root
|
|| *candidate_slot <= root
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
@ -850,21 +869,19 @@ impl Tower {
|
||||||
// 1) Not ancestors of `last_vote`, meaning being on different fork
|
// 1) Not ancestors of `last_vote`, meaning being on different fork
|
||||||
// 2) Not from before the current root as we can't determine if
|
// 2) Not from before the current root as we can't determine if
|
||||||
// anything before the root was an ancestor of `last_vote` or not
|
// anything before the root was an ancestor of `last_vote` or not
|
||||||
if !last_vote_ancestors.contains(lockout_interval_start)
|
if !last_vote_ancestors.contains(lockout_interval_start) && {
|
||||||
// Given a `lockout_interval_start` < root that appears in a
|
// Given a `lockout_interval_start` < root that appears in a
|
||||||
// bank for a `candidate_slot`, it must be that `lockout_interval_start`
|
// bank for a `candidate_slot`, it must be that `lockout_interval_start`
|
||||||
// is an ancestor of the current root, because `candidate_slot` is a
|
// is an ancestor of the current root, because `candidate_slot` is a
|
||||||
// descendant of the current root
|
// descendant of the current root
|
||||||
&& *lockout_interval_start > root
|
*lockout_interval_start > root
|
||||||
{
|
} {
|
||||||
let stake = epoch_vote_accounts
|
let stake = epoch_vote_accounts
|
||||||
.get(vote_account_pubkey)
|
.get(vote_account_pubkey)
|
||||||
.map(|(stake, _)| *stake)
|
.map(|(stake, _)| *stake)
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
locked_out_stake += stake;
|
locked_out_stake += stake;
|
||||||
if (locked_out_stake as f64 / total_stake as f64)
|
if (locked_out_stake as f64 / total_stake as f64) > SWITCH_FORK_THRESHOLD {
|
||||||
> SWITCH_FORK_THRESHOLD
|
|
||||||
{
|
|
||||||
return SwitchForkDecision::SwitchProof(switch_proof);
|
return SwitchForkDecision::SwitchProof(switch_proof);
|
||||||
}
|
}
|
||||||
locked_out_vote_accounts.insert(vote_account_pubkey);
|
locked_out_vote_accounts.insert(vote_account_pubkey);
|
||||||
|
@ -883,8 +900,7 @@ impl Tower {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if *candidate_latest_frozen_vote > last_voted_slot
|
if *candidate_latest_frozen_vote > last_voted_slot && {
|
||||||
&&
|
|
||||||
// Because `candidate_latest_frozen_vote` is the last vote made by some validator
|
// Because `candidate_latest_frozen_vote` is the last vote made by some validator
|
||||||
// in the cluster for a frozen bank `B` observed through gossip, we may have cleared
|
// in the cluster for a frozen bank `B` observed through gossip, we may have cleared
|
||||||
// that frozen bank `B` because we `set_root(root)` for a `root` on a different fork,
|
// that frozen bank `B` because we `set_root(root)` for a `root` on a different fork,
|
||||||
|
@ -906,9 +922,12 @@ impl Tower {
|
||||||
// is ok because validators voting on different unrooted forks should eventually vote
|
// is ok because validators voting on different unrooted forks should eventually vote
|
||||||
// on some descendant of the root, at which time they can be included in switching proofs.
|
// on some descendant of the root, at which time they can be included in switching proofs.
|
||||||
!Self::is_candidate_slot_descendant_of_last_vote(
|
!Self::is_candidate_slot_descendant_of_last_vote(
|
||||||
*candidate_latest_frozen_vote, last_voted_slot, ancestors)
|
*candidate_latest_frozen_vote,
|
||||||
|
last_voted_slot,
|
||||||
|
ancestors,
|
||||||
|
)
|
||||||
.unwrap_or(true)
|
.unwrap_or(true)
|
||||||
{
|
} {
|
||||||
let stake = epoch_vote_accounts
|
let stake = epoch_vote_accounts
|
||||||
.get(vote_account_pubkey)
|
.get(vote_account_pubkey)
|
||||||
.map(|(stake, _)| *stake)
|
.map(|(stake, _)| *stake)
|
||||||
|
@ -924,8 +943,6 @@ impl Tower {
|
||||||
// We have not detected sufficient lockout past the last voted slot to generate
|
// We have not detected sufficient lockout past the last voted slot to generate
|
||||||
// a switching proof
|
// a switching proof
|
||||||
SwitchForkDecision::FailedSwitchThreshold(locked_out_stake, total_stake)
|
SwitchForkDecision::FailedSwitchThreshold(locked_out_stake, total_stake)
|
||||||
})
|
|
||||||
.unwrap_or(SwitchForkDecision::SameFork)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
|
Loading…
Reference in New Issue