Skip to content

Commit

Permalink
fix(chain manager): fix substraction overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
girazoki authored and aesedepece committed Sep 22, 2020
1 parent 6106bc4 commit ed722bf
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions node/src/actors/chain_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1554,7 +1554,12 @@ impl ChainManager {
num_processed_blocks += 1;

let beacon = self.get_chain_beacon();
show_sync_progress(beacon, &sync_target, self.epoch_constants.unwrap());
show_sync_progress(
beacon,
&sync_target,
self.epoch_constants.unwrap(),
self.current_epoch.unwrap(),
);
}

(batch_succeeded, num_processed_blocks)
Expand Down Expand Up @@ -2201,6 +2206,7 @@ fn show_sync_progress(
beacon: CheckpointBeacon,
sync_target: &SyncTarget,
epoch_constants: EpochConstants,
current_epoch: u32,
) {
let target_checkpoint = sync_target.block.checkpoint;
// Show progress log
Expand All @@ -2215,8 +2221,8 @@ fn show_sync_progress(

// Block age is actually the difference in age: it assumes that the last
// block is 0 seconds old
let block_age =
(target_checkpoint - beacon.checkpoint) * u32::from(epoch_constants.checkpoints_period);
let block_age = current_epoch.saturating_sub(beacon.checkpoint)
* u32::from(epoch_constants.checkpoints_period);

let human_age = seconds_to_human_string(u64::from(block_age));
log::info!(
Expand Down

0 comments on commit ed722bf

Please sign in to comment.