CatapultServer  v0.5.0.1 (Elephant)
MemoryUtCache.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "MemoryCacheOptions.h"
23 #include "MemoryCacheProxy.h"
24 #include "UtCache.h"
26 #include "catapult/utils/Hashers.h"
28 #include <set>
29 #include <unordered_map>
30 
31 namespace catapult { namespace cache { struct TransactionData; } }
32 
33 namespace catapult { namespace cache {
34 
37  using TransactionDataContainer = std::set<TransactionData>;
38 
41  private:
42  using UnknownTransactions = std::vector<std::shared_ptr<const model::Transaction>>;
43  using IdLookup = std::unordered_map<Hash256, size_t, utils::ArrayHasher<Hash256>>;
45 
46  public:
49  explicit MemoryUtCacheView(
50  uint64_t maxResponseSize,
51  const TransactionDataContainer& transactionDataContainer,
52  const IdLookup& idLookup,
54 
55  public:
57  size_t size() const;
58 
60  bool contains(const Hash256& hash) const;
61 
63  void forEach(const TransactionInfoConsumer& consumer) const;
64 
68 
71  UnknownTransactions unknownTransactions(BlockFeeMultiplier minFeeMultiplier, const utils::ShortHashesSet& knownShortHashes) const;
72 
73  private:
78  };
79 
81  class MemoryUtCache : public UtCache {
82  public:
84  explicit MemoryUtCache(const MemoryCacheOptions& options);
85 
87  ~MemoryUtCache() override;
88 
89  public:
91  MemoryUtCacheView view() const;
92 
93  public:
94  UtCacheModifierProxy modifier() override;
95 
96  private:
97  struct Impl;
98 
99  private:
101  size_t m_idSequence;
102  std::unique_ptr<Impl> m_pImpl;
104  };
105 
107  class MemoryUtCacheProxy : public MemoryCacheProxy<MemoryUtCache, UtCache, UtCacheModifierProxy> {
109  };
110 }}
catapult::model::TransactionInfo::TransactionInfo
TransactionInfo()=default
Creates a transaction info.
catapult::cache::TransactionData::TransactionData
TransactionData(size_t id)
Definition: MemoryUtCache.cpp:36
catapult::utils::ToShortHash
ShortHash ToShortHash(const Hash256 &hash)
Gets the short hash corresponding to hash.
Definition: ShortHash.h:42
m_idSequence
size_t & m_idSequence
Definition: MemoryUtCache.cpp:196
m_counters
AccountCounters & m_counters
Definition: MemoryUtCache.cpp:199
catapult::cache::MemoryUtCacheView::m_idLookup
const IdLookup & m_idLookup
Definition: MemoryUtCache.h:76
CATAPULT_LOG
#define CATAPULT_LOG(SEV)
Writes a log entry to the default logger with SEV severity.
Definition: Logging.h:340
catapult::cache::MemoryUtCacheView::m_readLock
utils::SpinReaderWriterLock::ReaderLockGuard m_readLock
Definition: MemoryUtCache.h:77
catapult::cache::MemoryCacheProxy
A delegating proxy around a memory-based cache.
Definition: MemoryCacheProxy.h:29
catapult::cache::MemoryUtCacheView::size
size_t size() const
Returns the number of unconfirmed transactions in the cache.
Definition: MemoryUtCache.cpp:63
catapult::Hash256
utils::ByteArray< Hash256_Size, Hash256_tag > Hash256
Definition: src/catapult/types.h:47
Parser.debug
def debug(*args)
Definition: Parser.py:46
catapult::cache::MemoryUtCache::m_idSequence
size_t m_idSequence
Definition: MemoryUtCache.h:101
catapult::cache::MemoryUtCacheProxy
A delegating proxy around a MemoryUtCache.
Definition: MemoryUtCache.h:107
catapult::predicate
std::function< bool(TArgs...)> predicate
A predicate function.
Definition: functions.h:31
UtCache.h
catapult::cache::MemoryCacheOptions::MaxCacheSize
uint64_t MaxCacheSize
Maximum size of the cache.
Definition: MemoryCacheOptions.h:44
catapult::cache::MemoryUtCache::m_lock
utils::SpinReaderWriterLock m_lock
Definition: MemoryUtCache.h:103
m_transactionDataContainer
TransactionDataContainer & m_transactionDataContainer
Definition: MemoryUtCache.cpp:197
catapult::model::EntityRange
Represents a range of entities.
Definition: EntityRange.h:31
catapult::cache::MemoryUtCache::~MemoryUtCache
~MemoryUtCache() override
Destroys an unconfirmed transactions cache.
catapult::cache::LogSizes
void LogSizes(const char *name, size_t actual, uint64_t max)
Logs cache sizes for a cache with name at specified levels of fullness given its actual and max sizes...
Definition: CacheSizeLogger.h:27
m_maxCacheSize
uint64_t m_maxCacheSize
Definition: MemoryUtCache.cpp:195
catapult::model::EntityRange::begin
auto begin() const
Returns a const iterator that represents the first entity.
Definition: EntityRange.h:420
catapult::model::TransactionInfo
A transaction and its associated metadata.
Definition: EntityInfo.h:104
catapult::cache::MemoryUtCache::Impl
Definition: MemoryUtCache.cpp:209
catapult::cache::MemoryUtCache::MemoryUtCache
MemoryUtCache(const MemoryCacheOptions &options)
Creates an unconfirmed transactions cache around options.
Definition: MemoryUtCache.cpp:215
SpinReaderWriterLock.h
catapult::utils::BaseValue< uint32_t, BlockFeeMultiplier_tag >
m_idLookup
IdLookup & m_idLookup
Definition: MemoryUtCache.cpp:198
catapult::cache::MemoryUtCacheView::UnknownTransactions
std::vector< std::shared_ptr< const model::Transaction > > UnknownTransactions
Definition: MemoryUtCache.h:42
catapult::utils::BasicSpinReaderWriterLock::acquireReader
ReaderLockGuard acquireReader()
Blocks until a reader lock can be acquired.
Definition: SpinReaderWriterLock.h:153
catapult::cache::MemoryUtCacheView::IdLookup
std::unordered_map< Hash256, size_t, utils::ArrayHasher< Hash256 > > IdLookup
Definition: MemoryUtCache.h:43
catapult::cache::MemoryUtCacheView::shortHashes
model::ShortHashRange shortHashes() const
Definition: MemoryUtCache.cpp:78
catapult::cache::TransactionData::operator<
bool operator<(const TransactionData &rhs) const
Definition: MemoryUtCache.cpp:42
catapult::cache::TransactionData
Definition: MemoryUtCache.cpp:29
m_readLock
utils::SpinReaderWriterLock::ReaderLockGuard m_readLock
Definition: MemoryUtCache.cpp:200
catapult::model::EntityRange::PrepareFixed
static EntityRange PrepareFixed(size_t numElements, uint8_t **ppRangeData=nullptr)
Definition: EntityRange.h:265
catapult::cache::UtCache
An interface for caching unconfirmed transactions.
Definition: UtCache.h:56
catapult::cache::MemoryUtCacheView::m_maxResponseSize
uint64_t m_maxResponseSize
Definition: MemoryUtCache.h:74
MemoryUtCache.h
catapult::cache::MemoryCacheOptions::MaxResponseSize
uint64_t MaxResponseSize
Maximum response size.
Definition: MemoryCacheOptions.h:41
catapult::cache::MemoryUtCacheView::forEach
void forEach(const TransactionInfoConsumer &consumer) const
Calls consumer with all transaction infos until all are consumed or false is returned by consumer.
Definition: MemoryUtCache.cpp:71
catapult::cache::MemoryUtCacheView::TransactionInfoConsumer
predicate< const model::TransactionInfo & > TransactionInfoConsumer
Definition: MemoryUtCache.h:44
catapult::cache::UtCacheModifierProxy
Definition: UtCache.h:39
catapult::cache::MemoryUtCacheView::MemoryUtCacheView
MemoryUtCacheView(uint64_t maxResponseSize, const TransactionDataContainer &transactionDataContainer, const IdLookup &idLookup, utils::SpinReaderWriterLock::ReaderLockGuard &&readLock)
Definition: MemoryUtCache.cpp:52
catapult::cache::MemoryUtCacheView::contains
bool contains(const Hash256 &hash) const
Returns true if the cache contains an unconfirmed transaction with associated hash,...
Definition: MemoryUtCache.cpp:67
catapult::cache::TransactionData::TransactionData
TransactionData(const model::TransactionInfo &transactionInfo, size_t id)
Definition: MemoryUtCache.cpp:31
AccountCounters.h
catapult::utils::ShortHashesSet
std::unordered_set< ShortHash, ShortHashHasher > ShortHashesSet
Definition: ShortHash.h:39
size
uint64_t size
Definition: MemoryCounters.cpp:65
EntityInfo.h
catapult::cache::MemoryUtCache::m_pImpl
std::unique_ptr< Impl > m_pImpl
Definition: MemoryUtCache.h:102
m_writeLock
utils::SpinReaderWriterLock::WriterLockGuard m_writeLock
Definition: MemoryUtCache.cpp:201
MemoryCacheOptions.h
catapult::cache::MemoryUtCache::Impl::IdLookup
std::unordered_map< Hash256, size_t, utils::ArrayHasher< Hash256 > > IdLookup
Definition: MemoryUtCache.cpp:211
catapult::cache::MemoryUtCacheView
A read only view on top of unconfirmed transactions cache.
Definition: MemoryUtCache.h:40
catapult::utils::BasicSpinReaderWriterLock::ReaderLockGuard
A reader lock guard.
Definition: SpinReaderWriterLock.h:99
catapult::cache::MemoryUtCache
Cache for all unconfirmed transactions.
Definition: MemoryUtCache.h:81
FeeUtils.h
catapult::cache::MemoryUtCache::Impl::Counters
AccountCounters Counters
Definition: MemoryUtCache.cpp:212
m_options
CompareChainsOptions m_options
Definition: CompareChains.cpp:165
catapult::cache::MemoryUtCache::Impl::TransactionDataContainer
cache::TransactionDataContainer TransactionDataContainer
Definition: MemoryUtCache.cpp:210
catapult::cache::MemoryUtCache::modifier
UtCacheModifierProxy modifier() override
Gets a write only view of the cache.
Definition: MemoryUtCache.cpp:228
catapult::cache::TransactionDataContainer
std::set< TransactionData > TransactionDataContainer
Definition: MemoryUtCache.h:37
catapult
Definition: AddressExtractionExtension.cpp:28
Hashers.h
catapult::cache::TransactionData::Id
size_t Id
Definition: MemoryUtCache.cpp:47
catapult::cache::MemoryUtCacheView::unknownTransactions
UnknownTransactions unknownTransactions(BlockFeeMultiplier minFeeMultiplier, const utils::ShortHashesSet &knownShortHashes) const
Definition: MemoryUtCache.cpp:87
catapult::cache::MemoryUtCache::view
MemoryUtCacheView view() const
Gets a read only view based on this cache.
Definition: MemoryUtCache.cpp:223
catapult::model::CalculateTransactionFee
Amount CalculateTransactionFee(BlockFeeMultiplier feeMultiplier, const Transaction &transaction)
Calculates the fee for transaction contained in block with feeMultiplier.
Definition: FeeUtils.cpp:26
catapult::utils::ByteArray< Hash256_Size, Hash256_tag >
catapult::utils::NonCopyable
A class that can neither be copied nor moved.
Definition: NonCopyable.h:26
catapult::cache::MemoryCacheOptions
Options for customizing the behavior of a memory based cache.
Definition: MemoryCacheOptions.h:27
catapult::cache::AccountCounters
Counters for tracking how often an account is used.
Definition: AccountCounters.h:29
catapult::cache::UtCacheModifier
An interface for modifying an unconfirmed transactions cache.
Definition: UtCache.h:28
catapult::consumer
std::function< void(TArgs...)> consumer
A consumer function.
Definition: functions.h:35
CacheSizeLogger.h
catapult::Key
utils::ByteArray< Key_Size, Key_tag > Key
Definition: src/catapult/types.h:41
MemoryCacheProxy.h
catapult::utils::BasicSpinReaderWriterLock
Definition: SpinReaderWriterLock.h:36
RangeTypes.h
catapult::cache::MemoryUtCache::m_options
MemoryCacheOptions m_options
Definition: MemoryUtCache.h:97
catapult::cache::MemoryUtCacheView::m_transactionDataContainer
const TransactionDataContainer & m_transactionDataContainer
Definition: MemoryUtCache.h:75
catapult::model::TransactionInfo::copy
TransactionInfo copy() const
Creates a (shallow) copy of this info.
Definition: EntityInfo.h:122