diff --git a/src/side_chain.cpp b/src/side_chain.cpp index 367df71..21af2a4 100644 --- a/src/side_chain.cpp +++ b/src/side_chain.cpp @@ -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& shares, std::vector& rewards) diff --git a/src/side_chain.h b/src/side_chain.h index adc6686..2c9b0cd 100644 --- a/src/side_chain.h +++ b/src/side_chain.h @@ -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& shares, std::vector& rewards); @@ -95,6 +95,7 @@ private: std::map> m_blocksByHeight; std::unordered_map m_blocksById; std::unordered_set m_seenBlocks; + std::unordered_map m_seenWallets; std::vector m_difficultyData;