Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
61b2820
chore(gossipsub): use crates.io libp2p deps
jxs Feb 27, 2025
db3606e
chore(gossipsub): use crates.io libp2p deps
jxs Feb 27, 2025
c3c7dea
feature(gossipsub): switch internal async-channel,
jxs Mar 1, 2025
6984bc7
temp
jxs Mar 7, 2025
d333c99
address Elena's review
jxs Mar 21, 2025
bc25fa5
fix queue len check
jxs Mar 31, 2025
f7c402d
remove no longer use non priority queue
jxs Mar 31, 2025
40a9e4b
fix queue size
jxs Apr 2, 2025
36b3e4d
remove retain_mut and do not retain when polling the handler
jxs May 20, 2025
668e598
address Daniel review
jxs Jul 11, 2025
b985ed6
chore(gossipsub): use crates.io libp2p deps
jxs Feb 27, 2025
b81e8b9
Merge branch 'sigp-gossipsub' of github.com:sigp/rust-libp2p into rew…
jxs Jul 11, 2025
d05331e
fix tests
jxs Jul 11, 2025
1ff3055
fix tests
jxs Jul 11, 2025
6e514e3
cargo fmt
jxs Jul 11, 2025
abae6d6
address build with --no-default-features
jxs Jul 11, 2025
ba5a3c5
chore(gossipsub): use crates.io libp2p deps
jxs Feb 27, 2025
e36e5d4
update Cargo.lock
jxs Jul 12, 2025
48945c5
Merge branch 'sigp-gossipsub' of github.com:sigp/rust-libp2p into rew…
jxs Jul 12, 2025
6b43821
fix deps
jxs Jul 12, 2025
a174727
chore(gossipsub): use crates.io libp2p deps
jxs Feb 27, 2025
165a48f
Merge branch 'sigp-gossipsub' of github.com:sigp/rust-libp2p into rew…
jxs Jul 12, 2025
2a726cd
chore(gossipsub): use crates.io libp2p deps
jxs Feb 27, 2025
e923369
update queue design to reflect #574's design update
jxs Jul 31, 2025
0376077
address age review
jxs Aug 4, 2025
ecc89de
Merge branch 'sigp-gossipsub' of github.com:sigp/rust-libp2p into rew…
jxs Aug 4, 2025
3ad7673
clippy
jxs Aug 4, 2025
e70b854
chore(gossipsub): use crates.io libp2p deps
jxs Feb 27, 2025
777ee6b
Merge branch 'sigp-gossipsub' of github.com:sigp/rust-libp2p into rew…
jxs Aug 5, 2025
8a06797
add failed messages metrics
jxs Aug 11, 2025
44c5ecb
Merge branch 'master' of github.com:libp2p/rust-libp2p into rework-be…
jxs Aug 12, 2025
f0ddf0d
split high priority and low priority queue metrics
jxs Aug 14, 2025
550c542
Merge branch 'sigp-gossipsub' of github.com:sigp/rust-libp2p into rew…
jxs Aug 14, 2025
c3d4a2b
convert failed metrics to an Histogram,
jxs Aug 14, 2025
4263216
fix queue metrics
jxs Aug 18, 2025
119bef5
add age's commit
jxs Aug 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions protocols/gossipsub/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
- Remove peer penalty for duplicate messages.
See [PR 6112](https://github.com/libp2p/rust-libp2p/pull/6112)

- switch the internal `async-channel` used to dispatch messages from `NetworkBehaviour` to the `ConnectionHandler`
with an internal priority queue. See [PR XXXX](https://github.com/libp2p/rust-libp2p/pull/XXXX)

- Remove `Rpc` from the public API.
See [PR 6091](https://github.com/libp2p/rust-libp2p/pull/6091)

Expand All @@ -25,6 +28,7 @@

- Feature gate metrics related code. This changes some `Behaviour` constructor methods.
See [PR 6020](https://github.com/libp2p/rust-libp2p/pull/6020)

- Send IDONTWANT before Publishing a new message.
See [PR 6017](https://github.com/libp2p/rust-libp2p/pull/6017)

Expand Down
91 changes: 37 additions & 54 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ use crate::{
mcache::MessageCache,
peer_score::{PeerScore, PeerScoreParams, PeerScoreState, PeerScoreThresholds, RejectReason},
protocol::SIGNING_PREFIX,
rpc::Sender,
queue::Queue,
rpc_proto::proto,
subscription_filter::{AllowAllSubscriptionFilter, TopicSubscriptionFilter},
time_cache::DuplicateCache,
Expand Down Expand Up @@ -751,6 +751,7 @@ where
if self.send_message(
*peer_id,
RpcOut::Publish {
message_id: msg_id.clone(),
message: raw_message.clone(),
timeout: Delay::new(self.config.publish_queue_duration()),
},
Expand Down Expand Up @@ -1341,6 +1342,7 @@ where
self.send_message(
*peer_id,
RpcOut::Forward {
message_id: id.clone(),
message: msg,
timeout: Delay::new(self.config.forward_queue_duration()),
},
Expand Down Expand Up @@ -2081,9 +2083,9 @@ where
// steady-state size of the queues.
#[cfg(feature = "metrics")]
if let Some(m) = &mut self.metrics {
for sender_queue in self.connected_peers.values().map(|v| &v.sender) {
m.observe_priority_queue_size(sender_queue.priority_queue_len());
m.observe_non_priority_queue_size(sender_queue.non_priority_queue_len());
Comment thread
jxs marked this conversation as resolved.
for sender_queue in self.connected_peers.values().map(|v| &v.messages) {
m.observe_priority_queue_size(sender_queue.priority_len());
m.observe_non_priority_queue_size(sender_queue.non_priority_len());
}
}

Expand Down Expand Up @@ -2499,6 +2501,11 @@ where
// Report expired messages
for (peer_id, failed_messages) in self.failed_messages.drain() {
tracing::debug!("Peer couldn't consume messages: {:?}", failed_messages);
#[cfg(feature = "metrics")]
if let Some(metrics) = self.metrics.as_mut() {
metrics.observe_failed_priority_messages(failed_messages.priority);
metrics.observe_failed_non_priority_messages(failed_messages.non_priority);
}
self.events
.push_back(ToSwarm::GenerateEvent(Event::SlowPeer {
peer_id,
Expand Down Expand Up @@ -2746,6 +2753,7 @@ where
self.send_message(
*peer_id,
RpcOut::Forward {
message_id: msg_id.clone(),
message: message.clone(),
timeout: Delay::new(self.config.forward_queue_duration()),
},
Expand Down Expand Up @@ -2874,33 +2882,20 @@ where
return false;
}

// Try sending the message to the connection handler.
match peer.sender.send_message(rpc) {
// Try sending the message to the connection handler,
// High priority messages should not fail.
match peer.messages.try_push(rpc) {
Ok(()) => true,
Err(rpc) => {
// Sending failed because the channel is full.
tracing::warn!(peer=%peer_id, "Send Queue full. Could not send {:?}.", rpc);

// Update failed message counter.
let failed_messages = self.failed_messages.entry(peer_id).or_default();
match rpc {
RpcOut::Publish { .. } => {
failed_messages.priority += 1;
failed_messages.publish += 1;
}
RpcOut::Forward { .. } => {
failed_messages.non_priority += 1;
failed_messages.forward += 1;
}
RpcOut::IWant(_) | RpcOut::IHave(_) | RpcOut::IDontWant(_) => {
failed_messages.non_priority += 1;
}
RpcOut::Graft(_)
| RpcOut::Prune(_)
| RpcOut::Subscribe(_)
| RpcOut::Unsubscribe(_) => {
unreachable!("Channel for highpriority control messages is unbounded and should always be open.")
Comment thread
jxs marked this conversation as resolved.
}
if rpc.priority() {
failed_messages.priority += 1;
} else {
failed_messages.non_priority += 1;
}

// Update peer score.
Expand Down Expand Up @@ -3129,16 +3124,18 @@ where
kind: PeerKind::Floodsub,
connections: vec![],
outbound: false,
sender: Sender::new(self.config.connection_handler_queue_len()),
messages: Queue::new(self.config.connection_handler_queue_len()),
topics: Default::default(),
dont_send: LinkedHashMap::new(),
});
// Add the new connection
connected_peer.connections.push(connection_id);

Comment thread
jxs marked this conversation as resolved.
// This clones a reference to the Queue so any new handlers reference the same underlying
// queue. No data is actually cloned here.
Ok(Handler::new(
self.config.protocol_config(),
connected_peer.sender.new_receiver(),
connected_peer.messages.clone(),
))
}

Expand All @@ -3156,16 +3153,18 @@ where
// Diverging from the go implementation we only want to consider a peer as outbound peer
// if its first connection is outbound.
outbound: !self.px_peers.contains(&peer_id),
sender: Sender::new(self.config.connection_handler_queue_len()),
messages: Queue::new(self.config.connection_handler_queue_len()),
topics: Default::default(),
dont_send: LinkedHashMap::new(),
});
// Add the new connection
connected_peer.connections.push(connection_id);

// This clones a reference to the Queue so any new handlers reference the same underlying
// queue. No data is actually cloned here.
Ok(Handler::new(
self.config.protocol_config(),
connected_peer.sender.new_receiver(),
connected_peer.messages.clone(),
))
}

Expand Down Expand Up @@ -3207,6 +3206,8 @@ where
}
}
}
// rpc is only used for metrics code.
#[allow(unused_variables)]
HandlerEvent::MessageDropped(rpc) => {
// Account for this in the scoring logic
if let PeerScoreState::Active(peer_score) = &mut self.peer_score {
Expand All @@ -3215,32 +3216,7 @@ where

// Keep track of expired messages for the application layer.
let failed_messages = self.failed_messages.entry(propagation_source).or_default();
failed_messages.timeout += 1;
match rpc {
RpcOut::Publish { .. } => {
failed_messages.publish += 1;
}
RpcOut::Forward { .. } => {
failed_messages.forward += 1;
}
_ => {}
}

// Record metrics on the failure.
#[cfg(feature = "metrics")]
if let Some(metrics) = self.metrics.as_mut() {
match rpc {
RpcOut::Publish { message, .. } => {
metrics.publish_msg_dropped(&message.topic);
metrics.timeout_msg_dropped(&message.topic);
}
RpcOut::Forward { message, .. } => {
metrics.forward_msg_dropped(&message.topic);
metrics.timeout_msg_dropped(&message.topic);
}
_ => {}
}
}
failed_messages.non_priority += 1;
}
HandlerEvent::Message {
rpc,
Expand Down Expand Up @@ -3339,10 +3315,17 @@ where
"Could not handle IDONTWANT, peer doesn't exist in connected peer list");
continue;
};

// Remove messages from the queue.
#[allow(unused)]
let removed = peer.messages.remove_data_messages(&message_ids);

#[cfg(feature = "metrics")]
if let Some(metrics) = self.metrics.as_mut() {
metrics.register_idontwant(message_ids.len());
metrics.register_removed_messages(removed);
}

for message_id in message_ids {
peer.dont_send.insert(message_id, Instant::now());
// Don't exceed capacity.
Expand Down
Loading
Loading