Skip to content

Commit

Permalink
Fix node election rate unit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jurshsmith committed Mar 10, 2024
1 parent 23c8dfc commit ab87d8b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions chaindexing/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion chaindexing/src/repos/postgres_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit ab87d8b

Please sign in to comment.