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/logging.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();
31 const FullNodeConfig& getConfig() const { return conf_; }
32 std::shared_ptr<Network> getNetwork() const { return network_; }
33 std::shared_ptr<TransactionManager> getTransactionManager() const { return trx_mgr_; }
34 std::shared_ptr<DagManager> getDagManager() const { return dag_mgr_; }
35 std::shared_ptr<DbStorage> getDB() const { return db_; }
36 std::shared_ptr<PbftManager> getPbftManager() const { return pbft_mgr_; }
37 std::shared_ptr<VoteManager> getVoteManager() const { return vote_mgr_; }
38 std::shared_ptr<PbftChain> getPbftChain() const { return pbft_chain_; }
39 std::shared_ptr<final_chain::FinalChain> getFinalChain() const { return final_chain_; }
40 std::shared_ptr<metrics::MetricsService> getMetrics() const { return metrics_; }
41 // used only in tests
42 std::shared_ptr<DagBlockProposer> getDagBlockProposer() const { return dag_block_proposer_; }
43 std::shared_ptr<GasPricer> getGasPricer() const { return gas_pricer_; }
44 std::shared_ptr<pillar_chain::PillarChainManager> getPillarChainManager() const { return pillar_chain_mgr_; }
45
46 void rebuildDb();
47
48 void initialize(const std::filesystem::path& data_dir,
49 std::shared_ptr<boost::program_options::variables_map> options) const;
50
51 template <typename PluginType>
52 std::shared_ptr<PluginType> registerPlugin(cli::Config& cli_conf) {
53 auto plug = std::make_shared<PluginType>(shared_from_this());
54
55 std::string cli_plugin_desc = plug->name() + " plugin. " + plug->description() + "\nOptions";
56 boost::program_options::options_description plugin_cli_options(cli_plugin_desc);
57 plug->addOptions(plugin_cli_options);
58 if (!plugin_cli_options.options().empty()) {
59 cli_conf.addCliOptions(plugin_cli_options);
60 }
61
63
64 return plug;
65 }
66
67 std::string registeredPlugins() const {
68 std::string plugins;
69 return std::accumulate(available_plugins_.begin(), available_plugins_.end(), std::string(),
70 [](const auto& a, const auto& b) { return a.empty() ? b.first : a + " " + b.first; });
71 }
72 std::shared_ptr<Plugin> getPlugin(const std::string& name) const;
73
74 template <typename PluginType>
75 std::shared_ptr<PluginType> getPlugin(const std::string& name) const {
76 std::shared_ptr<Plugin> abs_plugin = getPlugin(name);
77 std::shared_ptr<PluginType> result = std::dynamic_pointer_cast<PluginType>(abs_plugin);
78
79 return result;
80 }
81 void addAvailablePlugin(std::shared_ptr<Plugin> plugin);
82
83 void enablePlugin(const std::string& name);
84
85 bool isPluginEnabled(const std::string& name) const;
86
87 private:
88 std::shared_ptr<util::ThreadPool> subscription_pool_ = std::make_shared<util::ThreadPool>(1);
90
91 // components
92 std::shared_ptr<DbStorage> db_;
93 std::shared_ptr<DbStorage> old_db_;
94 std::shared_ptr<GasPricer> gas_pricer_;
95 std::shared_ptr<DagManager> dag_mgr_;
96 std::shared_ptr<TransactionManager> trx_mgr_;
97 std::shared_ptr<Network> network_;
98 std::shared_ptr<DagBlockProposer> dag_block_proposer_;
99 std::shared_ptr<VoteManager> vote_mgr_;
100 std::shared_ptr<PbftManager> pbft_mgr_;
101 std::shared_ptr<PbftChain> pbft_chain_;
102 std::shared_ptr<pillar_chain::PillarChainManager> pillar_chain_mgr_;
103 std::shared_ptr<KeyManager> key_manager_;
104 std::shared_ptr<final_chain::FinalChain> final_chain_;
105 std::shared_ptr<metrics::MetricsService> metrics_;
106
107 std::map<std::string, std::shared_ptr<Plugin>> active_plugins_;
108 std::map<std::string, std::shared_ptr<Plugin>> available_plugins_;
109
110 void close();
111
117
118 // logging
120};
121
122} // namespace taraxa
Definition app_base.hpp:33
FullNodeConfig conf_
Definition app_base.hpp:65
Definition app.hpp:20
std::shared_ptr< final_chain::FinalChain > getFinalChain() const
Definition app.hpp:39
util::ThreadPool config_update_executor_
Definition app.hpp:89
std::shared_ptr< VoteManager > vote_mgr_
Definition app.hpp:99
virtual ~App()
Definition app.cpp:32
std::shared_ptr< DagBlockProposer > getDagBlockProposer() const
Definition app.hpp:42
App(const App &)=delete
std::shared_ptr< Network > getNetwork() const
Definition app.hpp:32
App()
Definition app.cpp:30
std::map< std::string, std::shared_ptr< Plugin > > available_plugins_
Definition app.hpp:108
std::shared_ptr< VoteManager > getVoteManager() const
Definition app.hpp:37
const FullNodeConfig & getConfig() const
Definition app.hpp:31
std::shared_ptr< DagManager > dag_mgr_
Definition app.hpp:95
std::shared_ptr< DbStorage > db_
Definition app.hpp:92
std::shared_ptr< pillar_chain::PillarChainManager > getPillarChainManager() const
Definition app.hpp:44
App & operator=(App &&)=delete
std::shared_ptr< PluginType > registerPlugin(cli::Config &cli_conf)
Definition app.hpp:52
std::shared_ptr< GasPricer > getGasPricer() const
Definition app.hpp:43
std::map< std::string, std::shared_ptr< Plugin > > active_plugins_
Definition app.hpp:107
std::shared_ptr< PluginType > getPlugin(const std::string &name) const
Definition app.hpp:75
std::shared_ptr< DagBlockProposer > dag_block_proposer_
Definition app.hpp:98
std::shared_ptr< metrics::MetricsService > metrics_
Definition app.hpp:105
std::shared_ptr< PbftManager > pbft_mgr_
Definition app.hpp:100
std::shared_ptr< PbftManager > getPbftManager() const
Definition app.hpp:36
std::shared_ptr< DagManager > getDagManager() const
Definition app.hpp:34
std::shared_ptr< KeyManager > key_manager_
Definition app.hpp:103
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:213
std::shared_ptr< DbStorage > old_db_
Definition app.hpp:93
App(App &&)=delete
std::shared_ptr< final_chain::FinalChain > final_chain_
Definition app.hpp:104
App & operator=(const App &)=delete
void addAvailablePlugin(std::shared_ptr< Plugin > plugin)
Definition app.cpp:34
std::shared_ptr< util::ThreadPool > subscription_pool_
Definition app.hpp:88
std::shared_ptr< DbStorage > getDB() const
Definition app.hpp:35
std::shared_ptr< TransactionManager > getTransactionManager() const
Definition app.hpp:33
std::shared_ptr< Plugin > getPlugin(const std::string &name) const
void rebuildDb()
Definition app.cpp:253
void start()
Definition app.cpp:155
void enablePlugin(const std::string &name)
Definition app.cpp:36
std::shared_ptr< TransactionManager > trx_mgr_
Definition app.hpp:96
logger::Logger logger_
Definition app.hpp:119
std::shared_ptr< PbftChain > getPbftChain() const
Definition app.hpp:38
std::shared_ptr< GasPricer > gas_pricer_
Definition app.hpp:94
std::string registeredPlugins() const
Definition app.hpp:67
bool isPluginEnabled(const std::string &name) const
Definition app.cpp:43
std::shared_ptr< PbftChain > pbft_chain_
Definition app.hpp:101
std::shared_ptr< pillar_chain::PillarChainManager > pillar_chain_mgr_
Definition app.hpp:102
void close()
Definition app.cpp:240
std::shared_ptr< Network > network_
Definition app.hpp:97
std::shared_ptr< metrics::MetricsService > getMetrics() const
Definition app.hpp:40
void init(const cli::Config &cli_conf)
Definition app.cpp:45
Definition plugin.hpp:9
Definition config.hpp:47
void addCliOptions(const bpo::options_description &options)
Definition config.cpp:16
Definition thread_pool.hpp:7
std::shared_ptr< spdlog::logger > Logger
Definition logging.hpp:12
Definition app.hpp:16
Definition config.hpp:41