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 crate::{
6    common::{initialize_not_light_node_modules, ClientComponents},
7    configuration::Configuration,
8};
9use blockgen::BlockGenerator;
10use cfx_rpc_builder::RpcServerHandle;
11use cfx_tasks::TaskManager;
12use cfxcore::{
13    pow::PowComputer, ConsensusGraph, NodeType, SynchronizationService,
14    TransactionPool,
15};
16use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
17use parking_lot::{Condvar, Mutex};
18use std::sync::Arc;
19use tokio::runtime::Runtime as TokioRuntime;
20
21pub struct FullClientExtraComponents {
22    pub consensus: Arc<ConsensusGraph>,
23    pub sync: Arc<SynchronizationService>,
24    pub txpool: Arc<TransactionPool>,
25    pub pow: Arc<PowComputer>,
26    /// Handle to the started ETH RPC server. This is version 2 of the ETH RPC.
27    /// Which use Rust async I/O
28    pub eth_rpc_server_handle: Option<RpcServerHandle>,
29    /// Handle to the started CFX RPC server. This is version 2 of the core
30    /// space RPC. Which use Rust async I/O. Only active when
31    /// `core_space_rpc_use_old_impl` is false.
32    pub cfx_rpc_server_handle: Option<RpcServerHandle>,
33    /// Debug handle for CFX RPC server with all APIs enabled when using the
34    /// new core space RPC implementation.
35    pub debug_cfx_rpc_server_handle: Option<RpcServerHandle>,
36    pub tokio_runtime: Arc<TokioRuntime>,
37    pub task_manager: TaskManager,
38}
39
40impl MallocSizeOf for FullClientExtraComponents {
41    fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize { unimplemented!() }
42}
43
44pub struct FullClient {}
45
46impl FullClient {
47    // Start all key components of Conflux and pass out their handles
48    pub fn start(
49        mut conf: Configuration, exit: Arc<(Mutex<bool>, Condvar)>,
50    ) -> Result<
51        Box<ClientComponents<BlockGenerator, FullClientExtraComponents>>,
52        String,
53    > {
54        let (
55            data_man,
56            pow,
57            txpool,
58            consensus,
59            sync,
60            blockgen,
61            pos_handler,
62            tokio_runtime,
63            eth_rpc_server_handle,
64            cfx_rpc_server_handle,
65            debug_cfx_rpc_server_handle,
66            task_manager,
67        ) = initialize_not_light_node_modules(&mut conf, exit, NodeType::Full)?;
68        Ok(Box::new(ClientComponents {
69            data_manager_weak_ptr: Arc::downgrade(&data_man),
70            blockgen: Some(blockgen),
71            pos_handler: Some(pos_handler),
72            other_components: FullClientExtraComponents {
73                consensus,
74                sync,
75                txpool,
76                pow,
77                eth_rpc_server_handle,
78                cfx_rpc_server_handle,
79                debug_cfx_rpc_server_handle,
80                tokio_runtime,
81                task_manager,
82            },
83        }))
84    }
85}