Skip to content

Commit

Permalink
Mark reserved peers as explicit for gossipsub to avoid reputation dec…
Browse files Browse the repository at this point in the history
…reasing
  • Loading branch information
xgreenx committed Oct 15, 2023
1 parent 9064a5e commit 002f19a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/services/p2p/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ pub(crate) fn build_transport(
(transport, connection_state)
}

fn peer_ids_set_from(multiaddr: &[Multiaddr]) -> HashSet<PeerId> {
pub fn peer_ids_set_from(multiaddr: &[Multiaddr]) -> HashSet<PeerId> {
multiaddr
.iter()
// Safety: as is the case with `bootstrap_nodes` it is assumed that `reserved_nodes` [`Multiadr`]
Expand Down
7 changes: 6 additions & 1 deletion crates/services/p2p/src/gossipsub/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ fn initialize_peer_score_thresholds() -> PeerScoreThresholds {

/// Given a `P2pConfig` containing `GossipsubConfig` creates a Gossipsub Behaviour
pub(crate) fn build_gossipsub_behaviour(p2p_config: &Config) -> Gossipsub {
if p2p_config.metrics {
let mut gossipsub = if p2p_config.metrics {
// Move to Metrics related feature flag
let mut p2p_registry = Registry::default();

Expand Down Expand Up @@ -208,7 +208,12 @@ pub(crate) fn build_gossipsub_behaviour(p2p_config: &Config) -> Gossipsub {
initialize_gossipsub(&mut gossipsub, p2p_config);

gossipsub
};
for peer_id in crate::config::peer_ids_set_from(&p2p_config.reserved_nodes) {
gossipsub.add_explicit_peer(&peer_id);
}

gossipsub
}

fn initialize_gossipsub(gossipsub: &mut Gossipsub, p2p_config: &Config) {
Expand Down
2 changes: 1 addition & 1 deletion crates/services/p2p/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ where
should_continue = true;
match next_service_request {
Some(TaskRequest::BroadcastTransaction(transaction)) => {
let broadcast = GossipsubBroadcastRequest::NewTx(transaction);
let tx_id = transaction.id(&self.chain_id);
let broadcast = GossipsubBroadcastRequest::NewTx(transaction);
let result = self.p2p_service.publish_message(broadcast);
if let Err(e) = result {
tracing::error!("Got an error during transaction {} broadcasting {}", tx_id, e);
Expand Down

0 comments on commit 002f19a

Please sign in to comment.