CatapultServer  v0.5.0.1 (Elephant)
UnlockedAccounts.h
Go to the documentation of this file.
1 
21 #pragma once
24 #include "catapult/utils/Hashers.h"
25 #include <vector>
26 
27 namespace catapult { namespace harvesting {
28 
29 #define UNLOCKED_ACCOUNTS_ADD_RESULT_LIST \
30  /* Account was successfully unlocked (it might have already been unlocked). */ \
31  ENUM_VALUE(Success) \
32  \
33  /* Account could not be unlocked because it is ineligible for harvesting. */ \
34  ENUM_VALUE(Failure_Harvesting_Ineligible) \
35  \
36  /* Account could not be unlocked because it is blocked from harvesting. */ \
37  ENUM_VALUE(Failure_Harvesting_Blocked) \
38  \
39  /* Account could not be unlocked because limit on the server has been hit. */ \
40  ENUM_VALUE(Failure_Server_Limit)
41 
42 #define ENUM_VALUE(LABEL) LABEL,
43  enum class UnlockedAccountsAddResult {
46  };
47 #undef ENUM_VALUE
48 
50  std::ostream& operator<<(std::ostream& out, UnlockedAccountsAddResult value);
51 
54  public:
57  const std::vector<crypto::KeyPair>& keyPairs,
59  : m_keyPairs(keyPairs)
60  , m_readLock(std::move(readLock))
61  {}
62 
63  public:
65  size_t size() const;
66 
68  bool contains(const Key& publicKey) const;
69 
71  auto begin() const {
72  return m_keyPairs.cbegin();
73  }
74 
76  auto end() const {
77  return m_keyPairs.cend();
78  }
79 
80  private:
81  const std::vector<crypto::KeyPair>& m_keyPairs;
83  };
84 
87  private:
89 
90  public:
93  size_t maxUnlockedAccounts,
94  std::vector<crypto::KeyPair>& keyPairs,
96  : m_maxUnlockedAccounts(maxUnlockedAccounts)
97  , m_keyPairs(keyPairs)
98  , m_readLock(std::move(readLock))
99  , m_writeLock(m_readLock.promoteToWriter())
100  {}
101 
102  public:
105 
107  void remove(const Key& publicKey);
108 
110  void removeIf(const KeyPredicate& predicate);
111 
112  private:
114  std::vector<crypto::KeyPair>& m_keyPairs;
117  };
118 
121  public:
123  explicit UnlockedAccounts(size_t maxUnlockedAccounts) : m_maxUnlockedAccounts(maxUnlockedAccounts)
124  {}
125 
126  public:
128  UnlockedAccountsView view() const;
129 
132 
133  private:
135  std::vector<crypto::KeyPair> m_keyPairs;
137  };
138 }}
catapult::harvesting::UnlockedAccountsModifier::m_writeLock
utils::SpinReaderWriterLock::WriterLockGuard m_writeLock
Definition: UnlockedAccounts.h:116
catapult::validators::DEFINE_STATEFUL_VALIDATOR
DEFINE_STATEFUL_VALIDATOR(EligibleHarvester, [](const auto &notification, const auto &context) { cache::ImportanceView view(context.Cache.template sub< cache::AccountStateCache >());return view.canHarvest(notification.Signer, context.Height) ? ValidationResult::Success :Failure_Core_Block_Harvester_Ineligible;})
catapult::harvesting::UnlockedAccountsModifier::m_keyPairs
std::vector< crypto::KeyPair > & m_keyPairs
Definition: UnlockedAccounts.h:114
catapult::harvesting::UnlockedAccounts::view
UnlockedAccountsView view() const
Gets a read only view of the unlocked accounts.
Definition: UnlockedAccounts.cpp:86
CATAPULT_LOG
#define CATAPULT_LOG(SEV)
Writes a log entry to the default logger with SEV severity.
Definition: Logging.h:340
catapult::harvesting::UnlockedAccounts::modifier
UnlockedAccountsModifier modifier()
Gets a write only view of the unlocked accounts.
Definition: UnlockedAccounts.cpp:91
NamespaceCache.h
catapult::predicate
std::function< bool(TArgs...)> predicate
A predicate function.
Definition: functions.h:31
catapult::harvesting::operator<<
std::ostream & operator<<(std::ostream &out, UnlockedAccountsAddResult value)
Insertion operator for outputting value to out.
catapult::harvesting::UnlockedAccountsAddResult::UNLOCKED_ACCOUNTS_ADD_RESULT_LIST
ValidatorContext.h
catapult::model::AccountLinkAction::Unlink
Unlink account.
catapult::validators::ValidationResult
ValidationResult
Enumeration of all possible validation results.
Definition: ValidationResult.h:51
catapult::validators::Notification
model::AccountAddressNotification Notification
Definition: AddressValidator.cpp:27
MacroBasedEnum.h
catapult::harvesting::UnlockedAccountsView::m_readLock
utils::SpinReaderWriterLock::ReaderLockGuard m_readLock
Definition: UnlockedAccounts.h:82
catapult::harvesting::UnlockedAccounts::m_keyPairs
std::vector< crypto::KeyPair > m_keyPairs
Definition: UnlockedAccounts.h:135
catapult::harvesting::UnlockedAccountsModifier
A write only view on top of unlocked accounts.
Definition: UnlockedAccounts.h:86
UnlockedAccounts.h
HashCache.h
catapult::hashcache::HashCache
DECLARE_SERVICE_REGISTRAR() HashCache()
Definition: HashCacheService.cpp:46
KeyPair.h
catapult::harvesting::UnlockedAccounts::UnlockedAccounts
UnlockedAccounts(size_t maxUnlockedAccounts)
Creates an unlocked accounts container that allows at most maxUnlockedAccounts unloced accounts.
Definition: UnlockedAccounts.h:123
catapult::harvesting::UnlockedAccounts::m_maxUnlockedAccounts
size_t m_maxUnlockedAccounts
Definition: UnlockedAccounts.h:134
catapult::utils::BasicSpinReaderWriterLock::acquireReader
ReaderLockGuard acquireReader()
Blocks until a reader lock can be acquired.
Definition: SpinReaderWriterLock.h:153
catapult::harvesting::UnlockedAccountsModifier::add
UnlockedAccountsAddResult add(crypto::KeyPair &&keyPair)
Adds (unlocks) the account identified by key pair (keyPair).
Definition: UnlockedAccounts.cpp:54
catapult::harvesting::UnlockedAccountsView::size
size_t size() const
Returns the number of unlocked accounts.
Definition: UnlockedAccounts.cpp:42
catapult::harvesting::UnlockedAccountsView
A read only view on top of unlocked accounts.
Definition: UnlockedAccounts.h:53
catapult::utils::BasicSpinReaderWriterLock::WriterLockGuard
A writer lock guard.
Definition: SpinReaderWriterLock.h:83
catapult::harvesting::UnlockedAccounts
Container of all unlocked (harvesting candidate) accounts.
Definition: UnlockedAccounts.h:120
catapult::crypto::KeyPair
Represents a pair of private key with associated public key.
Definition: KeyPair.h:33
catapult::model::AliasedMosaicIdNotification
AliasedDataNotification< MosaicId, Namespace_Aliased_MosaicId_Notification > AliasedMosaicIdNotification
Notification of an aliased mosaic id.
Definition: AliasNotifications.h:122
catapult::harvesting::UnlockedAccountsView::end
auto end() const
Returns a const iterator to the element following the last element of the underlying container.
Definition: UnlockedAccounts.h:76
catapult::harvesting::UnlockedAccountsView::m_keyPairs
const std::vector< crypto::KeyPair > & m_keyPairs
Definition: UnlockedAccounts.h:81
catapult::harvesting::UnlockedAccountsView::contains
bool contains(const Key &publicKey) const
Returns true if the public key belongs to an unlocked account, false otherwise.
Definition: UnlockedAccounts.cpp:46
catapult::model::NotificationType
NotificationType
Enumeration of all possible notification types.
Definition: NotificationType.h:43
catapult::harvesting::UnlockedAccountsModifier::UnlockedAccountsModifier
UnlockedAccountsModifier(size_t maxUnlockedAccounts, std::vector< crypto::KeyPair > &keyPairs, utils::SpinReaderWriterLock::ReaderLockGuard &&readLock)
Creates a view around maxUnlockedAccounts and keyPairs with lock context readLock.
Definition: UnlockedAccounts.h:92
catapult::harvesting::UnlockedAccountsModifier::KeyPredicate
predicate< const Key & > KeyPredicate
Definition: UnlockedAccounts.h:88
forwardsValidation.info
def info(*args)
Definition: forwardsValidation.py:12
Validators.h
AliasedType
static constexpr auto AliasedType
Definition: UnlinkAliasedDataConsistencyValidator.cpp:58
MacroBasedEnumIncludes.h
Validators.h
catapult::state::AliasType::Mosaic
Mosaic id alias.
catapult::model::AliasedAddressNotification
AliasedDataNotification< Address, Namespace_Aliased_Address_Notification > AliasedAddressNotification
Notification of an aliased address.
Definition: AliasNotifications.h:119
catapult::utils::MoveOnly
A class that can be moved but not copied.
Definition: NonCopyable.h:43
AccountStateCache.h
catapult::state::AliasType::Address
Account address alias.
catapult::harvesting::UnlockedAccountsAddResult
UnlockedAccountsAddResult
Possible results of an add (unlock) operation.
Definition: UnlockedAccounts.h:44
catapult::harvesting::UnlockedAccounts::m_lock
utils::SpinReaderWriterLock m_lock
Definition: UnlockedAccounts.h:136
catapult::validators::ValidationResult::Success
Validation succeeded.
catapult::utils::BasicSpinReaderWriterLock::ReaderLockGuard
A reader lock guard.
Definition: SpinReaderWriterLock.h:99
catapult::harvesting::UnlockedAccountsModifier::remove
void remove(const Key &publicKey)
Removes (locks) the account identified by the public key (publicKey).
Definition: UnlockedAccounts.cpp:65
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::harvesting::UnlockedAccountsView::UnlockedAccountsView
UnlockedAccountsView(const std::vector< crypto::KeyPair > &keyPairs, utils::SpinReaderWriterLock::ReaderLockGuard &&readLock)
Creates a view around keyPairs with lock context readLock.
Definition: UnlockedAccounts.h:56
Hashers.h
catapult::harvesting::UnlockedAccountsModifier::m_maxUnlockedAccounts
size_t m_maxUnlockedAccounts
Definition: UnlockedAccounts.h:113
DEFINE_UNLINK_ALIASED_DATA_VALIDATOR
#define DEFINE_UNLINK_ALIASED_DATA_VALIDATOR(VALIDATOR_NAME, TRAITS_NAME)
Definition: UnlinkAliasedDataConsistencyValidator.cpp:51
catapult::utils::ByteArray< Key_Size, Key_tag >
catapult::harvesting::UnlockedAccountsModifier::removeIf
void removeIf(const KeyPredicate &predicate)
Removes all accounts for which predicate returns true.
Definition: UnlockedAccounts.cpp:71
catapult::Key
utils::ByteArray< Key_Size, Key_tag > Key
Definition: src/catapult/types.h:41
catapult::harvesting::UnlockedAccountsView::begin
auto begin() const
Returns a const iterator to the first element of the underlying container.
Definition: UnlockedAccounts.h:71
catapult::utils::BasicSpinReaderWriterLock
Definition: SpinReaderWriterLock.h:36
TimestampedHash.h
catapult::harvesting::UnlockedAccountsModifier::m_readLock
utils::SpinReaderWriterLock::ReaderLockGuard m_readLock
Definition: UnlockedAccounts.h:115