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 <shared_mutex>
13 
14 #include <tbb/concurrent_unordered_set.h>
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 BatchSetType = tbb::concurrent_unordered_set<
32 
33  using ProposalMapType = std::map<
35  std::shared_ptr<const transport::OdOsNotification::ProposalType>>;
36  } // namespace detail
37 
39  public:
53  size_t transaction_limit,
54  std::shared_ptr<shared_model::interface::UnsafeProposalFactory>
55  proposal_factory,
56  std::shared_ptr<ametsuchi::TxPresenceCache> tx_cache,
58  size_t number_of_proposals = 3,
59  const consensus::Round &initial_round = {2, kFirstRejectRound});
60 
61  // --------------------- | OnDemandOrderingService |_---------------------
62 
63  void onCollaborationOutcome(consensus::Round round) override;
64 
65  // ----------------------- | OdOsNotification | --------------------------
66 
67  void onBatches(CollectionType batches) override;
68 
69  boost::optional<std::shared_ptr<const ProposalType>> onRequestProposal(
70  consensus::Round round) override;
71 
72  private:
77  void packNextProposals(const consensus::Round &round);
78 
84  void tryErase(const consensus::Round &current_round);
85 
89  bool batchAlreadyProcessed(
91 
95  size_t transaction_limit_;
96 
100  size_t number_of_proposals_;
101 
105  detail::ProposalMapType proposal_map_;
106 
110  detail::BatchSetType pending_batches_;
111 
115  std::shared_timed_mutex batches_mutex_, proposals_mutex_;
116 
117  std::shared_ptr<shared_model::interface::UnsafeProposalFactory>
118  proposal_factory_;
119 
123  std::shared_ptr<ametsuchi::TxPresenceCache> tx_cache_;
124 
128  logger::LoggerPtr log_;
129  };
130  } // namespace ordering
131 } // namespace iroha
132 
133 #endif // IROHA_ON_DEMAND_ORDERING_SERVICE_IMPL_HPP
tbb::concurrent_unordered_set< transport::OdOsNotification::TransactionBatchType, model::PointerBatchHasher, BatchHashEquality > BatchSetType
Definition: on_demand_ordering_service_impl.hpp:31
Definition: hash.hpp:16
Definition: mst_state.hpp:56
transport::OdOsNotification::TransactionBatchType TransactionBatchType
Definition: on_demand_ordering_service_impl.cpp:27
Definition: on_demand_ordering_service.hpp:17
std::shared_ptr< Logger > LoggerPtr
Definition: logger_fwd.hpp:22
Definition: on_demand_ordering_service_impl.hpp:38
Definition: block_query.hpp:14
std::map< consensus::Round, std::shared_ptr< const transport::OdOsNotification::ProposalType >> ProposalMapType
Definition: on_demand_ordering_service_impl.hpp:35
const consensus::RejectRoundType kFirstRejectRound
Definition: on_demand_common.cpp:11
Definition: transaction_batch.hpp:22
Definition: round.hpp:31
std::vector< TransactionBatchType > CollectionType
Definition: on_demand_os_transport.hpp:47