1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
use bytes::Bytes;
use crypto::publickey::Secret;
use devp2p::NetworkService;
use network::{
client_version::ClientVersion, ConnectionFilter, Error, ErrorKind,
NetworkConfiguration as BasicNetworkConfiguration, NetworkContext, NetworkProtocolHandler,
NonReservedPeerMode, PeerId, ProtocolId,
};
use std::{
collections::{BTreeMap, BTreeSet, HashMap},
io,
ops::RangeInclusive,
sync::{atomic, mpsc, Arc},
time::Duration,
};
use chain::{
fork_filter::ForkFilterApi, ChainSyncApi, SyncState, SyncStatus as EthSyncStatus,
ETH_PROTOCOL_VERSION_63, ETH_PROTOCOL_VERSION_64, ETH_PROTOCOL_VERSION_65,
ETH_PROTOCOL_VERSION_66, PAR_PROTOCOL_VERSION_1, PAR_PROTOCOL_VERSION_2,
};
use ethcore::{
client::{BlockChainClient, ChainMessageType, ChainNotify, NewBlocks},
snapshot::SnapshotService,
};
use ethereum_types::{H256, H512, U256, U64};
use io::TimerToken;
use network::IpFilter;
use parking_lot::{Mutex, RwLock};
use stats::{PrometheusMetrics, PrometheusRegistry};
use std::{
net::{AddrParseError, SocketAddr},
str::FromStr,
};
use sync_io::NetSyncIo;
use types::{
creation_status::CreationStatus, restoration_status::RestorationStatus,
transaction::UnverifiedTransaction, BlockNumber,
};
pub const PAR_PROTOCOL: ProtocolId = U64([0x706172]);
pub const ETH_PROTOCOL: ProtocolId = U64([0x657468]);
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WarpSync {
Enabled,
Disabled,
OnlyAndAfter(BlockNumber),
}
impl WarpSync {
pub fn is_enabled(&self) -> bool {
match *self {
WarpSync::Enabled => true,
WarpSync::OnlyAndAfter(_) => true,
WarpSync::Disabled => false,
}
}
pub fn is_warp_only(&self) -> bool {
if let WarpSync::OnlyAndAfter(_) = *self {
true
} else {
false
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct SyncConfig {
pub max_download_ahead_blocks: usize,
pub download_old_blocks: bool,
pub network_id: u64,
pub subprotocol_name: ProtocolId,
pub fork_block: Option<(BlockNumber, H256)>,
pub warp_sync: WarpSync,
pub eip1559_transition: BlockNumber,
pub new_transactions_stats_period: u64,
}
impl Default for SyncConfig {
fn default() -> SyncConfig {
SyncConfig {
max_download_ahead_blocks: 20000,
download_old_blocks: true,
network_id: 1,
subprotocol_name: ETH_PROTOCOL,
fork_block: None,
warp_sync: WarpSync::Disabled,
eip1559_transition: BlockNumber::max_value(),
new_transactions_stats_period: 0,
}
}
}
pub trait SyncProvider: Send + Sync + PrometheusMetrics {
fn status(&self) -> EthSyncStatus;
fn peers(&self) -> Vec<PeerInfo>;
fn enode(&self) -> Option<String>;
fn pending_transactions_stats(&self) -> BTreeMap<H256, TransactionStats>;
fn new_transactions_stats(&self) -> BTreeMap<H256, TransactionStats>;
}
#[derive(Debug)]
pub struct TransactionStats {
pub first_seen: u64,
pub propagated_to: BTreeMap<H512, usize>,
}
#[derive(Debug)]
pub struct PeerInfo {
pub id: Option<String>,
pub client_version: ClientVersion,
pub capabilities: Vec<String>,
pub remote_address: String,
pub local_address: String,
pub eth_info: Option<EthProtocolInfo>,
}
#[derive(Debug)]
pub struct EthProtocolInfo {
pub version: u32,
pub head: H256,
pub difficulty: Option<U256>,
}
#[derive(Debug)]
pub enum PriorityTask {
PropagateBlock {
started: ::std::time::Instant,
block: Bytes,
hash: H256,
difficulty: U256,
},
PropagateTransactions(::std::time::Instant, Arc<atomic::AtomicBool>),
}
impl PriorityTask {
pub fn starting(&self) {
match *self {
PriorityTask::PropagateTransactions(_, ref is_ready) => {
is_ready.store(true, atomic::Ordering::SeqCst)
}
_ => {}
}
}
}
pub struct Params {
pub config: SyncConfig,
pub chain: Arc<dyn BlockChainClient>,
pub forks: BTreeSet<BlockNumber>,
pub snapshot_service: Arc<dyn SnapshotService>,
pub network_config: NetworkConfiguration,
}
pub struct EthSync {
network: NetworkService,
eth_handler: Arc<SyncProtocolHandler>,
subprotocol_name: ProtocolId,
priority_tasks: Mutex<mpsc::Sender<PriorityTask>>,
new_transaction_hashes: crossbeam_channel::Sender<H256>,
}
impl EthSync {
pub fn new(
params: Params,
connection_filter: Option<Arc<dyn ConnectionFilter>>,
) -> Result<Arc<EthSync>, Error> {
let (priority_tasks_tx, priority_tasks_rx) = mpsc::channel();
let (new_transaction_hashes_tx, new_transaction_hashes_rx) = crossbeam_channel::unbounded();
let fork_filter = ForkFilterApi::new(&*params.chain, params.forks);
let sync = ChainSyncApi::new(
params.config,
&*params.chain,
fork_filter,
priority_tasks_rx,
new_transaction_hashes_rx,
);
let service = NetworkService::new(
params.network_config.clone().into_basic()?,
connection_filter,
)?;
let sync = Arc::new(EthSync {
network: service,
eth_handler: Arc::new(SyncProtocolHandler {
sync,
chain: params.chain,
snapshot_service: params.snapshot_service,
overlay: RwLock::new(HashMap::new()),
}),
subprotocol_name: params.config.subprotocol_name,
priority_tasks: Mutex::new(priority_tasks_tx),
new_transaction_hashes: new_transaction_hashes_tx,
});
Ok(sync)
}
pub fn priority_tasks(&self) -> mpsc::Sender<PriorityTask> {
self.priority_tasks.lock().clone()
}
pub fn new_transaction_hashes(&self) -> crossbeam_channel::Sender<H256> {
self.new_transaction_hashes.clone()
}
}
impl SyncProvider for EthSync {
fn status(&self) -> EthSyncStatus {
self.eth_handler.sync.status()
}
fn peers(&self) -> Vec<PeerInfo> {
self.network
.with_context_eval(self.subprotocol_name, |ctx| {
let peer_ids = self.network.connected_peers();
let peer_info = self.eth_handler.sync.peer_info(&peer_ids);
peer_ids
.into_iter()
.zip(peer_info)
.filter_map(|(peer_id, peer_info)| {
let session_info = ctx.session_info(peer_id)?;
Some(PeerInfo {
id: session_info.id.map(|id| format!("{:x}", id)),
client_version: session_info.client_version,
capabilities: session_info
.peer_capabilities
.into_iter()
.map(|c| c.to_string())
.collect(),
remote_address: session_info.remote_address,
local_address: session_info.local_address,
eth_info: peer_info,
})
})
.collect()
})
.unwrap_or_else(Vec::new)
}
fn enode(&self) -> Option<String> {
self.network.external_url()
}
fn pending_transactions_stats(&self) -> BTreeMap<H256, TransactionStats> {
self.eth_handler.sync.pending_transactions_stats()
}
fn new_transactions_stats(&self) -> BTreeMap<H256, TransactionStats> {
self.eth_handler.sync.new_transactions_stats()
}
}
impl PrometheusMetrics for EthSync {
fn prometheus_metrics(&self, r: &mut PrometheusRegistry) {
let scalar = |b| if b { 1i64 } else { 0i64 };
let sync_status = self.status();
r.register_gauge(
"sync_status",
"WaitingPeers(0), SnapshotManifest(1), SnapshotData(2), SnapshotWaiting(3), Blocks(4), Idle(5), Waiting(6), NewBlocks(7)",
match self.eth_handler.sync.status().state {
SyncState::WaitingPeers => 0,
SyncState::SnapshotManifest => 1,
SyncState::SnapshotData => 2,
SyncState::SnapshotWaiting => 3,
SyncState::Blocks => 4,
SyncState::Idle => 5,
SyncState::Waiting => 6,
SyncState::NewBlocks => 7,
});
for (key, value) in sync_status.item_sizes.iter() {
r.register_gauge(
&key,
format!("Total item number of {}", key).as_str(),
*value as i64,
);
}
r.register_gauge(
"net_peers",
"Total number of connected peers",
sync_status.num_peers as i64,
);
r.register_gauge(
"net_active_peers",
"Total number of active peers",
sync_status.num_active_peers as i64,
);
r.register_counter(
"sync_blocks_recieved",
"Number of blocks downloaded so far",
sync_status.blocks_received as i64,
);
r.register_counter(
"sync_blocks_total",
"Total number of blocks for the sync process",
sync_status.blocks_total as i64,
);
r.register_gauge(
"sync_blocks_highest",
"Highest block number in the download queue",
sync_status.highest_block_number.unwrap_or(0) as i64,
);
r.register_gauge(
"snapshot_download_active",
"1 if downloading snapshots",
scalar(sync_status.is_snapshot_syncing()),
);
r.register_gauge(
"snapshot_download_chunks",
"Snapshot chunks",
sync_status.num_snapshot_chunks as i64,
);
r.register_gauge(
"snapshot_download_chunks_done",
"Snapshot chunks downloaded",
sync_status.snapshot_chunks_done as i64,
);
let restoration = self.eth_handler.snapshot_service.restoration_status();
let creation = self.eth_handler.snapshot_service.creation_status();
let (manifest_block_num, _) = self
.eth_handler
.snapshot_service
.manifest_block()
.unwrap_or((0, H256::zero()));
r.register_gauge(
"snapshot_create_block",
"First block of the current snapshot creation",
if let CreationStatus::Ongoing { block_number } = creation {
block_number as i64
} else {
0
},
);
r.register_gauge(
"snapshot_restore_block",
"First block of the current snapshot restoration",
if let RestorationStatus::Ongoing { block_number, .. } = restoration {
block_number as i64
} else {
0
},
);
r.register_gauge(
"snapshot_manifest_block",
"First block number of the present snapshot",
manifest_block_num as i64,
);
}
}
const PEERS_TIMER: TimerToken = 0;
const MAINTAIN_SYNC_TIMER: TimerToken = 1;
const CONTINUE_SYNC_TIMER: TimerToken = 2;
const TX_TIMER: TimerToken = 3;
const PRIORITY_TIMER: TimerToken = 4;
const DELAYED_PROCESSING_TIMER: TimerToken = 5;
pub(crate) const PRIORITY_TIMER_INTERVAL: Duration = Duration::from_millis(250);
struct SyncProtocolHandler {
chain: Arc<dyn BlockChainClient>,
snapshot_service: Arc<dyn SnapshotService>,
sync: ChainSyncApi,
overlay: RwLock<HashMap<BlockNumber, Bytes>>,
}
impl NetworkProtocolHandler for SyncProtocolHandler {
fn initialize(&self, io: &dyn NetworkContext) {
if io.subprotocol_name() != PAR_PROTOCOL {
io.register_timer(PEERS_TIMER, Duration::from_millis(700))
.expect("Error registering peers timer");
io.register_timer(MAINTAIN_SYNC_TIMER, Duration::from_millis(1100))
.expect("Error registering sync timer");
io.register_timer(CONTINUE_SYNC_TIMER, Duration::from_millis(2500))
.expect("Error registering sync timer");
io.register_timer(TX_TIMER, Duration::from_millis(1300))
.expect("Error registering transactions timer");
io.register_timer(DELAYED_PROCESSING_TIMER, Duration::from_millis(2100))
.expect("Error registering delayed processing timer");
io.register_timer(PRIORITY_TIMER, PRIORITY_TIMER_INTERVAL)
.expect("Error registering peers timer");
}
}
fn read(&self, io: &dyn NetworkContext, peer: &PeerId, packet_id: u8, data: &[u8]) {
self.sync.dispatch_packet(
&mut NetSyncIo::new(io, &*self.chain, &*self.snapshot_service, &self.overlay),
*peer,
packet_id,
data,
);
}
fn connected(&self, io: &dyn NetworkContext, peer: &PeerId) {
trace_time!("sync::connected");
let warp_protocol = io.protocol_version(PAR_PROTOCOL, *peer).unwrap_or(0) != 0;
let warp_context = io.subprotocol_name() == PAR_PROTOCOL;
if warp_protocol == warp_context {
self.sync.write().on_peer_connected(
&mut NetSyncIo::new(io, &*self.chain, &*self.snapshot_service, &self.overlay),
*peer,
);
}
}
fn disconnected(&self, io: &dyn NetworkContext, peer: &PeerId) {
trace_time!("sync::disconnected");
if io.subprotocol_name() != PAR_PROTOCOL {
self.sync.write().on_peer_aborting(
&mut NetSyncIo::new(io, &*self.chain, &*self.snapshot_service, &self.overlay),
*peer,
);
}
}
fn timeout(&self, io: &dyn NetworkContext, timer: TimerToken) {
trace_time!("sync::timeout");
let mut io = NetSyncIo::new(io, &*self.chain, &*self.snapshot_service, &self.overlay);
match timer {
PEERS_TIMER => self.sync.write().maintain_peers(&mut io),
MAINTAIN_SYNC_TIMER => self.sync.write().maintain_sync(&mut io),
CONTINUE_SYNC_TIMER => self.sync.write().continue_sync(&mut io),
TX_TIMER => self.sync.write().propagate_new_transactions(&mut io),
PRIORITY_TIMER => self.sync.process_priority_queue(&mut io),
DELAYED_PROCESSING_TIMER => self.sync.process_delayed_requests(&mut io),
_ => warn!("Unknown timer {} triggered.", timer),
}
}
}
impl ChainNotify for EthSync {
fn block_pre_import(&self, bytes: &Bytes, hash: &H256, difficulty: &U256) {
let task = PriorityTask::PropagateBlock {
started: ::std::time::Instant::now(),
block: bytes.clone(),
hash: *hash,
difficulty: *difficulty,
};
if let Err(e) = self.priority_tasks.lock().send(task) {
warn!(target: "sync", "Unexpected error during priority block propagation: {:?}", e);
}
}
fn new_blocks(&self, new_blocks: NewBlocks) {
if new_blocks.has_more_blocks_to_import {
return;
}
self.network.with_context(self.subprotocol_name, |context| {
let mut sync_io = NetSyncIo::new(
context,
&*self.eth_handler.chain,
&*self.eth_handler.snapshot_service,
&self.eth_handler.overlay,
);
self.eth_handler.sync.write().chain_new_blocks(
&mut sync_io,
&new_blocks.imported,
&new_blocks.invalid,
new_blocks.route.enacted(),
new_blocks.route.retracted(),
&new_blocks.sealed,
&new_blocks.proposed,
);
});
}
fn start(&self) {
match self.network.start() {
Err((err, listen_address)) => match err.into() {
ErrorKind::Io(ref e) if e.kind() == io::ErrorKind::AddrInUse => {
warn!("Network port {:?} is already in use, make sure that another instance of an Ethereum client is not running or change the port using the --port option.", listen_address.expect("Listen address is not set."))
}
err => warn!("Error starting network: {}", err),
},
_ => {}
}
self.network
.register_protocol(
self.eth_handler.clone(),
self.subprotocol_name,
&[
ETH_PROTOCOL_VERSION_63,
ETH_PROTOCOL_VERSION_64,
ETH_PROTOCOL_VERSION_65,
ETH_PROTOCOL_VERSION_66,
],
)
.unwrap_or_else(|e| warn!("Error registering ethereum protocol: {:?}", e));
self.network
.register_protocol(
self.eth_handler.clone(),
PAR_PROTOCOL,
&[PAR_PROTOCOL_VERSION_1, PAR_PROTOCOL_VERSION_2],
)
.unwrap_or_else(|e| warn!("Error registering snapshot sync protocol: {:?}", e));
}
fn stop(&self) {
self.eth_handler.snapshot_service.abort_restore();
self.network.stop();
}
fn broadcast(&self, message_type: ChainMessageType) {
self.network.with_context(PAR_PROTOCOL, |context| {
let mut sync_io = NetSyncIo::new(
context,
&*self.eth_handler.chain,
&*self.eth_handler.snapshot_service,
&self.eth_handler.overlay,
);
match message_type {
ChainMessageType::Consensus(message) => self
.eth_handler
.sync
.write()
.propagate_consensus_packet(&mut sync_io, message),
}
});
}
fn transactions_received(&self, txs: &[UnverifiedTransaction], peer_id: PeerId) {
let mut sync = self.eth_handler.sync.write();
sync.transactions_received(txs, peer_id);
}
}
pub trait ManageNetwork: Send + Sync {
fn accept_unreserved_peers(&self);
fn deny_unreserved_peers(&self);
fn remove_reserved_peer(&self, peer: String) -> Result<(), String>;
fn add_reserved_peer(&self, peer: String) -> Result<(), String>;
fn start_network(&self);
fn stop_network(&self);
fn num_peers_range(&self) -> RangeInclusive<u32>;
fn with_proto_context(&self, proto: ProtocolId, f: &mut dyn FnMut(&dyn NetworkContext));
}
impl ManageNetwork for EthSync {
fn accept_unreserved_peers(&self) {
self.network
.set_non_reserved_mode(NonReservedPeerMode::Accept);
}
fn deny_unreserved_peers(&self) {
self.network
.set_non_reserved_mode(NonReservedPeerMode::Deny);
}
fn remove_reserved_peer(&self, peer: String) -> Result<(), String> {
self.network
.remove_reserved_peer(&peer)
.map_err(|e| format!("{:?}", e))
}
fn add_reserved_peer(&self, peer: String) -> Result<(), String> {
self.network
.add_reserved_peer(&peer)
.map_err(|e| format!("{:?}", e))
}
fn start_network(&self) {
self.start();
}
fn stop_network(&self) {
self.network.with_context(self.subprotocol_name, |context| {
let mut sync_io = NetSyncIo::new(
context,
&*self.eth_handler.chain,
&*self.eth_handler.snapshot_service,
&self.eth_handler.overlay,
);
self.eth_handler.sync.write().abort(&mut sync_io);
});
self.stop();
}
fn num_peers_range(&self) -> RangeInclusive<u32> {
self.network.num_peers_range()
}
fn with_proto_context(&self, proto: ProtocolId, f: &mut dyn FnMut(&dyn NetworkContext)) {
self.network.with_context_eval(proto, f);
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NetworkConfiguration {
pub config_path: Option<String>,
pub net_config_path: Option<String>,
pub listen_address: Option<String>,
pub public_address: Option<String>,
pub udp_port: Option<u16>,
pub nat_enabled: bool,
pub discovery_enabled: bool,
pub boot_nodes: Vec<String>,
pub use_secret: Option<Secret>,
pub max_peers: u32,
pub min_peers: u32,
pub max_pending_peers: u32,
pub snapshot_peers: u32,
pub reserved_nodes: Vec<String>,
pub allow_non_reserved: bool,
pub ip_filter: IpFilter,
pub client_version: String,
}
impl NetworkConfiguration {
pub fn new() -> Self {
From::from(BasicNetworkConfiguration::new())
}
pub fn new_local() -> Self {
From::from(BasicNetworkConfiguration::new_local())
}
pub fn into_basic(self) -> Result<BasicNetworkConfiguration, AddrParseError> {
Ok(BasicNetworkConfiguration {
config_path: self.config_path,
net_config_path: self.net_config_path,
listen_address: self
.listen_address
.map(|addr| SocketAddr::from_str(&addr))
.transpose()?,
public_address: self
.public_address
.map(|addr| SocketAddr::from_str(&addr))
.transpose()?,
udp_port: self.udp_port,
nat_enabled: self.nat_enabled,
discovery_enabled: self.discovery_enabled,
boot_nodes: self.boot_nodes,
use_secret: self.use_secret,
max_peers: self.max_peers,
min_peers: self.min_peers,
max_handshakes: self.max_pending_peers,
reserved_protocols: hash_map![PAR_PROTOCOL => self.snapshot_peers],
reserved_nodes: self.reserved_nodes,
ip_filter: self.ip_filter,
non_reserved_mode: if self.allow_non_reserved {
NonReservedPeerMode::Accept
} else {
NonReservedPeerMode::Deny
},
client_version: self.client_version,
})
}
}
impl From<BasicNetworkConfiguration> for NetworkConfiguration {
fn from(other: BasicNetworkConfiguration) -> Self {
NetworkConfiguration {
config_path: other.config_path,
net_config_path: other.net_config_path,
listen_address: other
.listen_address
.and_then(|addr| Some(format!("{}", addr))),
public_address: other
.public_address
.and_then(|addr| Some(format!("{}", addr))),
udp_port: other.udp_port,
nat_enabled: other.nat_enabled,
discovery_enabled: other.discovery_enabled,
boot_nodes: other.boot_nodes,
use_secret: other.use_secret,
max_peers: other.max_peers,
min_peers: other.min_peers,
max_pending_peers: other.max_handshakes,
snapshot_peers: *other.reserved_protocols.get(&PAR_PROTOCOL).unwrap_or(&0),
reserved_nodes: other.reserved_nodes,
ip_filter: other.ip_filter,
allow_non_reserved: match other.non_reserved_mode {
NonReservedPeerMode::Accept => true,
_ => false,
},
client_version: other.client_version,
}
}
}
#[derive(Debug, Clone)]
pub struct ServiceConfiguration {
pub sync: SyncConfig,
pub net: NetworkConfiguration,
pub io_path: String,
}
#[derive(Debug, Clone)]
pub struct PeerNumbers {
pub connected: usize,
pub active: usize,
pub max: usize,
pub min: usize,
}