CatapultServer  v0.5.0.1 (Elephant)
AccountStateCacheDelta.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "AccountStateBaseSets.h"
28 
29 namespace catapult { namespace cache {
30 
33  public:
35 
36  private:
39 
40  public:
43  using ContainsKey = ContainsMixin<
52 
53  // no mutable key accessor because address-to-key pairs are immutable
54  };
55 
58  : public utils::MoveOnly
68  public:
70 
71  public:
74  const AccountStateCacheTypes::BaseSetDeltaPointers& accountStateSets,
75  const AccountStateCacheTypes::Options& options,
77 
78  private:
80  const AccountStateCacheTypes::BaseSetDeltaPointers& accountStateSets,
81  const AccountStateCacheTypes::Options& options,
83  std::unique_ptr<AccountStateCacheDeltaMixins::KeyLookupAdapter>&& pKeyLookupAdapter);
84 
85  public:
88 
93 
94  public:
97 
99  uint64_t importanceGrouping() const;
100 
102  Amount minHarvesterBalance() const;
103 
106 
107  public:
109  void addAccount(const Address& address, Height addressHeight);
110 
113  void addAccount(const Key& publicKey, Height publicKeyHeight);
114 
116  void addAccount(const state::AccountState& accountState);
117 
118  public:
121  void queueRemove(const Address& address, Height height);
122 
125  void queueRemove(const Key& publicKey, Height height);
126 
128  void commitRemovals();
129 
130  public:
135 
138  };
139 
142 
143  private:
144  Address getAddress(const Key& publicKey);
145 
146  void remove(const Address& address, Height height);
147  void remove(const Key& publicKey, Height height);
148 
149  private:
150  // height is first component for a nicer equals
151  template<typename TArray>
152  using ArrayHeightPair = std::pair<Height, TArray>;
153 
154  template<typename TArray>
156  size_t operator()(const ArrayHeightPair<TArray>& arrayHeightPair) const {
157  return Hasher(arrayHeightPair.second);
158  }
159 
161  };
162 
163  template<typename TArray>
164  using QueuedRemovalSet = std::unordered_set<ArrayHeightPair<TArray>, ArrayHeightPairHasher<TArray>>;
165 
166  private:
169 
172  std::unique_ptr<AccountStateCacheDeltaMixins::KeyLookupAdapter> m_pKeyLookupAdapter;
173 
176  };
177 
179  class AccountStateCacheDelta : public ReadOnlyViewSupplier<BasicAccountStateCacheDelta> {
180  public:
183  const AccountStateCacheTypes::BaseSetDeltaPointers& accountStateSets,
184  const AccountStateCacheTypes::Options& options,
186  : ReadOnlyViewSupplier(accountStateSets, options, highValueAddresses)
187  {}
188  };
189 }}
ReadOnlyAccountStateCache.h
catapult::cache::BasicCacheMixins::MutableAccessor
MutableAccessorMixin< TSet, TCacheDescriptor > MutableAccessor
Definition: CacheMixinAliases.h:36
catapult::cache::BasicAccountStateCacheDelta::ArrayHeightPair
std::pair< Height, TArray > ArrayHeightPair
Definition: AccountStateCacheDelta.h:152
catapult::cache::BasicCacheMixins::Size
SizeMixin< TSet > Size
Definition: CacheMixinAliases.h:31
catapult::cache::BasicAccountStateCacheDelta::queueRemove
void queueRemove(const Address &address, Height height)
Definition: AccountStateCacheDelta.cpp:162
catapult::cache::BasicAccountStateCacheDelta::ArrayHeightPairHasher
Definition: AccountStateCacheDelta.h:155
m_removed
model::AddressSet & m_removed
Definition: AccountStateCacheDelta.cpp:216
catapult::cache::AccountStateCacheDeltaMixins::ConstAccessorAddress
AddressMixins::ConstAccessor ConstAccessorAddress
Definition: AccountStateCacheDelta.h:46
catapult::cache::BasicCacheMixins::DeltaElements
deltaset::DeltaElementsMixin< TSet > DeltaElements
Definition: CacheMixinAliases.h:47
catapult::state::AccountState::PublicKey
Key PublicKey
Public key of an account. Present if PublicKeyHeight > 0.
Definition: AccountState.h:64
catapult::cache::BasicAccountStateCacheDelta::addAccount
void addAccount(const Address &address, Height addressHeight)
If not present, adds an account to the cache at given height (addressHeight) using address.
Definition: AccountStateCacheDelta.cpp:90
catapult::cache::BasicAccountStateCacheDelta::commitRemovals
void commitRemovals()
Commits all queued removals.
Definition: AccountStateCacheDelta.cpp:170
catapult::cache::AccountStateCacheTypes::Options::ImportanceGrouping
uint64_t ImportanceGrouping
Importance grouping.
Definition: AccountStateCacheTypes.h:84
catapult::cache::BasicAccountStateCacheDelta::HighValueAddressesTuple
Tuple composed of information about high value addresses that is returned by highValueAddresses.
Definition: AccountStateCacheDelta.h:132
catapult::cache::ReadOnlyViewSupplier
Decorates a view and supplies a read-only view.
Definition: ReadOnlyViewSupplier.h:28
catapult::cache::BasicAccountStateCacheDelta::m_pKeyToAddress
AccountStateCacheTypes::KeyLookupMapTypes::BaseSetDeltaPointerType m_pKeyToAddress
Definition: AccountStateCacheDelta.h:168
catapult::cache::BasicAccountStateCacheDelta::BasicAccountStateCacheDelta
BasicAccountStateCacheDelta(const AccountStateCacheTypes::BaseSetDeltaPointers &accountStateSets, const AccountStateCacheTypes::Options &options, const model::AddressSet &highValueAddresses)
Creates a delta around accountStateSets, options and highValueAddresses.
Definition: AccountStateCacheDelta.cpp:29
catapult::model::AddressSet
std::unordered_set< Address, utils::ArrayHasher< Address > > AddressSet
Unordered set of addresses.
Definition: ContainerTypes.h:41
catapult::predicate
std::function< bool(TArgs...)> predicate
A predicate function.
Definition: functions.h:31
catapult::deltaset::DeltaElementsMixin
Mixin that wraps BaseSetDelta and provides a facade on top of BaseSetDelta::deltas().
Definition: DeltaElementsMixin.h:30
catapult::cache::PatriciaTreeCacheMixins::PatriciaTreeDelta
PatriciaTreeDeltaMixin< TSet, typename TCacheDescriptor::PatriciaTree::DeltaType > PatriciaTreeDelta
Definition: CacheMixinAliases.h:54
catapult::state::AccountState
Account state data.
Definition: AccountState.h:44
catapult::Height
utils::BaseValue< uint64_t, Height_tag > Height
Definition: src/catapult/types.h:85
catapult::state::AccountState::PublicKeyHeight
Height PublicKeyHeight
Height at which public key has been obtained.
Definition: AccountState.h:67
catapult::cache::detail::UnorderedMapAdapter::BaseSetDeltaType
typename BaseSetType::DeltaType BaseSetDeltaType
Base set delta type.
Definition: CacheDescriptorAdapters.h:84
ReadOnlyViewSupplier.h
catapult::cache::AccountStateCacheDeltaMixins::DeltaElements
AddressMixins::DeltaElements DeltaElements
Definition: AccountStateCacheDelta.h:51
functions.h
AccountStateCacheDelta.h
catapult::cache::BasicAccountStateCacheDelta::HighValueAddressesTuple::Removed
model::AddressSet Removed
Addresses of accounts that were high value but are no longer high value after application of all delt...
Definition: AccountStateCacheDelta.h:137
catapult::cache::AccountStateCacheTypes::Options::HarvestingMosaicId
MosaicId HarvestingMosaicId
Mosaic id used to provide harvesting ability.
Definition: AccountStateCacheTypes.h:94
catapult::cache::BasicAccountStateCacheDelta::ArrayHeightPairHasher::operator()
size_t operator()(const ArrayHeightPair< TArray > &arrayHeightPair) const
Definition: AccountStateCacheDelta.h:156
catapult::cache::BasicAccountStateCacheDelta::remove
void remove(const Address &address, Height height)
Definition: AccountStateCacheDelta.cpp:124
catapult::cache::AccountStateBaseSetDeltaPointers
Definition: AccountStateBaseSets.h:41
catapult::utils::BaseValue< uint64_t, Amount_tag >
catapult::cache::PatriciaTreeCacheMixins
Grouping of all basic and patricia tree cache mixins for a single set.
Definition: CacheMixinAliases.h:52
catapult::cache::ConstAccessorMixin
A mixin for adding const access support to a cache.
Definition: CacheMixins.h:190
catapult::cache::AccountStateCacheDeltaMixins::Size
AddressMixins::Size Size
Definition: AccountStateCacheDelta.h:41
catapult::cache::AccountStateCacheTypes::Options
Custom sub view options.
Definition: AccountStateCacheTypes.h:79
catapult::cache::BasicAccountStateCacheDelta::m_queuedRemoveByPublicKey
QueuedRemovalSet< Key > m_queuedRemoveByPublicKey
Definition: AccountStateCacheDelta.h:175
catapult::state::AccountState::Address
catapult::Address Address
Address of an account.
Definition: AccountState.h:58
catapult::cache::BasicCacheMixins::Contains
ContainsMixin< TSet, TCacheDescriptor > Contains
Definition: CacheMixinAliases.h:32
catapult::cache::BasicAccountStateCacheDelta::minHarvesterBalance
Amount minHarvesterBalance() const
Gets the minimum harvester balance.
Definition: AccountStateCacheDelta.cpp:71
catapult::cache::BasicCacheMixins::ConstAccessor
ConstAccessorMixin< TSet, TCacheDescriptor > ConstAccessor
Definition: CacheMixinAliases.h:35
HexFormatter.h
AccountStateBaseSets.h
catapult::cache::BasicAccountStateCacheDelta::HighValueAddressesTuple::Current
model::AddressSet Current
Addresses of accounts that are high value after application of all delta changes.
Definition: AccountStateCacheDelta.h:134
catapult::cache::ContainsMixin
A mixin for adding contains support to a cache.
Definition: CacheMixins.h:54
catapult::cache::BasicAccountStateCacheDelta::m_pStateByAddress
AccountStateCacheTypes::PrimaryTypes::BaseSetDeltaPointerType m_pStateByAddress
Definition: AccountStateCacheDelta.h:167
catapult::cache::ConstAccessorMixin::find
const_iterator find(const KeyType &key) const
Finds the cache value identified by key.
Definition: CacheMixins.h:207
catapult::cache::MutableAccessorMixin::find
iterator find(const KeyType &key)
Finds the cache value identified by key.
Definition: CacheMixins.h:239
catapult::cache::BasicAccountStateCacheDelta::m_pKeyLookupAdapter
std::unique_ptr< AccountStateCacheDeltaMixins::KeyLookupAdapter > m_pKeyLookupAdapter
Definition: AccountStateCacheDelta.h:172
catapult::cache::AccountStateCacheDelta
Delta on top of the account state cache.
Definition: AccountStateCacheDelta.h:179
Address.h
catapult::cache::AccountStateCacheDelta::AccountStateCacheDelta
AccountStateCacheDelta(const AccountStateCacheTypes::BaseSetDeltaPointers &accountStateSets, const AccountStateCacheTypes::Options &options, const model::AddressSet &highValueAddresses)
Creates a delta around accountStateSets, options and highValueAddresses.
Definition: AccountStateCacheDelta.h:182
catapult::model::PublicKeyToAddress
Address PublicKeyToAddress(const Key &publicKey, NetworkIdentifier networkIdentifier)
Creates an address from a public key (publicKey) for the network identified by networkIdentifier.
Definition: Address.cpp:50
catapult::cache::BasicAccountStateCacheDelta::networkIdentifier
model::NetworkIdentifier networkIdentifier() const
Gets the network identifier.
Definition: AccountStateCacheDelta.cpp:63
catapult::cache::PatriciaTreeDeltaMixin
A mixin for adding patricia tree support to a delta cache.
Definition: PatriciaTreeCacheMixins.h:62
catapult::utils::MoveOnly
A class that can be moved but not copied.
Definition: NonCopyable.h:43
CacheMixinAliases.h
catapult::cache::BasicAccountStateCacheDelta::harvestingMosaicId
MosaicId harvestingMosaicId() const
Gets the harvesting mosaic id.
Definition: AccountStateCacheDelta.cpp:75
catapult::model::NetworkIdentifier
NetworkIdentifier
Possible network identifiers.
Definition: NetworkInfo.h:45
catapult::cache::BasicAccountStateCacheDelta::m_highValueAddresses
const model::AddressSet & m_highValueAddresses
Definition: AccountStateCacheDelta.h:171
catapult::cache::BasicAccountStateCacheDelta
Basic delta on top of the account state cache.
Definition: AccountStateCacheDelta.h:57
catapult::cache::AccountStateCacheTypes::Options::CurrencyMosaicId
MosaicId CurrencyMosaicId
Mosaic id used as primary chain currency.
Definition: AccountStateCacheTypes.h:91
ContainerTypes.h
catapult::cache::AccountStateCacheTypes::KeyLookupMapTypesDescriptor
Describes a key-based interface on top of an account state cache.
Definition: AccountStateCacheTypes.h:101
catapult::cache::AccountStateCacheTypes::ComposedLookupAdapter
Definition: AccountStateCacheTypes.h:121
m_options
CompareChainsOptions m_options
Definition: CompareChains.cpp:165
catapult::cache::ContainsMixin::contains
bool contains(const KeyType &key) const
Gets a value indicating whether or not the cache contains an element with key.
Definition: CacheMixins.h:65
catapult::cache::AccountStateCacheTypes::Options::MinHarvesterBalance
Amount MinHarvesterBalance
Definition: AccountStateCacheTypes.h:88
Casting.h
AccountStateCacheSerializers.h
catapult::cache::BasicAccountStateCacheDelta::importanceGrouping
uint64_t importanceGrouping() const
Gets the network importance grouping.
Definition: AccountStateCacheDelta.cpp:67
catapult::cache::AccountStateCacheTypes::Options::NetworkIdentifier
model::NetworkIdentifier NetworkIdentifier
Network identifier.
Definition: AccountStateCacheTypes.h:81
catapult::cache::detail::UnorderedMapAdapter::BaseSetDeltaPointerType
std::shared_ptr< BaseSetDeltaType > BaseSetDeltaPointerType
Base set delta pointer type.
Definition: CacheDescriptorAdapters.h:87
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::cache::BasicAccountStateCacheDelta::highValueAddresses
HighValueAddressesTuple highValueAddresses() const
Gets all high value addresses.
Definition: AccountStateCacheDelta.cpp:220
catapult::cache::SizeMixin
A mixin for adding size support to a cache.
Definition: CacheMixins.h:36
catapult::cache::AccountStateCacheDeltaMixins::MutableAccessorAddress
AddressMixins::MutableAccessor MutableAccessorAddress
Definition: AccountStateCacheDelta.h:48
catapult::cache::BasicAccountStateCacheDelta::m_queuedRemoveByAddress
QueuedRemovalSet< Address > m_queuedRemoveByAddress
Definition: AccountStateCacheDelta.h:174
catapult::cache::BasicAccountStateCacheDelta::QueuedRemovalSet
std::unordered_set< ArrayHeightPair< TArray >, ArrayHeightPairHasher< TArray > > QueuedRemovalSet
Definition: AccountStateCacheDelta.h:164
catapult::cache::AccountStateCacheDeltaMixins
Mixins used by the account state cache delta.
Definition: AccountStateCacheDelta.h:32
catapult::utils::ByteArray
Base class for wrappers of byte array types, to provide some type-safety.
Definition: ByteArray.h:29
catapult::cache::BasicAccountStateCacheDelta::m_options
const AccountStateCacheTypes::Options & m_options
Definition: AccountStateCacheDelta.h:170
catapult::cache::BasicAccountStateCacheDelta::getAddress
Address getAddress(const Key &publicKey)
Definition: AccountStateCacheDelta.cpp:79
catapult::cache::ReadOnlyAccountStateCache
A read-only overlay on top of an account cache.
Definition: ReadOnlyAccountStateCache.h:36
m_current
model::AddressSet & m_current
Definition: AccountStateCacheDelta.cpp:215
catapult::cache::BasicAccountStateCacheDelta::ArrayHeightPairHasher::Hasher
utils::ArrayHasher< TArray > Hasher
Definition: AccountStateCacheDelta.h:160
catapult::Key
utils::ByteArray< Key_Size, Key_tag > Key
Definition: src/catapult/types.h:41
catapult::cache::MutableAccessorMixin
Definition: CacheMixins.h:222
catapult::cache::AccountStateCacheDeltaMixins::ContainsAddress
AddressMixins::Contains ContainsAddress
Definition: AccountStateCacheDelta.h:42
m_original
const model::AddressSet & m_original
Definition: AccountStateCacheDelta.cpp:214
catapult::utils::ArrayHasher< TArray >
catapult::cache::BasicCacheMixins
Grouping of all basic cache mixins for a single set.
Definition: CacheMixinAliases.h:30