mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-08-20 05:28:47 -06:00
P2PServer: fixed ever growing memory usage
This commit is contained in:
parent
3bc03e4801
commit
a06f4dcdcd
@ -640,15 +640,16 @@ void P2PServer::on_broadcast()
|
|||||||
uint8_t* p = p0;
|
uint8_t* p = p0;
|
||||||
|
|
||||||
bool send_pruned = true;
|
bool send_pruned = true;
|
||||||
{
|
|
||||||
ReadLock lock(client->m_broadcastedHashesLock);
|
const hash* a = client->m_broadcastedHashes;
|
||||||
|
const hash* b = client->m_broadcastedHashes + array_size(&P2PClient::m_broadcastedHashes);
|
||||||
|
|
||||||
for (const hash& id : data->ancestor_hashes) {
|
for (const hash& id : data->ancestor_hashes) {
|
||||||
if (client->m_broadcastedHashes.find(id) == client->m_broadcastedHashes.end()) {
|
if (std::find(a, b, id) == b) {
|
||||||
send_pruned = false;
|
send_pruned = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (send_pruned) {
|
if (send_pruned) {
|
||||||
LOGINFO(6, "sending BLOCK_BROADCAST (pruned) to " << log::Gray() << static_cast<char*>(client->m_addrString));
|
LOGINFO(6, "sending BLOCK_BROADCAST (pruned) to " << log::Gray() << static_cast<char*>(client->m_addrString));
|
||||||
@ -834,13 +835,12 @@ P2PServer::P2PClient::P2PClient()
|
|||||||
, m_lastAlive(0)
|
, m_lastAlive(0)
|
||||||
, m_lastBroadcastTimestamp(0)
|
, m_lastBroadcastTimestamp(0)
|
||||||
, m_lastBlockrequestTimestamp(0)
|
, m_lastBlockrequestTimestamp(0)
|
||||||
|
, m_broadcastedHashes{}
|
||||||
{
|
{
|
||||||
uv_rwlock_init_checked(&m_broadcastedHashesLock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
P2PServer::P2PClient::~P2PClient()
|
P2PServer::P2PClient::~P2PClient()
|
||||||
{
|
{
|
||||||
uv_rwlock_destroy(&m_broadcastedHashesLock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void P2PServer::P2PClient::reset()
|
void P2PServer::P2PClient::reset()
|
||||||
@ -860,8 +860,10 @@ void P2PServer::P2PClient::reset()
|
|||||||
m_lastBroadcastTimestamp = 0;
|
m_lastBroadcastTimestamp = 0;
|
||||||
m_lastBlockrequestTimestamp = 0;
|
m_lastBlockrequestTimestamp = 0;
|
||||||
|
|
||||||
WriteLock lock(m_broadcastedHashesLock);
|
for (hash& h : m_broadcastedHashes) {
|
||||||
m_broadcastedHashes.clear();
|
h = {};
|
||||||
|
}
|
||||||
|
m_broadcastedHashesIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool P2PServer::P2PClient::on_connect()
|
bool P2PServer::P2PClient::on_connect()
|
||||||
@ -1487,10 +1489,7 @@ bool P2PServer::P2PClient::on_block_broadcast(const uint8_t* buf, uint32_t size)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
m_broadcastedHashes[m_broadcastedHashesIndex.fetch_add(1) % array_size(&P2PClient::m_broadcastedHashes)] = server->m_block->m_sidechainId;
|
||||||
WriteLock lock2(m_broadcastedHashesLock);
|
|
||||||
m_broadcastedHashes.insert(server->m_block->m_sidechainId);
|
|
||||||
}
|
|
||||||
|
|
||||||
const MinerData& miner_data = server->m_pool->miner_data();
|
const MinerData& miner_data = server->m_pool->miner_data();
|
||||||
|
|
||||||
|
@ -115,8 +115,8 @@ public:
|
|||||||
time_t m_lastBroadcastTimestamp;
|
time_t m_lastBroadcastTimestamp;
|
||||||
time_t m_lastBlockrequestTimestamp;
|
time_t m_lastBlockrequestTimestamp;
|
||||||
|
|
||||||
uv_rwlock_t m_broadcastedHashesLock;
|
hash m_broadcastedHashes[8];
|
||||||
std::set<hash> m_broadcastedHashes;
|
std::atomic<uint32_t> m_broadcastedHashesIndex{ 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
void broadcast(const PoolBlock& block);
|
void broadcast(const PoolBlock& block);
|
||||||
|
Loading…
Reference in New Issue
Block a user