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 "cryptography/hash.hpp"
23 
24 namespace iroha {
26  public:
32  using SharedState = std::shared_ptr<MstState>;
33  using SharedBatch = std::shared_ptr<TransactionBatch>;
34 
36  const AccountIdType &account_id) const override;
37 
41  const std::optional<shared_model::interface::types::HashType>
42  &first_tx_hash) const override;
43 
45  std::shared_ptr<ametsuchi::TxPresenceCache> &cache) override;
46 
47  void removeTransaction(HashType const &hash) override;
48 
49  void updatedBatchesHandler(const SharedState &updated_batches) override;
50 
51  void removeBatch(const SharedBatch &batch) override;
52 
53  private:
54  void removeFromStorage(const HashType &first_tx_hash,
55  const std::set<AccountIdType> &batch_creators,
56  uint64_t batch_size);
57 
58  static std::set<AccountIdType> batchCreators(const TransactionBatch &batch);
59 
60  bool isReplay(shared_model::interface::TransactionBatch const &batch);
61 
62  std::weak_ptr<ametsuchi::TxPresenceCache> presence_cache_;
63 
67  mutable std::shared_timed_mutex mutex_;
68 
83  struct AccountBatches {
84  using BatchPtr = std::shared_ptr<TransactionBatch>;
85  using BatchesBimap = boost::bimap<
86  boost::bimaps::unordered_set_of<HashType,
88  boost::bimaps::unordered_multiset_of<
89  BatchPtr,
92 
93  std::list<BatchPtr> batches;
94  std::
95  unordered_map<HashType, decltype(batches)::iterator, HashType::Hasher>
96  index;
97  BatchesBimap txs_to_batches;
98 
99  uint64_t all_transactions_quantity{0};
100  };
101 
105  std::unordered_map<AccountIdType, AccountBatches> storage_;
106  };
107 
108 } // namespace iroha
109 
110 #endif // IROHA_PENDING_TXS_STORAGE_IMPL_HPP
void insertPresenceCache(std::shared_ptr< ametsuchi::TxPresenceCache > &cache) override
Definition: pending_txs_storage_impl.cpp:150
Definition: hash.hpp:18
void removeTransaction(HashType const &hash) override
Definition: pending_txs_storage_impl.cpp:189
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:27
Definition: transaction_batch.hpp:64
Definition: result_fwd.hpp:27
shared_model::interface::types::HashType HashType
Definition: pending_txs_storage_impl.hpp:28
shared_model::interface::types::SharedTxsCollectionType SharedTxsCollectionType
Definition: pending_txs_storage_impl.hpp:30
Definition: block_query.hpp:15
Definition: pending_txs_storage_impl.hpp:25
std::string AccountIdType
Type of account id.
Definition: types.hpp:38
hash256_t hash(const T &pb)
Definition: pb_common.hpp:43
Definition: transaction_batch.hpp:22
std::shared_ptr< MstState > SharedState
Definition: pending_txs_storage_impl.hpp:32
std::vector< std::shared_ptr< Transaction > > SharedTxsCollectionType
Definition: transaction_sequence_common.hpp:27
void updatedBatchesHandler(const SharedState &updated_batches) override
Definition: pending_txs_storage_impl.cpp:92
uint16_t TransactionsNumberType
Type of a number of transactions in block and query response page.
Definition: types.hpp:86
void removeBatch(const SharedBatch &batch) override
Definition: pending_txs_storage_impl.cpp:181
Definition: hash.hpp:23
std::shared_ptr< shared_model::interface::TransactionBatch > BatchPtr
Definition: mst_types.hpp:23
Definition: pending_txs_storage.hpp:23
SharedTxsCollectionType getPendingTransactions(const AccountIdType &account_id) const override
Definition: pending_txs_storage_impl.cpp:15
std::shared_ptr< TransactionBatch > SharedBatch
Definition: pending_txs_storage_impl.hpp:33