From 3f7fe04124e5618ac9a369c58c692b56fc3df433 Mon Sep 17 00:00:00 2001 From: Stephen Akridge Date: Thu, 23 Jan 2020 14:40:00 -0800 Subject: [PATCH] Consensus fix, don't consider threshold check if lockouts are not increased --- core/src/consensus.rs | 46 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/core/src/consensus.rs b/core/src/consensus.rs index 8bc4598372..3af9698916 100644 --- a/core/src/consensus.rs +++ b/core/src/consensus.rs @@ -321,13 +321,27 @@ impl Tower { if let Some(fork_stake) = stake_lockouts.get(&vote.slot) { let lockout = fork_stake.stake as f64 / total_staked as f64; trace!( - "fork_stake {} {} {} {}", + "fork_stake slot: {} lockout: {} fork_stake: {} total_stake: {}", slot, lockout, fork_stake.stake, total_staked ); - lockout > self.threshold_size + for (new_lockout, original_lockout) in + lockouts.votes.iter().zip(self.lockouts.votes.iter()) + { + if new_lockout.slot == original_lockout.slot { + if new_lockout.confirmation_count <= self.threshold_depth as u32 { + break; + } + if new_lockout.confirmation_count != original_lockout.confirmation_count { + return lockout > self.threshold_size; + } + } else { + break; + } + } + true } else { false } @@ -742,6 +756,34 @@ mod test { assert!(!tower.check_vote_stake_threshold(1, &stakes, 2)); } + #[test] + fn test_check_vote_threshold_lockouts_not_updated() { + solana_logger::setup(); + let mut tower = Tower::new_for_tests(1, 0.67); + let stakes = vec![ + ( + 0, + StakeLockout { + stake: 1, + lockout: 8, + }, + ), + ( + 1, + StakeLockout { + stake: 2, + lockout: 8, + }, + ), + ] + .into_iter() + .collect(); + tower.record_vote(0, Hash::default()); + tower.record_vote(1, Hash::default()); + tower.record_vote(2, Hash::default()); + assert!(tower.check_vote_stake_threshold(6, &stakes, 2)); + } + #[test] fn test_lockout_is_updated_for_entire_branch() { let mut stake_lockouts = HashMap::new();