hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
mst_state.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_MST_STATE_HPP
7 #define IROHA_MST_STATE_HPP
8 
9 #include <queue>
10 #include <unordered_set>
11 #include <vector>
12 
13 #include "logger/logger.hpp"
16 
17 namespace iroha {
18 
23  class Completer {
24  public:
30  virtual bool operator()(const DataType &batch) const = 0;
31 
38  virtual bool operator()(const DataType &batch,
39  const TimeType &time) const = 0;
40 
41  virtual ~Completer() = default;
42  };
43 
48  public:
53  bool operator()(const DataType &left_tx, const DataType &right_tx) const;
54  };
55 
61  class DefaultCompleter : public Completer {
66  public:
67  explicit DefaultCompleter(std::chrono::minutes expiration_time);
68 
69  bool operator()(const DataType &batch) const override;
70 
71  bool operator()(const DataType &tx, const TimeType &time) const override;
72 
73  private:
74  std::chrono::minutes expiration_time_;
75  };
76 
77  using CompleterType = std::shared_ptr<const Completer>;
78 
79  class MstState {
80  public:
81  // -----------------------------| public api |------------------------------
82 
88  static MstState empty(const CompleterType &completer);
89 
95  StateUpdateResult operator+=(const DataType &rhs);
96 
102  StateUpdateResult operator+=(const MstState &rhs);
103 
112  MstState operator-(const MstState &rhs) const;
113 
117  bool isEmpty() const;
118 
124  bool operator==(const MstState &rhs) const;
125 
129  std::unordered_set<DataType,
132  getBatches() const;
133 
139  MstState eraseByTime(const TimeType &time);
140 
146  bool contains(const DataType &element) const;
147 
148  private:
149  // --------------------------| private api |------------------------------
150 
154  class Less {
155  public:
156  bool operator()(const DataType &left, const DataType &right) const;
157  };
158 
159  using InternalStateType =
160  std::unordered_set<DataType,
161  iroha::model::PointerBatchHasher,
163 
164  using IndexType =
165  std::priority_queue<DataType, std::vector<DataType>, Less>;
166 
167  explicit MstState(const CompleterType &completer,
168  logger::Logger log = logger::log("MstState"));
169 
170  MstState(const CompleterType &completer,
171  const InternalStateType &transactions,
172  logger::Logger log = logger::log("MstState"));
173 
180  void insertOne(StateUpdateResult &state_update, const DataType &rhs_tx);
181 
186  void rawInsert(const DataType &rhs_tx);
187 
188  // -----------------------------| fields |------------------------------
189 
190  CompleterType completer_;
191 
192  InternalStateType internal_state_;
193 
194  IndexType index_;
195 
196  logger::Logger log_;
197  };
198 
199 } // namespace iroha
200 
201 #endif // IROHA_MST_STATE_HPP
virtual ~Completer()=default
Definition: hash.hpp:16
Definition: mst_state.hpp:47
Definition: mst_state.hpp:79
Definition: mst_state.hpp:61
Definition: mst_state.hpp:23
std::shared_ptr< spdlog::logger > Logger
Definition: logger.hpp:26
std::shared_ptr< const Completer > CompleterType
Definition: mst_state.hpp:77
Definition: block_query.hpp:16
virtual bool operator()(const DataType &batch) const =0
shared_model::interface::types::TimestampType TimeType
Definition: mst_types.hpp:25
Logger log(const std::string &tag)
Definition: logger.cpp:48
Definition: mst_types.hpp:47
BatchPtr DataType
Definition: mst_types.hpp:40