mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-06-18 20:11:01 +00:00
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:
@@ -87,11 +87,13 @@ impl Chain {
|
|||||||
|
|
||||||
let mut best = Block::zero();
|
let mut best = Block::zero();
|
||||||
let mut finalized = Block::zero();
|
let mut finalized = Block::zero();
|
||||||
|
let mut timestamp = None;
|
||||||
|
|
||||||
for (nid, node) in self.nodes.iter_mut() {
|
for (nid, node) in self.nodes.iter_mut() {
|
||||||
if !node.update_stale(threshold) {
|
if !node.update_stale(threshold) {
|
||||||
if node.best().height > best.height {
|
if node.best().height > best.height {
|
||||||
best = *node.best();
|
best = *node.best();
|
||||||
|
timestamp = Some(node.best_timestamp());
|
||||||
}
|
}
|
||||||
|
|
||||||
if node.finalized().height > finalized.height {
|
if node.finalized().height > finalized.height {
|
||||||
@@ -106,9 +108,9 @@ impl Chain {
|
|||||||
self.best = best;
|
self.best = best;
|
||||||
self.finalized = finalized;
|
self.finalized = finalized;
|
||||||
self.block_times.reset();
|
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));
|
self.serializer.push(feed::BestFinalized(finalized.height, finalized.hash));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,6 +74,10 @@ impl Node {
|
|||||||
&self.best.block
|
&self.best.block
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn best_timestamp(&self) -> u64 {
|
||||||
|
self.best.block_timestamp
|
||||||
|
}
|
||||||
|
|
||||||
pub fn finalized(&self) -> &Block {
|
pub fn finalized(&self) -> &Block {
|
||||||
&self.finalized
|
&self.finalized
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user