CatapultServer  v0.5.0.1 (Elephant)
AccountStateCache.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "AccountStateCacheDelta.h"
23 #include "AccountStateCacheView.h"
25 
26 namespace catapult { namespace cache {
27 
28  using AccountStateBasicCache = BasicCache<
29  AccountStateCacheDescriptor,
33 
36  public:
39  : BasicAccountStateCache(config, options, std::make_unique<model::AddressSet>())
40  {}
41 
42  private:
44  const CacheConfiguration& config,
45  const AccountStateCacheTypes::Options& options,
46  std::unique_ptr<model::AddressSet>&& pHighValueAddresses)
47  : AccountStateBasicCache(config, AccountStateCacheTypes::Options(options), *pHighValueAddresses)
48  , m_pHighValueAddresses(std::move(pHighValueAddresses))
49  {}
50 
51  public:
53  void init(model::AddressSet&& highValueAddresses) {
54  *m_pHighValueAddresses = std::move(highValueAddresses);
55  }
56 
59  void commit(const CacheDeltaType& delta) {
60  // high value addresses need to be captured before committing because committing clears the deltas
61  auto highValueAddresses = delta.highValueAddresses().Current;
63  *m_pHighValueAddresses = std::move(highValueAddresses);
64  }
65 
66  private:
67  // unique pointer to allow set reference to be valid after moves of this cache
68  std::unique_ptr<model::AddressSet> m_pHighValueAddresses;
69  };
70 
72  class AccountStateCache : public SynchronizedCacheWithInit<BasicAccountStateCache> {
73  public:
75 
76  public:
81  , m_importanceGrouping(options.ImportanceGrouping)
82  {}
83 
84  public:
87  return m_networkIdentifier;
88  }
89 
91  uint64_t importanceGrouping() const {
92  return m_importanceGrouping;
93  }
94 
95  private:
98  };
99 }}
catapult::cache::SynchronizedCacheWithInit
Decorator that synchronizes access to a cache and allows custom cache initialization.
Definition: SynchronizedCache.h:277
catapult::cache::BasicAccountStateCache::m_pHighValueAddresses
std::unique_ptr< model::AddressSet > m_pHighValueAddresses
Definition: AccountStateCache.h:68
catapult::cache::BasicAccountStateCache::commit
void commit(const CacheDeltaType &delta)
Definition: AccountStateCache.h:59
DEFINE_CACHE_CONSTANTS
#define DEFINE_CACHE_CONSTANTS(NAME)
Defines cache constants for a cache with NAME.
Definition: CacheConstants.h:42
catapult::cache::BasicCache::commit
void commit(const CacheDeltaType &delta)
Commits all pending changes from delta to the underlying storage.
Definition: BasicCache.h:64
catapult::cache::AccountStateCache::AccountStateCache
AccountStateCache(const CacheConfiguration &config, const AccountStateCacheTypes::Options &options)
Creates a cache around config and options.
Definition: AccountStateCache.h:78
catapult::cache::AccountStateCache::m_importanceGrouping
uint64_t m_importanceGrouping
Definition: AccountStateCache.h:97
catapult::model::AddressSet
std::unordered_set< Address, utils::ArrayHasher< Address > > AddressSet
Unordered set of addresses.
Definition: ContainerTypes.h:41
catapult::tools::Options
boost::program_options::variables_map Options
Provides access to parsed options.
Definition: Options.h:34
catapult::cache::AccountStateCacheTypes
AccountState cache types.
Definition: AccountStateCacheTypes.h:74
BasicCache.h
AccountStateCacheDelta.h
catapult::cache::AccountStateCacheTypes::Options
Custom sub view options.
Definition: AccountStateCacheTypes.h:79
AccountStateCacheView.h
catapult::cache::AccountStateCache::importanceGrouping
uint64_t importanceGrouping() const
Gets the network importance grouping.
Definition: AccountStateCache.h:91
catapult::cache::AccountStateCache::m_networkIdentifier
model::NetworkIdentifier m_networkIdentifier
Definition: AccountStateCache.h:96
catapult::cache::AccountStateCache::networkIdentifier
model::NetworkIdentifier networkIdentifier() const
Gets the network identifier.
Definition: AccountStateCache.h:86
catapult::cache::AccountStateCacheTypes::BaseSets
AccountStateBaseSets BaseSets
Definition: AccountStateCacheTypes.h:191
catapult::cache::CacheId::AccountState
catapult::model::NetworkIdentifier
NetworkIdentifier
Possible network identifiers.
Definition: NetworkInfo.h:45
catapult::cache::AccountStateCache
Synchronized cache composed of stateful account information.
Definition: AccountStateCache.h:72
catapult::cache::BasicCache
Definition: BasicCache.h:32
catapult::cache::BasicCache::CacheDeltaType
typename TCacheDescriptor::CacheDeltaType CacheDeltaType
Definition: BasicCache.h:36
catapult::cache::AccountStateBasicCache
BasicCache< AccountStateCacheDescriptor, AccountStateCacheTypes::BaseSets, AccountStateCacheTypes::Options, const model::AddressSet & > AccountStateBasicCache
Definition: AccountStateCache.h:32
catapult::cache::CacheConfiguration
Cache configuration.
Definition: CacheConfiguration.h:37
catapult::cache::BasicAccountStateCache::init
void init(model::AddressSet &&highValueAddresses)
Initializes the cache with highValueAddresses.
Definition: AccountStateCache.h:53
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::cache::BasicAccountStateCache::BasicAccountStateCache
BasicAccountStateCache(const CacheConfiguration &config, const AccountStateCacheTypes::Options &options)
Creates a cache around config and options.
Definition: AccountStateCache.h:38
catapult::cache::BasicAccountStateCache::BasicAccountStateCache
BasicAccountStateCache(const CacheConfiguration &config, const AccountStateCacheTypes::Options &options, std::unique_ptr< model::AddressSet > &&pHighValueAddresses)
Definition: AccountStateCache.h:43
catapult::cache::BasicAccountStateCache
Cache composed of stateful account information.
Definition: AccountStateCache.h:35