Skip to content

Commit

Permalink
fix(message): timestamp evaluation (#547)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Apr 13, 2021
1 parent 0bdf04d commit 60fee19
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ use std::{
};
use tokio::sync::RwLock;

// The library do not request a milestone from the node if we have one in the (x / 100, x/ 100 + 100) range
const MILESTONE_CACHE_RANGE: u32 = 100;
/// The node issue a milestone every 10 seconds.
const MILESTONE_ISSUE_RATE_SECS: i64 = 10;

type MilestoneCache = RwLock<HashMap<Range<u32>, MilestoneResponse>>;
fn milestone_cache() -> &'static MilestoneCache {
Expand Down Expand Up @@ -982,8 +985,10 @@ impl<'a> MessageBuilder<'a> {
}
Entry::Occupied(entry) => {
let milestone = *entry.get();
date_time =
DateTime::from_utc(NaiveDateTime::from_timestamp(milestone.timestamp as i64, 0), Utc);
let index_diff = ms_index as i64 - milestone.index as i64;
let approx_timestamp =
milestone.timestamp as i64 + (index_diff * MILESTONE_ISSUE_RATE_SECS);
date_time = DateTime::from_utc(NaiveDateTime::from_timestamp(approx_timestamp, 0), Utc);
}
}
date_time
Expand Down

0 comments on commit 60fee19

Please sign in to comment.