Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
network-gossip: Do not report peer on duplicate message if its the fi…
Browse files Browse the repository at this point in the history
…rst time (#13508)

Two peers can send us the same gossip message. Before this pr we would have reported the second peer
for sending a duplicate message. However, this isn't correct if we haven't seen the message from
this peer yet. So, we should not report them as they can not be aware of our internal state.
  • Loading branch information
bkchr authored Mar 2, 2023
1 parent 4aa213c commit 7d00033
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion client/network-gossip/src/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,15 @@ impl<B: BlockT> ConsensusGossip<B> {
protocol = %self.protocol,
"Ignored already known message",
);
network.report_peer(who, rep::DUPLICATE_GOSSIP);

// If the peer already send us the message once, let's report them.
if self
.peers
.get_mut(&who)
.map_or(false, |p| !p.known_messages.insert(message_hash))
{
network.report_peer(who, rep::DUPLICATE_GOSSIP);
}
continue
}

Expand Down Expand Up @@ -814,4 +822,30 @@ mod tests {
to_forward,
);
}

// Two peers can send us the same gossip message. We should not report the second peer
// sending the gossip message as long as its the first time the peer send us this message.
#[test]
fn do_not_report_peer_for_first_time_duplicate_gossip_message() {
let mut consensus = ConsensusGossip::<Block>::new(Arc::new(AllowAll), "/foo".into(), None);

let mut network = NoOpNetwork::default();

let peer_id = PeerId::random();
consensus.new_peer(&mut network, peer_id, ObservedRole::Full);
assert!(consensus.peers.contains_key(&peer_id));

let peer_id2 = PeerId::random();
consensus.new_peer(&mut network, peer_id2, ObservedRole::Full);
assert!(consensus.peers.contains_key(&peer_id2));

let message = vec![vec![1, 2, 3]];
consensus.on_incoming(&mut network, peer_id, message.clone());
consensus.on_incoming(&mut network, peer_id2, message.clone());

assert_eq!(
vec![(peer_id, rep::GOSSIP_SUCCESS)],
network.inner.lock().unwrap().peer_reports
);
}
}

0 comments on commit 7d00033

Please sign in to comment.