From 4260b3b41690368eb4cf4923fc3930bf43a4946e Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Wed, 28 Oct 2020 16:59:11 -0600 Subject: [PATCH] Sample votes from ancestors back to root --- runtime/src/bank.rs | 16 +++++++++++++--- sdk/src/stake_weighted_timestamp.rs | 3 ++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 3d1168cc5b..dbcbb21c60 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -60,7 +60,7 @@ use solana_sdk::{ slot_hashes::SlotHashes, slot_history::SlotHistory, stake_weighted_timestamp::{ - calculate_stake_weighted_timestamp, EstimateType, TIMESTAMP_SLOT_RANGE, + calculate_stake_weighted_timestamp, EstimateType, DEPRECATED_TIMESTAMP_SLOT_RANGE, }, system_transaction, sysvar::{self}, @@ -1489,7 +1489,13 @@ impl Bank { .filter_map(|(pubkey, (_, account))| { VoteState::from(&account).and_then(|state| { let timestamp_slot = state.last_timestamp.slot; - if self.slot().checked_sub(timestamp_slot)? <= TIMESTAMP_SLOT_RANGE as u64 { + if (self + .feature_set + .is_active(&feature_set::timestamp_bounding::id()) + && self.ancestors.contains_key(×tamp_slot)) + || self.slot().checked_sub(timestamp_slot)? + <= DEPRECATED_TIMESTAMP_SLOT_RANGE as u64 + { Some(( pubkey, (state.last_timestamp.slot, state.last_timestamp.timestamp), @@ -9695,7 +9701,7 @@ mod tests { let validator_vote_keypairs1 = ValidatorVoteKeypairs::new_rand(); let validator_keypairs = vec![&validator_vote_keypairs0, &validator_vote_keypairs1]; let GenesisConfigInfo { - genesis_config, + mut genesis_config, mint_keypair: _, voting_keypair: _, } = create_genesis_config_with_vote_accounts( @@ -9703,6 +9709,10 @@ mod tests { &validator_keypairs, vec![10_000; 2], ); + genesis_config + .accounts + .remove(&feature_set::timestamp_bounding::id()) + .unwrap(); let mut bank = Bank::new(&genesis_config); assert_eq!( bank.get_timestamp_estimate(EstimateType::Unbounded, None), diff --git a/sdk/src/stake_weighted_timestamp.rs b/sdk/src/stake_weighted_timestamp.rs index 54733844fc..2ea172cd87 100644 --- a/sdk/src/stake_weighted_timestamp.rs +++ b/sdk/src/stake_weighted_timestamp.rs @@ -10,7 +10,8 @@ use std::{ time::Duration, }; -pub const TIMESTAMP_SLOT_RANGE: usize = 16; +pub const TIMESTAMP_SLOT_RANGE: usize = 32; +pub const DEPRECATED_TIMESTAMP_SLOT_RANGE: usize = 16; // Deprecated. Remove in the Solana v1.6.0 timeframe const MAX_ALLOWABLE_DRIFT_PERCENTAGE: u32 = 25; pub enum EstimateType {