TARAXA
node.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <libdevcore/SHA3.h>
4 #include <libdevcrypto/Common.h>
5 
6 #include <atomic>
7 #include <boost/asio.hpp>
8 #include <memory>
9 
10 #include "common/thread_pool.hpp"
11 #include "config/config.hpp"
12 #include "network/http_server.hpp"
13 #include "network/rpc/DebugFace.h"
14 #include "network/rpc/EthFace.h"
15 #include "network/rpc/NetFace.h"
16 #include "network/rpc/TaraxaFace.h"
17 #include "network/rpc/TestFace.h"
18 #include "network/ws_server.hpp"
19 #include "pbft/pbft_chain.hpp"
20 #include "storage/storage.hpp"
22 
23 namespace taraxa {
24 namespace metrics {
25 class MetricsService;
26 }
27 
28 namespace pillar_chain {
29 class PillarChainManager;
30 }
31 
32 class Network;
33 class DagBlockProposer;
34 class DagManager;
35 class DagBlock;
36 struct Transaction;
37 class TransactionManager;
38 class GasPricer;
39 class PbftManager;
40 struct NetworkConfig;
41 class KeyManager;
42 
43 class FullNode : public std::enable_shared_from_this<FullNode> {
44  public:
45  explicit FullNode(FullNodeConfig const &conf);
46  ~FullNode();
47 
48  FullNode(const FullNode &) = delete;
49  FullNode(FullNode &&) = delete;
50  FullNode &operator=(const FullNode &) = delete;
51  FullNode &operator=(FullNode &&) = delete;
52 
53  void start();
54  bool isStarted() const { return started_; }
55  auto const &getConfig() const { return conf_; }
56  auto const &getNetwork() const { return network_; }
57  auto const &getTransactionManager() const { return trx_mgr_; }
58  auto const &getDagManager() const { return dag_mgr_; }
59  auto const &getDB() const { return db_; }
60  auto const &getPbftManager() const { return pbft_mgr_; }
61  auto const &getVoteManager() const { return vote_mgr_; }
62  auto const &getPbftChain() const { return pbft_chain_; }
63  auto const &getFinalChain() const { return final_chain_; }
64  // used only in tests
66  auto const &getGasPricer() const { return gas_pricer_; }
67 
68  auto const &getAddress() const { return kp_.address(); }
69  auto const &getSecretKey() const { return kp_.secret(); }
70  auto const &getVrfSecretKey() const { return conf_.vrf_secret; }
71 
72  std::shared_ptr<pillar_chain::PillarChainManager> getPillarChainManager() const { return pillar_chain_mgr_; }
73 
74  // For Debug
75  uint64_t getProposedBlocksCount() const;
76 
77  void rebuildDb();
78 
79  private:
81 
82  // should be destroyed after all components, since they may depend on it through unsafe pointers
83  std::unique_ptr<util::ThreadPool> rpc_thread_pool_;
84  std::unique_ptr<util::ThreadPool> graphql_thread_pool_;
85 
86  // In cae we will you config for this TP, it needs to be unique_ptr !!!
88 
89  std::atomic<bool> stopped_ = true;
90  // configuration
92  // Ethereum key pair
94 
95  // components
96  std::shared_ptr<DbStorage> db_;
97  std::shared_ptr<DbStorage> old_db_;
98  std::shared_ptr<GasPricer> gas_pricer_;
99  std::shared_ptr<DagManager> dag_mgr_;
100  std::shared_ptr<TransactionManager> trx_mgr_;
101  std::shared_ptr<Network> network_;
102  std::shared_ptr<DagBlockProposer> dag_block_proposer_;
103  std::shared_ptr<VoteManager> vote_mgr_;
104  std::shared_ptr<PbftManager> pbft_mgr_;
105  std::shared_ptr<PbftChain> pbft_chain_;
106  std::shared_ptr<pillar_chain::PillarChainManager> pillar_chain_mgr_;
107  std::shared_ptr<KeyManager> key_manager_;
108  std::shared_ptr<final_chain::FinalChain> final_chain_;
109  std::shared_ptr<net::HttpServer> jsonrpc_http_;
110  std::shared_ptr<net::HttpServer> graphql_http_;
111  std::shared_ptr<net::WsServer> jsonrpc_ws_;
112  std::shared_ptr<net::WsServer> graphql_ws_;
113  std::unique_ptr<JsonRpcServer> jsonrpc_api_;
114  std::unique_ptr<metrics::MetricsService> metrics_;
115 
116  // logging
118 
119  std::atomic_bool started_ = 0;
120 
121  void init();
122  void close();
123 
128  void setupMetricsUpdaters();
129 };
130 
131 } // namespace taraxa
Definition: ModularServer.h:61
Definition: Common.h:154
Secret const & secret() const
Definition: Common.h:167
Address const & address() const
Retrieve the associated address of the public key.
Definition: Common.h:173
Definition: node.hpp:43
void setupMetricsUpdaters()
Method that is used to register metrics updaters. So we don't need to pass metrics classes instances ...
Definition: node.cpp:144
void start()
Definition: node.cpp:169
FullNode & operator=(FullNode &&)=delete
~FullNode()
Definition: node.cpp:39
void init()
Definition: node.cpp:41
auto const & getSecretKey() const
Definition: node.hpp:69
auto const & getConfig() const
Definition: node.hpp:55
auto const & getPbftChain() const
Definition: node.hpp:62
FullNode(FullNode &&)=delete
std::shared_ptr< net::WsServer > graphql_ws_
Definition: node.hpp:112
void close()
Definition: node.cpp:360
FullNode(const FullNode &)=delete
LOG_OBJECTS_DEFINE std::atomic_bool started_
Definition: node.hpp:119
bool isStarted() const
Definition: node.hpp:54
std::shared_ptr< DbStorage > db_
Definition: node.hpp:96
auto const & getVoteManager() const
Definition: node.hpp:61
auto const & getFinalChain() const
Definition: node.hpp:63
std::atomic< bool > stopped_
Definition: node.hpp:89
auto const & getNetwork() const
Definition: node.hpp:56
std::shared_ptr< net::HttpServer > jsonrpc_http_
Definition: node.hpp:109
std::unique_ptr< metrics::MetricsService > metrics_
Definition: node.hpp:114
auto const & getDagManager() const
Definition: node.hpp:58
auto const & getPbftManager() const
Definition: node.hpp:60
std::shared_ptr< net::WsServer > jsonrpc_ws_
Definition: node.hpp:111
FullNode(FullNodeConfig const &conf)
Definition: node.cpp:37
std::shared_ptr< Network > network_
Definition: node.hpp:101
auto const & getVrfSecretKey() const
Definition: node.hpp:70
void rebuildDb()
Definition: node.cpp:374
std::shared_ptr< final_chain::FinalChain > final_chain_
Definition: node.hpp:108
std::shared_ptr< PbftManager > pbft_mgr_
Definition: node.hpp:104
std::shared_ptr< GasPricer > gas_pricer_
Definition: node.hpp:98
auto const & getAddress() const
Definition: node.hpp:68
std::unique_ptr< util::ThreadPool > rpc_thread_pool_
Definition: node.hpp:83
std::shared_ptr< KeyManager > key_manager_
Definition: node.hpp:107
std::shared_ptr< PbftChain > pbft_chain_
Definition: node.hpp:105
std::shared_ptr< VoteManager > vote_mgr_
Definition: node.hpp:103
std::shared_ptr< DbStorage > old_db_
Definition: node.hpp:97
util::ThreadPool subscription_pool_
Definition: node.hpp:87
FullNode & operator=(const FullNode &)=delete
std::unique_ptr< util::ThreadPool > graphql_thread_pool_
Definition: node.hpp:84
auto const & getGasPricer() const
Definition: node.hpp:66
std::unique_ptr< JsonRpcServer > jsonrpc_api_
Definition: node.hpp:113
std::shared_ptr< pillar_chain::PillarChainManager > getPillarChainManager() const
Definition: node.hpp:72
FullNodeConfig conf_
Definition: node.hpp:91
auto & getDagBlockProposer()
Definition: node.hpp:65
dev::KeyPair kp_
Definition: node.hpp:93
uint64_t getProposedBlocksCount() const
Definition: node.cpp:443
std::shared_ptr< DagBlockProposer > dag_block_proposer_
Definition: node.hpp:102
auto const & getDB() const
Definition: node.hpp:59
std::shared_ptr< TransactionManager > trx_mgr_
Definition: node.hpp:100
std::shared_ptr< net::HttpServer > graphql_http_
Definition: node.hpp:110
std::shared_ptr< DagManager > dag_mgr_
Definition: node.hpp:99
std::shared_ptr< pillar_chain::PillarChainManager > pillar_chain_mgr_
Definition: node.hpp:106
auto const & getTransactionManager() const
Definition: node.hpp:57
class for metrics collecting. Registering specific metrics classes and creating prometheus server(exp...
Definition: metrics_service.hpp:16
Definition: thread_pool.hpp:9
#define LOG_OBJECTS_DEFINE
Definition: logger.hpp:60
Definition: config.hpp:8
Definition: config.hpp:24
vrf_wrapper::vrf_sk_t vrf_secret
Definition: config.hpp:45