mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-11-16 15:57:39 +00:00
Optimized SideChain::miner_count()
This commit is contained in:
parent
d05d47fa75
commit
9579be5c7d
2 changed files with 12 additions and 7 deletions
|
@ -61,6 +61,7 @@ SideChain::SideChain(p2pool* pool, NetworkType type, const char* pool_name)
|
|||
: m_pool(pool)
|
||||
, m_networkType(type)
|
||||
, m_chainTip{ nullptr }
|
||||
, m_seenWalletsLastPruneTime(0)
|
||||
, m_poolName(pool_name ? pool_name : "default")
|
||||
, m_targetBlockTime(10)
|
||||
, m_minDifficulty(MIN_DIFFICULTY, 0)
|
||||
|
@ -846,14 +847,17 @@ uint64_t SideChain::miner_count()
|
|||
|
||||
MutexLock lock(m_seenWalletsLock);
|
||||
|
||||
// Delete wallets that weren't seen for more than 72 hours and return how many remain
|
||||
for (auto it = m_seenWallets.begin(); it != m_seenWallets.end();) {
|
||||
if (it->second + 72 * 60 * 60 <= cur_time) {
|
||||
it = m_seenWallets.erase(it);
|
||||
}
|
||||
else {
|
||||
++it;
|
||||
// Every 5 minutes, delete wallets that weren't seen for more than 72 hours
|
||||
if (m_seenWalletsLastPruneTime + 5 * 60 <= cur_time) {
|
||||
for (auto it = m_seenWallets.begin(); it != m_seenWallets.end();) {
|
||||
if (it->second + 72 * 60 * 60 < cur_time) {
|
||||
it = m_seenWallets.erase(it);
|
||||
}
|
||||
else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
m_seenWalletsLastPruneTime = cur_time;
|
||||
}
|
||||
|
||||
return m_seenWallets.size();
|
||||
|
|
|
@ -105,6 +105,7 @@ private:
|
|||
|
||||
uv_mutex_t m_seenWalletsLock;
|
||||
unordered_map<hash, uint64_t> m_seenWallets;
|
||||
uint64_t m_seenWalletsLastPruneTime;
|
||||
|
||||
uv_mutex_t m_seenBlocksLock;
|
||||
unordered_set<hash> m_seenBlocks;
|
||||
|
|
Loading…
Reference in a new issue