Fix timestamp overflow (#7886)

* Split timestamp calculation into separate fn for math unit testing

* Add failing test

* Fix failing test; also bump stakes to near expected cluster max supply

* Don't error on timestamp of slot 0
This commit is contained in:
Tyera Eulberg
2020-01-20 17:54:44 -07:00
committed by GitHub
parent 52bc4a3598
commit 21d5fe6272
2 changed files with 142 additions and 17 deletions

View File

@ -404,7 +404,8 @@ impl VoteState {
) -> Result<(), VoteError> {
if (slot < self.last_timestamp.slot || timestamp < self.last_timestamp.timestamp)
|| ((slot == self.last_timestamp.slot || timestamp == self.last_timestamp.timestamp)
&& BlockTimestamp { slot, timestamp } != self.last_timestamp)
&& BlockTimestamp { slot, timestamp } != self.last_timestamp
&& self.last_timestamp.slot != 0)
{
return Err(VoteError::TimestampTooOld);
}
@ -1403,5 +1404,9 @@ mod tests {
timestamp: timestamp + 1
}
);
// Test initial vote
vote_state.last_timestamp = BlockTimestamp::default();
assert_eq!(vote_state.process_timestamp(0, timestamp), Ok(()));
}
}