CatapultServer  v0.5.0.1 (Elephant)
RecentHashCache.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "HashCheckOptions.h"
24 #include "catapult/utils/Hashers.h"
25 #include "catapult/types.h"
26 #include <unordered_map>
27 
28 namespace catapult { namespace consumers {
29 
32  public:
34  RecentHashCache(const chain::TimeSupplier& timeSupplier, const HashCheckOptions& options);
35 
36  public:
38  size_t size() const;
39 
40  public:
43  bool add(const Hash256& hash);
44 
46  bool contains(const Hash256& hash) const;
47 
48  private:
49  bool checkAndUpdateExisting(const Hash256& hash, const Timestamp& time);
50 
51  void pruneCache(const Timestamp& time);
52 
53  void tryAddToCache(const Hash256& hash, const Timestamp& time);
54 
55  private:
59  std::unordered_map<Hash256, Timestamp, utils::ArrayHasher<Hash256>> m_cache;
60  };
61 }}
catapult::consumers::HashCheckOptions::CacheDuration
uint64_t CacheDuration
Amount of time a hash should be cached.
Definition: HashCheckOptions.h:42
CATAPULT_LOG
#define CATAPULT_LOG(SEV)
Writes a log entry to the default logger with SEV severity.
Definition: Logging.h:340
catapult::consumers::RecentHashCache::size
size_t size() const
Gets the size of the cache.
Definition: RecentHashCache.cpp:33
colorPrint.warning
def warning(*args)
Definition: colorPrint.py:10
catapult::consumers::RecentHashCache::add
bool add(const Hash256 &hash)
Definition: RecentHashCache.cpp:37
catapult::consumers::RecentHashCache::m_options
HashCheckOptions m_options
Definition: RecentHashCache.h:57
HashCheckOptions.h
catapult::utils::BaseValue< uint64_t, Timestamp_tag >
catapult::consumers::RecentHashCache::m_cache
std::unordered_map< Hash256, Timestamp, utils::ArrayHasher< Hash256 > > m_cache
Definition: RecentHashCache.h:59
catapult::consumers::RecentHashCache::tryAddToCache
void tryAddToCache(const Hash256 &hash, const Timestamp &time)
Definition: RecentHashCache.cpp:72
RecentHashCache.h
catapult::consumers::RecentHashCache::m_lastPruneTime
Timestamp m_lastPruneTime
Definition: RecentHashCache.h:58
m_timeSupplier
TimeSupplier m_timeSupplier
Definition: JointValidator.cpp:85
catapult::consumers::RecentHashCache::contains
bool contains(const Hash256 &hash) const
Returns true if the cache contains hash, false otherwise.
Definition: RecentHashCache.cpp:48
catapult::utils::map_erase_if
void map_erase_if(TMap &map, TPredicate predicate)
Removes all entries from map that fulfill the given predicate.
Definition: ContainerHelpers.h:27
catapult::consumers::HashCheckOptions::PruneInterval
uint64_t PruneInterval
Minimum amount of time between cache pruning.
Definition: HashCheckOptions.h:45
ChainFunctions.h
m_options
CompareChainsOptions m_options
Definition: CompareChains.cpp:165
catapult::chain::TimeSupplier
supplier< Timestamp > TimeSupplier
Supplies a timestamp.
Definition: ChainFunctions.h:39
types.h
catapult::Timestamp
utils::BaseValue< uint64_t, Timestamp_tag > Timestamp
Definition: src/catapult/types.h:73
catapult::consumers::HashCheckOptions::MaxCacheSize
uint64_t MaxCacheSize
Maximum size of the cache.
Definition: HashCheckOptions.h:48
catapult
Definition: AddressExtractionExtension.cpp:28
Hashers.h
catapult::consumers::RecentHashCache::pruneCache
void pruneCache(const Timestamp &time)
Definition: RecentHashCache.cpp:62
catapult::consumers::RecentHashCache::RecentHashCache
RecentHashCache(const chain::TimeSupplier &timeSupplier, const HashCheckOptions &options)
Creates a recent hash cache around timeSupplier and options.
Definition: RecentHashCache.cpp:27
catapult::consumers::HashCheckOptions
Options for configuring the hash check consumer.
Definition: HashCheckOptions.h:27
catapult::consumers::RecentHashCache::m_timeSupplier
chain::TimeSupplier m_timeSupplier
Definition: RecentHashCache.h:56
Logging.h
catapult::utils::ByteArray< Hash256_Size, Hash256_tag >
catapult::consumers::RecentHashCache
A hash cache that holds recently seen hashes.
Definition: RecentHashCache.h:31
ContainerHelpers.h
catapult::consumers::RecentHashCache::checkAndUpdateExisting
bool checkAndUpdateExisting(const Hash256 &hash, const Timestamp &time)
Definition: RecentHashCache.cpp:52