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 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 ArchiveClientExtraComponents {
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 ArchiveClientExtraComponents {
41    fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
42        let tx_pool_size = self.txpool.size_of(ops);
43        let consensus_graph_size = self.consensus.size_of(ops);
44        let sync_graph_size =
45            self.sync.get_synchronization_graph().size_of(ops);
46        tx_pool_size + consensus_graph_size + sync_graph_size
47    }
48}
49
50pub struct ArchiveClient {}
51
52impl ArchiveClient {
53    // Start all key components of Conflux and pass out their handles
54    pub fn start(
55        mut conf: Configuration, exit: Arc<(Mutex<bool>, Condvar)>,
56    ) -> Result<
57        Box<ClientComponents<BlockGenerator, ArchiveClientExtraComponents>>,
58        String,
59    > {
60        Self::process_config(&mut conf);
61        let (
62            data_man,
63            pow,
64            txpool,
65            consensus,
66            sync,
67            blockgen,
68            pos_handler,
69            tokio_runtime,
70            eth_rpc_server_handle,
71            cfx_rpc_server_handle,
72            debug_cfx_rpc_server_handle,
73            task_manager,
74        ) = initialize_not_light_node_modules(
75            &mut conf,
76            exit,
77            NodeType::Archive,
78        )?;
79        Ok(Box::new(ClientComponents {
80            data_manager_weak_ptr: Arc::downgrade(&data_man),
81            blockgen: Some(blockgen),
82            pos_handler: Some(pos_handler),
83            other_components: ArchiveClientExtraComponents {
84                consensus,
85                sync,
86                txpool,
87                pow,
88                eth_rpc_server_handle,
89                cfx_rpc_server_handle,
90                debug_cfx_rpc_server_handle,
91                tokio_runtime,
92                task_manager,
93            },
94        }))
95    }
96
97    fn process_config(conf: &mut Configuration) {
98        if conf.raw_conf.max_outgoing_peers_archive.is_none() {
99            conf.raw_conf.max_outgoing_peers_archive = Some(8);
100        }
101    }
102}