Check distance for timestamp

This commit is contained in:
Stephen Akridge
2020-04-20 08:50:09 -07:00
committed by Michael Vines
parent 840ebfe625
commit db6540772c

View File

@ -202,6 +202,14 @@ pub fn make_accounts_hashes_message(
Some(CrdsValue::new_signed(message, keypair))
}
fn distance(a: u64, b: u64) -> u64 {
if a > b {
a - b
} else {
b - a
}
}
// TODO These messages should go through the gpu pipeline for spam filtering
#[derive(Serialize, Deserialize, Debug)]
#[allow(clippy::large_enum_variant)]
@ -1032,7 +1040,7 @@ impl ClusterInfo {
let mut num_live_peers = 1i64;
peers.iter().for_each(|p| {
// A peer is considered live if they generated their contact info recently
if timestamp() - p.wallclock <= CRDS_GOSSIP_PULL_CRDS_TIMEOUT_MS {
if distance(timestamp(), p.wallclock) <= CRDS_GOSSIP_PULL_CRDS_TIMEOUT_MS {
num_live_peers += 1;
}
});