Skip to content

feat(network): enable add extra-protocol to network component by ScrollNetworkBuilder #282

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

Open
wants to merge 3 commits into
base: scroll
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
27 changes: 23 additions & 4 deletions crates/scroll/node/src/builder/network.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use reth_eth_wire_types::BasicNetworkPrimitives;
use reth_network::{
config::NetworkMode, transform::header::HeaderTransform, NetworkConfig, NetworkHandle,
NetworkManager, PeersInfo,
config::NetworkMode,
protocol::{RlpxSubProtocol, RlpxSubProtocols},
transform::header::HeaderTransform,
NetworkConfig, NetworkHandle, NetworkManager, PeersInfo,
};
use reth_node_api::TxTy;
use reth_node_builder::{components::NetworkBuilder, BuilderContext, FullNodeTypes};
Expand All @@ -15,8 +17,24 @@ use scroll_alloy_hardforks::ScrollHardforks;
use std::fmt::Debug;

/// The network builder for Scroll.
#[derive(Debug, Default, Clone, Copy)]
pub struct ScrollNetworkBuilder;
#[derive(Debug, Default)]
pub struct ScrollNetworkBuilder {
/// Additional RLPx sub-protocols to be added to the network.
scroll_sub_protocols: RlpxSubProtocols,
}

impl ScrollNetworkBuilder {
/// Create a new [`ScrollNetworkBuilder`] with default configuration.
pub fn new() -> Self {
Self { scroll_sub_protocols: RlpxSubProtocols::default() }
}

/// Add a scroll sub-protocol to the network builder.
pub fn with_sub_protocol(mut self, protocol: RlpxSubProtocol) -> Self {
self.scroll_sub_protocols.push(protocol);
self
}
}

impl<Node, Pool> NetworkBuilder<Node, Pool> for ScrollNetworkBuilder
where
Expand Down Expand Up @@ -46,6 +64,7 @@ where
let config = NetworkConfig {
network_mode: NetworkMode::Work,
header_transform: Box::new(transform),
extra_protocols: self.scroll_sub_protocols,
..config
};

Expand Down
2 changes: 1 addition & 1 deletion crates/scroll/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl ScrollNode {
.pool(ScrollPoolBuilder::default())
.executor(ScrollExecutorBuilder::default())
.payload(BasicPayloadServiceBuilder::new(ScrollPayloadBuilderBuilder::default()))
.network(ScrollNetworkBuilder)
.network(ScrollNetworkBuilder::new())
.executor(ScrollExecutorBuilder)
.consensus(ScrollConsensusBuilder)
}
Expand Down
Loading