mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-03-12 09:29:51 +00:00
P2PServer: fixed ever growing memory usage
This commit is contained in:
parent
3bc03e4801
commit
a06f4dcdcd
2 changed files with 16 additions and 17 deletions
|
@ -640,13 +640,14 @@ void P2PServer::on_broadcast()
|
|||
uint8_t* p = p0;
|
||||
|
||||
bool send_pruned = true;
|
||||
{
|
||||
ReadLock lock(client->m_broadcastedHashesLock);
|
||||
for (const hash& id : data->ancestor_hashes) {
|
||||
if (client->m_broadcastedHashes.find(id) == client->m_broadcastedHashes.end()) {
|
||||
send_pruned = false;
|
||||
break;
|
||||
}
|
||||
|
||||
const hash* a = client->m_broadcastedHashes;
|
||||
const hash* b = client->m_broadcastedHashes + array_size(&P2PClient::m_broadcastedHashes);
|
||||
|
||||
for (const hash& id : data->ancestor_hashes) {
|
||||
if (std::find(a, b, id) == b) {
|
||||
send_pruned = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -834,13 +835,12 @@ P2PServer::P2PClient::P2PClient()
|
|||
, m_lastAlive(0)
|
||||
, m_lastBroadcastTimestamp(0)
|
||||
, m_lastBlockrequestTimestamp(0)
|
||||
, m_broadcastedHashes{}
|
||||
{
|
||||
uv_rwlock_init_checked(&m_broadcastedHashesLock);
|
||||
}
|
||||
|
||||
P2PServer::P2PClient::~P2PClient()
|
||||
{
|
||||
uv_rwlock_destroy(&m_broadcastedHashesLock);
|
||||
}
|
||||
|
||||
void P2PServer::P2PClient::reset()
|
||||
|
@ -860,8 +860,10 @@ void P2PServer::P2PClient::reset()
|
|||
m_lastBroadcastTimestamp = 0;
|
||||
m_lastBlockrequestTimestamp = 0;
|
||||
|
||||
WriteLock lock(m_broadcastedHashesLock);
|
||||
m_broadcastedHashes.clear();
|
||||
for (hash& h : m_broadcastedHashes) {
|
||||
h = {};
|
||||
}
|
||||
m_broadcastedHashesIndex = 0;
|
||||
}
|
||||
|
||||
bool P2PServer::P2PClient::on_connect()
|
||||
|
@ -1487,10 +1489,7 @@ bool P2PServer::P2PClient::on_block_broadcast(const uint8_t* buf, uint32_t size)
|
|||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
WriteLock lock2(m_broadcastedHashesLock);
|
||||
m_broadcastedHashes.insert(server->m_block->m_sidechainId);
|
||||
}
|
||||
m_broadcastedHashes[m_broadcastedHashesIndex.fetch_add(1) % array_size(&P2PClient::m_broadcastedHashes)] = server->m_block->m_sidechainId;
|
||||
|
||||
const MinerData& miner_data = server->m_pool->miner_data();
|
||||
|
||||
|
|
|
@ -115,8 +115,8 @@ public:
|
|||
time_t m_lastBroadcastTimestamp;
|
||||
time_t m_lastBlockrequestTimestamp;
|
||||
|
||||
uv_rwlock_t m_broadcastedHashesLock;
|
||||
std::set<hash> m_broadcastedHashes;
|
||||
hash m_broadcastedHashes[8];
|
||||
std::atomic<uint32_t> m_broadcastedHashesIndex{ 0 };
|
||||
};
|
||||
|
||||
void broadcast(const PoolBlock& block);
|
||||
|
|
Loading…
Reference in a new issue