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"
21 #include "main/server_runner.hpp"
22 #include "main/startup_params.hpp"
25 #include "torii/tls_params.hpp"
26 
27 namespace google::protobuf {
28  class Empty;
29 }
30 
31 namespace iroha {
32  class PendingTransactionStorage;
33  class MstProcessor;
34  class MstStorage;
35  namespace ametsuchi {
36  class WsvRestorer;
37  class TxPresenceCache;
38  class Storage;
39  class ReconnectionStrategyFactory;
40  class PostgresOptions;
41  class RocksDbOptions;
42  struct PoolWrapper;
43  struct RocksDBContext;
44  class VmCaller;
45  } // namespace ametsuchi
46  namespace consensus {
47  namespace yac {
48  class YacInit;
49  } // namespace yac
50  } // namespace consensus
51  namespace network {
52  template <typename Response>
54  class BlockLoader;
55  class ChannelPool;
57  class ConsensusGate;
58  class MstTransport;
59  class OrderingGate;
62  struct GrpcChannelParams;
63  struct TlsCredentials;
64  } // namespace network
65  namespace ordering {
67  }
68  namespace protocol {
69  class Proposal;
70  class Query;
71  class BlocksQuery;
72  } // namespace protocol
73  namespace simulator {
74  class Simulator;
75  }
76  namespace synchronizer {
77  class Synchronizer;
78  }
79  namespace torii {
80  class QueryProcessor;
81  class StatusBus;
82  class CommandService;
84  class QueryService;
86  struct TlsParams;
87  } // namespace torii
88  namespace validation {
89  class ChainValidator;
90  class StatefulValidator;
91  } // namespace validation
92 } // namespace iroha
93 
94 namespace shared_model {
95  namespace crypto {
96  class Keypair;
97  }
98  namespace interface {
99  template <typename Interface, typename Transport>
101  class Proposal;
102  class QueryResponseFactory;
105  } // namespace interface
106  namespace validation {
107  struct Settings;
108  }
109 } // namespace shared_model
110 
111 class Irohad {
112  public:
114 
131  Irohad(const IrohadConfig &config,
132  std::unique_ptr<iroha::ametsuchi::PostgresOptions> pg_opt,
133  std::unique_ptr<iroha::ametsuchi::RocksDbOptions> rdb_opt,
134  const std::string &listen_ip,
135  const boost::optional<shared_model::crypto::Keypair> &keypair,
136  logger::LoggerManagerTreePtr logger_manager,
137  iroha::StartupWsvDataPolicy startup_wsv_data_policy,
138  iroha::StartupWsvSynchronizationPolicy startup_wsv_sync_policy,
139  std::optional<std::shared_ptr<const iroha::network::GrpcChannelParams>>
140  maybe_grpc_channel_params,
141  const boost::optional<iroha::GossipPropagationStrategyParams>
142  &opt_mst_gossip_params,
143  boost::optional<IrohadConfig::InterPeerTls> inter_peer_tls_config =
144  boost::none);
145 
149  virtual RunResult init();
150 
155  RunResult restoreWsv();
156 
160  RunResult validateKeypair();
161 
165  virtual RunResult dropStorage();
166 
167  RunResult resetWsv();
168 
173  RunResult run();
174 
175  virtual ~Irohad();
176 
177  protected:
178  // -----------------------| component initialization |------------------------
179  virtual RunResult initStorage(
180  iroha::StartupWsvDataPolicy startup_wsv_data_policy,
181  iroha::StorageType type);
182 
183  RunResult initTlsCredentials();
184 
185  RunResult initPeerCertProvider();
186 
187  RunResult initClientFactory();
188 
189  virtual RunResult initCryptoProvider();
190 
191  virtual RunResult initBatchParser();
192 
193  virtual RunResult initValidators();
194 
195  virtual RunResult initNetworkClient();
196 
197  virtual RunResult initFactories();
198 
199  virtual RunResult initPersistentCache();
200 
201  virtual RunResult initPendingTxsStorageWithCache();
202 
203  virtual RunResult initOrderingGate();
204 
205  virtual RunResult initSimulator();
206 
207  virtual RunResult initConsensusCache();
208 
209  virtual RunResult initBlockLoader();
210 
211  virtual RunResult initConsensusGate();
212 
213  virtual RunResult initSynchronizer();
214 
215  virtual RunResult initPeerCommunicationService();
216 
217  virtual RunResult initStatusBus();
218 
219  virtual RunResult initMstProcessor();
220 
221  virtual RunResult initPendingTxsStorage();
222 
223  virtual RunResult initTransactionCommandService();
224 
225  virtual RunResult initQueryService();
226 
227  virtual RunResult initSettings();
228 
229  virtual RunResult initValidatorsConfigs();
230 
234  virtual RunResult initWsvRestorer();
235 
236  // constructor dependencies
238  const std::string listen_ip_;
239  boost::optional<shared_model::crypto::Keypair> keypair_;
241  std::optional<std::shared_ptr<const iroha::network::GrpcChannelParams>>
243  boost::optional<iroha::GossipPropagationStrategyParams>
245  boost::optional<IrohadConfig::InterPeerTls> inter_peer_tls_config_;
246 
247  boost::optional<std::shared_ptr<const iroha::network::TlsCredentials>>
249  boost::optional<std::shared_ptr<const iroha::network::TlsCredentials>>
251  boost::optional<
252  std::shared_ptr<const iroha::network::PeerTlsCertificatesProvider>>
254 
255  // pending transactions storage
256  std::shared_ptr<iroha::PendingTransactionStorage> pending_txs_storage_;
257 
258  // query response factory
259  std::shared_ptr<shared_model::interface::QueryResponseFactory>
261 
262  // ------------------------| internal dependencies |-------------------------
263  std::optional<std::unique_ptr<iroha::ametsuchi::VmCaller>> vm_caller_;
264  std::shared_ptr<iroha::ametsuchi::RocksDBContext> db_context_;
265 
266  public:
267  std::unique_ptr<iroha::ametsuchi::PostgresOptions> pg_opt_;
268  std::unique_ptr<iroha::ametsuchi::RocksDbOptions> rdb_opt_;
269  std::shared_ptr<iroha::ametsuchi::Storage> storage;
270 
271  protected:
272  std::shared_ptr<iroha::Subscription> subscription_engine_;
273 
274  // initialization objects
275  std::shared_ptr<iroha::ordering::OnDemandOrderingInit> ordering_init;
276  std::shared_ptr<iroha::consensus::yac::YacInit> yac_init;
278 
279  // IR-907 14.09.2020 @lebdron: remove it from here
280  std::shared_ptr<iroha::ametsuchi::PoolWrapper> pool_wrapper_;
281 
282  std::shared_ptr<iroha::network::GenericClientFactory>
284 
285  // Settings
286  std::shared_ptr<const shared_model::validation::Settings> settings_;
287 
288  // WSV restorer
289  std::shared_ptr<iroha::ametsuchi::WsvRestorer> wsv_restorer_;
290 
291  // crypto provider
295 
296  // batch parser
297  std::shared_ptr<shared_model::interface::TransactionBatchParser> batch_parser;
298 
299  // validators
300  std::shared_ptr<shared_model::validation::ValidatorsConfig>
302  std::shared_ptr<shared_model::validation::ValidatorsConfig>
304  std::shared_ptr<shared_model::validation::ValidatorsConfig>
306  std::shared_ptr<iroha::validation::StatefulValidator> stateful_validator;
307  std::shared_ptr<iroha::validation::ChainValidator> chain_validator;
308 
309  // async call
310  std::shared_ptr<iroha::network::AsyncGrpcClient<google::protobuf::Empty>>
312 
313  // transaction batch factory
314  std::shared_ptr<shared_model::interface::TransactionBatchFactory>
316 
317  // transaction factory
322 
323  // query factory
328 
329  // blocks query factory
332  iroha::protocol::BlocksQuery>>
334 
335  // persistent cache
336  std::shared_ptr<iroha::ametsuchi::TxPresenceCache> persistent_cache;
337 
338  // proposal factory
341  iroha::protocol::Proposal>>
343 
344  // ordering gate
345  std::shared_ptr<iroha::network::OrderingGate> ordering_gate;
346 
347  // simulator
348  std::shared_ptr<iroha::simulator::Simulator> simulator;
349 
350  // block cache for consensus and block loader
351  std::shared_ptr<iroha::consensus::ConsensusResultCache>
353 
354  // block loader
355  std::shared_ptr<iroha::network::BlockLoader> block_loader;
356 
357  // synchronizer
358  std::shared_ptr<iroha::synchronizer::Synchronizer> synchronizer;
359 
360  // pcs
361  std::shared_ptr<iroha::network::PeerCommunicationService> pcs;
362 
363  // status bus
364  std::shared_ptr<iroha::torii::StatusBus> status_bus_;
365 
366  // mst
367  std::shared_ptr<iroha::MstStorage> mst_storage;
368  std::shared_ptr<iroha::network::MstTransport> mst_transport;
369  std::shared_ptr<iroha::MstProcessor> mst_processor;
370 
371  // transaction service
372  std::shared_ptr<iroha::torii::TransactionProcessor> tx_processor;
373  std::shared_ptr<iroha::torii::CommandService> command_service;
374  std::shared_ptr<iroha::torii::CommandServiceTransportGrpc>
376 
377  // query service
378  std::shared_ptr<iroha::torii::QueryService> query_service;
379 
380  // consensus gate
381  std::shared_ptr<iroha::network::ConsensusGate> consensus_gate;
382 
383  std::unique_ptr<iroha::network::ServerRunner> torii_server;
384  boost::optional<std::unique_ptr<iroha::network::ServerRunner>>
385  torii_tls_server = boost::none;
386  std::unique_ptr<iroha::network::ServerRunner> internal_server;
387 
389 
391 };
392 
393 #endif // IROHA_APPLICATION_HPP
std::shared_ptr< iroha::torii::StatusBus > status_bus_
Definition: application.hpp:364
StartupWsvSynchronizationPolicy
Definition: startup_params.hpp:26
Definition: transaction_processor.hpp:28
std::shared_ptr< iroha::ametsuchi::PoolWrapper > pool_wrapper_
Definition: application.hpp:280
Definition: block_query.hpp:17
std::shared_ptr< shared_model::crypto::AbstractCryptoModelSigner< shared_model::interface::Block > > crypto_signer_
Definition: application.hpp:294
iroha::network::BlockLoaderInit loader_init
Definition: application.hpp:277
Definition: ordering_gate.hpp:27
std::shared_ptr< iroha::torii::CommandServiceTransportGrpc > command_service_transport
Definition: application.hpp:375
std::shared_ptr< iroha::Subscription > subscription_engine_
Definition: application.hpp:272
Definition: on_demand_ordering_init.hpp:67
std::shared_ptr< iroha::PendingTransactionStorage > pending_txs_storage_
Definition: application.hpp:256
Definition: command_client.hpp:16
std::shared_ptr< iroha::ordering::OnDemandOrderingInit > ordering_init
Definition: application.hpp:275
Definition: query.hpp:36
std::shared_ptr< iroha::validation::StatefulValidator > stateful_validator
Definition: application.hpp:306
std::shared_ptr< iroha::ametsuchi::RocksDBContext > db_context_
Definition: application.hpp:264
std::shared_ptr< iroha::network::AsyncGrpcClient< google::protobuf::Empty > > async_call_
Definition: application.hpp:311
std::shared_ptr< iroha::network::GenericClientFactory > inter_peer_client_factory_
Definition: application.hpp:283
Definition: block_loader_init.hpp:24
Definition: synchronizer.hpp:19
std::unique_ptr< iroha::ametsuchi::PostgresOptions > pg_opt_
Definition: application.hpp:267
Definition: channel_pool.hpp:14
Definition: blocks_query.hpp:20
Definition: peer_communication_service.hpp:24
std::shared_ptr< iroha::ametsuchi::Storage > storage
Definition: application.hpp:269
Definition: query_response_factory.hpp:39
Definition: result_fwd.hpp:27
logger::LoggerManagerTreePtr log_manager_
application root log manager
Definition: application.hpp:388
Definition: proposal.hpp:17
Definition: application.hpp:27
std::shared_ptr< shared_model::interface::AbstractTransportFactory< shared_model::interface::Query, iroha::protocol::Query > > query_factory
Definition: application.hpp:327
std::optional< std::shared_ptr< const iroha::network::GrpcChannelParams > > maybe_grpc_channel_params_
Definition: application.hpp:242
boost::optional< std::shared_ptr< const iroha::network::TlsCredentials > > my_inter_peer_tls_creds_
Definition: application.hpp:248
Definition: grpc_channel_params.hpp:16
std::shared_ptr< iroha::network::PeerCommunicationService > pcs
Definition: application.hpp:361
std::shared_ptr< shared_model::interface::AbstractTransportFactory< shared_model::interface::Transaction, iroha::protocol::Transaction > > transaction_factory
Definition: application.hpp:321
std::shared_ptr< Logger > LoggerPtr
Definition: logger_fwd.hpp:22
std::shared_ptr< iroha::consensus::yac::YacInit > yac_init
Definition: application.hpp:276
std::shared_ptr< iroha::MstProcessor > mst_processor
Definition: application.hpp:369
expected::Result< std::shared_ptr< iroha::ametsuchi::Storage >, std::string > initStorage(std::shared_ptr< ametsuchi::RocksDBContext > db_context, 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, std::function< void(std::shared_ptr< shared_model::interface::Block const >)> callback, logger::LoggerManagerTreePtr log_manager)
Definition: storage_init.cpp:91
std::shared_ptr< iroha::ametsuchi::WsvRestorer > wsv_restorer_
Definition: application.hpp:289
std::shared_ptr< shared_model::interface::TransactionBatchParser > batch_parser
Definition: application.hpp:297
std::shared_ptr< iroha::network::ConsensusGate > consensus_gate
Definition: application.hpp:381
iroha::StartupWsvSynchronizationPolicy startup_wsv_sync_policy_
Definition: application.hpp:240
Definition: block.hpp:16
boost::optional< std::shared_ptr< const iroha::network::TlsCredentials > > torii_tls_creds_
Definition: application.hpp:250
std::shared_ptr< shared_model::validation::ValidatorsConfig > validators_config_
Definition: application.hpp:301
Definition: block_loader.hpp:36
std::shared_ptr< iroha::consensus::ConsensusResultCache > consensus_result_cache_
Definition: application.hpp:352
std::shared_ptr< const shared_model::validation::Settings > settings_
Definition: application.hpp:286
std::shared_ptr< iroha::ametsuchi::TxPresenceCache > persistent_cache
Definition: application.hpp:336
std::shared_ptr< iroha::MstStorage > mst_storage
Definition: application.hpp:367
Definition: block_query.hpp:15
Definition: peer_tls_certificates_provider.hpp:25
StartupWsvDataPolicy
Definition: startup_params.hpp:13
Definition: iroha_conf_loader.hpp:23
std::shared_ptr< iroha::validation::ChainValidator > chain_validator
Definition: application.hpp:307
IrohadConfig config_
Definition: application.hpp:237
Definition: query_service.hpp:32
Definition: application.hpp:111
std::shared_ptr< LoggerManagerTree > LoggerManagerTreePtr
Definition: logger_manager_fwd.hpp:14
Definition: generic_client_factory.hpp:17
std::shared_ptr< iroha::network::OrderingGate > ordering_gate
Definition: application.hpp:345
boost::optional< shared_model::crypto::Keypair > keypair_
Definition: application.hpp:239
Definition: transaction_batch_parser.hpp:18
std::shared_ptr< shared_model::interface::AbstractTransportFactory< shared_model::interface::Proposal, iroha::protocol::Proposal > > proposal_factory
Definition: application.hpp:342
logger::LoggerPtr log_
log for local messages
Definition: application.hpp:390
std::shared_ptr< shared_model::validation::ValidatorsConfig > block_validators_config_
Definition: application.hpp:305
std::shared_ptr< iroha::torii::TransactionProcessor > tx_processor
Definition: application.hpp:372
Definition: mst_transport.hpp:42
std::shared_ptr< iroha::simulator::Simulator > simulator
Definition: application.hpp:348
boost::optional< iroha::GossipPropagationStrategyParams > opt_mst_gossip_params_
Definition: application.hpp:244
Definition: consensus_gate.hpp:20
std::shared_ptr< shared_model::interface::TransactionBatchFactory > transaction_batch_factory_
Definition: application.hpp:315
boost::optional< std::shared_ptr< const iroha::network::PeerTlsCertificatesProvider > > peer_tls_certificates_provider_
Definition: application.hpp:253
std::unique_ptr< iroha::network::ServerRunner > torii_server
Definition: application.hpp:383
Definition: status_bus.hpp:15
Definition: command_service.hpp:22
Definition: transaction_batch_factory.hpp:23
std::unique_ptr< iroha::network::ServerRunner > internal_server
Definition: application.hpp:386
std::shared_ptr< iroha::torii::CommandService > command_service
Definition: application.hpp:373
std::shared_ptr< shared_model::interface::AbstractTransportFactory< shared_model::interface::BlocksQuery, iroha::protocol::BlocksQuery > > blocks_query_factory
Definition: application.hpp:333
std::shared_ptr< iroha::synchronizer::Synchronizer > synchronizer
Definition: application.hpp:358
Definition: application.hpp:53
Definition: command_executor.hpp:13
const std::string listen_ip_
Definition: application.hpp:238
std::unique_ptr< iroha::ametsuchi::RocksDbOptions > rdb_opt_
Definition: application.hpp:268
StorageType
Definition: startup_params.hpp:18
std::shared_ptr< iroha::torii::QueryService > query_service
Definition: application.hpp:378
Definition: transaction.hpp:23
std::shared_ptr< shared_model::interface::QueryResponseFactory > query_response_factory_
Definition: application.hpp:260
Definition: tls_params.hpp:23
Definition: command_service_transport_grpc.hpp:28
std::shared_ptr< shared_model::validation::ValidatorsConfig > proposal_validators_config_
Definition: application.hpp:303
std::optional< std::unique_ptr< iroha::ametsuchi::VmCaller > > vm_caller_
Definition: application.hpp:263
Definition: query_processor.hpp:28
boost::optional< IrohadConfig::InterPeerTls > inter_peer_tls_config_
Definition: application.hpp:245
std::shared_ptr< iroha::network::BlockLoader > block_loader
Definition: application.hpp:355
std::shared_ptr< iroha::network::MstTransport > mst_transport
Definition: application.hpp:368
Definition: cluster_order.hpp:16
Definition: tls_credentials.hpp:16
Definition: abstract_crypto_model_signer.hpp:16