client/node_types/
archive.rs1use jsonrpc_http_server::Server as HttpServer;
6use jsonrpc_tcp_server::Server as TcpServer;
7use jsonrpc_ws_server::Server as WsServer;
8
9use crate::{
10 common::{initialize_not_light_node_modules, ClientComponents},
11 configuration::Configuration,
12};
13use blockgen::BlockGenerator;
14use cfx_rpc_builder::RpcServerHandle;
15use cfx_tasks::TaskManager;
16use cfxcore::{
17 pow::PowComputer, ConsensusGraph, NodeType, SynchronizationService,
18 TransactionPool,
19};
20use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
21use parking_lot::{Condvar, Mutex};
22use std::sync::Arc;
23use tokio::runtime::Runtime as TokioRuntime;
24
25pub struct ArchiveClientExtraComponents {
26 pub consensus: Arc<ConsensusGraph>,
27 pub debug_rpc_http_server: Option<HttpServer>,
28 pub rpc_http_server: Option<HttpServer>,
29 pub debug_rpc_tpc_server: Option<TcpServer>,
30 pub rpc_tcp_server: Option<TcpServer>,
31 pub debug_rpc_ws_server: Option<WsServer>,
32 pub rpc_ws_server: Option<WsServer>,
33 pub sync: Arc<SynchronizationService>,
34 pub txpool: Arc<TransactionPool>,
35 pub pow: Arc<PowComputer>,
36 pub eth_rpc_server_handle: Option<RpcServerHandle>,
39 pub cfx_rpc_server_handle: Option<RpcServerHandle>,
43 pub debug_cfx_rpc_server_handle: Option<RpcServerHandle>,
46 pub tokio_runtime: Arc<TokioRuntime>,
47 pub task_manager: TaskManager,
48}
49
50impl MallocSizeOf for ArchiveClientExtraComponents {
51 fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
52 let tx_pool_size = self.txpool.size_of(ops);
53 let consensus_graph_size = self.consensus.size_of(ops);
54 let sync_graph_size =
55 self.sync.get_synchronization_graph().size_of(ops);
56 tx_pool_size + consensus_graph_size + sync_graph_size
57 }
58}
59
60pub struct ArchiveClient {}
61
62impl ArchiveClient {
63 pub fn start(
65 mut conf: Configuration, exit: Arc<(Mutex<bool>, Condvar)>,
66 ) -> Result<
67 Box<ClientComponents<BlockGenerator, ArchiveClientExtraComponents>>,
68 String,
69 > {
70 Self::process_config(&mut conf);
71 let (
72 data_man,
73 pow,
74 txpool,
75 consensus,
76 sync,
77 blockgen,
78 debug_rpc_http_server,
79 rpc_http_server,
80 debug_rpc_tpc_server,
81 rpc_tcp_server,
82 debug_rpc_ws_server,
83 rpc_ws_server,
84 pos_handler,
85 tokio_runtime,
86 eth_rpc_server_handle,
87 cfx_rpc_server_handle,
88 debug_cfx_rpc_server_handle,
89 task_manager,
90 ) = initialize_not_light_node_modules(
91 &mut conf,
92 exit,
93 NodeType::Archive,
94 )?;
95 Ok(Box::new(ClientComponents {
96 data_manager_weak_ptr: Arc::downgrade(&data_man),
97 blockgen: Some(blockgen),
98 pos_handler: Some(pos_handler),
99 other_components: ArchiveClientExtraComponents {
100 consensus,
101 debug_rpc_http_server,
102 rpc_http_server,
103 debug_rpc_tpc_server,
104 rpc_tcp_server,
105 debug_rpc_ws_server,
106 rpc_ws_server,
107 sync,
108 txpool,
109 pow,
110 eth_rpc_server_handle,
111 cfx_rpc_server_handle,
112 debug_cfx_rpc_server_handle,
113 tokio_runtime,
114 task_manager,
115 },
116 }))
117 }
118
119 fn process_config(conf: &mut Configuration) {
120 if conf.raw_conf.max_outgoing_peers_archive.is_none() {
121 conf.raw_conf.max_outgoing_peers_archive = Some(8);
122 }
123 }
124}