Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to publish to at least mesh_n peers #5357

Merged
merged 5 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
39 changes: 37 additions & 2 deletions beacon_node/lighthouse_network/src/gossipsub/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,40 @@ where
|| !self.score_below_threshold(p, |ts| ts.publish_threshold).0
}));
} else {
match self.mesh.get(&raw_message.topic) {
match self.mesh.get(&topic_hash) {
// Mesh peers
Some(mesh_peers) => {
// We have a mesh set. We want to make sure to publish to at least `mesh_n`
// peers (if possible).
let needed_extra_peers = self.config.mesh_n().saturating_sub(mesh_peers.len());

if needed_extra_peers > 0 {
// We don't have `mesh_n` peers in our mesh, we will randomly select extras
// and publish to them.

let explicit_peers = &self.explicit_peers;
let scores = self
.peer_score
.as_ref()
.map(|(score, thresholds, ..)| (score, thresholds));
// Get a random set of peers that are appropriate to send messages too.
let peer_list = get_random_peers(
&self.connected_peers,
&topic_hash,
needed_extra_peers,
|peer| {
!mesh_peers.contains(peer)
&& !explicit_peers.contains(peer)
&& scores
.map(|(score, thresholds)| {
AgeManning marked this conversation as resolved.
Show resolved Hide resolved
score.score(peer) > thresholds.publish_threshold
})
.unwrap_or(true)
},
);
recipient_peers.extend(peer_list);
}

recipient_peers.extend(mesh_peers);
}
// Gossipsub peers
Expand Down Expand Up @@ -729,10 +760,14 @@ where
}
}

if publish_failed {
if recipient_peers.is_empty() {
return Err(PublishError::InsufficientPeers);
}

if publish_failed {
return Err(PublishError::AllQueuesFull(recipient_peers.len()));
}

tracing::debug!(message=%msg_id, "Published message");

if let Some(metrics) = self.metrics.as_mut() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,8 @@ fn test_publish_without_flood_publishing() {
let config: Config = Config::default();
assert_eq!(
publishes.len(),
config.mesh_n_low(),
"Should send a publish message to all known peers"
config.mesh_n(),
"Should send a publish message to at least mesh_n peers"
);

assert!(
Expand Down
3 changes: 3 additions & 0 deletions beacon_node/lighthouse_network/src/gossipsub/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ pub enum PublishError {
MessageTooLarge,
/// The compression algorithm failed.
TransformFailed(std::io::Error),
/// Messages could not be sent because all queues for peers were full. The usize represents the
/// number of peers that have full queues.
AllQueuesFull(usize),
}

impl std::fmt::Display for PublishError {
Expand Down
Loading