mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-01-05 18:29:23 +00:00
SideChain: use a separate lock for m_seenBlocks
This commit is contained in:
parent
b45540ca08
commit
f59e9171e8
2 changed files with 11 additions and 7 deletions
|
@ -77,6 +77,7 @@ SideChain::SideChain(p2pool* pool, NetworkType type, const char* pool_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
uv_mutex_init_checked(&m_sidechainLock);
|
uv_mutex_init_checked(&m_sidechainLock);
|
||||||
|
uv_mutex_init_checked(&m_seenBlocksLock);
|
||||||
|
|
||||||
m_difficultyData.reserve(m_chainWindowSize);
|
m_difficultyData.reserve(m_chainWindowSize);
|
||||||
|
|
||||||
|
@ -147,6 +148,7 @@ SideChain::SideChain(p2pool* pool, NetworkType type, const char* pool_name)
|
||||||
SideChain::~SideChain()
|
SideChain::~SideChain()
|
||||||
{
|
{
|
||||||
uv_mutex_destroy(&m_sidechainLock);
|
uv_mutex_destroy(&m_sidechainLock);
|
||||||
|
uv_mutex_destroy(&m_seenBlocksLock);
|
||||||
for (auto& it : m_blocksById) {
|
for (auto& it : m_blocksById) {
|
||||||
delete it.second;
|
delete it.second;
|
||||||
}
|
}
|
||||||
|
@ -343,21 +345,21 @@ bool SideChain::get_shares(PoolBlock* tip, std::vector<MinerShare>& shares) cons
|
||||||
|
|
||||||
bool SideChain::block_seen(const PoolBlock& block)
|
bool SideChain::block_seen(const PoolBlock& block)
|
||||||
{
|
{
|
||||||
MutexLock lock(m_sidechainLock);
|
|
||||||
|
|
||||||
// Check if it's some old block
|
// Check if it's some old block
|
||||||
if (m_chainTip && m_chainTip->m_sidechainHeight > block.m_sidechainHeight + m_chainWindowSize * 2 &&
|
const PoolBlock* tip = m_chainTip;
|
||||||
block.m_cumulativeDifficulty < m_chainTip->m_cumulativeDifficulty) {
|
if (tip && tip->m_sidechainHeight > block.m_sidechainHeight + m_chainWindowSize * 2 &&
|
||||||
|
block.m_cumulativeDifficulty < tip->m_cumulativeDifficulty) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if it was received before
|
// Check if it was received before
|
||||||
|
MutexLock lock(m_seenBlocksLock);
|
||||||
return !m_seenBlocks.insert(block.m_sidechainId).second;
|
return !m_seenBlocks.insert(block.m_sidechainId).second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SideChain::unsee_block(const PoolBlock& block)
|
void SideChain::unsee_block(const PoolBlock& block)
|
||||||
{
|
{
|
||||||
MutexLock lock(m_sidechainLock);
|
MutexLock lock(m_seenBlocksLock);
|
||||||
m_seenBlocks.erase(block.m_sidechainId);
|
m_seenBlocks.erase(block.m_sidechainId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1541,7 +1543,7 @@ void SideChain::prune_old_blocks()
|
||||||
auto it2 = m_blocksById.find(block->m_sidechainId);
|
auto it2 = m_blocksById.find(block->m_sidechainId);
|
||||||
if (it2 != m_blocksById.end()) {
|
if (it2 != m_blocksById.end()) {
|
||||||
m_blocksById.erase(it2);
|
m_blocksById.erase(it2);
|
||||||
m_seenBlocks.erase(block->m_sidechainId);
|
unsee_block(*block);
|
||||||
delete block;
|
delete block;
|
||||||
++num_blocks_pruned;
|
++num_blocks_pruned;
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,9 +97,11 @@ private:
|
||||||
PoolBlock* m_chainTip;
|
PoolBlock* m_chainTip;
|
||||||
std::map<uint64_t, std::vector<PoolBlock*>> m_blocksByHeight;
|
std::map<uint64_t, std::vector<PoolBlock*>> m_blocksByHeight;
|
||||||
unordered_map<hash, PoolBlock*> m_blocksById;
|
unordered_map<hash, PoolBlock*> m_blocksById;
|
||||||
unordered_set<hash> m_seenBlocks;
|
|
||||||
unordered_map<hash, time_t> m_seenWallets;
|
unordered_map<hash, time_t> m_seenWallets;
|
||||||
|
|
||||||
|
uv_mutex_t m_seenBlocksLock;
|
||||||
|
unordered_set<hash> m_seenBlocks;
|
||||||
|
|
||||||
std::vector<DifficultyData> m_difficultyData;
|
std::vector<DifficultyData> m_difficultyData;
|
||||||
|
|
||||||
std::string m_poolName;
|
std::string m_poolName;
|
||||||
|
|
Loading…
Reference in a new issue