Skip to content

Commit

Permalink
remove old fork choice measure and stats - vote stake * lockout
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoranYi committed Jan 16, 2024
1 parent c7ddf00 commit aea4b12
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 28 deletions.
17 changes: 1 addition & 16 deletions core/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ pub(crate) struct ComputedBankState {
pub voted_stakes: VotedStakes,
pub total_stake: Stake,
pub bank_stake: Stake,
pub bank_weight: u128,
// Tree of intervals of lockouts of the form [slot, slot + slot.lockout],
// keyed by end of the range
pub lockout_intervals: LockoutIntervals,
Expand Down Expand Up @@ -319,7 +318,6 @@ impl Tower {
let mut vote_slots = HashSet::new();
let mut voted_stakes = HashMap::new();
let mut total_stake = 0;
let mut bank_weight = 0;
let mut bank_stake = 0;
// Tree of intervals of lockouts of the form [slot, slot + slot.lockout],
// keyed by end of the range
Expand Down Expand Up @@ -391,7 +389,6 @@ impl Tower {
process_slot_vote_unchecked(&mut vote_state, bank_slot);

for vote in &vote_state.votes {
bank_weight += vote.lockout.lockout() as u128 * voted_stake as u128;
bank_stake += voted_stake;
vote_slots.insert(vote.slot());
}
Expand All @@ -401,13 +398,11 @@ impl Tower {
let vote =
Lockout::new_with_confirmation_count(root, MAX_LOCKOUT_HISTORY as u32);
trace!("ROOT: {}", vote.slot());
bank_weight += vote.lockout() as u128 * voted_stake as u128;
vote_slots.insert(vote.slot());
}
}
if let Some(root) = vote_state.root_slot {
let vote = Lockout::new_with_confirmation_count(root, MAX_LOCKOUT_HISTORY as u32);
bank_weight += vote.lockout() as u128 * voted_stake as u128;
bank_stake += voted_stake;
vote_slots.insert(vote.slot());
}
Expand Down Expand Up @@ -444,7 +439,6 @@ impl Tower {
voted_stakes,
total_stake,
bank_stake,
bank_weight,
lockout_intervals,
my_latest_landed_vote,
}
Expand Down Expand Up @@ -2275,7 +2269,6 @@ pub mod test {
let ComputedBankState {
voted_stakes,
total_stake,
bank_weight,
..
} = Tower::collect_vote_lockouts(
&Pubkey::default(),
Expand All @@ -2290,10 +2283,6 @@ pub mod test {
let mut new_votes = latest_validator_votes_for_frozen_banks.take_votes_dirty_set(0);
new_votes.sort();
assert_eq!(new_votes, account_latest_votes);

// Each account has 1 vote in it. After simulating a vote in collect_vote_lockouts,
// the account will have 2 votes, with lockout 2 + 4 = 6. So expected weight for
assert_eq!(bank_weight, 12)
}

#[test]
Expand Down Expand Up @@ -2330,11 +2319,7 @@ pub mod test {
assert_eq!(tower.vote_state.root_slot, Some(0));
let mut latest_validator_votes_for_frozen_banks =
LatestValidatorVotesForFrozenBanks::default();
let ComputedBankState {
voted_stakes,
bank_weight,
..
} = Tower::collect_vote_lockouts(
let ComputedBankState { voted_stakes, .. } = Tower::collect_vote_lockouts(
&Pubkey::default(),
MAX_LOCKOUT_HISTORY as u64,
&accounts,
Expand Down
8 changes: 7 additions & 1 deletion core/src/consensus/progress_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ impl ForkProgress {
#[derive(Debug, Clone, Default)]
pub struct ForkStats {
pub bank_stake: Stake,
pub fork_weight: u128,
pub total_stake: Stake,
pub block_height: u64,
pub has_voted: bool,
Expand All @@ -310,6 +309,13 @@ pub struct ForkStats {
pub my_latest_landed_vote: Option<Slot>,
}

impl ForkStats {
/// Return the percentage of bank_stake over total_stake.
pub fn bank_weight(&self) -> u64 {
100 * self.bank_stake / self.total_stake
}
}

#[derive(Clone, Default)]
pub struct PropagatedStats {
pub propagated_validators: HashSet<Pubkey>,
Expand Down
17 changes: 6 additions & 11 deletions core/src/replay_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3296,7 +3296,6 @@ impl ReplayStage {
voted_stakes,
total_stake,
bank_stake,
bank_weight,
lockout_intervals,
my_latest_landed_vote,
..
Expand All @@ -3308,7 +3307,6 @@ impl ReplayStage {
stats.total_stake = total_stake;
stats.voted_stakes = voted_stakes;
stats.lockout_intervals = lockout_intervals;
stats.fork_weight = bank_weight;
stats.block_height = bank.block_height();
stats.my_latest_landed_vote = my_latest_landed_vote;
stats.computed = true;
Expand All @@ -3317,17 +3315,14 @@ impl ReplayStage {
"bank_weight",
("slot", bank_slot, i64),
("bank_stake", stats.bank_stake, i64),
// u128 too large for influx, convert to hex
("weight", format!("{:X}", stats.fork_weight), String),
("bank_weight", stats.bank_weight(), i64),
);

info!(
"{} slot_weight: {} {:2}% {}% {:.2} {}",
"{} slot_weight: {} {:2}% {}%",
my_vote_pubkey,
bank_slot,
100 * stats.bank_stake / stats.total_stake, // percentage vote stake in total_stake
100 * stats.fork_weight / stats.total_stake as u128,
((stats.fork_weight / stats.total_stake as u128) as f64).log2(), // average lockout depth for voted stake
stats.bank_weight(), // percentage bank stake in total_stake
bank.parent().map(|b| b.slot()).unwrap_or(0)
);
}
Expand Down Expand Up @@ -3671,7 +3666,7 @@ impl ReplayStage {
vote_threshold,
propagated_stake,
is_leader_slot,
fork_weight,
bank_weight,
total_threshold_stake,
total_epoch_stake,
) = {
Expand All @@ -3684,7 +3679,7 @@ impl ReplayStage {
fork_stats.vote_threshold,
propagated_stats.propagated_validators_stake,
propagated_stats.is_leader_slot,
fork_stats.fork_weight,
fork_stats.bank_weight(),
fork_stats.total_stake,
propagated_stats.total_epoch_stake,
)
Expand Down Expand Up @@ -3719,7 +3714,7 @@ impl ReplayStage {
&& propagation_confirmed
&& switch_fork_decision.can_vote()
{
info!("voting: {} {}", candidate_vote_bank.slot(), fork_weight);
info!("voting: {} {}", candidate_vote_bank.slot(), bank_weight);
SelectVoteAndResetForkResult {
vote_bank: Some((candidate_vote_bank.clone(), switch_fork_decision)),
reset_bank: Some(candidate_vote_bank.clone()),
Expand Down

0 comments on commit aea4b12

Please sign in to comment.