hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
yac.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_YAC_HPP
7 #define IROHA_YAC_HPP
8 
9 #include "consensus/yac/transport/yac_network_interface.hpp" // for YacNetworkNotifications
10 #include "consensus/yac/yac_gate.hpp" // for HashGate
11 
12 #include <memory>
13 #include <mutex>
14 
15 #include <boost/optional.hpp>
16 #include <rxcpp/rx.hpp>
17 #include "consensus/yac/cluster_order.hpp" // for ClusterOrdering
18 #include "consensus/yac/outcome_messages.hpp" // because messages passed by value
19 #include "consensus/yac/storage/yac_vote_storage.hpp" // for VoteStorage
20 #include "logger/logger_fwd.hpp"
21 
22 namespace iroha {
23  namespace consensus {
24  namespace yac {
25 
26  class YacCryptoProvider;
27  class Timer;
28 
29  class Yac : public HashGate, public YacNetworkNotifications {
30  public:
35  static std::shared_ptr<Yac> create(
36  YacVoteStorage vote_storage,
37  std::shared_ptr<YacNetwork> network,
38  std::shared_ptr<YacCryptoProvider> crypto,
39  std::shared_ptr<Timer> timer,
40  ClusterOrdering order,
41  Round round,
42  rxcpp::observe_on_one_worker worker,
43  logger::LoggerPtr log);
44 
45  Yac(YacVoteStorage vote_storage,
46  std::shared_ptr<YacNetwork> network,
47  std::shared_ptr<YacCryptoProvider> crypto,
48  std::shared_ptr<Timer> timer,
49  ClusterOrdering order,
50  Round round,
51  rxcpp::observe_on_one_worker worker,
52  logger::LoggerPtr log);
53 
54  ~Yac() override;
55 
56  // ------|Hash gate|------
57 
58  void vote(YacHash hash, ClusterOrdering order) override;
59 
60  rxcpp::observable<Answer> onOutcome() override;
61 
62  // ------|Network notifications|------
63 
64  void onState(std::vector<VoteMessage> state) override;
65 
66  private:
67  // ------|Private interface|------
68 
73  void votingStep(VoteMessage vote);
74 
78  void closeRound();
79 
85  boost::optional<std::shared_ptr<shared_model::interface::Peer>>
86  findPeer(const VoteMessage &vote);
87 
89  void removeUnknownPeersVotes(std::vector<VoteMessage> &votes);
90 
91  // ------|Apply data|------
96  void applyState(const std::vector<VoteMessage> &state,
97  std::unique_lock<std::mutex> &lock);
98 
99  // ------|Propagation|------
100  void propagateState(const std::vector<VoteMessage> &msg);
101  void propagateStateDirectly(const shared_model::interface::Peer &to,
102  const std::vector<VoteMessage> &msg);
103  void tryPropagateBack(const std::vector<VoteMessage> &state);
104 
105  // ------|Logger|------
106  logger::LoggerPtr log_;
107 
108  std::mutex mutex_;
109 
110  // ------|One round|------
111  ClusterOrdering cluster_order_;
112  Round round_;
113 
114  // ------|Fields|------
115  rxcpp::observe_on_one_worker worker_;
116  rxcpp::composite_subscription notifier_lifetime_;
117  rxcpp::subjects::synchronize<Answer, decltype(worker_)> notifier_;
118  YacVoteStorage vote_storage_;
119  std::shared_ptr<YacNetwork> network_;
120  std::shared_ptr<YacCryptoProvider> crypto_;
121  std::shared_ptr<Timer> timer_;
122  };
123  } // namespace yac
124  } // namespace consensus
125 } // namespace iroha
126 
127 #endif // IROHA_YAC_HPP
~Yac() override
Definition: yac.cpp:84
Definition: cluster_order.hpp:28
Definition: peer.hpp:18
static std::shared_ptr< Yac > create(YacVoteStorage vote_storage, std::shared_ptr< YacNetwork > network, std::shared_ptr< YacCryptoProvider > crypto, std::shared_ptr< Timer > timer, ClusterOrdering order, Round round, rxcpp::observe_on_one_worker worker, logger::LoggerPtr log)
Definition: yac.cpp:47
Definition: yac_hash_provider.hpp:30
std::shared_ptr< Logger > LoggerPtr
Definition: logger_fwd.hpp:22
Definition: yac_gate.hpp:26
Definition: yac_vote_storage.hpp:63
void vote(YacHash hash, ClusterOrdering order) override
Definition: yac.cpp:90
Yac(YacVoteStorage vote_storage, std::shared_ptr< YacNetwork > network, std::shared_ptr< YacCryptoProvider > crypto, std::shared_ptr< Timer > timer, ClusterOrdering order, Round round, rxcpp::observe_on_one_worker worker, logger::LoggerPtr log)
Definition: yac.cpp:66
Definition: block_query.hpp:16
hash256_t hash(const T &pb)
Definition: pb_common.hpp:43
Definition: yac.hpp:29
rxcpp::observable< Answer > onOutcome() override
Definition: yac.cpp:105
void onState(std::vector< VoteMessage > state) override
Definition: yac.cpp:139
Definition: vote_message.hpp:22
Definition: round.hpp:31
Definition: yac_network_interface.hpp:24