Skip to content

Commit 54a1974

Browse files
committed
poh-recorder: skew leader clock
1 parent 7437655 commit 54a1974

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

poh/src/poh_recorder.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//!
1313
#[cfg(feature = "dev-context-only-utils")]
1414
use qualifier_attr::qualifiers;
15+
use solana_clock::DEFAULT_MS_PER_SLOT;
1516
use {
1617
crate::{
1718
poh_controller::PohController, poh_service::PohService, record_channels::record_channels,
@@ -977,13 +978,39 @@ impl PohRecorder {
977978
self.clear_bank();
978979
}
979980

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+
980999
pub fn working_bank_block_producer_time_nanos(&self) -> u64 {
981-
self.working_bank()
1000+
let mut working_bank_time = self
1001+
.working_bank()
9821002
.unwrap()
9831003
.start
9841004
.duration_since(UNIX_EPOCH)
9851005
.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)
9871014
}
9881015

9891016
fn produce_block_footer(&self, working_bank: &WorkingBank) -> VersionedBlockMarker {

0 commit comments

Comments
 (0)