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 
12 #include "cryptography/keypair.hpp"
15 #include "logger/logger_fwd.hpp"
20 #include "main/server_runner.hpp"
22 #include "torii/tls_params.hpp"
23 
24 namespace iroha {
25  class PendingTransactionStorage;
26  class PendingTransactionStorageInit;
27  class MstProcessor;
28  namespace ametsuchi {
29  class WsvRestorer;
30  class TxPresenceCache;
31  class Storage;
32  class ReconnectionStrategyFactory;
33  class PostgresOptions;
34  struct PoolWrapper;
35  } // namespace ametsuchi
36  namespace consensus {
37  namespace yac {
38  class YacInit;
39  } // namespace yac
40  } // namespace consensus
41  namespace network {
42  class BlockLoader;
43  class ConsensusGate;
44  class MstTransport;
45  class OrderingGate;
46  class PeerCommunicationService;
47  class PeerTlsCertificatesProvider;
48  struct TlsCredentials;
49  } // namespace network
50  namespace simulator {
51  class Simulator;
52  }
53  namespace synchronizer {
54  class Synchronizer;
55  }
56  namespace torii {
57  class QueryProcessor;
58  class StatusBus;
59  class CommandService;
61  class QueryService;
62 
63  struct TlsParams;
64  } // namespace torii
65  namespace validation {
66  class ChainValidator;
67  class StatefulValidator;
68  } // namespace validation
69 } // namespace iroha
70 
71 namespace shared_model {
72  namespace crypto {
73  class Keypair;
74  }
75  namespace interface {
76  class QueryResponseFactory;
77  class TransactionBatchFactory;
78  } // namespace interface
79 } // namespace shared_model
80 
81 class Irohad {
82  public:
83  using RunResult = iroha::expected::Result<void, std::string>;
84 
113  Irohad(const boost::optional<std::string> &block_store_dir,
114  std::unique_ptr<iroha::ametsuchi::PostgresOptions> pg_opt,
115  const std::string &listen_ip,
116  size_t torii_port,
117  size_t internal_port,
118  size_t max_proposal_size,
119  std::chrono::milliseconds proposal_delay,
120  std::chrono::milliseconds vote_delay,
121  std::chrono::minutes mst_expiration_time,
122  const shared_model::crypto::Keypair &keypair,
123  std::chrono::milliseconds max_rounds_delay,
124  size_t stale_stream_max_rounds,
125  boost::optional<shared_model::interface::types::PeerList>
126  opt_alternative_peers,
127  logger::LoggerManagerTreePtr logger_manager,
128  const boost::optional<iroha::GossipPropagationStrategyParams>
129  &opt_mst_gossip_params = boost::none,
130  const boost::optional<iroha::torii::TlsParams> &torii_tls_params =
131  boost::none,
132  boost::optional<IrohadConfig::InterPeerTls> inter_peer_tls_config =
133  boost::none);
134 
138  virtual RunResult init();
139 
144  RunResult restoreWsv();
145 
149  virtual void dropStorage();
150 
155  RunResult run();
156 
157  virtual ~Irohad();
158 
159  protected:
160  // -----------------------| component initialization |------------------------
161  virtual RunResult initStorage(
162  std::unique_ptr<iroha::ametsuchi::PostgresOptions> pg_opt);
163 
164  RunResult initTlsCredentials();
165 
166  RunResult initPeerCertProvider();
167 
168  virtual RunResult initCryptoProvider();
169 
170  virtual RunResult initBatchParser();
171 
172  virtual RunResult initValidators();
173 
174  virtual RunResult initNetworkClient();
175 
176  virtual RunResult initFactories();
177 
178  virtual RunResult initPersistentCache();
179 
180  virtual RunResult initOrderingGate();
181 
182  virtual RunResult initSimulator();
183 
184  virtual RunResult initConsensusCache();
185 
186  virtual RunResult initBlockLoader();
187 
188  virtual RunResult initConsensusGate();
189 
190  virtual RunResult initSynchronizer();
191 
192  virtual RunResult initPeerCommunicationService();
193 
194  virtual RunResult initStatusBus();
195 
196  virtual RunResult initMstProcessor();
197 
198  virtual RunResult initPendingTxsStorage();
199 
200  virtual RunResult initTransactionCommandService();
201 
202  virtual RunResult initQueryService();
203 
204  virtual RunResult initSettings();
205 
206  virtual RunResult initValidatorsConfigs();
207 
211  virtual RunResult initWsvRestorer();
212 
213  // constructor dependencies
214  const boost::optional<std::string> block_store_dir_;
215  const std::string listen_ip_;
216  size_t torii_port_;
217  boost::optional<iroha::torii::TlsParams> torii_tls_params_;
220  std::chrono::milliseconds proposal_delay_;
221  std::chrono::milliseconds vote_delay_;
223  std::chrono::minutes mst_expiration_time_;
224  std::chrono::milliseconds max_rounds_delay_;
226  const boost::optional<shared_model::interface::types::PeerList>
228  boost::optional<iroha::GossipPropagationStrategyParams>
230  boost::optional<IrohadConfig::InterPeerTls> inter_peer_tls_config_;
231 
232  boost::optional<std::shared_ptr<const iroha::network::TlsCredentials>>
234  boost::optional<std::shared_ptr<const iroha::network::TlsCredentials>>
236  boost::optional<
237  std::shared_ptr<const iroha::network::PeerTlsCertificatesProvider>>
239 
240  std::unique_ptr<iroha::PendingTransactionStorageInit>
242 
243  // pending transactions storage
244  std::shared_ptr<iroha::PendingTransactionStorage> pending_txs_storage_;
245 
246  // query response factory
247  std::shared_ptr<shared_model::interface::QueryResponseFactory>
249 
250  // ------------------------| internal dependencies |-------------------------
251  public:
253  std::shared_ptr<iroha::ametsuchi::Storage> storage;
254 
255  protected:
256  // initialization objects
258  std::unique_ptr<iroha::consensus::yac::YacInit> yac_init;
260 
261  std::shared_ptr<iroha::ametsuchi::PoolWrapper> pool_wrapper_;
262 
263  // Settings
264  std::shared_ptr<const shared_model::validation::Settings> settings_;
265 
266  // WSV restorer
267  std::shared_ptr<iroha::ametsuchi::WsvRestorer> wsv_restorer_;
268 
269  // crypto provider
273 
274  // batch parser
275  std::shared_ptr<shared_model::interface::TransactionBatchParser> batch_parser;
276 
277  // validators
278  std::shared_ptr<shared_model::validation::ValidatorsConfig>
280  std::shared_ptr<shared_model::validation::ValidatorsConfig>
282  std::shared_ptr<shared_model::validation::ValidatorsConfig>
284  std::shared_ptr<iroha::validation::StatefulValidator> stateful_validator;
285  std::shared_ptr<iroha::validation::ChainValidator> chain_validator;
286 
287  // async call
288  std::shared_ptr<iroha::network::AsyncGrpcClient<google::protobuf::Empty>>
290 
291  // transaction batch factory
292  std::shared_ptr<shared_model::interface::TransactionBatchFactory>
294 
295  // transaction factory
300 
301  // query factory
306 
307  // blocks query factory
310  iroha::protocol::BlocksQuery>>
312 
313  // persistent cache
314  std::shared_ptr<iroha::ametsuchi::TxPresenceCache> persistent_cache;
315 
316  // proposal factory
319  iroha::protocol::Proposal>>
321 
322  // ordering gate
323  std::shared_ptr<iroha::network::OrderingGate> ordering_gate;
324 
325  // simulator
326  std::shared_ptr<iroha::simulator::Simulator> simulator;
327 
328  // block cache for consensus and block loader
329  std::shared_ptr<iroha::consensus::ConsensusResultCache>
331 
332  // block loader
333  std::shared_ptr<iroha::network::BlockLoader> block_loader;
334 
335  // synchronizer
336  std::shared_ptr<iroha::synchronizer::Synchronizer> synchronizer;
337 
338  // pcs
339  std::shared_ptr<iroha::network::PeerCommunicationService> pcs;
340 
341  // status bus
342  std::shared_ptr<iroha::torii::StatusBus> status_bus_;
343 
344  // mst
345  std::shared_ptr<iroha::network::MstTransport> mst_transport;
346  std::shared_ptr<iroha::MstProcessor> mst_processor;
347 
348  // transaction service
349  std::shared_ptr<iroha::torii::CommandService> command_service;
350  std::shared_ptr<iroha::torii::CommandServiceTransportGrpc>
352 
353  // query service
354  std::shared_ptr<iroha::torii::QueryService> query_service;
355 
356  // consensus gate
357  std::shared_ptr<iroha::network::ConsensusGate> consensus_gate;
358  rxcpp::composite_subscription consensus_gate_objects_lifetime;
359  rxcpp::subjects::subject<iroha::consensus::GateObject> consensus_gate_objects;
360  rxcpp::composite_subscription consensus_gate_events_subscription;
361 
362  std::unique_ptr<iroha::network::ServerRunner> torii_server;
363  boost::optional<std::unique_ptr<iroha::network::ServerRunner>>
364  torii_tls_server = boost::none;
365  std::unique_ptr<iroha::network::ServerRunner> internal_server;
366 
368 
370 };
371 
372 #endif // IROHA_APPLICATION_HPP
iroha::expected::Result< void, std::string > RunResult
Definition: application.hpp:83
std::shared_ptr< iroha::torii::StatusBus > status_bus_
Definition: application.hpp:342
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:272
iroha::network::BlockLoaderInit loader_init
Definition: application.hpp:259
std::shared_ptr< iroha::torii::CommandServiceTransportGrpc > command_service_transport
Definition: application.hpp:351
std::shared_ptr< iroha::PendingTransactionStorage > pending_txs_storage_
Definition: application.hpp:244
Definition: command_client.hpp:16
bool is_mst_supported_
Definition: application.hpp:222
Definition: query.hpp:35
std::shared_ptr< iroha::validation::StatefulValidator > stateful_validator
Definition: application.hpp:284
std::shared_ptr< iroha::network::AsyncGrpcClient< google::protobuf::Empty > > async_call_
Definition: application.hpp:289
std::chrono::minutes mst_expiration_time_
Definition: application.hpp:223
Definition: block_loader_init.hpp:22
Definition: synchronizer.hpp:19
Definition: blocks_query.hpp:20
Definition: keypair.hpp:19
std::shared_ptr< iroha::ametsuchi::Storage > storage
Definition: application.hpp:253
logger::LoggerManagerTreePtr log_manager_
application root log manager
Definition: application.hpp:367
size_t internal_port_
Definition: application.hpp:218
Definition: proposal.hpp:17
std::shared_ptr< shared_model::interface::AbstractTransportFactory< shared_model::interface::Query, iroha::protocol::Query > > query_factory
Definition: application.hpp:305
const boost::optional< shared_model::interface::types::PeerList > opt_alternative_peers_
Definition: application.hpp:227
boost::optional< std::shared_ptr< const iroha::network::TlsCredentials > > my_inter_peer_tls_creds_
Definition: application.hpp:233
std::shared_ptr< iroha::network::PeerCommunicationService > pcs
Definition: application.hpp:339
rxcpp::composite_subscription consensus_gate_events_subscription
Definition: application.hpp:360
std::shared_ptr< shared_model::interface::AbstractTransportFactory< shared_model::interface::Transaction, iroha::protocol::Transaction > > transaction_factory
Definition: application.hpp:299
std::shared_ptr< Logger > LoggerPtr
Definition: logger_fwd.hpp:22
std::shared_ptr< iroha::MstProcessor > mst_processor
Definition: application.hpp:346
std::shared_ptr< iroha::ametsuchi::WsvRestorer > wsv_restorer_
Definition: application.hpp:267
std::shared_ptr< shared_model::interface::TransactionBatchParser > batch_parser
Definition: application.hpp:275
size_t stale_stream_max_rounds_
Definition: application.hpp:225
std::shared_ptr< iroha::network::ConsensusGate > consensus_gate
Definition: application.hpp:357
Definition: stateful_validator.hpp:19
std::chrono::milliseconds proposal_delay_
Definition: application.hpp:220
Definition: block.hpp:16
boost::optional< std::shared_ptr< const iroha::network::TlsCredentials > > torii_tls_creds_
Definition: application.hpp:235
std::chrono::milliseconds max_rounds_delay_
Definition: application.hpp:224
std::shared_ptr< shared_model::validation::ValidatorsConfig > validators_config_
Definition: application.hpp:279
Definition: chain_validator.hpp:30
std::shared_ptr< iroha::consensus::ConsensusResultCache > consensus_result_cache_
Definition: application.hpp:330
std::shared_ptr< const shared_model::validation::Settings > settings_
Definition: application.hpp:264
std::unique_ptr< iroha::consensus::yac::YacInit > yac_init
Definition: application.hpp:258
std::shared_ptr< iroha::ametsuchi::TxPresenceCache > persistent_cache
Definition: application.hpp:314
Definition: block_query.hpp:14
iroha::network::OnDemandOrderingInit ordering_init
Definition: application.hpp:257
std::chrono::milliseconds vote_delay_
Definition: application.hpp:221
const boost::optional< std::string > block_store_dir_
Definition: application.hpp:214
std::shared_ptr< iroha::validation::ChainValidator > chain_validator
Definition: application.hpp:285
Definition: query_service.hpp:35
Definition: application.hpp:81
std::shared_ptr< LoggerManagerTree > LoggerManagerTreePtr
Definition: logger_manager_fwd.hpp:14
std::shared_ptr< iroha::network::OrderingGate > ordering_gate
Definition: application.hpp:323
std::shared_ptr< shared_model::interface::AbstractTransportFactory< shared_model::interface::Proposal, iroha::protocol::Proposal > > proposal_factory
Definition: application.hpp:320
logger::LoggerPtr log_
log for local messages
Definition: application.hpp:369
std::shared_ptr< shared_model::validation::ValidatorsConfig > block_validators_config_
Definition: application.hpp:283
Definition: on_demand_ordering_init.hpp:32
std::shared_ptr< iroha::simulator::Simulator > simulator
Definition: application.hpp:326
boost::optional< iroha::GossipPropagationStrategyParams > opt_mst_gossip_params_
Definition: application.hpp:229
rxcpp::composite_subscription consensus_gate_objects_lifetime
Definition: application.hpp:358
rxcpp::subjects::subject< iroha::consensus::GateObject > consensus_gate_objects
Definition: application.hpp:359
std::shared_ptr< shared_model::interface::TransactionBatchFactory > transaction_batch_factory_
Definition: application.hpp:293
boost::optional< std::shared_ptr< const iroha::network::PeerTlsCertificatesProvider > > peer_tls_certificates_provider_
Definition: application.hpp:238
std::unique_ptr< iroha::network::ServerRunner > torii_server
Definition: application.hpp:362
Definition: status_bus.hpp:17
Definition: command_service.hpp:26
std::unique_ptr< iroha::network::ServerRunner > internal_server
Definition: application.hpp:365
shared_model::crypto::Keypair keypair
Definition: application.hpp:252
std::shared_ptr< iroha::torii::CommandService > command_service
Definition: application.hpp:349
std::shared_ptr< shared_model::interface::AbstractTransportFactory< shared_model::interface::BlocksQuery, iroha::protocol::BlocksQuery > > blocks_query_factory
Definition: application.hpp:311
std::shared_ptr< iroha::synchronizer::Synchronizer > synchronizer
Definition: application.hpp:336
size_t torii_port_
Definition: application.hpp:216
Definition: command_executor.hpp:12
const std::string listen_ip_
Definition: application.hpp:215
std::shared_ptr< iroha::torii::QueryService > query_service
Definition: application.hpp:354
Definition: transaction.hpp:23
std::shared_ptr< shared_model::interface::QueryResponseFactory > query_response_factory_
Definition: application.hpp:248
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:281
size_t max_proposal_size_
Definition: application.hpp:219
std::unique_ptr< iroha::PendingTransactionStorageInit > pending_txs_storage_init
Definition: application.hpp:241
Definition: query_processor.hpp:28
boost::optional< IrohadConfig::InterPeerTls > inter_peer_tls_config_
Definition: application.hpp:230
std::shared_ptr< iroha::network::BlockLoader > block_loader
Definition: application.hpp:333
boost::optional< iroha::torii::TlsParams > torii_tls_params_
Definition: application.hpp:217
std::shared_ptr< iroha::network::MstTransport > mst_transport
Definition: application.hpp:345
Definition: abstract_crypto_model_signer.hpp:16