client/node_types/
archive.rs

1// Copyright 2019 Conflux Foundation. All rights reserved.
2// Conflux is free software and distributed under GNU General Public License.
3// See http://www.gnu.org/licenses/
4
5use 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    /// Handle to the started ETH RPC server. This is version 2 of the ETH RPC.
37    /// Which use Rust async I/O
38    pub eth_rpc_server_handle: Option<RpcServerHandle>,
39    pub tokio_runtime: Arc<TokioRuntime>,
40    pub task_manager: TaskManager,
41}
42
43impl MallocSizeOf for ArchiveClientExtraComponents {
44    fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
45        let tx_pool_size = self.txpool.size_of(ops);
46        let consensus_graph_size = self.consensus.size_of(ops);
47        let sync_graph_size =
48            self.sync.get_synchronization_graph().size_of(ops);
49        tx_pool_size + consensus_graph_size + sync_graph_size
50    }
51}
52
53pub struct ArchiveClient {}
54
55impl ArchiveClient {
56    // Start all key components of Conflux and pass out their handles
57    pub fn start(
58        mut conf: Configuration, exit: Arc<(Mutex<bool>, Condvar)>,
59    ) -> Result<
60        Box<ClientComponents<BlockGenerator, ArchiveClientExtraComponents>>,
61        String,
62    > {
63        Self::process_config(&mut conf);
64        let (
65            data_man,
66            pow,
67            txpool,
68            consensus,
69            sync,
70            blockgen,
71            debug_rpc_http_server,
72            rpc_http_server,
73            debug_rpc_tpc_server,
74            rpc_tcp_server,
75            debug_rpc_ws_server,
76            rpc_ws_server,
77            pos_handler,
78            tokio_runtime,
79            eth_rpc_server_handle,
80            task_manager,
81        ) = initialize_not_light_node_modules(
82            &mut conf,
83            exit,
84            NodeType::Archive,
85        )?;
86        Ok(Box::new(ClientComponents {
87            data_manager_weak_ptr: Arc::downgrade(&data_man),
88            blockgen: Some(blockgen),
89            pos_handler: Some(pos_handler),
90            other_components: ArchiveClientExtraComponents {
91                consensus,
92                debug_rpc_http_server,
93                rpc_http_server,
94                debug_rpc_tpc_server,
95                rpc_tcp_server,
96                debug_rpc_ws_server,
97                rpc_ws_server,
98                sync,
99                txpool,
100                pow,
101                eth_rpc_server_handle,
102                tokio_runtime,
103                task_manager,
104            },
105        }))
106    }
107
108    fn process_config(conf: &mut Configuration) {
109        if conf.raw_conf.max_outgoing_peers_archive.is_none() {
110            conf.raw_conf.max_outgoing_peers_archive = Some(8);
111        }
112    }
113}