Skip to content

Commit aca3454

Browse files
authored
refactor(gossipsub): remove derive-builder dev-dependency (#3270)
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.
1 parent d5f4acc commit aca3454

File tree

3 files changed

+44
-19
lines changed

3 files changed

+44
-19
lines changed

protocols/gossipsub/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ prometheus-client = "0.18.0"
3737

3838
[dev-dependencies]
3939
async-std = "1.6.3"
40-
derive_builder = "0.11.1"
4140
env_logger = "0.10.0"
4241
hex = "0.4.2"
4342
libp2p-mplex = { path = "../../muxers/mplex" }

protocols/gossipsub/src/behaviour/tests.rs

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ use std::hash::{Hash, Hasher};
3838
use std::thread::sleep;
3939
use std::time::Duration;
4040

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

109108
(gs, peers, topic_hashes)
110109
}
111-
}
112110

113-
impl<D, F> InjectNodesBuilder<D, F>
114-
where
115-
D: DataTransform + Default + Clone + Send + 'static,
116-
F: TopicSubscriptionFilter + Clone + Default + Send + 'static,
117-
{
118-
pub fn create_network(&self) -> (Gossipsub<D, F>, Vec<PeerId>, Vec<TopicHash>) {
119-
self.build().unwrap().create_network()
111+
fn peer_no(mut self, peer_no: usize) -> Self {
112+
self.peer_no = peer_no;
113+
self
114+
}
115+
116+
fn topics(mut self, topics: Vec<String>) -> Self {
117+
self.topics = topics;
118+
self
119+
}
120+
121+
#[allow(clippy::wrong_self_convention)]
122+
fn to_subscribe(mut self, to_subscribe: bool) -> Self {
123+
self.to_subscribe = to_subscribe;
124+
self
125+
}
126+
127+
fn gs_config(mut self, gs_config: GossipsubConfig) -> Self {
128+
self.gs_config = gs_config;
129+
self
130+
}
131+
132+
fn explicit(mut self, explicit: usize) -> Self {
133+
self.explicit = explicit;
134+
self
135+
}
136+
137+
fn outbound(mut self, outbound: usize) -> Self {
138+
self.outbound = outbound;
139+
self
140+
}
141+
142+
fn scoring(mut self, scoring: Option<(PeerScoreParams, PeerScoreThresholds)>) -> Self {
143+
self.scoring = scoring;
144+
self
145+
}
146+
147+
fn subscription_filter(mut self, subscription_filter: F) -> Self {
148+
self.subscription_filter = subscription_filter;
149+
self
120150
}
121151
}
122152

123-
fn inject_nodes<D, F>() -> InjectNodesBuilder<D, F>
153+
fn inject_nodes<D, F>() -> InjectNodes<D, F>
124154
where
125155
D: DataTransform + Default + Clone + Send + 'static,
126156
F: TopicSubscriptionFilter + Clone + Default + Send + 'static,
127157
{
128-
InjectNodesBuilder::default()
158+
InjectNodes::default()
129159
}
130160

131-
fn inject_nodes1() -> InjectNodesBuilder<IdentityTransform, AllowAllSubscriptionFilter> {
132-
inject_nodes()
161+
fn inject_nodes1() -> InjectNodes<IdentityTransform, AllowAllSubscriptionFilter> {
162+
InjectNodes::<IdentityTransform, AllowAllSubscriptionFilter>::default()
133163
}
134164

135165
// helper functions for testing

protocols/gossipsub/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,6 @@ mod topic;
154154
mod transform;
155155
mod types;
156156

157-
#[cfg(test)]
158-
#[macro_use]
159-
extern crate derive_builder;
160-
161157
mod rpc_proto;
162158

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

0 commit comments

Comments
 (0)