hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
on_demand_ordering_gate.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_ON_DEMAND_ORDERING_GATE_HPP
7 #define IROHA_ON_DEMAND_ORDERING_GATE_HPP
8 
10 
11 #include <shared_mutex>
12 
13 #include <boost/variant.hpp>
14 #include <rxcpp/rx-lite.hpp>
18 #include "logger/logger_fwd.hpp"
22 
23 namespace iroha {
24  namespace ametsuchi {
25  class TxPresenceCache;
26  }
27 
28  namespace ordering {
29 
35  public:
36  struct RoundSwitch {
38  std::shared_ptr<const LedgerState> ledger_state;
39 
41  std::shared_ptr<const LedgerState> ledger_state)
42  : next_round(std::move(next_round)),
43  ledger_state(std::move(ledger_state)) {}
44  };
45 
47  std::shared_ptr<OnDemandOrderingService> ordering_service,
48  std::unique_ptr<transport::OdOsNotification> network_client,
49  rxcpp::observable<
50  std::shared_ptr<const cache::OrderingGateCache::HashesSetType>>
51  processed_tx_hashes,
52  rxcpp::observable<RoundSwitch> round_switch_events,
53  std::shared_ptr<cache::OrderingGateCache>
54  cache, // TODO: IR-1863 12.11.18 kamilsa change cache to
55  // unique_ptr
56  std::shared_ptr<shared_model::interface::UnsafeProposalFactory>
57  factory,
58  std::shared_ptr<ametsuchi::TxPresenceCache> tx_cache,
59  std::shared_ptr<ProposalCreationStrategy> proposal_creation_strategy,
60  size_t transaction_limit,
61  logger::LoggerPtr log);
62 
63  ~OnDemandOrderingGate() override;
64 
65  void propagateBatch(
66  std::shared_ptr<shared_model::interface::TransactionBatch> batch)
67  override;
68 
69  rxcpp::observable<network::OrderingEvent> onProposal() override;
70 
71  void stop() override;
72 
73  private:
77  boost::optional<std::shared_ptr<const shared_model::interface::Proposal>>
78  processProposalRequest(
79  boost::optional<
80  std::shared_ptr<const OnDemandOrderingService::ProposalType>>
81  proposal) const;
82 
83  void sendCachedTransactions();
84 
88  std::shared_ptr<const shared_model::interface::Proposal>
89  removeReplaysAndDuplicates(
90  std::shared_ptr<const shared_model::interface::Proposal> proposal)
91  const;
92 
93  logger::LoggerPtr log_;
94 
96  size_t transaction_limit_;
97  std::shared_ptr<OnDemandOrderingService> ordering_service_;
98  std::unique_ptr<transport::OdOsNotification> network_client_;
99  rxcpp::composite_subscription processed_tx_hashes_subscription_;
100  rxcpp::composite_subscription round_switch_subscription_;
101  std::shared_ptr<cache::OrderingGateCache> cache_;
102  std::shared_ptr<shared_model::interface::UnsafeProposalFactory>
103  proposal_factory_;
104  std::shared_ptr<ametsuchi::TxPresenceCache> tx_cache_;
105 
106  std::shared_timed_mutex stop_mutex_;
107  bool stop_requested_{false};
108 
109  rxcpp::composite_subscription proposal_notifier_lifetime_;
110  rxcpp::subjects::subject<network::OrderingEvent> proposal_notifier_;
111  };
112 
113  } // namespace ordering
114 } // namespace iroha
115 
116 #endif // IROHA_ON_DEMAND_ORDERING_GATE_HPP
Definition: ordering_gate.hpp:28
RoundSwitch(consensus::Round next_round, std::shared_ptr< const LedgerState > ledger_state)
Definition: on_demand_ordering_gate.hpp:40
Definition: peer.hpp:48
std::shared_ptr< Logger > LoggerPtr
Definition: logger_fwd.hpp:22
Definition: block_query.hpp:15
Definition: on_demand_ordering_gate.hpp:36
std::shared_ptr< const LedgerState > ledger_state
Definition: on_demand_ordering_gate.hpp:38
Definition: round.hpp:31
Definition: on_demand_ordering_gate.hpp:34
consensus::Round next_round
Definition: on_demand_ordering_gate.hpp:37