hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
pending_txs_storage_impl.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_PENDING_TXS_STORAGE_IMPL_HPP
7 #define IROHA_PENDING_TXS_STORAGE_IMPL_HPP
8 
10 
11 #include <list>
12 #include <memory>
13 #include <set>
14 #include <shared_mutex>
15 #include <unordered_map>
16 
17 #include <boost/bimap.hpp>
18 #include <boost/bimap/unordered_multiset_of.hpp>
19 #include <boost/bimap/unordered_set_of.hpp>
20 #include <rxcpp/rx-lite.hpp>
21 #include "cryptography/hash.hpp"
24 
25 namespace iroha {
26 
27  class MstState;
28 
30  private:
31  struct private_tag {};
32 
33  public:
39  using SharedState = std::shared_ptr<MstState>;
40  using SharedBatch = std::shared_ptr<TransactionBatch>;
41  using StateObservable = rxcpp::observable<SharedState>;
42  using BatchObservable = rxcpp::observable<SharedBatch>;
43  using PreparedTransactionDescriptor = std::pair<AccountIdType, HashType>;
45  rxcpp::observable<PreparedTransactionDescriptor>;
46  using FinalizedTransactionsObservable = rxcpp::observable<HashType>;
47 
48  PendingTransactionStorageImpl(PendingTransactionStorageImpl::private_tag);
49 
51  delete;
53  PendingTransactionStorageImpl const &) = delete;
54 
55  static std::shared_ptr<PendingTransactionStorageImpl> create(
56  StateObservable updated_batches,
57  BatchObservable prepared_batch,
58  BatchObservable expired_batch,
59  PreparedTransactionsObservable prepared_txs,
60  FinalizedTransactionsObservable finalized_txs);
61 
63  const AccountIdType &account_id) const override;
64 
68  const std::optional<shared_model::interface::types::HashType>
69  &first_tx_hash) const override;
70 
72  std::shared_ptr<ametsuchi::TxPresenceCache> &cache) override;
73 
74  private:
75  void updatedBatchesHandler(const SharedState &updated_batches);
76 
77  void removeBatch(const SharedBatch &batch);
78 
79  void removeBatch(const PreparedTransactionDescriptor &prepared_transaction);
80 
81  void removeFromStorage(const HashType &first_tx_hash,
82  const std::set<AccountIdType> &batch_creators,
83  uint64_t batch_size);
84 
85  void removeTransaction(HashType const &hash);
86 
87  static std::set<AccountIdType> batchCreators(const TransactionBatch &batch);
88 
89  bool isReplay(shared_model::interface::TransactionBatch const &batch);
90 
91  std::weak_ptr<ametsuchi::TxPresenceCache> presence_cache_;
92 
96  mutable std::shared_timed_mutex mutex_;
97 
112  struct AccountBatches {
113  using BatchPtr = std::shared_ptr<TransactionBatch>;
114  using BatchesBimap = boost::bimap<
115  boost::bimaps::unordered_set_of<HashType,
117  boost::bimaps::unordered_multiset_of<
118  BatchPtr,
121 
122  std::list<BatchPtr> batches;
123  std::
124  unordered_map<HashType, decltype(batches)::iterator, HashType::Hasher>
125  index;
126  BatchesBimap txs_to_batches;
127 
128  uint64_t all_transactions_quantity{0};
129  };
130 
134  std::unordered_map<AccountIdType, AccountBatches> storage_;
135  };
136 
137 } // namespace iroha
138 
139 #endif // IROHA_PENDING_TXS_STORAGE_IMPL_HPP
Definition: hash.hpp:18
rxcpp::observable< SharedBatch > BatchObservable
Definition: pending_txs_storage_impl.hpp:42
crypto::Hash HashType
Type of hash.
Definition: types.hpp:34
Definition: hash.hpp:16
shared_model::interface::types::AccountIdType AccountIdType
Definition: pending_txs_storage_impl.hpp:34
Definition: transaction_batch.hpp:64
Definition: result_fwd.hpp:27
PendingTransactionStorageImpl & operator=(PendingTransactionStorageImpl const &)=delete
shared_model::interface::types::HashType HashType
Definition: pending_txs_storage_impl.hpp:35
rxcpp::observable< PreparedTransactionDescriptor > PreparedTransactionsObservable
Definition: pending_txs_storage_impl.hpp:45
std::pair< AccountIdType, HashType > PreparedTransactionDescriptor
Definition: pending_txs_storage_impl.hpp:43
shared_model::interface::types::SharedTxsCollectionType SharedTxsCollectionType
Definition: pending_txs_storage_impl.hpp:37
Definition: block_query.hpp:15
Definition: pending_txs_storage_impl.hpp:29
std::string AccountIdType
Type of account id.
Definition: types.hpp:38
hash256_t hash(const T &pb)
Definition: pb_common.hpp:43
SharedTxsCollectionType getPendingTransactions(const AccountIdType &account_id) const override
Definition: pending_txs_storage_impl.cpp:84
PendingTransactionStorageImpl(PendingTransactionStorageImpl::private_tag)
Definition: pending_txs_storage_impl.cpp:14
rxcpp::observable< SharedState > StateObservable
Definition: pending_txs_storage_impl.hpp:41
Definition: transaction_batch.hpp:22
std::shared_ptr< MstState > SharedState
Definition: pending_txs_storage_impl.hpp:39
std::vector< std::shared_ptr< Transaction > > SharedTxsCollectionType
Definition: transaction_sequence_common.hpp:27
void insertPresenceCache(std::shared_ptr< ametsuchi::TxPresenceCache > &cache) override
Definition: pending_txs_storage_impl.cpp:222
uint16_t TransactionsNumberType
Type of a number of transactions in block and query response page.
Definition: types.hpp:84
static std::shared_ptr< PendingTransactionStorageImpl > create(StateObservable updated_batches, BatchObservable prepared_batch, BatchObservable expired_batch, PreparedTransactionsObservable prepared_txs, FinalizedTransactionsObservable finalized_txs)
Definition: pending_txs_storage_impl.cpp:18
rxcpp::observable< HashType > FinalizedTransactionsObservable
Definition: pending_txs_storage_impl.hpp:46
Definition: hash.hpp:23
std::shared_ptr< shared_model::interface::TransactionBatch > BatchPtr
Definition: mst_types.hpp:23
Definition: pending_txs_storage.hpp:22
std::shared_ptr< TransactionBatch > SharedBatch
Definition: pending_txs_storage_impl.hpp:40