CatapultServer  v0.5.0.1 (Elephant)
MemoryPtCache.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "MemoryCacheOptions.h"
23 #include "MemoryCacheProxy.h"
24 #include "PtCache.h"
25 #include "ShortHashPair.h"
28 #include "catapult/utils/Hashers.h"
30 #include <unordered_map>
31 
32 namespace catapult { namespace cache { class PtData; } }
33 
34 namespace catapult { namespace cache {
35 
36  using PtDataContainer = std::unordered_map<Hash256, PtData, utils::ArrayHasher<Hash256>>;
37 
40  private:
41  using UnknownTransactionInfos = std::vector<model::CosignedTransactionInfo>;
42 
43  public:
46  explicit MemoryPtCacheView(
47  uint64_t maxResponseSize,
48  const PtDataContainer& transactionDataContainer,
50 
51  public:
53  size_t size() const;
54 
57 
61 
63  UnknownTransactionInfos unknownTransactions(const ShortHashPairMap& knownShortHashPairs) const;
64 
65  private:
69  };
70 
72  class MemoryPtCache : public PtCache {
73  public:
75  explicit MemoryPtCache(const MemoryCacheOptions& options);
76 
78  ~MemoryPtCache() override;
79 
80  public:
82  MemoryPtCacheView view() const;
83 
84  public:
85  PtCacheModifierProxy modifier() override;
86 
87  private:
88  struct Impl;
89 
90  private:
92  std::unique_ptr<Impl> m_pImpl;
94  };
95 
97  class MemoryPtCacheProxy : public MemoryCacheProxy<MemoryPtCache, PtCache, PtCacheModifierProxy> {
99  };
100 }}
catapult::utils::ToShortHash
ShortHash ToShortHash(const Hash256 &hash)
Gets the short hash corresponding to hash.
Definition: ShortHash.h:42
m_timestampedHashes
std::set< state::TimestampedHash > & m_timestampedHashes
Definition: MemoryPtCache.cpp:257
catapult::model::Cosignature
A cosignature.
Definition: Cosignature.h:29
catapult::cache::MemoryPtCacheView::find
model::WeakCosignedTransactionInfo find(const Hash256 &hash) const
Finds a partial transaction in the cache with associated hash or returns nullptr if no such transacti...
Definition: MemoryPtCache.cpp:106
catapult::cache::MemoryCacheProxy
A delegating proxy around a memory-based cache.
Definition: MemoryCacheProxy.h:29
catapult::cache::PtDataContainer
std::unordered_map< Hash256, PtData, utils::ArrayHasher< Hash256 > > PtDataContainer
Definition: MemoryPtCache.h:36
catapult::model::WeakCosignedTransactionInfo
Wrapper around a transaction and its cosignatures.
Definition: WeakCosignedTransactionInfo.h:29
catapult::model::DetachedTransactionInfo::copy
DetachedTransactionInfo copy() const
Creates a (shallow) copy of this info.
Definition: EntityInfo.h:92
catapult::cache::ShortHashPairMap
std::unordered_map< utils::ShortHash, utils::ShortHash, utils::ShortHashHasher > ShortHashPairMap
A map composed of short hash pairs where the key is the transaction short hash and the value is the c...
Definition: ShortHashPair.h:57
catapult::Hash256
utils::ByteArray< Hash256_Size, Hash256_tag > Hash256
Definition: src/catapult/types.h:47
catapult::cache::PtData::weakCosignedTransactionInfo
model::WeakCosignedTransactionInfo weakCosignedTransactionInfo() const
Definition: MemoryPtCache.cpp:58
catapult::crypto::Sha3_256
void Sha3_256(const RawBuffer &dataBuffer, Hash256 &hash) noexcept
Calculates the 256-bit SHA3 hash of dataBuffer into hash.
Definition: Hashes.cpp:81
WeakCosignedTransactionInfo.h
catapult::model::CosignedTransactionInfo
Definition: CosignedTransactionInfo.h:30
catapult::cache::MemoryPtCache::m_options
MemoryCacheOptions m_options
Definition: MemoryPtCache.h:88
m_readLock
utils::SpinReaderWriterLock::ReaderLockGuard m_readLock
Definition: MemoryPtCache.cpp:258
catapult::cache::MemoryCacheOptions::MaxCacheSize
uint64_t MaxCacheSize
Maximum size of the cache.
Definition: MemoryCacheOptions.h:44
catapult::cache::PtData
Definition: MemoryPtCache.cpp:30
catapult::cache::PtData::cosignatures
const std::vector< model::Cosignature > & cosignatures() const
Definition: MemoryPtCache.cpp:50
catapult::cache::PtData::entityHash
const Hash256 & entityHash() const
Definition: MemoryPtCache.cpp:46
catapult::model::EntityRange
Represents a range of entities.
Definition: EntityRange.h:31
catapult::cache::MemoryPtCacheProxy
A delegating proxy around a MemoryPtCache.
Definition: MemoryPtCache.h:97
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
catapult::model::EntityRange::begin
auto begin() const
Returns a const iterator that represents the first entity.
Definition: EntityRange.h:420
MemoryPtCache.h
catapult::cache::MemoryPtCache::Impl
Definition: MemoryPtCache.cpp:267
SpinReaderWriterLock.h
catapult::utils::BasicSpinReaderWriterLock::acquireReader
ReaderLockGuard acquireReader()
Blocks until a reader lock can be acquired.
Definition: SpinReaderWriterLock.h:153
catapult::cache::PtData::m_cosignatures
std::vector< model::Cosignature > m_cosignatures
Definition: MemoryPtCache.cpp:88
Hashes.h
catapult::model::EntityRange::PrepareFixed
static EntityRange PrepareFixed(size_t numElements, uint8_t **ppRangeData=nullptr)
Definition: EntityRange.h:265
CosignedTransactionInfo.h
catapult::cache::MemoryPtCacheView::MemoryPtCacheView
MemoryPtCacheView(uint64_t maxResponseSize, const PtDataContainer &transactionDataContainer, utils::SpinReaderWriterLock::ReaderLockGuard &&readLock)
Definition: MemoryPtCache.cpp:93
catapult::cache::MemoryPtCacheView::shortHashPairs
ShortHashPairRange shortHashPairs() const
Definition: MemoryPtCache.cpp:113
catapult::cache::PtData::cosignaturesHash
const Hash256 & cosignaturesHash() const
Definition: MemoryPtCache.cpp:54
m_writeLock
utils::SpinReaderWriterLock::WriterLockGuard m_writeLock
Definition: MemoryPtCache.cpp:259
catapult::cache::PtData::timestampedHash
state::TimestampedHash timestampedHash() const
Definition: MemoryPtCache.cpp:62
catapult::cache::MemoryCacheOptions::MaxResponseSize
uint64_t MaxResponseSize
Maximum response size.
Definition: MemoryCacheOptions.h:41
catapult::cache::MemoryPtCache::m_lock
utils::SpinReaderWriterLock m_lock
Definition: MemoryPtCache.h:93
m_maxCacheSize
uint64_t m_maxCacheSize
Definition: MemoryPtCache.cpp:255
catapult::cache::MemoryPtCache::~MemoryPtCache
~MemoryPtCache() override
Destroys a partial transactions cache.
catapult::cache::MemoryPtCacheView::m_transactionDataContainer
const PtDataContainer & m_transactionDataContainer
Definition: MemoryPtCache.h:67
ShortHashPair.h
catapult::cache::PtData::transactionInfo
model::DetachedTransactionInfo transactionInfo() const
Definition: MemoryPtCache.cpp:38
catapult::cache::MemoryPtCache::view
MemoryPtCacheView view() const
Gets a read only view based on this cache.
Definition: MemoryPtCache.cpp:279
size
uint64_t size
Definition: MemoryCounters.cpp:65
catapult::state::TimestampedHash
Represents a hash with attached timestamp.
Definition: TimestampedHash.h:31
catapult::cache::PtData::add
bool add(const Key &signer, const Signature &signature)
Definition: MemoryPtCache.cpp:67
catapult::cache::PtData::transaction
std::shared_ptr< const model::Transaction > transaction() const
Definition: MemoryPtCache.cpp:42
MemoryCacheOptions.h
catapult::cache::MemoryPtCache::Impl::TransactionDataContainer
PtDataContainer TransactionDataContainer
Definition: MemoryPtCache.cpp:268
catapult::cache::PtData::m_transactionInfo
model::DetachedTransactionInfo m_transactionInfo
Definition: MemoryPtCache.cpp:86
catapult::utils::BasicSpinReaderWriterLock::ReaderLockGuard
A reader lock guard.
Definition: SpinReaderWriterLock.h:99
catapult::cache::MemoryPtCacheView::m_readLock
utils::SpinReaderWriterLock::ReaderLockGuard m_readLock
Definition: MemoryPtCache.h:68
m_options
CompareChainsOptions m_options
Definition: CompareChains.cpp:165
catapult::cache::MemoryPtCacheView::unknownTransactions
UnknownTransactionInfos unknownTransactions(const ShortHashPairMap &knownShortHashPairs) const
Gets a vector of all unknown transaction infos in the cache that do not have a short hash pair in kno...
Definition: MemoryPtCache.cpp:126
catapult::cache::MemoryPtCacheView::size
size_t size() const
Returns the number of partial transactions in the cache.
Definition: MemoryPtCache.cpp:102
catapult::Timestamp
utils::BaseValue< uint64_t, Timestamp_tag > Timestamp
Definition: src/catapult/types.h:73
catapult::cache::MemoryPtCacheView
A read only view on top of partial transactions cache.
Definition: MemoryPtCache.h:39
catapult::model::EntityInfo::pEntity
std::shared_ptr< TEntity > pEntity
Entity pointer.
Definition: EntityInfo.h:45
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::cache::PtCacheModifierProxy
Definition: PtCache.h:47
Hashers.h
catapult::cache::MemoryPtCache
Cache for all partial transactions.
Definition: MemoryPtCache.h:72
catapult::cache::PtCache
An interface for caching partial transactions.
Definition: PtCache.h:71
catapult::cache::MemoryPtCacheView::m_maxResponseSize
uint64_t m_maxResponseSize
Definition: MemoryPtCache.h:66
catapult::utils::ByteArray< Hash256_Size, Hash256_tag >
catapult::cache::MemoryPtCache::MemoryPtCache
MemoryPtCache(const MemoryCacheOptions &options)
Creates a partial transactions cache around options.
Definition: MemoryPtCache.cpp:272
catapult::model::CosignedTransactionInfo::EntityHash
Hash256 EntityHash
Transaction entity hash.
Definition: CosignedTransactionInfo.h:32
catapult::cache::MemoryCacheOptions
Options for customizing the behavior of a memory based cache.
Definition: MemoryCacheOptions.h:27
catapult::model::EntityInfo::EntityHash
Hash256 EntityHash
Entity hash.
Definition: EntityInfo.h:48
catapult::model::CosignedTransactionInfo::Cosignatures
std::vector< Cosignature > Cosignatures
Cosignatures (optional).
Definition: CosignedTransactionInfo.h:38
catapult::cache::MemoryPtCache::m_pImpl
std::unique_ptr< Impl > m_pImpl
Definition: MemoryPtCache.h:92
catapult::cache::MemoryPtCache::Impl::TimestampedHashes
std::set< state::TimestampedHash > TimestampedHashes
Definition: MemoryPtCache.cpp:269
CacheSizeLogger.h
catapult::Key
utils::ByteArray< Key_Size, Key_tag > Key
Definition: src/catapult/types.h:41
MemoryCacheProxy.h
catapult::model::CosignedTransactionInfo::pTransaction
std::shared_ptr< const Transaction > pTransaction
Transaction pointer (optional).
Definition: CosignedTransactionInfo.h:35
m_transactionDataContainer
PtDataContainer & m_transactionDataContainer
Definition: MemoryPtCache.cpp:256
catapult::utils::BasicSpinReaderWriterLock
Definition: SpinReaderWriterLock.h:36
TimestampedHash.h
catapult::cache::MemoryPtCache::modifier
PtCacheModifierProxy modifier() override
Gets a write only view of the cache.
Definition: MemoryPtCache.cpp:284
PtCache.h
catapult::cache::PtData::m_cosignaturesHash
Hash256 m_cosignaturesHash
Definition: MemoryPtCache.cpp:87
catapult::model::DetachedTransactionInfo
Definition: EntityInfo.h:77
catapult::cache::PtData::PtData
PtData(const model::DetachedTransactionInfo &transactionInfo)
Definition: MemoryPtCache.cpp:32
catapult::cache::MemoryPtCacheView::UnknownTransactionInfos
std::vector< model::CosignedTransactionInfo > UnknownTransactionInfos
Definition: MemoryPtCache.h:41
Cosignature.h