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