Count all miners that were active in last 24 hours

pull/11/head
SChernykh 3 years ago
parent e1b4649c2a
commit fbdef7d058

@ -484,6 +484,8 @@ void SideChain::add_block(const PoolBlock& block)
else {
verify_loop(new_block);
}
m_seenWallets[new_block->m_minerWallet.spend_public_key()] = new_block->m_localTimestamp;
}
bool SideChain::has_block(const hash& id)
@ -668,9 +670,23 @@ difficulty_type SideChain::total_hashes() const
return m_chainTip ? m_chainTip->m_cumulativeDifficulty : difficulty_type();
}
uint64_t SideChain::miner_count() const
uint64_t SideChain::miner_count()
{
return m_chainTip ? m_chainTip->m_outputs.size() : 0;
const time_t cur_time = time(nullptr);
MutexLock lock(m_sidechainLock);
// Delete wallets that weren't seen for more than 24 hours and return how many remain
for (auto it = m_seenWallets.begin(); it != m_seenWallets.end();) {
if (it->second + 24 * 60 * 60 <= cur_time) {
it = m_seenWallets.erase(it);
}
else {
++it;
}
}
return m_seenWallets.size();
}
bool SideChain::split_reward(uint64_t reward, const std::vector<MinerShare>& shares, std::vector<uint64_t>& rewards)

@ -66,7 +66,7 @@ public:
const difficulty_type& difficulty() const { return m_curDifficulty; }
difficulty_type total_hashes() const;
uint64_t block_time() const { return m_targetBlockTime; }
uint64_t miner_count() const;
uint64_t miner_count();
static bool split_reward(uint64_t reward, const std::vector<MinerShare>& shares, std::vector<uint64_t>& rewards);
@ -95,6 +95,7 @@ private:
std::map<uint64_t, std::vector<PoolBlock*>> m_blocksByHeight;
std::unordered_map<hash, PoolBlock*> m_blocksById;
std::unordered_set<hash> m_seenBlocks;
std::unordered_map<hash, time_t> m_seenWallets;
std::vector<DifficultyData> m_difficultyData;

Loading…
Cancel
Save