Skip to content

Commit

Permalink
remove feature gate
Browse files Browse the repository at this point in the history
  • Loading branch information
bw-solana committed Nov 30, 2023
1 parent 4ecbf6a commit 3b9c8e7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 64 deletions.
59 changes: 16 additions & 43 deletions core/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use {
solana_runtime::{bank::Bank, bank_forks::BankForks, commitment::VOTE_THRESHOLD_SIZE},
solana_sdk::{
clock::{Slot, UnixTimestamp},
feature_set::FeatureSet,
hash::Hash,
instruction::Instruction,
pubkey::Pubkey,
Expand All @@ -45,7 +44,6 @@ use {
Bound::{Included, Unbounded},
Deref,
},
sync::Arc,
},
thiserror::Error,
};
Expand Down Expand Up @@ -1099,19 +1097,16 @@ impl Tower {
slot: Slot,
voted_stakes: &VotedStakes,
total_stake: Stake,
feature_set: Option<&Arc<FeatureSet>>,
) -> ThresholdDecision {
// Generate the vote state assuming this vote is included.
let mut vote_state = self.vote_state.clone();
process_slot_vote_unchecked(&mut vote_state, slot);

// Assemble all the vote thresholds and depths to check.
let mut vote_thresholds_and_depths = vec![(self.threshold_depth, self.threshold_size)];
if feature_set.as_ref().map_or(true, |fs| {
fs.is_active(&solana_sdk::feature_set::additional_vote_stake_threshold::id())
}) {
vote_thresholds_and_depths.push((VOTE_THRESHOLD_DEPTH_SHALLOW, SWITCH_FORK_THRESHOLD));
}
let vote_thresholds_and_depths = vec![
(VOTE_THRESHOLD_DEPTH_SHALLOW, SWITCH_FORK_THRESHOLD),
(self.threshold_depth, self.threshold_size),
];

// Check one by one. If any threshold fails, return failure.
for (threshold_depth, threshold_size) in vote_thresholds_and_depths {
Expand Down Expand Up @@ -2345,9 +2340,7 @@ pub mod test {
fn test_check_vote_threshold_without_votes() {
let tower = Tower::new_for_tests(1, 0.67);
let stakes = vec![(0, 1)].into_iter().collect();
assert!(tower
.check_vote_stake_thresholds(0, &stakes, 2, None)
.passed());
assert!(tower.check_vote_stake_thresholds(0, &stakes, 2).passed());
}

#[test]
Expand All @@ -2360,7 +2353,7 @@ pub mod test {
tower.record_vote(i, Hash::default());
}
assert!(!tower
.check_vote_stake_thresholds(MAX_LOCKOUT_HISTORY as u64 + 1, &stakes, 2, None)
.check_vote_stake_thresholds(MAX_LOCKOUT_HISTORY as u64 + 1, &stakes, 2)
.passed());
}

Expand Down Expand Up @@ -2476,18 +2469,14 @@ pub mod test {
let mut tower = Tower::new_for_tests(1, 0.67);
let stakes = vec![(0, 1)].into_iter().collect();
tower.record_vote(0, Hash::default());
assert!(!tower
.check_vote_stake_thresholds(1, &stakes, 2, None)
.passed());
assert!(!tower.check_vote_stake_thresholds(1, &stakes, 2).passed());
}
#[test]
fn test_check_vote_threshold_above_threshold() {
let mut tower = Tower::new_for_tests(1, 0.67);
let stakes = vec![(0, 2)].into_iter().collect();
tower.record_vote(0, Hash::default());
assert!(tower
.check_vote_stake_thresholds(1, &stakes, 2, None)
.passed());
assert!(tower.check_vote_stake_thresholds(1, &stakes, 2).passed());
}

#[test]
Expand All @@ -2500,7 +2489,7 @@ pub mod test {
tower.record_vote(slot as Slot, Hash::default());
}
assert!(tower
.check_vote_stake_thresholds(VOTE_THRESHOLD_DEPTH.try_into().unwrap(), &stakes, 4, None)
.check_vote_stake_thresholds(VOTE_THRESHOLD_DEPTH.try_into().unwrap(), &stakes, 4)
.passed());
}

Expand All @@ -2514,12 +2503,7 @@ pub mod test {
tower.record_vote(slot as Slot, Hash::default());
}
assert!(!tower
.check_vote_stake_thresholds(
VOTE_THRESHOLD_DEPTH.try_into().unwrap(),
&stakes,
10,
None
)
.check_vote_stake_thresholds(VOTE_THRESHOLD_DEPTH.try_into().unwrap(), &stakes, 10)
.passed());
}

Expand All @@ -2533,12 +2517,7 @@ pub mod test {
tower.record_vote(slot as Slot, Hash::default());
}
assert!(!tower
.check_vote_stake_thresholds(
VOTE_THRESHOLD_DEPTH.try_into().unwrap(),
&stakes,
10,
None
)
.check_vote_stake_thresholds(VOTE_THRESHOLD_DEPTH.try_into().unwrap(), &stakes, 10)
.passed());
}

