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 <boost/optional.hpp>
10 #include <memory>
11 #include <mutex>
12 #include <rxcpp/rx.hpp>
13 
14 #include "consensus/yac/cluster_order.hpp" // for ClusterOrdering
15 #include "consensus/yac/outcome_messages.hpp" // because messages passed by value
16 #include "consensus/yac/storage/yac_vote_storage.hpp" // for VoteStorage
17 #include "consensus/yac/transport/yac_network_interface.hpp" // for YacNetworkNotifications
18 #include "consensus/yac/yac_gate.hpp" // for HashGate
19 #include "logger/logger.hpp"
20 
21 namespace iroha {
22  namespace consensus {
23  namespace yac {
24 
25  class YacCryptoProvider;
26  class Timer;
27 
28  class Yac : public HashGate, public YacNetworkNotifications {
29  public:
34  static std::shared_ptr<Yac> create(
35  YacVoteStorage vote_storage,
36  std::shared_ptr<YacNetwork> network,
37  std::shared_ptr<YacCryptoProvider> crypto,
38  std::shared_ptr<Timer> timer,
39  ClusterOrdering order,
40  logger::Logger log = logger::log("YAC"));
41 
42  Yac(YacVoteStorage vote_storage,
43  std::shared_ptr<YacNetwork> network,
44  std::shared_ptr<YacCryptoProvider> crypto,
45  std::shared_ptr<Timer> timer,
46  ClusterOrdering order,
47  logger::Logger log = logger::log("YAC"));
48 
49  // ------|Hash gate|------
50 
51  void vote(YacHash hash, ClusterOrdering order) override;
52 
53  rxcpp::observable<Answer> onOutcome() override;
54 
55  // ------|Network notifications|------
56 
57  void onState(std::vector<VoteMessage> state) override;
58 
59  private:
60  // ------|Private interface|------
61 
66  void votingStep(VoteMessage vote);
67 
71  void closeRound();
72 
78  boost::optional<std::shared_ptr<shared_model::interface::Peer>>
79  findPeer(const VoteMessage &vote);
80 
81  // ------|Apply data|------
82  void applyState(const std::vector<VoteMessage> &state);
83 
84  // ------|Propagation|------
85  void propagateState(const std::vector<VoteMessage> &msg);
86  void propagateStateDirectly(const shared_model::interface::Peer &to,
87  const std::vector<VoteMessage> &msg);
88 
89  // ------|Fields|------
90  YacVoteStorage vote_storage_;
91  std::shared_ptr<YacNetwork> network_;
92  std::shared_ptr<YacCryptoProvider> crypto_;
93  std::shared_ptr<Timer> timer_;
94  rxcpp::subjects::subject<Answer> notifier_;
95  std::mutex mutex_;
96 
97  // ------|One round|------
98  ClusterOrdering cluster_order_;
99 
100  // ------|Logger|------
101  logger::Logger log_;
102  };
103  } // namespace yac
104  } // namespace consensus
105 } // namespace iroha
106 
107 #endif // IROHA_YAC_HPP
Definition: cluster_order.hpp:28
Yac(YacVoteStorage vote_storage, std::shared_ptr< YacNetwork > network, std::shared_ptr< YacCryptoProvider > crypto, std::shared_ptr< Timer > timer, ClusterOrdering order, logger::Logger log=logger::log("YAC"))
Definition: yac.cpp:50
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, logger::Logger log=logger::log("YAC"))
Definition: yac.cpp:39
Definition: peer.hpp:18
Definition: yac_hash_provider.hpp:30
Definition: yac_gate.hpp:26
Definition: yac_vote_storage.hpp:59
void vote(YacHash hash, ClusterOrdering order) override
Definition: yac.cpp:65
std::shared_ptr< spdlog::logger > Logger
Definition: logger.hpp:26
Definition: block_query.hpp:16
hash256_t hash(const T &pb)
Definition: pb_common.hpp:43
Logger log(const std::string &tag)
Definition: logger.cpp:48
Definition: yac.hpp:28
rxcpp::observable< Answer > onOutcome() override
Definition: yac.cpp:77
void onState(std::vector< VoteMessage > state) override
Definition: yac.cpp:83
Definition: vote_message.hpp:22
Definition: yac_network_interface.hpp:24