Saturating sub timestamp from now to avoid possible undeflowr (#420)

This commit is contained in:
James Wilson
2021-10-01 16:55:35 +01:00
committed by GitHub
parent 18a3d7a42f
commit 38c5dff0b7
+2 -2
View File
@@ -259,7 +259,7 @@ impl Chain {
self.best.hash,
);
if let Some(timestamp) = self.timestamp {
self.block_times.push(now - timestamp);
self.block_times.push(now.saturating_sub(timestamp));
self.average_block_time = Some(self.block_times.average());
}
self.timestamp = Some(now);
@@ -271,7 +271,7 @@ impl Chain {
propagation_time = Some(0);
} else if block.height == self.best.height {
if let Some(timestamp) = self.timestamp {
propagation_time = Some(now - timestamp);
propagation_time = Some(now.saturating_sub(timestamp));
}
}