Expand All @@ -2549,19 +2528,15 @@ pub mod test {
tower.record_vote(0, Hash::default());
tower.record_vote(1, Hash::default());
tower.record_vote(2, Hash::default());
assert!(tower
.check_vote_stake_thresholds(6, &stakes, 2, None)
.passed());
assert!(tower.check_vote_stake_thresholds(6, &stakes, 2).passed());
}

#[test]
fn test_check_vote_threshold_above_threshold_no_stake() {
let mut tower = Tower::new_for_tests(1, 0.67);
let stakes = HashMap::new();
tower.record_vote(0, Hash::default());
assert!(!tower
.check_vote_stake_thresholds(1, &stakes, 2, None)
.passed());
assert!(!tower.check_vote_stake_thresholds(1, &stakes, 2).passed());
}

#[test]
Expand All @@ -2572,9 +2547,7 @@ pub mod test {
tower.record_vote(0, Hash::default());
tower.record_vote(1, Hash::default());
tower.record_vote(2, Hash::default());
assert!(tower
.check_vote_stake_thresholds(6, &stakes, 2, None)
.passed());
assert!(tower.check_vote_stake_thresholds(6, &stakes, 2).passed());
}

#[test]
Expand Down Expand Up @@ -2638,7 +2611,7 @@ pub mod test {
&mut LatestValidatorVotesForFrozenBanks::default(),
);
assert!(tower
.check_vote_stake_thresholds(vote_to_evaluate, &voted_stakes, total_stake, None)
.check_vote_stake_thresholds(vote_to_evaluate, &voted_stakes, total_stake)
.passed());

// CASE 2: Now we want to evaluate a vote for slot VOTE_THRESHOLD_DEPTH + 1. This slot
Expand All @@ -2658,7 +2631,7 @@ pub mod test {
&mut LatestValidatorVotesForFrozenBanks::default(),
);
assert!(!tower
.check_vote_stake_thresholds(vote_to_evaluate, &voted_stakes, total_stake, None)
.check_vote_stake_thresholds(vote_to_evaluate, &voted_stakes, total_stake)
.passed());
}

Expand Down
20 changes: 4 additions & 16 deletions core/src/replay_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ use {
},
solana_sdk::{
clock::{BankId, Slot, MAX_PROCESSING_AGE, NUM_CONSECUTIVE_LEADER_SLOTS},
feature_set::FeatureSet,
genesis_config::ClusterType,
hash::Hash,
pubkey::Pubkey,
Expand Down Expand Up @@ -3228,13 +3227,7 @@ impl ReplayStage {
// Since we are updating our tower we need to update associated caches for previously computed
// slots as well.
for slot in frozen_banks.iter().map(|b| b.slot()) {
Self::cache_tower_stats(
progress,
tower,
slot,
ancestors,
&bank.feature_set,
);
Self::cache_tower_stats(progress, tower, slot, ancestors);
}
}
}
Expand Down Expand Up @@ -3296,7 +3289,7 @@ impl ReplayStage {
cluster_slots,
);

Self::cache_tower_stats(progress, tower, bank_slot, ancestors, &bank.feature_set);
Self::cache_tower_stats(progress, tower, bank_slot, ancestors);
}
new_stats
}
Expand All @@ -3306,18 +3299,13 @@ impl ReplayStage {
tower: &Tower,
slot: Slot,
ancestors: &HashMap<u64, HashSet<u64>>,
feature_set: &Arc<FeatureSet>,
) {
let stats = progress
.get_fork_stats_mut(slot)
.expect("All frozen banks must exist in the Progress map");

stats.vote_threshold = tower.check_vote_stake_thresholds(
slot,
&stats.voted_stakes,
stats.total_stake,
Some(feature_set),
);
stats.vote_threshold =
tower.check_vote_stake_thresholds(slot, &stats.voted_stakes, stats.total_stake);
stats.is_locked_out = tower.is_locked_out(
slot,
ancestors
Expand Down
5 changes: 0 additions & 5 deletions sdk/src/feature_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,10 +732,6 @@ pub mod enable_zk_transfer_with_fee {
solana_sdk::declare_id!("zkNLP7EQALfC1TYeB3biDU7akDckj8iPkvh9y2Mt2K3");
}

pub mod additional_vote_stake_threshold {
solana_sdk::declare_id!("CvgUdmzBnu4kwtL1nurkhK7iXPAdY6QnTKS41H3Jz574");
}

lazy_static! {
/// Map of feature identifiers to user-visible description
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
Expand Down Expand Up @@ -914,7 +910,6 @@ lazy_static! {
(validate_fee_collector_account::id(), "validate fee collector account #33888"),
(disable_rent_fees_collection::id(), "Disable rent fees collection #33945"),
(enable_zk_transfer_with_fee::id(), "enable Zk Token proof program transfer with fee"),
(additional_vote_stake_threshold::id(), "Add an additional vote stake threshold"),
/*************** ADD NEW FEATURES HERE ***************/
]
.iter()
Expand Down

0 comments on commit 3b9c8e7

Please sign in to comment.