Fix consensus threshold when new root is created (#8093)
When a new root is created, the oldest slot is popped off but when the logic checks for identical slots, it assumes that any difference means a slot was popped off the front.
This commit is contained in:
parent
927f272f0e
commit
0172d2a065
|
@ -337,21 +337,16 @@ impl Tower {
|
||||||
fork_stake.stake,
|
fork_stake.stake,
|
||||||
total_staked
|
total_staked
|
||||||
);
|
);
|
||||||
for (new_lockout, original_lockout) in
|
if vote.confirmation_count as usize > self.threshold_depth {
|
||||||
lockouts.votes.iter().zip(self.lockouts.votes.iter())
|
for old_vote in &self.lockouts.votes {
|
||||||
{
|
if old_vote.slot == vote.slot
|
||||||
if new_lockout.slot == original_lockout.slot {
|
&& old_vote.confirmation_count == vote.confirmation_count
|
||||||
if new_lockout.confirmation_count <= self.threshold_depth as u32 {
|
{
|
||||||
break;
|
return true;
|
||||||
}
|
}
|
||||||
if new_lockout.confirmation_count != original_lockout.confirmation_count {
|
|
||||||
return lockout > self.threshold_size;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
true
|
lockout > self.threshold_size
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -832,6 +827,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_double_partition() {
|
fn test_double_partition() {
|
||||||
|
solana_logger::setup();
|
||||||
let node_keypair = Keypair::new();
|
let node_keypair = Keypair::new();
|
||||||
let vote_keypair = Keypair::new();
|
let vote_keypair = Keypair::new();
|
||||||
let node_pubkey = node_keypair.pubkey();
|
let node_pubkey = node_keypair.pubkey();
|
||||||
|
@ -1008,6 +1004,24 @@ mod test {
|
||||||
assert!(tower.check_vote_stake_threshold(0, &stakes, 2));
|
assert!(tower.check_vote_stake_threshold(0, &stakes, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_check_vote_threshold_no_skip_lockout_with_new_root() {
|
||||||
|
solana_logger::setup();
|
||||||
|
let mut tower = Tower::new_for_tests(4, 0.67);
|
||||||
|
let mut stakes = HashMap::new();
|
||||||
|
for i in 0..(MAX_LOCKOUT_HISTORY as u64 + 1) {
|
||||||
|
stakes.insert(
|
||||||
|
i,
|
||||||
|
StakeLockout {
|
||||||
|
stake: 1,
|
||||||
|
lockout: 8,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
tower.record_vote(i, Hash::default());
|
||||||
|
}
|
||||||
|
assert!(!tower.check_vote_stake_threshold(MAX_LOCKOUT_HISTORY as u64 + 1, &stakes, 2));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_is_slot_confirmed_not_enough_stake_failure() {
|
fn test_is_slot_confirmed_not_enough_stake_failure() {
|
||||||
let tower = Tower::new_for_tests(1, 0.67);
|
let tower = Tower::new_for_tests(1, 0.67);
|
||||||
|
|
Loading…
Reference in New Issue