Skip to content

Commit

Permalink
refactor(gossipsub): remove derive-builder dev-dependency (#3270)
Browse files Browse the repository at this point in the history
Remove the `derive_builder` dev-dependency in gossipsub. We can manually implement the builder functionality on top of the `Default` instance of `InjectNodes`.

Resolved #3228.
  • Loading branch information
StemCll authored Dec 22, 2022
1 parent d5f4acc commit aca3454
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 19 deletions.
1 change: 0 additions & 1 deletion protocols/gossipsub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ prometheus-client = "0.18.0"

[dev-dependencies]
async-std = "1.6.3"
derive_builder = "0.11.1"
env_logger = "0.10.0"
hex = "0.4.2"
libp2p-mplex = { path = "../../muxers/mplex" }
Expand Down
58 changes: 44 additions & 14 deletions protocols/gossipsub/src/behaviour/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ use std::hash::{Hash, Hasher};
use std::thread::sleep;
use std::time::Duration;

#[derive(Default, Builder, Debug)]
#[builder(default)]
#[derive(Default, Debug)]
struct InjectNodes<D, F>
// TODO: remove trait bound Default when this issue is fixed:
// https://github.com/colin-kiegel/rust-derive-builder/issues/93
Expand Down Expand Up @@ -108,28 +107,59 @@ where

(gs, peers, topic_hashes)
}
}

impl<D, F> InjectNodesBuilder<D, F>
where
D: DataTransform + Default + Clone + Send + 'static,
F: TopicSubscriptionFilter + Clone + Default + Send + 'static,
{
pub fn create_network(&self) -> (Gossipsub<D, F>, Vec<PeerId>, Vec<TopicHash>) {
self.build().unwrap().create_network()
fn peer_no(mut self, peer_no: usize) -> Self {
self.peer_no = peer_no;
self
}

fn topics(mut self, topics: Vec<String>) -> Self {
self.topics = topics;
self
}

#[allow(clippy::wrong_self_convention)]
fn to_subscribe(mut self, to_subscribe: bool) -> Self {
self.to_subscribe = to_subscribe;
self
}

fn gs_config(mut self, gs_config: GossipsubConfig) -> Self {
self.gs_config = gs_config;
self
}

fn explicit(mut self, explicit: usize) -> Self {
self.explicit = explicit;
self
}

fn outbound(mut self, outbound: usize) -> Self {
self.outbound = outbound;
self
}

fn scoring(mut self, scoring: Option<(PeerScoreParams, PeerScoreThresholds)>) -> Self {
self.scoring = scoring;
self
}

fn subscription_filter(mut self, subscription_filter: F) -> Self {
self.subscription_filter = subscription_filter;
self
}
}

fn inject_nodes<D, F>() -> InjectNodesBuilder<D, F>
fn inject_nodes<D, F>() -> InjectNodes<D, F>
where
D: DataTransform + Default + Clone + Send + 'static,
F: TopicSubscriptionFilter + Clone + Default + Send + 'static,
{
InjectNodesBuilder::default()
InjectNodes::default()
}

fn inject_nodes1() -> InjectNodesBuilder<IdentityTransform, AllowAllSubscriptionFilter> {
inject_nodes()
fn inject_nodes1() -> InjectNodes<IdentityTransform, AllowAllSubscriptionFilter> {
InjectNodes::<IdentityTransform, AllowAllSubscriptionFilter>::default()
}

// helper functions for testing
Expand Down
4 changes: 0 additions & 4 deletions protocols/gossipsub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,6 @@ mod topic;
mod transform;
mod types;

#[cfg(test)]
#[macro_use]
extern crate derive_builder;

mod rpc_proto;

pub use self::behaviour::{Gossipsub, GossipsubEvent, MessageAuthenticity};
Expand Down

0 comments on commit aca3454

Please sign in to comment.