Skip to content

Commit 1686397

Browse files
yiweichigreged93
andauthored
feat(network): enable add extra-protocol to network component by ScrollNetworkBuilder (#282)
* fix: scroll-wire initialization * fix: compile * fix: ci * fix: docs Signed-off-by: Gregory Edison <gregory.edison1993@gmail.com> --------- Signed-off-by: Gregory Edison <gregory.edison1993@gmail.com> Co-authored-by: Gregory Edison <gregory.edison1993@gmail.com>
1 parent 4271872 commit 1686397

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

crates/scroll/node/src/builder/network.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use reth_eth_wire_types::BasicNetworkPrimitives;
22
use reth_network::{
3-
config::NetworkMode, transform::header::HeaderTransform, NetworkConfig, NetworkHandle,
4-
NetworkManager, PeersInfo,
3+
config::NetworkMode,
4+
protocol::{RlpxSubProtocol, RlpxSubProtocols},
5+
transform::header::HeaderTransform,
6+
NetworkConfig, NetworkHandle, NetworkManager, PeersInfo,
57
};
68
use reth_node_api::TxTy;
79
use reth_node_builder::{components::NetworkBuilder, BuilderContext, FullNodeTypes};
@@ -15,8 +17,24 @@ use scroll_alloy_hardforks::ScrollHardforks;
1517
use std::fmt::Debug;
1618

1719
/// The network builder for Scroll.
18-
#[derive(Debug, Default, Clone, Copy)]
19-
pub struct ScrollNetworkBuilder;
20+
#[derive(Debug, Default)]
21+
pub struct ScrollNetworkBuilder {
22+
/// Additional `RLPx` sub-protocols to be added to the network.
23+
scroll_sub_protocols: RlpxSubProtocols,
24+
}
25+
26+
impl ScrollNetworkBuilder {
27+
/// Create a new [`ScrollNetworkBuilder`] with default configuration.
28+
pub fn new() -> Self {
29+
Self { scroll_sub_protocols: RlpxSubProtocols::default() }
30+
}
31+
32+
/// Add a scroll sub-protocol to the network builder.
33+
pub fn with_sub_protocol(mut self, protocol: RlpxSubProtocol) -> Self {
34+
self.scroll_sub_protocols.push(protocol);
35+
self
36+
}
37+
}
2038

2139
impl<Node, Pool> NetworkBuilder<Node, Pool> for ScrollNetworkBuilder
2240
where
@@ -46,6 +64,7 @@ where
4664
let config = NetworkConfig {
4765
network_mode: NetworkMode::Work,
4866
header_transform: Box::new(transform),
67+
extra_protocols: self.scroll_sub_protocols,
4968
..config
5069
};
5170

crates/scroll/node/src/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl ScrollNode {
4343
.pool(ScrollPoolBuilder::default())
4444
.executor(ScrollExecutorBuilder::default())
4545
.payload(BasicPayloadServiceBuilder::new(ScrollPayloadBuilderBuilder::default()))
46-
.network(ScrollNetworkBuilder)
46+
.network(ScrollNetworkBuilder::new())
4747
.executor(ScrollExecutorBuilder)
4848
.consensus(ScrollConsensusBuilder)
4949
}

0 commit comments

Comments
 (0)