Clear crypto derivation/key cache when a block is found

pull/51/head
SChernykh 3 years ago
parent 4fce76576f
commit 4bcaa41c8e

@ -227,6 +227,14 @@ public:
return true;
}
void clear()
{
MutexLock lock(m);
derivations.clear();
public_keys.clear();
}
private:
uv_mutex_t m;
std::unordered_map<std::array<uint8_t, HASH_SIZE * 2>, hash> derivations;
@ -245,4 +253,9 @@ bool derive_public_key(const hash& derivation, size_t output_index, const hash&
return cache.get_public_key(derivation, output_index, base, derived_key);
}
void clear_crypto_cache()
{
cache.clear();
}
} // namespace p2pool

@ -23,5 +23,6 @@ void generate_keys(hash& pub, hash& sec);
bool check_keys(const hash& pub, const hash& sec);
bool generate_key_derivation(const hash& key1, const hash& key2, hash& derivation);
bool derive_public_key(const hash& derivation, size_t output_index, const hash& base, hash& derived_key);
void clear_crypto_cache();
} // namespace p2pool

@ -1055,6 +1055,8 @@ void p2pool::api_update_stats_mod()
void p2pool::api_update_block_found(const ChainMain* data)
{
clear_crypto_cache();
if (!m_api) {
return;
}

@ -126,7 +126,7 @@ namespace std {
template<>
struct hash<p2pool::hash>
{
FORCEINLINE size_t operator()(const p2pool::hash& value) const
FORCEINLINE size_t operator()(const p2pool::hash& value) const noexcept
{
uint64_t result = 0xcbf29ce484222325ull;
for (size_t i = 0; i < p2pool::HASH_SIZE; ++i) {
@ -139,7 +139,7 @@ struct hash<p2pool::hash>
template<size_t N>
struct hash<std::array<uint8_t, N>>
{
FORCEINLINE size_t operator()(const std::array<uint8_t, N>& value) const
FORCEINLINE size_t operator()(const std::array<uint8_t, N>& value) const noexcept
{
uint64_t result = 0xcbf29ce484222325ull;
for (size_t i = 0; i < N; ++i) {

Loading…
Cancel
Save