hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
unique_creation_proposal_strategy.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_UNIQUE_CREATION_PROPOSAL_STRATEGY_HPP
7 #define IROHA_UNIQUE_CREATION_PROPOSAL_STRATEGY_HPP
8 
10 
11 #include <memory>
12 #include <mutex>
13 
14 #include "common/ring_buffer.hpp"
15 
16 namespace iroha {
17  namespace ordering {
18 
24  delete;
26  UniqueCreationProposalStrategy const &) = delete;
27 
29  delete;
31  UniqueCreationProposalStrategy &&) = delete;
32 
33  inline bool contains(RoundType round) {
34  bool is_exists = false;
35  requested_.foreach ([&is_exists, &round](auto /*h*/, auto const &data) {
36  if (round == data) {
37  is_exists = true;
38  return false;
39  }
40  return true;
41  });
42  return is_exists;
43  }
44 
45  public:
47 
49  size_t /*peers_in_round*/) override {}
50 
51  bool shouldCreateRound(RoundType round) override {
52  std::lock_guard<std::mutex> guard(mutex_);
53  return !contains(round);
54  }
55 
56  boost::optional<RoundType> onProposalRequest(RoundType round) override {
57  std::lock_guard<std::mutex> guard(mutex_);
58  if (!contains(round)) {
59  requested_.push([](auto, auto &) {}, [](auto, auto &) {}, round);
60  }
61  return boost::none;
62  }
63 
64  private:
67 
68  std::mutex mutex_;
69  RoundCollectionType requested_;
70  };
71  } // namespace ordering
72 } // namespace iroha
73 
74 #endif // IROHA_UNIQUE_CREATION_PROPOSAL_STRATEGY_HPP
Definition: unique_creation_proposal_strategy.hpp:22
Definition: block_query.hpp:15
void push(FuncOnAdd &&on_add, FuncOnRemove &&on_remove, Args &&... args)
Definition: ring_buffer.hpp:140
void foreach(Func &&f)
Definition: ring_buffer.hpp:156
void onCollaborationOutcome(RoundType, size_t) override
Definition: unique_creation_proposal_strategy.hpp:48
Definition: ordering_service_proposal_creation_strategy.hpp:19
boost::optional< RoundType > onProposalRequest(RoundType round) override
Definition: unique_creation_proposal_strategy.hpp:56
Definition: round.hpp:31
bool shouldCreateRound(RoundType round) override
Definition: unique_creation_proposal_strategy.hpp:51