hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
on_demand_ordering_service_impl.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_ON_DEMAND_ORDERING_SERVICE_IMPL_HPP
7 #define IROHA_ON_DEMAND_ORDERING_SERVICE_IMPL_HPP
8 
10 
11 #include <map>
12 #include <mutex>
13 #include <shared_mutex>
14 
16 #include "logger/logger_fwd.hpp"
18 // TODO 2019-03-15 andrei: IR-403 Separate BatchHashEquality and MstState
21 
22 namespace iroha {
23  namespace ametsuchi {
24  class TxPresenceCache;
25  }
26  namespace ordering {
27  namespace detail {
28  using ProposalMapType =
29  std::map<consensus::Round,
30  std::optional<std::shared_ptr<
32  } // namespace detail
33 
35  public:
47  size_t transaction_limit,
48  std::shared_ptr<shared_model::interface::UnsafeProposalFactory>
49  proposal_factory,
50  std::shared_ptr<ametsuchi::TxPresenceCache> tx_cache,
52  size_t number_of_proposals = 3);
53 
54  // --------------------- | OnDemandOrderingService |_---------------------
55 
56  void onBatches(CollectionType batches) override;
57 
58  std::optional<std::shared_ptr<const ProposalType>> onRequestProposal(
59  consensus::Round round) override;
60 
61  void onCollaborationOutcome(consensus::Round round) override;
62 
63  void onTxsCommitted(const HashesSetType &hashes) override {
64  removeFromBatchesCache(hashes);
65  }
66 
67  void processReceivedProposal(CollectionType batches) override;
68 
69  private:
74  std::optional<std::shared_ptr<shared_model::interface::Proposal>>
75  packNextProposals(const consensus::Round &round);
76 
77  using TransactionsCollectionType =
78  std::vector<std::shared_ptr<shared_model::interface::Transaction>>;
79 
80  std::optional<std::shared_ptr<shared_model::interface::Proposal>>
81  tryCreateProposal(
82  consensus::Round const &round,
83  const TransactionsCollectionType &txs,
85 
91  void tryErase(const consensus::Round &current_round);
92 
96  bool batchAlreadyProcessed(
98 
99  bool insertBatchToCache(
100  std::shared_ptr<shared_model::interface::TransactionBatch> const
101  &batch);
102 
103  void removeFromBatchesCache(
105 
106  bool isEmptyBatchesCache() const override;
107 
108  void forCachedBatches(
109  std::function<void(const BatchesSetType &)> const &f) const override;
110 
111  std::vector<std::shared_ptr<shared_model::interface::Transaction>>
112  getTransactionsFromBatchesCache(size_t requested_tx_amount);
113 
114  bool hasProposal(consensus::Round round) const override;
115 
119  size_t transaction_limit_;
120 
124  size_t number_of_proposals_;
125 
129  detail::ProposalMapType proposal_map_;
130 
134  mutable std::mutex proposals_mutex_;
135 
136  mutable std::shared_timed_mutex batches_cache_cs_;
137  BatchesSetType batches_cache_, used_batches_cache_;
138 
139  std::shared_ptr<shared_model::interface::UnsafeProposalFactory>
140  proposal_factory_;
141 
145  std::shared_ptr<ametsuchi::TxPresenceCache> tx_cache_;
146 
150  logger::LoggerPtr log_;
151 
155  consensus::Round current_round_;
156  };
157  } // namespace ordering
158 } // namespace iroha
159 
160 #endif // IROHA_ON_DEMAND_ORDERING_SERVICE_IMPL_HPP
Definition: block_query.hpp:17
void onTxsCommitted(const HashesSetType &hashes) override
Definition: on_demand_ordering_service_impl.hpp:63
std::vector< TransactionBatchType > CollectionType
Definition: on_demand_ordering_service.hpp:60
Definition: on_demand_ordering_service.hpp:28
Definition: proposal.hpp:17
std::unordered_set< shared_model::crypto::Hash, shared_model::crypto::Hash::Hasher > HashesSetType
Definition: on_demand_ordering_service.hpp:73
std::shared_ptr< Logger > LoggerPtr
Definition: logger_fwd.hpp:22
Definition: on_demand_ordering_service_impl.hpp:34
Definition: block_query.hpp:15
std::unordered_set< std::shared_ptr< shared_model::interface::TransactionBatch >, BatchPointerHasher, shared_model::interface::BatchHashEquality > BatchesSetType
Definition: on_demand_ordering_service.hpp:49
Definition: transaction_batch.hpp:22
Definition: round.hpp:31
std::map< consensus::Round, std::optional< std::shared_ptr< const OnDemandOrderingService::ProposalType > >> ProposalMapType
Definition: on_demand_ordering_service_impl.hpp:31
uint64_t TimestampType
Type of timestamp.
Definition: types.hpp:69