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