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-lite.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 #include <rxcpp/operators/rx-observe_on.hpp>
23 
24 namespace iroha {
25  namespace consensus {
26  namespace yac {
27 
28  class YacCryptoProvider;
29  class Timer;
30 
31  class Yac : public HashGate, public YacNetworkNotifications {
32  public:
37  static std::shared_ptr<Yac> create(
38  YacVoteStorage vote_storage,
39  std::shared_ptr<YacNetwork> network,
40  std::shared_ptr<YacCryptoProvider> crypto,
41  std::shared_ptr<Timer> timer,
42  ClusterOrdering order,
43  Round round,
44  rxcpp::observe_on_one_worker worker,
45  logger::LoggerPtr log);
46 
47  Yac(YacVoteStorage vote_storage,
48  std::shared_ptr<YacNetwork> network,
49  std::shared_ptr<YacCryptoProvider> crypto,
50  std::shared_ptr<Timer> timer,
51  ClusterOrdering order,
52  Round round,
53  rxcpp::observe_on_one_worker worker,
54  logger::LoggerPtr log);
55 
56  ~Yac() override;
57 
58  // ------|Hash gate|------
59 
60  void vote(YacHash hash,
61  ClusterOrdering order,
62  boost::optional<ClusterOrdering> alternative_order =
63  boost::none) override;
64 
65  rxcpp::observable<Answer> onOutcome() override;
66 
67  // ------|Network notifications|------
68 
69  void onState(std::vector<VoteMessage> state) override;
70 
71  void stop() override;
72 
73  private:
74  // ------|Private interface|------
75 
80  void votingStep(VoteMessage vote, uint32_t attempt = 0);
81 
85  void closeRound();
86 
88  ClusterOrdering &getCurrentOrder();
89 
95  boost::optional<std::shared_ptr<shared_model::interface::Peer>>
96  findPeer(const VoteMessage &vote);
97 
99  void removeUnknownPeersVotes(std::vector<VoteMessage> &votes,
100  ClusterOrdering &order);
101 
102  // ------|Apply data|------
107  void applyState(const std::vector<VoteMessage> &state,
108  std::unique_lock<std::mutex> &lock);
109 
110  // ------|Propagation|------
111  void propagateState(const std::vector<VoteMessage> &msg);
112  void propagateStateDirectly(const shared_model::interface::Peer &to,
113  const std::vector<VoteMessage> &msg);
114  void tryPropagateBack(const std::vector<VoteMessage> &state);
115 
116  // ------|Logger|------
117  logger::LoggerPtr log_;
118 
119  std::mutex mutex_;
120 
121  // ------|One round|------
122  ClusterOrdering cluster_order_;
123  boost::optional<ClusterOrdering> alternative_order_;
124  Round round_;
125 
126  // ------|Fields|------
127  rxcpp::observe_on_one_worker worker_;
128  rxcpp::composite_subscription notifier_lifetime_;
129  rxcpp::subjects::synchronize<Answer, decltype(worker_)> notifier_;
130  YacVoteStorage vote_storage_;
131  std::shared_ptr<YacNetwork> network_;
132  std::shared_ptr<YacCryptoProvider> crypto_;
133  std::shared_ptr<Timer> timer_;
134  };
135  } // namespace yac
136  } // namespace consensus
137 } // namespace iroha
138 
139 #endif // IROHA_YAC_HPP
~Yac() override
Definition: yac.cpp:68
Definition: cluster_order.hpp:23
Definition: peer.hpp:20
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:31
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
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:50
Definition: block_query.hpp:15
hash256_t hash(const T &pb)
Definition: pb_common.hpp:43
Definition: yac.hpp:31
rxcpp::observable< Answer > onOutcome() override
Definition: yac.cpp:99
void vote(YacHash hash, ClusterOrdering order, boost::optional< ClusterOrdering > alternative_order=boost::none) override
Definition: yac.cpp:78
void stop() override
Prevent any new outgoing network activity. Be passive.
Definition: yac.cpp:72
void onState(std::vector< VoteMessage > state) override
Definition: yac.cpp:134
Definition: vote_message.hpp:22
Definition: round.hpp:31
Definition: yac_network_interface.hpp:24