From ab87d8bceec81f5c4bfa4a8acfe2a86448e5299e Mon Sep 17 00:00:00 2001 From: Joshua Oladele Date: Sun, 10 Mar 2024 09:07:09 +0100 Subject: [PATCH] Fix node election rate unit --- chaindexing/src/nodes.rs | 6 +++--- chaindexing/src/repos/postgres_repo.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/chaindexing/src/nodes.rs b/chaindexing/src/nodes.rs index 6d8c12b..1df691d 100644 --- a/chaindexing/src/nodes.rs +++ b/chaindexing/src/nodes.rs @@ -15,11 +15,11 @@ pub struct Node { } impl Node { - pub fn get_min_active_at(node_election_rate_ms: u64) -> i64 { - let now = chrono::Utc::now().timestamp_millis(); + pub fn get_min_active_at_in_secs(node_election_rate_ms: u64) -> i64 { + let now_ms = chrono::Utc::now().timestamp_millis(); // Not active if not kept active at least 2 elections away - now - node_election_rate_ms as i64 + (now_ms - node_election_rate_ms as i64) / 1_000 } fn is_leader(&self, leader: &Node) -> bool { diff --git a/chaindexing/src/repos/postgres_repo.rs b/chaindexing/src/repos/postgres_repo.rs index c2078ad..fd95dd2 100644 --- a/chaindexing/src/repos/postgres_repo.rs +++ b/chaindexing/src/repos/postgres_repo.rs @@ -231,7 +231,7 @@ impl Repo for PostgresRepo { use crate::diesels::schema::chaindexing_nodes::dsl::*; chaindexing_nodes - .filter(last_active_at.gt(Node::get_min_active_at(node_election_rate_ms))) + .filter(last_active_at.gt(Node::get_min_active_at_in_secs(node_election_rate_ms))) .load(conn) .await .unwrap()