mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 15:47:58 +00:00
Do not send messages twice in bitfield distribution (#2005)
* Do not send messages twice in bitfield distribution This removes a bug which resulted in sending bitfield messages multiple times by not checking if we already relayed them. Besides that it also adds an optimization to not relay a message to a peer that send us this message. * Review comments * Break some lines
This commit is contained in:
@@ -166,6 +166,15 @@ impl<M> NetworkBridgeEvent<M> {
|
||||
pub struct View(pub Vec<Hash>);
|
||||
|
||||
impl View {
|
||||
/// Replace `self` with `new`.
|
||||
///
|
||||
/// Returns an iterator that will yield all elements of `new` that were not part of `self`.
|
||||
pub fn replace_difference(&mut self, new: View) -> impl Iterator<Item = &Hash> {
|
||||
let old = std::mem::replace(self, new);
|
||||
|
||||
self.0.iter().filter(move |h| !old.contains(h))
|
||||
}
|
||||
|
||||
/// Returns an iterator of the hashes present in `Self` but not in `other`.
|
||||
pub fn difference<'a>(&'a self, other: &'a View) -> impl Iterator<Item = &'a Hash> + 'a {
|
||||
self.0.iter().filter(move |h| !other.contains(h))
|
||||
|
||||
Reference in New Issue
Block a user