|
12 | 12 | //! |
13 | 13 | #[cfg(feature = "dev-context-only-utils")] |
14 | 14 | use qualifier_attr::qualifiers; |
| 15 | +use solana_clock::DEFAULT_MS_PER_SLOT; |
15 | 16 | use { |
16 | 17 | crate::{ |
17 | 18 | poh_controller::PohController, poh_service::PohService, record_channels::record_channels, |
@@ -977,13 +978,39 @@ impl PohRecorder { |
977 | 978 | self.clear_bank(); |
978 | 979 | } |
979 | 980 |
|
| 981 | + fn skew_block_producer_time_nanos( |
| 982 | + parent_slot: Slot, |
| 983 | + parent_time: u64, |
| 984 | + working_bank_slot: Slot, |
| 985 | + working_bank_time: u64, |
| 986 | + ) -> u64 { |
| 987 | + let default_ns_per_slot = DEFAULT_MS_PER_SLOT * 1_000_000; |
| 988 | + let diff_slots = working_bank_slot.saturating_sub(parent_slot); |
| 989 | + |
| 990 | + let min_working_bank_time = parent_time.saturating_add(1); |
| 991 | + let max_working_bank_time = |
| 992 | + parent_time.saturating_add(2 * diff_slots * default_ns_per_slot); |
| 993 | + |
| 994 | + working_bank_time |
| 995 | + .max(min_working_bank_time) |
| 996 | + .min(max_working_bank_time) |
| 997 | + } |
| 998 | + |
980 | 999 | pub fn working_bank_block_producer_time_nanos(&self) -> u64 { |
981 | | - self.working_bank() |
| 1000 | + let mut working_bank_time = self |
| 1001 | + .working_bank() |
982 | 1002 | .unwrap() |
983 | 1003 | .start |
984 | 1004 | .duration_since(UNIX_EPOCH) |
985 | 1005 | .expect("Misconfigured system clock; couldn't measure block producer time.") |
986 | | - .as_nanos() as u64 |
| 1006 | + .as_nanos() as u64; |
| 1007 | + |
| 1008 | + let Some(parent) = self.working_bank().unwrap().bank.parent() else { |
| 1009 | + return working_bank_time; |
| 1010 | + }; |
| 1011 | + |
| 1012 | + let parent_time = parent.clock().unix_timestamp as u64; |
| 1013 | + Self::skew_block_producer_time_nanos(parent_time, working_bank_time) |
987 | 1014 | } |
988 | 1015 |
|
989 | 1016 | fn produce_block_footer(&self, working_bank: &WorkingBank) -> VersionedBlockMarker { |
|
0 commit comments