TARAXA
Loading...
Searching...
No Matches
app.hpp
Go to the documentation of this file.
1#pragma once
3
4#include <boost/program_options/options_description.hpp>
5#include <boost/program_options/variables_map.hpp>
6#include <memory>
7
8#include "cli/config.hpp"
9#include "common/app_base.hpp"
11#include "config/config.hpp"
13#include "logger/logger.hpp"
14#include "plugin/plugin.hpp"
15
16namespace taraxa {
17
18class Plugin;
19
20class App : public std::enable_shared_from_this<App>, public AppBase {
21 public:
22 App();
23 virtual ~App();
24
25 App(const App&) = delete;
26 App(App&&) = delete;
27 App& operator=(const App&) = delete;
28 App& operator=(App&&) = delete;
29 void init(const cli::Config& cli_conf);
30 void start();
32 const FullNodeConfig& getConfig() const { return conf_; }
33 std::shared_ptr<Network> getNetwork() const { return network_; }
34 std::shared_ptr<TransactionManager> getTransactionManager() const { return trx_mgr_; }
35 std::shared_ptr<DagManager> getDagManager() const { return dag_mgr_; }
36 std::shared_ptr<DbStorage> getDB() const { return db_; }
37 std::shared_ptr<PbftManager> getPbftManager() const { return pbft_mgr_; }
38 std::shared_ptr<VoteManager> getVoteManager() const { return vote_mgr_; }
39 std::shared_ptr<PbftChain> getPbftChain() const { return pbft_chain_; }
40 std::shared_ptr<final_chain::FinalChain> getFinalChain() const { return final_chain_; }
41 std::shared_ptr<metrics::MetricsService> getMetrics() const { return metrics_; }
42 // used only in tests
43 std::shared_ptr<DagBlockProposer> getDagBlockProposer() const { return dag_block_proposer_; }
44 std::shared_ptr<GasPricer> getGasPricer() const { return gas_pricer_; }
45 std::shared_ptr<pillar_chain::PillarChainManager> getPillarChainManager() const { return pillar_chain_mgr_; }
46
47 void rebuildDb();
48
49 void initialize(const std::filesystem::path& data_dir,
50 std::shared_ptr<boost::program_options::variables_map> options) const;
51
52 template <typename PluginType>
53 std::shared_ptr<PluginType> registerPlugin(cli::Config& cli_conf) {
54 auto plug = std::make_shared<PluginType>(shared_from_this());
55
56 std::string cli_plugin_desc = plug->name() + " plugin. " + plug->description() + "\nOptions";
57 boost::program_options::options_description plugin_cli_options(cli_plugin_desc);
58 plug->addOptions(plugin_cli_options);
59 if (!plugin_cli_options.options().empty()) {
60 cli_conf.addCliOptions(plugin_cli_options);
61 }
62
64
65 return plug;
66 }
67
68 std::string registeredPlugins() const {
69 std::string plugins;
70 return std::accumulate(available_plugins_.begin(), available_plugins_.end(), std::string(),
71 [](const auto& a, const auto& b) { return a.empty() ? b.first : a + " " + b.first; });
72 }
73 std::shared_ptr<Plugin> getPlugin(const std::string& name) const;
74
75 template <typename PluginType>
76 std::shared_ptr<PluginType> getPlugin(const std::string& name) const {
77 std::shared_ptr<Plugin> abs_plugin = getPlugin(name);
78 std::shared_ptr<PluginType> result = std::dynamic_pointer_cast<PluginType>(abs_plugin);
79
80 return result;
81 }
82 void addAvailablePlugin(std::shared_ptr<Plugin> plugin);
83
84 void enablePlugin(const std::string& name);
85
86 bool isPluginEnabled(const std::string& name) const;
87
89
90 private:
91 std::shared_ptr<util::ThreadPool> subscription_pool_ = std::make_shared<util::ThreadPool>(1);
93
94 // components
95 std::shared_ptr<DbStorage> db_;
96 std::shared_ptr<DbStorage> old_db_;
97 std::shared_ptr<GasPricer> gas_pricer_;
98 std::shared_ptr<DagManager> dag_mgr_;
99 std::shared_ptr<TransactionManager> trx_mgr_;
100 std::shared_ptr<Network> network_;
101 std::shared_ptr<DagBlockProposer> dag_block_proposer_;
102 std::shared_ptr<VoteManager> vote_mgr_;
103 std::shared_ptr<PbftManager> pbft_mgr_;
104 std::shared_ptr<PbftChain> pbft_chain_;
105 std::shared_ptr<pillar_chain::PillarChainManager> pillar_chain_mgr_;
106 std::shared_ptr<KeyManager> key_manager_;
107 std::shared_ptr<final_chain::FinalChain> final_chain_;
108 std::shared_ptr<metrics::MetricsService> metrics_;
109
110 std::map<std::string, std::shared_ptr<Plugin>> active_plugins_;
111 std::map<std::string, std::shared_ptr<Plugin>> available_plugins_;
112
113 void close();
114
120
121 // logging
123};
124
125} // namespace taraxa
Definition app_base.hpp:34
FullNodeConfig conf_
Definition app_base.hpp:69
Definition app.hpp:20
std::shared_ptr< final_chain::FinalChain > getFinalChain() const
Definition app.hpp:40
util::ThreadPool config_update_executor_
Definition app.hpp:92
std::shared_ptr< VoteManager > vote_mgr_
Definition app.hpp:102
virtual ~App()
Definition app.cpp:34
std::shared_ptr< DagBlockProposer > getDagBlockProposer() const
Definition app.hpp:43
App(const App &)=delete
std::shared_ptr< Network > getNetwork() const
Definition app.hpp:33
void scheduleLoggingConfigUpdate()
Definition app.cpp:231
App()
Definition app.cpp:32
std::map< std::string, std::shared_ptr< Plugin > > available_plugins_
Definition app.hpp:111
std::shared_ptr< VoteManager > getVoteManager() const
Definition app.hpp:38
const FullNodeConfig & getConfig() const
Definition app.hpp:32
std::shared_ptr< DagManager > dag_mgr_
Definition app.hpp:98
std::shared_ptr< DbStorage > db_
Definition app.hpp:95
std::shared_ptr< pillar_chain::PillarChainManager > getPillarChainManager() const
Definition app.hpp:45
App & operator=(App &&)=delete
std::shared_ptr< PluginType > registerPlugin(cli::Config &cli_conf)
Definition app.hpp:53
std::shared_ptr< GasPricer > getGasPricer() const
Definition app.hpp:44
std::map< std::string, std::shared_ptr< Plugin > > active_plugins_
Definition app.hpp:110
std::shared_ptr< PluginType > getPlugin(const std::string &name) const
Definition app.hpp:76
std::shared_ptr< DagBlockProposer > dag_block_proposer_
Definition app.hpp:101
std::shared_ptr< metrics::MetricsService > metrics_
Definition app.hpp:108
std::shared_ptr< PbftManager > pbft_mgr_
Definition app.hpp:103
std::shared_ptr< PbftManager > getPbftManager() const
Definition app.hpp:37
std::shared_ptr< DagManager > getDagManager() const
Definition app.hpp:35
std::shared_ptr< KeyManager > key_manager_
Definition app.hpp:106
void initialize(const std::filesystem::path &data_dir, std::shared_ptr< boost::program_options::variables_map > options) const
void setupMetricsUpdaters()
Method that is used to register metrics updaters. So we don't need to pass metrics classes instances ...
Definition app.cpp:263
std::shared_ptr< DbStorage > old_db_
Definition app.hpp:96
App(App &&)=delete
std::shared_ptr< final_chain::FinalChain > final_chain_
Definition app.hpp:107
App & operator=(const App &)=delete
void addAvailablePlugin(std::shared_ptr< Plugin > plugin)
Definition app.cpp:36
std::shared_ptr< util::ThreadPool > subscription_pool_
Definition app.hpp:91
std::shared_ptr< DbStorage > getDB() const
Definition app.hpp:36
std::shared_ptr< TransactionManager > getTransactionManager() const
Definition app.hpp:34
std::shared_ptr< Plugin > getPlugin(const std::string &name) const
Definition app.cpp:38
void rebuildDb()
Definition app.cpp:300
void start()
Definition app.cpp:170
void enablePlugin(const std::string &name)
Definition app.cpp:46
std::shared_ptr< TransactionManager > trx_mgr_
Definition app.hpp:99
std::shared_ptr< PbftChain > getPbftChain() const
Definition app.hpp:39
std::shared_ptr< GasPricer > gas_pricer_
Definition app.hpp:97
std::string registeredPlugins() const
Definition app.hpp:68
bool isPluginEnabled(const std::string &name) const
Definition app.cpp:53
std::shared_ptr< PbftChain > pbft_chain_
Definition app.hpp:104
FullNodeConfig & getMutableConfig()
Definition app.hpp:31
std::shared_ptr< pillar_chain::PillarChainManager > pillar_chain_mgr_
Definition app.hpp:105
void close()
Definition app.cpp:290
std::shared_ptr< Network > network_
Definition app.hpp:100
std::shared_ptr< metrics::MetricsService > getMetrics() const
Definition app.hpp:41
void init(const cli::Config &cli_conf)
Definition app.cpp:55
Definition plugin.hpp:9
Definition config.hpp:46
void addCliOptions(const bpo::options_description &options)
Definition config.cpp:16
Definition thread_pool.hpp:7
#define LOG_OBJECTS_DEFINE
Definition logger.hpp:60
Definition app.hpp:16
Definition config.hpp:40