Move TendermintMachine from start_num, time to last_num, time

Provides an explicitly clear API clearer to program around.

Also adds additional time code to handle an edge case.
This commit is contained in:
Luke Parker
2022-10-30 04:27:15 -04:00
parent edb2e00db7
commit 1af6117155
2 changed files with 35 additions and 20 deletions

View File

@@ -61,11 +61,11 @@ impl<T: TendermintValidator> TendermintAuthority<T> {
let info = self.0.client.info();
// Header::Number: TryInto<u64> doesn't implement Debug and can't be unwrapped
let start_number = match TryInto::<u64>::try_into(info.best_number) {
Ok(best) => BlockNumber(best + 1),
let last_number = match info.best_number.try_into() {
Ok(best) => BlockNumber(best),
Err(_) => panic!("BlockNumber exceeded u64"),
};
let start_time = Commit::<TendermintValidators<T>>::decode(
let last_time = Commit::<TendermintValidators<T>>::decode(
&mut self
.0
.client
@@ -76,7 +76,7 @@ impl<T: TendermintValidator> TendermintAuthority<T> {
.as_ref(),
)
.map(|commit| commit.end_time)
// TODO: Genesis start time
// TODO: Genesis start time + BLOCK_TIME
.unwrap_or_else(|_| SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs());
let proposal = self
@@ -88,7 +88,7 @@ impl<T: TendermintValidator> TendermintAuthority<T> {
self.0.clone(),
// TODO
0, // ValidatorId
(start_number, start_time),
(last_number, last_time),
proposal,
));
}