client/node_types/
archive.rs1use 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 pub eth_rpc_server_handle: Option<RpcServerHandle>,
29 pub cfx_rpc_server_handle: Option<RpcServerHandle>,
33 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 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}