Skip to content
Snippets Groups Projects
Unverified Commit d4657f86 authored by Alexandru Vasile's avatar Alexandru Vasile Committed by GitHub
Browse files

litep2p/peerstore: Fix bump last updated time (#4971)


This PR bumps the last time of a reputation update of a peer.
Doing so ensures the peer remains in the peerstore for longer than 1
hour.

Libp2p updates the `last_updated` field as well.

Small summary for the peerstore:
- A: when peers are reported the `last_updated` time is set to current
time (not done before this PR)
- B: peers that were not updated for 1 hour are removed from the
peerstore
- the reputation of the peers is decaying to zero over time
- peers are reported with a reputation change (positive or negative
depending on the behavior)

Because, (A) was not updating the `last_updated` time, we might lose the
reputation of peers that are constantly updated after 1hour because of
(B).

cc @paritytech/networking

Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>
parent 7290042a
Branches
No related merge requests found
Pipeline #484410 waiting for manual action with stages
in 1 hour, 19 minutes, and 1 second
......@@ -85,6 +85,11 @@ impl PeerInfo {
self.reputation < BANNED_THRESHOLD
}
fn add_reputation(&mut self, increment: i32) {
self.reputation = self.reputation.saturating_add(increment);
self.bump_last_updated();
}
fn decay_reputation(&mut self, seconds_passed: u64) {
// Note that decaying the reputation value happens "on its own",
// so we don't do `bump_last_updated()`.
......@@ -103,6 +108,10 @@ impl PeerInfo {
}
}
}
fn bump_last_updated(&mut self) {
self.last_updated = Instant::now();
}
}
#[derive(Debug, Default)]
......@@ -169,7 +178,7 @@ impl PeerStoreProvider for PeerstoreHandle {
match lock.peers.get_mut(&peer) {
Some(info) => {
info.reputation = info.reputation.saturating_add(reputation_change.value);
info.add_reputation(reputation_change.value);
},
None => {
lock.peers.insert(
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment