Timestamp first vote (#11856)

This commit is contained in:
Tyera Eulberg
2020-08-26 12:34:02 -06:00
committed by GitHub
parent 1988ee9cd6
commit 5c7d743883

View File

@ -344,7 +344,9 @@ impl Tower {
} }
fn maybe_timestamp(&mut self, current_slot: Slot) -> Option<UnixTimestamp> { fn maybe_timestamp(&mut self, current_slot: Slot) -> Option<UnixTimestamp> {
if current_slot > self.last_timestamp.slot { if current_slot > self.last_timestamp.slot
|| self.last_timestamp.slot == 0 && current_slot == self.last_timestamp.slot
{
let timestamp = Utc::now().timestamp(); let timestamp = Utc::now().timestamp();
if timestamp >= self.last_timestamp.timestamp { if timestamp >= self.last_timestamp.timestamp {
self.last_timestamp = BlockTimestamp { self.last_timestamp = BlockTimestamp {
@ -1821,7 +1823,7 @@ pub mod test {
#[test] #[test]
fn test_maybe_timestamp() { fn test_maybe_timestamp() {
let mut tower = Tower::default(); let mut tower = Tower::default();
assert!(tower.maybe_timestamp(0).is_none()); assert!(tower.maybe_timestamp(0).is_some());
assert!(tower.maybe_timestamp(1).is_some()); assert!(tower.maybe_timestamp(1).is_some());
assert!(tower.maybe_timestamp(0).is_none()); // Refuse to timestamp an older slot assert!(tower.maybe_timestamp(0).is_none()); // Refuse to timestamp an older slot
assert!(tower.maybe_timestamp(1).is_none()); // Refuse to timestamp the same slot twice assert!(tower.maybe_timestamp(1).is_none()); // Refuse to timestamp the same slot twice