Skip to content

Commit e26f2ce

Browse files
authored
Fix network status version check (starcoinorg#2976)
1 parent 344396f commit e26f2ce

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

network-p2p/peerset/src/lib.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub const BANNED_THRESHOLD: i32 = 82 * (i32::min_value() / 100);
5757
const DISCONNECT_REPUTATION_CHANGE: i32 = -256;
5858
/// Amount of time between the moment we disconnect from a node and the moment we remove it from
5959
/// the list.
60-
const FORGET_AFTER: Duration = Duration::from_secs(3600);
60+
const FORGET_AFTER: Duration = Duration::from_secs(10);
6161

6262
#[derive(Debug)]
6363
enum Action {
@@ -523,13 +523,8 @@ impl Peerset {
523523
self.message_queue.push_back(Message::Banned(peer_id))
524524
}
525525
peer_reputation.set_reputation(after);
526-
if after != 0 {
527-
continue;
528-
}
529-
530526
drop(peer_reputation);
531-
532-
// If the peer reaches a reputation of 0, and there is no connection to it,
527+
// If the peer has no connection to it,
533528
// forget it.
534529
for set_index in 0..self.data.num_sets() {
535530
match self.data.peer(set_index, &peer_id) {

network-p2p/peerset/src/peersstate.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -607,11 +607,10 @@ impl<'a> NotConnectedPeer<'a> {
607607
peer.sets[self.set] = MembershipState::NotMember;
608608

609609
// Remove the peer from `self.state.nodes` entirely if it isn't a member of any set.
610-
if peer.reputation == 0
611-
&& peer
612-
.sets
613-
.iter()
614-
.all(|set| matches!(set, MembershipState::NotMember))
610+
if peer
611+
.sets
612+
.iter()
613+
.all(|set| matches!(set, MembershipState::NotMember))
615614
{
616615
self.state.nodes.remove(&*self.peer_id);
617616
}

network-p2p/src/protocol.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,17 +490,17 @@ impl Protocol {
490490
}
491491
self.peerset_handle.report_peer(who, rep::GENESIS_MISMATCH);
492492
self.behaviour.disconnect_peer(&who, set_id);
493-
return CustomMessageOutcome::None;
493+
return CustomMessageOutcome::Banned(who);
494494
}
495-
if status.version < MIN_VERSION && CURRENT_VERSION < status.min_supported_version {
495+
if status.version < MIN_VERSION || CURRENT_VERSION < status.min_supported_version {
496496
log!(
497497
target: "network-p2p",
498498
if self.important_peers.contains(&who) { Level::Warn } else { Level::Debug },
499499
"Peer {:?} using unsupported protocol version {}", who, status.version
500500
);
501501
self.peerset_handle.report_peer(who, rep::BAD_PROTOCOL);
502502
self.behaviour.disconnect_peer(&who, set_id);
503-
return CustomMessageOutcome::None;
503+
return CustomMessageOutcome::Banned(who);
504504
}
505505
debug!(target: "network-p2p", "Connected {}", who);
506506
let peer = Peer {

0 commit comments

Comments
 (0)