client/node_types/
full.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 FullClientExtraComponents {
26    pub consensus: Arc<ConsensusGraph>,
27    pub debug_rpc_http_server: Option<HttpServer>,
28    pub rpc_http_server: Option<HttpServer>,
29    pub debug_rpc_tcp_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    /// Handle to the started CFX RPC server. This is version 2 of the core
40    /// space RPC. Which use Rust async I/O. Only active when
41    /// `core_space_rpc_use_old_impl` is false.
42    pub cfx_rpc_server_handle: Option<RpcServerHandle>,
43    /// Debug handle for CFX RPC server with all APIs enabled when using the
44    /// new core space RPC implementation.
45    pub debug_cfx_rpc_server_handle: Option<RpcServerHandle>,
46    pub tokio_runtime: Arc<TokioRuntime>,
47    pub task_manager: TaskManager,
48}
49
50impl MallocSizeOf for FullClientExtraComponents {
51    fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize { unimplemented!() }
52}
53
54pub struct FullClient {}
55
56impl FullClient {
57    // Start all key components of Conflux and pass out their handles
58    pub fn start(
59        mut conf: Configuration, exit: Arc<(Mutex<bool>, Condvar)>,
60    ) -> Result<
61        Box<ClientComponents<BlockGenerator, FullClientExtraComponents>>,
62        String,
63    > {
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_tcp_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            cfx_rpc_server_handle,
81            debug_cfx_rpc_server_handle,
82            task_manager,
83        ) = initialize_not_light_node_modules(&mut conf, exit, NodeType::Full)?;
84        Ok(Box::new(ClientComponents {
85            data_manager_weak_ptr: Arc::downgrade(&data_man),
86            blockgen: Some(blockgen),
87            pos_handler: Some(pos_handler),
88            other_components: FullClientExtraComponents {
89                consensus,
90                debug_rpc_http_server,
91                rpc_http_server,
92                debug_rpc_tcp_server,
93                rpc_tcp_server,
94                debug_rpc_ws_server,
95                rpc_ws_server,
96                sync,
97                txpool,
98                pow,
99                eth_rpc_server_handle,
100                cfx_rpc_server_handle,
101                debug_cfx_rpc_server_handle,
102                tokio_runtime,
103                task_manager,
104            },
105        }))
106    }
107}