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 ConsensusGate;
48  class MstTransport;
49  class OrderingGate;
50  class PeerCommunicationService;
51  class PeerTlsCertificatesProvider;
52  struct TlsCredentials;
53  } // namespace network
54  namespace simulator {
55  class Simulator;
56  }
57  namespace synchronizer {
58  class Synchronizer;
59  }
60  namespace torii {
61  class QueryProcessor;
62  class StatusBus;
63  class CommandService;
65  class QueryService;
66 
67  struct TlsParams;
68  } // namespace torii
69  namespace validation {
70  class ChainValidator;
71  class StatefulValidator;
72  } // namespace validation
73 } // namespace iroha
74 
75 namespace shared_model {
76  namespace crypto {
77  class Keypair;
78  }
79  namespace interface {
80  class QueryResponseFactory;
81  class TransactionBatchFactory;
82  } // namespace interface
83 } // namespace shared_model
84 
85 class Irohad {
86  public:
88 
118  Irohad(const boost::optional<std::string> &block_store_dir,
119  std::unique_ptr<iroha::ametsuchi::PostgresOptions> pg_opt,
120  const std::string &listen_ip,
121  size_t torii_port,
122  size_t internal_port,
123  size_t max_proposal_size,
124  std::chrono::milliseconds proposal_delay,
125  std::chrono::milliseconds vote_delay,
126  std::chrono::minutes mst_expiration_time,
127  const shared_model::crypto::Keypair &keypair,
128  std::chrono::milliseconds max_rounds_delay,
129  size_t stale_stream_max_rounds,
130  boost::optional<shared_model::interface::types::PeerList>
131  opt_alternative_peers,
132  logger::LoggerManagerTreePtr logger_manager,
133  iroha::StartupWsvDataPolicy startup_wsv_data_policy,
134  const boost::optional<iroha::GossipPropagationStrategyParams>
135  &opt_mst_gossip_params = boost::none,
136  const boost::optional<iroha::torii::TlsParams> &torii_tls_params =
137  boost::none,
138  boost::optional<IrohadConfig::InterPeerTls> inter_peer_tls_config =
139  boost::none);
140 
144  virtual RunResult init();
145 
150  RunResult restoreWsv();
151 
155  RunResult validateKeypair();
156 
160  virtual RunResult dropStorage();
161 
162  RunResult resetWsv();
163 
168  RunResult run();
169 
170  virtual ~Irohad();
171 
172  protected:
173  // -----------------------| component initialization |------------------------
174  virtual RunResult initStorage(
175  iroha::StartupWsvDataPolicy startup_wsv_data_policy);
176 
177  RunResult initTlsCredentials();
178 
179  RunResult initPeerCertProvider();
180 
181  virtual RunResult initCryptoProvider();
182 
183  virtual RunResult initBatchParser();
184 
185  virtual RunResult initValidators();
186 
187  virtual RunResult initNetworkClient();
188 
189  virtual RunResult initFactories();
190 
191  virtual RunResult initPersistentCache();
192 
193  virtual RunResult initPendingTxsStorageWithCache();
194 
195  virtual RunResult initOrderingGate();
196 
197  virtual RunResult initSimulator();
198 
199  virtual RunResult initConsensusCache();
200 
201  virtual RunResult initBlockLoader();
202 
203  virtual RunResult initConsensusGate();
204 
205  virtual RunResult initSynchronizer();
206 
207  virtual RunResult initPeerCommunicationService();
208 
209  virtual RunResult initStatusBus();
210 
211  virtual RunResult initMstProcessor();
212 
213  virtual RunResult initPendingTxsStorage();
214 
215  virtual RunResult initTransactionCommandService();
216 
217  virtual RunResult initQueryService();
218 
219  virtual RunResult initSettings();
220 
221  virtual RunResult initValidatorsConfigs();
222 
226  virtual RunResult initWsvRestorer();
227 
228  // constructor dependencies
229  const boost::optional<std::string> block_store_dir_;
230  const std::string listen_ip_;
231  size_t torii_port_;
232  boost::optional<iroha::torii::TlsParams> torii_tls_params_;
235  std::chrono::milliseconds proposal_delay_;
236  std::chrono::milliseconds vote_delay_;
238  std::chrono::minutes mst_expiration_time_;
239  std::chrono::milliseconds max_rounds_delay_;
241  const boost::optional<shared_model::interface::types::PeerList>
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  std::unique_ptr<iroha::PendingTransactionStorageInit>
257 
258  // pending transactions storage
259  std::shared_ptr<iroha::PendingTransactionStorage> pending_txs_storage_;
260 
261  // query response factory
262  std::shared_ptr<shared_model::interface::QueryResponseFactory>
264 
265  // ------------------------| internal dependencies |-------------------------
266  std::optional<std::unique_ptr<iroha::ametsuchi::VmCaller>> vm_caller_;
267 
268  public:
270  std::unique_ptr<iroha::ametsuchi::PostgresOptions> pg_opt_;
271  std::shared_ptr<iroha::ametsuchi::Storage> storage;
272 
273  protected:
274  rxcpp::observable<shared_model::interface::types::HashType> finalized_txs_;
275 
276  // initialization objects
278  std::unique_ptr<iroha::consensus::yac::YacInit> yac_init;
280 
281  std::shared_ptr<iroha::ametsuchi::PoolWrapper> pool_wrapper_;
282 
283  // Settings
284  std::shared_ptr<const shared_model::validation::Settings> settings_;
285 
286  // WSV restorer
287  std::shared_ptr<iroha::ametsuchi::WsvRestorer> wsv_restorer_;
288 
289  // crypto provider
293 
294  // batch parser
295  std::shared_ptr<shared_model::interface::TransactionBatchParser> batch_parser;
296 
297  // validators
298  std::shared_ptr<shared_model::validation::ValidatorsConfig>
300  std::shared_ptr<shared_model::validation::ValidatorsConfig>
302  std::shared_ptr<shared_model::validation::ValidatorsConfig>
304  std::shared_ptr<iroha::validation::StatefulValidator> stateful_validator;
305  std::shared_ptr<iroha::validation::ChainValidator> chain_validator;
306 
307  // async call
308  std::shared_ptr<iroha::network::AsyncGrpcClient<google::protobuf::Empty>>
310 
311  // transaction batch factory
312  std::shared_ptr<shared_model::interface::TransactionBatchFactory>
314 
315  // transaction factory
320 
321  // query factory
326 
327  // blocks query factory
330  iroha::protocol::BlocksQuery>>
332 
333  // persistent cache
334  std::shared_ptr<iroha::ametsuchi::TxPresenceCache> persistent_cache;
335 
336  // proposal factory
339  iroha::protocol::Proposal>>
341 
342  // ordering gate
343  std::shared_ptr<iroha::network::OrderingGate> ordering_gate;
344 
345  // simulator
346  std::shared_ptr<iroha::simulator::Simulator> simulator;
347 
348  // block cache for consensus and block loader
349  std::shared_ptr<iroha::consensus::ConsensusResultCache>
351 
352  // block loader
353  std::shared_ptr<iroha::network::BlockLoader> block_loader;
354 
355  // synchronizer
356  std::shared_ptr<iroha::synchronizer::Synchronizer> synchronizer;
357 
358  // pcs
359  std::shared_ptr<iroha::network::PeerCommunicationService> pcs;
360 
361  // status bus
362  std::shared_ptr<iroha::torii::StatusBus> status_bus_;
363 
364  // mst
365  std::shared_ptr<iroha::network::MstTransport> mst_transport;
366  std::shared_ptr<iroha::MstProcessor> mst_processor;
367 
368  // transaction service
369  std::shared_ptr<iroha::torii::CommandService> command_service;
370  std::shared_ptr<iroha::torii::CommandServiceTransportGrpc>
372 
373  // query service
374  std::shared_ptr<iroha::torii::QueryService> query_service;
375 
376  // consensus gate
377  std::shared_ptr<iroha::network::ConsensusGate> consensus_gate;
378  rxcpp::composite_subscription consensus_gate_objects_lifetime;
379  rxcpp::subjects::subject<iroha::consensus::GateObject> consensus_gate_objects;
380  rxcpp::composite_subscription consensus_gate_events_subscription;
381 
382  std::unique_ptr<iroha::network::ServerRunner> torii_server;
383  boost::optional<std::unique_ptr<iroha::network::ServerRunner>>
384  torii_tls_server = boost::none;
385  std::unique_ptr<iroha::network::ServerRunner> internal_server;
386 
388 
390 };
391 
392 #endif // IROHA_APPLICATION_HPP
std::shared_ptr< iroha::torii::StatusBus > status_bus_
Definition: application.hpp:362
std::shared_ptr< iroha::ametsuchi::PoolWrapper > pool_wrapper_
Definition: application.hpp:281
std::shared_ptr< shared_model::crypto::AbstractCryptoModelSigner< shared_model::interface::Block > > crypto_signer_
Definition: application.hpp:292
iroha::network::BlockLoaderInit loader_init
Definition: application.hpp:279
std::shared_ptr< iroha::torii::CommandServiceTransportGrpc > command_service_transport
Definition: application.hpp:371
std::shared_ptr< iroha::PendingTransactionStorage > pending_txs_storage_
Definition: application.hpp:259
Definition: command_client.hpp:16
bool is_mst_supported_
Definition: application.hpp:237
Definition: query.hpp:36
std::shared_ptr< iroha::validation::StatefulValidator > stateful_validator
Definition: application.hpp:304
std::shared_ptr< iroha::network::AsyncGrpcClient< google::protobuf::Empty > > async_call_
Definition: application.hpp:309
std::chrono::minutes mst_expiration_time_
Definition: application.hpp:238
Definition: block_loader_init.hpp:22
Definition: synchronizer.hpp:19
std::unique_ptr< iroha::ametsuchi::PostgresOptions > pg_opt_
Definition: application.hpp:270
Definition: blocks_query.hpp:20
Definition: keypair.hpp:19
std::shared_ptr< iroha::ametsuchi::Storage > storage
Definition: application.hpp:271
Definition: result_fwd.hpp:27
logger::LoggerManagerTreePtr log_manager_
application root log manager
Definition: application.hpp:387
size_t internal_port_
Definition: application.hpp:233
Definition: proposal.hpp:17
std::shared_ptr< shared_model::interface::AbstractTransportFactory< shared_model::interface::Query, iroha::protocol::Query > > query_factory
Definition: application.hpp:325
const boost::optional< shared_model::interface::types::PeerList > opt_alternative_peers_
Definition: application.hpp:242
boost::optional< std::shared_ptr< const iroha::network::TlsCredentials > > my_inter_peer_tls_creds_
Definition: application.hpp:248
std::shared_ptr< iroha::network::PeerCommunicationService > pcs
Definition: application.hpp:359
rxcpp::composite_subscription consensus_gate_events_subscription
Definition: application.hpp:380
std::shared_ptr< shared_model::interface::AbstractTransportFactory< shared_model::interface::Transaction, iroha::protocol::Transaction > > transaction_factory
Definition: application.hpp:319
std::shared_ptr< Logger > LoggerPtr
Definition: logger_fwd.hpp:22
std::shared_ptr< iroha::MstProcessor > mst_processor
Definition: application.hpp:366
std::shared_ptr< iroha::ametsuchi::WsvRestorer > wsv_restorer_
Definition: application.hpp:287
std::shared_ptr< shared_model::interface::TransactionBatchParser > batch_parser
Definition: application.hpp:295
size_t stale_stream_max_rounds_
Definition: application.hpp:240
std::shared_ptr< iroha::network::ConsensusGate > consensus_gate
Definition: application.hpp:377
Definition: stateful_validator.hpp:19
std::chrono::milliseconds proposal_delay_
Definition: application.hpp:235
Definition: block.hpp:16
boost::optional< std::shared_ptr< const iroha::network::TlsCredentials > > torii_tls_creds_
Definition: application.hpp:250
std::chrono::milliseconds max_rounds_delay_
Definition: application.hpp:239
std::shared_ptr< shared_model::validation::ValidatorsConfig > validators_config_
Definition: application.hpp:299
Definition: chain_validator.hpp:30
std::shared_ptr< iroha::consensus::ConsensusResultCache > consensus_result_cache_
Definition: application.hpp:350
std::shared_ptr< const shared_model::validation::Settings > settings_
Definition: application.hpp:284
std::unique_ptr< iroha::consensus::yac::YacInit > yac_init
Definition: application.hpp:278
std::shared_ptr< iroha::ametsuchi::TxPresenceCache > persistent_cache
Definition: application.hpp:334
Definition: block_query.hpp:15
iroha::network::OnDemandOrderingInit ordering_init
Definition: application.hpp:277
std::chrono::milliseconds vote_delay_
Definition: application.hpp:236
StartupWsvDataPolicy
Policy regarging possible existing WSV data at startup.
Definition: startup_params.hpp:11
const boost::optional< std::string > block_store_dir_
Definition: application.hpp:229
std::shared_ptr< iroha::validation::ChainValidator > chain_validator
Definition: application.hpp:305
Definition: query_service.hpp:35
Definition: application.hpp:85
std::shared_ptr< LoggerManagerTree > LoggerManagerTreePtr
Definition: logger_manager_fwd.hpp:14
std::shared_ptr< iroha::network::OrderingGate > ordering_gate
Definition: application.hpp:343
std::shared_ptr< shared_model::interface::AbstractTransportFactory< shared_model::interface::Proposal, iroha::protocol::Proposal > > proposal_factory
Definition: application.hpp:340
logger::LoggerPtr log_
log for local messages
Definition: application.hpp:389
std::shared_ptr< shared_model::validation::ValidatorsConfig > block_validators_config_
Definition: application.hpp:303
Definition: on_demand_ordering_init.hpp:30
rxcpp::observable< shared_model::interface::types::HashType > finalized_txs_
Definition: application.hpp:274
std::shared_ptr< iroha::simulator::Simulator > simulator
Definition: application.hpp:346
boost::optional< iroha::GossipPropagationStrategyParams > opt_mst_gossip_params_
Definition: application.hpp:244
rxcpp::composite_subscription consensus_gate_objects_lifetime
Definition: application.hpp:378
rxcpp::subjects::subject< iroha::consensus::GateObject > consensus_gate_objects
Definition: application.hpp:379
std::shared_ptr< shared_model::interface::TransactionBatchFactory > transaction_batch_factory_
Definition: application.hpp:313
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:382
Definition: status_bus.hpp:17
Definition: command_service.hpp:26
std::unique_ptr< iroha::network::ServerRunner > internal_server
Definition: application.hpp:385
shared_model::crypto::Keypair keypair
Definition: application.hpp:269
std::shared_ptr< iroha::torii::CommandService > command_service
Definition: application.hpp:369
std::shared_ptr< shared_model::interface::AbstractTransportFactory< shared_model::interface::BlocksQuery, iroha::protocol::BlocksQuery > > blocks_query_factory
Definition: application.hpp:331
std::shared_ptr< iroha::synchronizer::Synchronizer > synchronizer
Definition: application.hpp:356
size_t torii_port_
Definition: application.hpp:231
Definition: command_executor.hpp:12
const std::string listen_ip_
Definition: application.hpp:230
std::shared_ptr< iroha::torii::QueryService > query_service
Definition: application.hpp:374
Definition: transaction.hpp:23
std::shared_ptr< shared_model::interface::QueryResponseFactory > query_response_factory_
Definition: application.hpp:263
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:301
size_t max_proposal_size_
Definition: application.hpp:234
std::unique_ptr< iroha::PendingTransactionStorageInit > pending_txs_storage_init
Definition: application.hpp:256
std::optional< std::unique_ptr< iroha::ametsuchi::VmCaller > > vm_caller_
Definition: application.hpp:266
Definition: query_processor.hpp:31
boost::optional< IrohadConfig::InterPeerTls > inter_peer_tls_config_
Definition: application.hpp:245
std::shared_ptr< iroha::network::BlockLoader > block_loader
Definition: application.hpp:353
boost::optional< iroha::torii::TlsParams > torii_tls_params_
Definition: application.hpp:232
std::shared_ptr< iroha::network::MstTransport > mst_transport
Definition: application.hpp:365
Definition: abstract_crypto_model_signer.hpp:16