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 
9 #include <list>
10 #include <set>
11 #include <shared_mutex>
12 #include <unordered_map>
13 
14 #include <rxcpp/rx.hpp>
17 
18 namespace iroha {
19 
20  class MstState;
21 
23  public:
29  using SharedState = std::shared_ptr<MstState>;
30  using SharedBatch = std::shared_ptr<TransactionBatch>;
31  using StateObservable = rxcpp::observable<SharedState>;
32  using BatchObservable = rxcpp::observable<SharedBatch>;
33  using PreparedTransactionDescriptor = std::pair<AccountIdType, HashType>;
35  rxcpp::observable<PreparedTransactionDescriptor>;
36 
38  BatchObservable prepared_batch,
39  BatchObservable expired_batch,
40  PreparedTransactionsObservable prepared_txs);
41 
43 
45  const AccountIdType &account_id) const override;
46 
47  expected::Result<Response, ErrorCode> getPendingTransactions(
50  const boost::optional<shared_model::interface::types::HashType>
51  &first_tx_hash) const override;
52 
53  private:
54  void updatedBatchesHandler(const SharedState &updated_batches);
55 
56  void removeBatch(const SharedBatch &batch);
57 
58  void removeBatch(const PreparedTransactionDescriptor &prepared_transaction);
59 
60  void removeFromStorage(const HashType &first_tx_hash,
61  const std::set<AccountIdType> &batch_creators,
62  uint64_t batch_size);
63 
64  static std::set<AccountIdType> batchCreators(const TransactionBatch &batch);
65 
69  rxcpp::composite_subscription updated_batches_subscription_;
70  rxcpp::composite_subscription prepared_batch_subscription_;
71  rxcpp::composite_subscription expired_batch_subscription_;
72  rxcpp::composite_subscription prepared_transactions_subscription_;
73 
77  mutable std::shared_timed_mutex mutex_;
78 
93  struct AccountBatches {
94  std::list<std::shared_ptr<TransactionBatch>> batches;
95  std::
96  unordered_map<HashType, decltype(batches)::iterator, HashType::Hasher>
97  index;
98  uint64_t all_transactions_quantity{0};
99  };
100 
104  std::unordered_map<AccountIdType, AccountBatches> storage_;
105  };
106 
107 } // namespace iroha
108 
109 #endif // IROHA_PENDING_TXS_STORAGE_IMPL_HPP
Definition: hash.hpp:18
rxcpp::observable< SharedBatch > BatchObservable
Definition: pending_txs_storage_impl.hpp:32
crypto::Hash HashType
Type of hash.
Definition: types.hpp:35
shared_model::interface::types::AccountIdType AccountIdType
Definition: pending_txs_storage_impl.hpp:24
rxcpp::observable< PreparedTransactionDescriptor > PreparedTransactionsObservable
Definition: pending_txs_storage_impl.hpp:35
std::pair< AccountIdType, HashType > PreparedTransactionDescriptor
Definition: pending_txs_storage_impl.hpp:33
shared_model::interface::types::SharedTxsCollectionType SharedTxsCollectionType
Definition: pending_txs_storage_impl.hpp:27
Definition: block_query.hpp:14
Definition: pending_txs_storage_impl.hpp:22
std::string AccountIdType
Type of account id.
Definition: types.hpp:39
SharedTxsCollectionType getPendingTransactions(const AccountIdType &account_id) const override
Definition: pending_txs_storage_impl.cpp:44
rxcpp::observable< SharedState > StateObservable
Definition: pending_txs_storage_impl.hpp:31
Definition: transaction_batch.hpp:22
std::shared_ptr< MstState > SharedState
Definition: pending_txs_storage_impl.hpp:29
uint16_t TransactionsNumberType
Type of a number of transactions in block and query response page.
Definition: types.hpp:81
PendingTransactionStorageImpl(StateObservable updated_batches, BatchObservable prepared_batch, BatchObservable expired_batch, PreparedTransactionsObservable prepared_txs)
Definition: pending_txs_storage_impl.cpp:13
Definition: pending_txs_storage.hpp:21
std::vector< std::shared_ptr< Transaction >> SharedTxsCollectionType
Definition: transaction_sequence_common.hpp:27
std::shared_ptr< TransactionBatch > SharedBatch
Definition: pending_txs_storage_impl.hpp:30
~PendingTransactionStorageImpl() override
Definition: pending_txs_storage_impl.cpp:36