v1.4: Update timestamp max allowable drift to 50% of PoH (#14532)

* Add timestamp warp

* Change max_allowable_drift to 50%

* Fill in PR#

* Fix rpc test setup
This commit is contained in:
Tyera Eulberg
2021-01-11 15:49:19 -07:00
committed by GitHub
parent 664e772d0f
commit 375295a605
4 changed files with 230 additions and 31 deletions

View File

@@ -60,7 +60,9 @@ use solana_sdk::{
slot_hashes::SlotHashes,
slot_history::SlotHistory,
stake_weighted_timestamp::{
calculate_stake_weighted_timestamp, EstimateType, DEPRECATED_TIMESTAMP_SLOT_RANGE,
calculate_stake_weighted_timestamp, EstimateType,
DEPRECATED_MAX_ALLOWABLE_DRIFT_PERCENTAGE, DEPRECATED_TIMESTAMP_SLOT_RANGE,
MAX_ALLOWABLE_DRIFT_PERCENTAGE,
},
system_transaction,
sysvar::{self},
@@ -1286,18 +1288,36 @@ impl Bank {
// needed for timestamp bounding, but isn't yet corrected for the activation slot
let epoch_start_timestamp = if self.slot() > timestamp_bounding_activation_slot
{
let epoch = if let Some(epoch) = parent_epoch {
epoch
let warp_timestamp = self
.feature_set
.activated_slot(&feature_set::warp_timestamp::id());
if warp_timestamp == Some(self.slot()) {
None
} else {
self.epoch()
};
let first_slot_in_epoch =
self.epoch_schedule.get_first_slot_in_epoch(epoch);
Some((first_slot_in_epoch, self.clock().epoch_start_timestamp))
let epoch = if let Some(epoch) = parent_epoch {
epoch
} else {
self.epoch()
};
let first_slot_in_epoch =
self.epoch_schedule.get_first_slot_in_epoch(epoch);
Some((first_slot_in_epoch, self.clock().epoch_start_timestamp))
}
} else {
None
};
(EstimateType::Bounded, epoch_start_timestamp)
let max_allowable_drift = if self
.feature_set
.is_active(&feature_set::warp_timestamp::id())
{
MAX_ALLOWABLE_DRIFT_PERCENTAGE
} else {
DEPRECATED_MAX_ALLOWABLE_DRIFT_PERCENTAGE
};
(
EstimateType::Bounded(max_allowable_drift),
epoch_start_timestamp,
)
} else {
(EstimateType::Unbounded, None)
};
@@ -11058,6 +11078,10 @@ pub(crate) mod tests {
.accounts
.remove(&feature_set::timestamp_bounding::id())
.unwrap();
genesis_config
.accounts
.remove(&feature_set::warp_timestamp::id())
.unwrap();
genesis_config.epoch_schedule = EpochSchedule::new(slots_in_epoch);
let bank = Bank::new(&genesis_config);