Set block timestamp when reseting stale nodes (#209)

* fix: Prevent stale nodes from updating chain head

* Set block timestamp when reseting stale nodes
This commit is contained in:
Maciej Hirsz
2019-12-06 13:50:30 +01:00
committed by GitHub
parent f2fc89e374
commit 92fb9d28de
2 changed files with 8 additions and 2 deletions
+4 -2
View File
@@ -87,11 +87,13 @@ impl Chain {
let mut best = Block::zero();
let mut finalized = Block::zero();
let mut timestamp = None;
for (nid, node) in self.nodes.iter_mut() {
if !node.update_stale(threshold) {
if node.best().height > best.height {
best = *node.best();
timestamp = Some(node.best_timestamp());
}
if node.finalized().height > finalized.height {
@@ -106,9 +108,9 @@ impl Chain {
self.best = best;
self.finalized = finalized;
self.block_times.reset();
self.timestamp = None;
self.timestamp = timestamp;
self.serializer.push(feed::BestBlock(self.best.height, now, None));
self.serializer.push(feed::BestBlock(self.best.height, timestamp.unwrap_or_else(|| now), None));
self.serializer.push(feed::BestFinalized(finalized.height, finalized.hash));
}
}
+4
View File
@@ -74,6 +74,10 @@ impl Node {
&self.best.block
}
pub fn best_timestamp(&self) -> u64 {
self.best.block_timestamp
}
pub fn finalized(&self) -> &Block {
&self.finalized
}