hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
application.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_APPLICATION_HPP
7 #define IROHA_APPLICATION_HPP
8 
9 #include <optional>
10 
14 #include "cryptography/keypair.hpp"
17 #include "logger/logger_fwd.hpp"
22 #include "main/server_runner.hpp"
23 #include "main/startup_params.hpp"
25 #include "torii/tls_params.hpp"
26 
27 namespace iroha {
28  class PendingTransactionStorage;
29  class PendingTransactionStorageInit;
30  class MstProcessor;
31  namespace ametsuchi {
32  class WsvRestorer;
33  class TxPresenceCache;
34  class Storage;
35  class ReconnectionStrategyFactory;
36  class PostgresOptions;
37  struct PoolWrapper;
38  class VmCaller;
39  } // namespace ametsuchi
40  namespace consensus {
41  namespace yac {
42  class YacInit;
43  } // namespace yac
44  } // namespace consensus
45  namespace network {
46  class BlockLoader;
47  class ChannelPool;
48  class GenericClientFactory;
49  class ConsensusGate;
50  class MstTransport;
51  class OrderingGate;
52  class PeerCommunicationService;
53  class PeerTlsCertificatesProvider;
54  struct GrpcChannelParams;
55  struct TlsCredentials;
56  } // namespace network
57  namespace protocol {
58  class Query;
59  class BlocksQuery;
60  } // namespace protocol
61  namespace simulator {
62  class Simulator;
63  }
64  namespace synchronizer {
65  class Synchronizer;
66  }
67  namespace torii {
68  class QueryProcessor;
69  class StatusBus;
70  class CommandService;
72  class QueryService;
73 
74  struct TlsParams;
75  } // namespace torii
76  namespace validation {
77  class ChainValidator;
78  class StatefulValidator;
79  } // namespace validation
80 } // namespace iroha
81 
82 namespace shared_model {
83  namespace crypto {
84  class Keypair;
85  }
86  namespace interface {
87  class QueryResponseFactory;
88  class TransactionBatchFactory;
89  } // namespace interface
90  namespace validation {
91  struct Settings;
92  }
93 } // namespace shared_model
94 
95 class Irohad {
96  public:
98 
114  Irohad(const IrohadConfig &config,
115  std::unique_ptr<iroha::ametsuchi::PostgresOptions> pg_opt,
116  const std::string &listen_ip,
117  const boost::optional<shared_model::crypto::Keypair> &keypair,
118  logger::LoggerManagerTreePtr logger_manager,
119  iroha::StartupWsvDataPolicy startup_wsv_data_policy,
120  iroha::StartupWsvSynchronizationPolicy startup_wsv_sync_policy,
121  std::shared_ptr<const iroha::network::GrpcChannelParams>
122  grpc_channel_params,
123  const boost::optional<iroha::GossipPropagationStrategyParams>
124  &opt_mst_gossip_params,
125  boost::optional<IrohadConfig::InterPeerTls> inter_peer_tls_config =
126  boost::none);
127 
131  virtual RunResult init();
132 
137  RunResult restoreWsv();
138 
142  RunResult validateKeypair();
143 
147  virtual RunResult dropStorage();
148 
149  RunResult resetWsv();
150 
155  RunResult run();
156 
157  virtual ~Irohad();
158 
159  protected:
160  // -----------------------| component initialization |------------------------
161  virtual RunResult initStorage(
162  iroha::StartupWsvDataPolicy startup_wsv_data_policy);
163 
164  RunResult initTlsCredentials();
165 
166  RunResult initPeerCertProvider();
167 
168  RunResult initClientFactory();
169 
170  virtual RunResult initCryptoProvider();
171 
172  virtual RunResult initBatchParser();
173 
174  virtual RunResult initValidators();
175 
176  virtual RunResult initNetworkClient();
177 
178  virtual RunResult initFactories();
179 
180  virtual RunResult initPersistentCache();
181 
182  virtual RunResult initPendingTxsStorageWithCache();
183 
184  virtual RunResult initOrderingGate();
185 
186  virtual RunResult initSimulator();
187 
188  virtual RunResult initConsensusCache();
189 
190  virtual RunResult initBlockLoader();
191 
192  virtual RunResult initConsensusGate();
193 
194  virtual RunResult initSynchronizer();
195 
196  virtual RunResult initPeerCommunicationService();
197 
198  virtual RunResult initStatusBus();
199 
200  virtual RunResult initMstProcessor();
201 
202  virtual RunResult initPendingTxsStorage();
203 
204  virtual RunResult initTransactionCommandService();
205 
206  virtual RunResult initQueryService();
207 
208  virtual RunResult initSettings();
209 
210  virtual RunResult initValidatorsConfigs();
211 
215  virtual RunResult initWsvRestorer();
216 
217  // constructor dependencies
219  const std::string listen_ip_;
220  boost::optional<shared_model::crypto::Keypair> keypair_;
222  std::shared_ptr<const iroha::network::GrpcChannelParams> grpc_channel_params_;
223  boost::optional<iroha::GossipPropagationStrategyParams>
225  boost::optional<IrohadConfig::InterPeerTls> inter_peer_tls_config_;
226 
227  boost::optional<std::shared_ptr<const iroha::network::TlsCredentials>>
229  boost::optional<std::shared_ptr<const iroha::network::TlsCredentials>>
231  boost::optional<
232  std::shared_ptr<const iroha::network::PeerTlsCertificatesProvider>>
234 
235  std::unique_ptr<iroha::PendingTransactionStorageInit>
237 
238  // pending transactions storage
239  std::shared_ptr<iroha::PendingTransactionStorage> pending_txs_storage_;
240 
241  // query response factory
242  std::shared_ptr<shared_model::interface::QueryResponseFactory>
244 
245  // ------------------------| internal dependencies |-------------------------
246  std::optional<std::unique_ptr<iroha::ametsuchi::VmCaller>> vm_caller_;
247 
248  public:
249  std::unique_ptr<iroha::ametsuchi::PostgresOptions> pg_opt_;
250  std::shared_ptr<iroha::ametsuchi::Storage> storage;
251 
252  protected:
253  rxcpp::observable<shared_model::interface::types::HashType> finalized_txs_;
254 
255  // initialization objects
257  std::unique_ptr<iroha::consensus::yac::YacInit> yac_init;
259 
260  // IR-907 14.09.2020 @lebdron: remove it from here
261  std::shared_ptr<iroha::ametsuchi::PoolWrapper> pool_wrapper_;
262 
263  std::shared_ptr<iroha::network::GenericClientFactory>
265 
266  // Settings
267  std::shared_ptr<const shared_model::validation::Settings> settings_;
268 
269  // WSV restorer
270  std::shared_ptr<iroha::ametsuchi::WsvRestorer> wsv_restorer_;
271 
272  // crypto provider
276 
277  // batch parser
278  std::shared_ptr<shared_model::interface::TransactionBatchParser> batch_parser;
279 
280  // validators
281  std::shared_ptr<shared_model::validation::ValidatorsConfig>
283  std::shared_ptr<shared_model::validation::ValidatorsConfig>
285  std::shared_ptr<shared_model::validation::ValidatorsConfig>
287  std::shared_ptr<iroha::validation::StatefulValidator> stateful_validator;
288  std::shared_ptr<iroha::validation::ChainValidator> chain_validator;
289 
290  // async call
291  std::shared_ptr<iroha::network::AsyncGrpcClient<google::protobuf::Empty>>
293 
294  // transaction batch factory
295  std::shared_ptr<shared_model::interface::TransactionBatchFactory>
297 
298  // transaction factory
303 
304  // query factory
309 
310  // blocks query factory
313  iroha::protocol::BlocksQuery>>
315 
316  // persistent cache
317  std::shared_ptr<iroha::ametsuchi::TxPresenceCache> persistent_cache;
318 
319  // proposal factory
322  iroha::protocol::Proposal>>
324 
325  // ordering gate
326  std::shared_ptr<iroha::network::OrderingGate> ordering_gate;
327 
328  // simulator
329  std::shared_ptr<iroha::simulator::Simulator> simulator;
330 
331  // block cache for consensus and block loader
332  std::shared_ptr<iroha::consensus::ConsensusResultCache>
334 
335  // block loader
336  std::shared_ptr<iroha::network::BlockLoader> block_loader;
337 
338  // synchronizer
339  std::shared_ptr<iroha::synchronizer::Synchronizer> synchronizer;
340 
341  // pcs
342  std::shared_ptr<iroha::network::PeerCommunicationService> pcs;
343 
344  // status bus
345  std::shared_ptr<iroha::torii::StatusBus> status_bus_;
346 
347  // mst
348  std::shared_ptr<iroha::network::MstTransport> mst_transport;
349  std::shared_ptr<iroha::MstProcessor> mst_processor;
350 
351  // transaction service
352  std::shared_ptr<iroha::torii::CommandService> command_service;
353  std::shared_ptr<iroha::torii::CommandServiceTransportGrpc>
355 
356  // query service
357  std::shared_ptr<iroha::torii::QueryService> query_service;
358 
359  // consensus gate
360  std::shared_ptr<iroha::network::ConsensusGate> consensus_gate;
361  rxcpp::composite_subscription consensus_gate_objects_lifetime;
362  rxcpp::subjects::subject<iroha::consensus::GateObject> consensus_gate_objects;
363  rxcpp::composite_subscription consensus_gate_events_subscription;
364 
365  std::unique_ptr<iroha::network::ServerRunner> torii_server;
366  boost::optional<std::unique_ptr<iroha::network::ServerRunner>>
367  torii_tls_server = boost::none;
368  std::unique_ptr<iroha::network::ServerRunner> internal_server;
369 
371 
373 };
374 
375 #endif // IROHA_APPLICATION_HPP
std::shared_ptr< iroha::torii::StatusBus > status_bus_
Definition: application.hpp:345
StartupWsvSynchronizationPolicy
Definition: startup_params.hpp:21
std::shared_ptr< iroha::ametsuchi::PoolWrapper > pool_wrapper_
Definition: application.hpp:261
std::shared_ptr< shared_model::crypto::AbstractCryptoModelSigner< shared_model::interface::Block > > crypto_signer_
Definition: application.hpp:275
iroha::network::BlockLoaderInit loader_init
Definition: application.hpp:258
std::shared_ptr< iroha::torii::CommandServiceTransportGrpc > command_service_transport
Definition: application.hpp:354
Definition: on_demand_ordering_init.hpp:70
std::shared_ptr< iroha::PendingTransactionStorage > pending_txs_storage_
Definition: application.hpp:239
Definition: command_client.hpp:16
iroha::ordering::OnDemandOrderingInit ordering_init
Definition: application.hpp:256
Definition: query.hpp:36
std::shared_ptr< iroha::validation::StatefulValidator > stateful_validator
Definition: application.hpp:287
std::shared_ptr< iroha::network::AsyncGrpcClient< google::protobuf::Empty > > async_call_
Definition: application.hpp:292
std::shared_ptr< iroha::network::GenericClientFactory > inter_peer_client_factory_
Definition: application.hpp:264
Definition: block_loader_init.hpp:24
Definition: synchronizer.hpp:19
std::unique_ptr< iroha::ametsuchi::PostgresOptions > pg_opt_
Definition: application.hpp:249
Definition: blocks_query.hpp:20
std::shared_ptr< iroha::ametsuchi::Storage > storage
Definition: application.hpp:250
Definition: result_fwd.hpp:27
logger::LoggerManagerTreePtr log_manager_
application root log manager
Definition: application.hpp:370
Definition: proposal.hpp:17
std::shared_ptr< shared_model::interface::AbstractTransportFactory< shared_model::interface::Query, iroha::protocol::Query > > query_factory
Definition: application.hpp:308
std::shared_ptr< const iroha::network::GrpcChannelParams > grpc_channel_params_
Definition: application.hpp:222
boost::optional< std::shared_ptr< const iroha::network::TlsCredentials > > my_inter_peer_tls_creds_
Definition: application.hpp:228
std::shared_ptr< iroha::network::PeerCommunicationService > pcs
Definition: application.hpp:342
rxcpp::composite_subscription consensus_gate_events_subscription
Definition: application.hpp:363
std::shared_ptr< shared_model::interface::AbstractTransportFactory< shared_model::interface::Transaction, iroha::protocol::Transaction > > transaction_factory
Definition: application.hpp:302
std::shared_ptr< Logger > LoggerPtr
Definition: logger_fwd.hpp:22
std::shared_ptr< iroha::MstProcessor > mst_processor
Definition: application.hpp:349
std::shared_ptr< iroha::ametsuchi::WsvRestorer > wsv_restorer_
Definition: application.hpp:270
std::shared_ptr< shared_model::interface::TransactionBatchParser > batch_parser
Definition: application.hpp:278
std::shared_ptr< iroha::network::ConsensusGate > consensus_gate
Definition: application.hpp:360
iroha::StartupWsvSynchronizationPolicy startup_wsv_sync_policy_
Definition: application.hpp:221
Definition: block.hpp:16
boost::optional< std::shared_ptr< const iroha::network::TlsCredentials > > torii_tls_creds_
Definition: application.hpp:230
std::shared_ptr< shared_model::validation::ValidatorsConfig > validators_config_
Definition: application.hpp:282
std::shared_ptr< iroha::consensus::ConsensusResultCache > consensus_result_cache_
Definition: application.hpp:333
expected::Result< std::shared_ptr< iroha::ametsuchi::Storage >, std::string > initStorage(iroha::ametsuchi::PostgresOptions const &pg_opt, std::shared_ptr< iroha::ametsuchi::PoolWrapper > pool_wrapper, std::shared_ptr< iroha::PendingTransactionStorage > pending_txs_storage, std::shared_ptr< shared_model::interface::QueryResponseFactory > query_response_factory, boost::optional< std::string > block_storage_dir, std::optional< std::reference_wrapper< const iroha::ametsuchi::VmCaller >> vm_caller_ref, logger::LoggerManagerTreePtr log_manager)
std::shared_ptr< const shared_model::validation::Settings > settings_
Definition: application.hpp:267
std::unique_ptr< iroha::consensus::yac::YacInit > yac_init
Definition: application.hpp:257
std::shared_ptr< iroha::ametsuchi::TxPresenceCache > persistent_cache
Definition: application.hpp:317
Definition: block_query.hpp:15
StartupWsvDataPolicy
Definition: startup_params.hpp:13
Definition: iroha_conf_loader.hpp:20
std::shared_ptr< iroha::validation::ChainValidator > chain_validator
Definition: application.hpp:288
IrohadConfig config_
Definition: application.hpp:218
Definition: query_service.hpp:35
Definition: application.hpp:95
std::shared_ptr< LoggerManagerTree > LoggerManagerTreePtr
Definition: logger_manager_fwd.hpp:14
std::shared_ptr< iroha::network::OrderingGate > ordering_gate
Definition: application.hpp:326
boost::optional< shared_model::crypto::Keypair > keypair_
Definition: application.hpp:220
std::shared_ptr< shared_model::interface::AbstractTransportFactory< shared_model::interface::Proposal, iroha::protocol::Proposal > > proposal_factory
Definition: application.hpp:323
logger::LoggerPtr log_
log for local messages
Definition: application.hpp:372
std::shared_ptr< shared_model::validation::ValidatorsConfig > block_validators_config_
Definition: application.hpp:286
rxcpp::observable< shared_model::interface::types::HashType > finalized_txs_
Definition: application.hpp:253
std::shared_ptr< iroha::simulator::Simulator > simulator
Definition: application.hpp:329
boost::optional< iroha::GossipPropagationStrategyParams > opt_mst_gossip_params_
Definition: application.hpp:224
rxcpp::composite_subscription consensus_gate_objects_lifetime
Definition: application.hpp:361
rxcpp::subjects::subject< iroha::consensus::GateObject > consensus_gate_objects
Definition: application.hpp:362
std::shared_ptr< shared_model::interface::TransactionBatchFactory > transaction_batch_factory_
Definition: application.hpp:296
boost::optional< std::shared_ptr< const iroha::network::PeerTlsCertificatesProvider > > peer_tls_certificates_provider_
Definition: application.hpp:233
std::unique_ptr< iroha::network::ServerRunner > torii_server
Definition: application.hpp:365
Definition: status_bus.hpp:17
Definition: command_service.hpp:26
std::unique_ptr< iroha::network::ServerRunner > internal_server
Definition: application.hpp:368
std::shared_ptr< iroha::torii::CommandService > command_service
Definition: application.hpp:352
std::shared_ptr< shared_model::interface::AbstractTransportFactory< shared_model::interface::BlocksQuery, iroha::protocol::BlocksQuery > > blocks_query_factory
Definition: application.hpp:314
std::shared_ptr< iroha::synchronizer::Synchronizer > synchronizer
Definition: application.hpp:339
Definition: command_executor.hpp:12
const std::string listen_ip_
Definition: application.hpp:219
Definition: on_demand_ordering_init.hpp:33
std::shared_ptr< iroha::torii::QueryService > query_service
Definition: application.hpp:357
Definition: transaction.hpp:23
std::shared_ptr< shared_model::interface::QueryResponseFactory > query_response_factory_
Definition: application.hpp:243
Definition: tls_params.hpp:23
Definition: command_service_transport_grpc.hpp:34
std::shared_ptr< shared_model::validation::ValidatorsConfig > proposal_validators_config_
Definition: application.hpp:284
std::unique_ptr< iroha::PendingTransactionStorageInit > pending_txs_storage_init
Definition: application.hpp:236
std::optional< std::unique_ptr< iroha::ametsuchi::VmCaller > > vm_caller_
Definition: application.hpp:246
Definition: query_processor.hpp:31
boost::optional< IrohadConfig::InterPeerTls > inter_peer_tls_config_
Definition: application.hpp:225
std::shared_ptr< iroha::network::BlockLoader > block_loader
Definition: application.hpp:336
std::shared_ptr< iroha::network::MstTransport > mst_transport
Definition: application.hpp:348
Definition: abstract_crypto_model_signer.hpp:16