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 <boost/range/adaptor/filtered.hpp>
12 #include <boost/range/adaptor/indirected.hpp>
13 #include <map>
14 #include <mutex>
15 #include <shared_mutex>
16 
17 #include <tbb/concurrent_unordered_set.h>
19 #include "logger/logger_fwd.hpp"
21 // TODO 2019-03-15 andrei: IR-403 Separate BatchHashEquality and MstState
25 
26 namespace iroha {
27  namespace ametsuchi {
28  class TxPresenceCache;
29  }
30  namespace ordering {
31  namespace detail {
32  using BatchSetType = tbb::concurrent_unordered_set<
36 
37  using ProposalMapType =
38  std::map<consensus::Round,
39  boost::optional<std::shared_ptr<
41  } // namespace detail
42 
44  public:
57  size_t transaction_limit,
58  std::shared_ptr<shared_model::interface::UnsafeProposalFactory>
59  proposal_factory,
60  std::shared_ptr<ametsuchi::TxPresenceCache> tx_cache,
61  std::shared_ptr<ProposalCreationStrategy> proposal_creation_strategy,
63  size_t number_of_proposals = 3);
64 
65  // --------------------- | OnDemandOrderingService |_---------------------
66 
67  void onCollaborationOutcome(consensus::Round round) override;
68 
69  void onTxsCommitted(const HashesSetType &hashes) override {
70  removeFromBatchesCache(hashes);
71  }
72 
73  // ----------------------- | OdOsNotification | --------------------------
74 
75  void onBatches(CollectionType batches) override;
76 
77  boost::optional<std::shared_ptr<const ProposalType>> onRequestProposal(
78  consensus::Round round) override;
79 
80  private:
85  boost::optional<std::shared_ptr<shared_model::interface::Proposal>>
86  packNextProposals(const consensus::Round &round);
87 
88  boost::optional<
89  std::shared_ptr<const OnDemandOrderingServiceImpl::ProposalType>>
90  uploadProposal(consensus::Round round);
91 
92  using TransactionsCollectionType =
93  std::vector<std::shared_ptr<shared_model::interface::Transaction>>;
94 
95  boost::optional<std::shared_ptr<shared_model::interface::Proposal>>
96  tryCreateProposal(
97  consensus::Round const &round,
98  const TransactionsCollectionType &txs,
100 
106  void tryErase(const consensus::Round &current_round);
107 
111  bool batchAlreadyProcessed(
113 
114  void insertBatchToCache(
115  std::shared_ptr<shared_model::interface::TransactionBatch> const
116  &batch);
117 
118  void removeFromBatchesCache(
120 
121  bool isEmptyBatchesCache() const;
122 
123  void forCachedBatches(
124  std::function<void(const transport::OdOsNotification::BatchesSetType
125  &)> const &f) override;
126 
127  std::vector<std::shared_ptr<shared_model::interface::Transaction>>
128  getTransactionsFromBatchesCache(size_t requested_tx_amount);
129 
133  size_t transaction_limit_;
134 
138  size_t number_of_proposals_;
139 
143  detail::ProposalMapType proposal_map_;
144 
148  std::mutex proposals_mutex_;
149 
150  mutable std::shared_timed_mutex batches_cache_cs_;
151  BatchesSetType batches_cache_;
152 
153  std::shared_ptr<shared_model::interface::UnsafeProposalFactory>
154  proposal_factory_;
155 
159  std::shared_ptr<ametsuchi::TxPresenceCache> tx_cache_;
160 
164  std::shared_ptr<ProposalCreationStrategy> proposal_creation_strategy_;
165 
169  logger::LoggerPtr log_;
170 
174  consensus::Round current_round_;
175  };
176  } // namespace ordering
177 } // namespace iroha
178 
179 #endif // IROHA_ON_DEMAND_ORDERING_SERVICE_IMPL_HPP
std::unordered_set< std::shared_ptr< shared_model::interface::TransactionBatch >, BatchPointerHasher, shared_model::interface::BatchHashEquality > BatchesSetType
Definition: on_demand_os_transport.hpp:54
void onTxsCommitted(const HashesSetType &hashes) override
Definition: on_demand_ordering_service_impl.hpp:69
Definition: hash.hpp:16
Definition: transaction_batch.hpp:64
transport::OdOsNotification::TransactionBatchType TransactionBatchType
Definition: on_demand_ordering_service_impl.cpp:27
Definition: on_demand_ordering_service.hpp:17
Definition: proposal.hpp:17
std::unordered_set< shared_model::crypto::Hash, shared_model::crypto::Hash::Hasher > HashesSetType
Definition: on_demand_ordering_service.hpp:21
std::shared_ptr< Logger > LoggerPtr
Definition: logger_fwd.hpp:22
Definition: on_demand_ordering_service_impl.hpp:43
Definition: block_query.hpp:15
std::map< consensus::Round, boost::optional< std::shared_ptr< const transport::OdOsNotification::ProposalType > >> ProposalMapType
Definition: on_demand_ordering_service_impl.hpp:40
tbb::concurrent_unordered_set< transport::OdOsNotification::TransactionBatchType, model::PointerBatchHasher, shared_model::interface::BatchHashEquality > BatchSetType
Definition: on_demand_ordering_service_impl.hpp:35
Definition: transaction_batch.hpp:22
Definition: round.hpp:31
std::vector< TransactionBatchType > CollectionType
Definition: on_demand_os_transport.hpp:65
uint64_t TimestampType
Type of timestamp.
Definition: types.hpp:67