Skip to content

Commit 840670d

Browse files
committed
fix(node): remove useless new_from_config constructor
1 parent 8588efe commit 840670d

File tree

2 files changed

+24
-45
lines changed

2 files changed

+24
-45
lines changed

src/core/builder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ impl NodeBuilder {
204204
pub fn build_node(&mut self) -> Result<(NodeDefault, Client), SqlInitializationError> {
205205
let peer_store = SqlitePeerDb::new(self.network, self.config.data_path.clone())?;
206206
let header_store = SqliteHeaderDb::new(self.network, self.config.data_path.clone())?;
207-
Ok(Node::new_from_config(
208-
core::mem::take(&mut self.config),
207+
Ok(Node::new(
209208
self.network,
209+
core::mem::take(&mut self.config),
210210
peer_store,
211211
header_store,
212212
))
@@ -218,9 +218,9 @@ impl NodeBuilder {
218218
peer_store: P,
219219
header_store: H,
220220
) -> (Node<H, P>, Client) {
221-
Node::new_from_config(
222-
core::mem::take(&mut self.config),
221+
Node::new(
223222
self.network,
223+
core::mem::take(&mut self.config),
224224
peer_store,
225225
header_store,
226226
)

src/core/node.rs

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{collections::HashSet, ops::DerefMut, sync::Arc, time::Duration};
1+
use std::{ops::DerefMut, sync::Arc, time::Duration};
22

33
use bitcoin::{
44
block::Header,
@@ -25,8 +25,7 @@ use crate::{
2525
core::{error::FetchHeaderError, peer_map::PeerMap},
2626
db::traits::{HeaderStore, PeerStore},
2727
filters::{cfheader_chain::AppendAttempt, error::CFilterSyncError},
28-
network::dns::DnsResolver,
29-
ConnectionType, PeerStoreSizeConfig, RejectPayload, TrustedPeer, TxBroadcastPolicy,
28+
RejectPayload, TxBroadcastPolicy,
3029
};
3130

3231
use super::{
@@ -46,7 +45,6 @@ use super::{
4645
pub(crate) const ADDR_V2_VERSION: u32 = 70015;
4746
const LOOP_TIMEOUT: u64 = 1;
4847

49-
type Whitelist = Vec<TrustedPeer>;
5048
type PeerRequirement = usize;
5149

5250
/// The state of the node with respect to connected peers.
@@ -79,21 +77,26 @@ pub struct Node<H: HeaderStore, P: PeerStore> {
7977
}
8078

8179
impl<H: HeaderStore, P: PeerStore> Node<H, P> {
82-
#[allow(clippy::too_many_arguments)]
8380
pub(crate) fn new(
8481
network: Network,
85-
white_list: Whitelist,
86-
dns_resolver: DnsResolver,
87-
scripts: HashSet<ScriptBuf>,
88-
header_checkpoint: Option<HeaderCheckpoint>,
89-
required_peers: PeerRequirement,
90-
target_peer_size: PeerStoreSizeConfig,
91-
connection_type: ConnectionType,
92-
timeout_config: PeerTimeoutConfig,
93-
filter_sync_policy: FilterSyncPolicy,
82+
config: NodeConfig,
9483
peer_store: P,
9584
header_store: H,
9685
) -> (Self, Client) {
86+
let NodeConfig {
87+
required_peers,
88+
white_list,
89+
dns_resolver,
90+
addresses,
91+
data_path: _,
92+
header_checkpoint,
93+
connection_type,
94+
target_peer_size,
95+
response_timeout,
96+
max_connection_time,
97+
filter_sync_policy,
98+
} = config;
99+
let timeout_config = PeerTimeoutConfig::new(response_timeout, max_connection_time);
97100
// Set up a communication channel between the node and client
98101
let (log_tx, log_rx) = mpsc::channel::<Log>(32);
99102
let (warn_tx, warn_rx) = mpsc::unbounded_channel::<Warning>();
@@ -128,13 +131,13 @@ impl<H: HeaderStore, P: PeerStore> Node<H, P> {
128131
// Build the chain
129132
let chain = Chain::new(
130133
network,
131-
scripts,
134+
addresses,
132135
checkpoint,
133136
checkpoints,
134137
dialog.clone(),
135138
height_monitor,
136139
header_store,
137-
required_peers,
140+
required_peers.into(),
138141
);
139142
let chain = Arc::new(Mutex::new(chain));
140143
(
@@ -143,7 +146,7 @@ impl<H: HeaderStore, P: PeerStore> Node<H, P> {
143146
chain,
144147
peer_map,
145148
tx_broadcaster,
146-
required_peers,
149+
required_peers: required_peers.into(),
147150
dialog,
148151
client_recv: Arc::new(Mutex::new(crx)),
149152
peer_recv: Arc::new(Mutex::new(mrx)),
@@ -153,30 +156,6 @@ impl<H: HeaderStore, P: PeerStore> Node<H, P> {
153156
)
154157
}
155158

156-
pub(crate) fn new_from_config(
157-
config: NodeConfig,
158-
network: Network,
159-
peer_store: P,
160-
header_store: H,
161-
) -> (Self, Client) {
162-
let timeout_config =
163-
PeerTimeoutConfig::new(config.response_timeout, config.max_connection_time);
164-
Node::new(
165-
network,
166-
config.white_list,
167-
config.dns_resolver,
168-
config.addresses,
169-
config.header_checkpoint,
170-
config.required_peers as PeerRequirement,
171-
config.target_peer_size,
172-
config.connection_type,
173-
timeout_config,
174-
config.filter_sync_policy,
175-
peer_store,
176-
header_store,
177-
)
178-
}
179-
180159
/// Run the node continuously. Typically run on a separate thread than the underlying application.
181160
///
182161
/// # Errors

0 commit comments

Comments
 (0)