P2PServer: delete old cached blocks after initial sync

Saves ~20 MB of memory
This commit is contained in:
SChernykh
2021-10-01 15:21:32 +02:00
parent 00281fb006
commit 2a3cd13b19
7 changed files with 48 additions and 9 deletions
+12 -5
View File
@@ -102,14 +102,11 @@ P2PServer::~P2PServer()
uv_mutex_destroy(&m_peerListLock);
uv_mutex_destroy(&m_broadcastLock);
uv_mutex_destroy(&m_missingBlockRequestsLock);
clear_cached_blocks();
uv_rwlock_destroy(&m_cachedBlocksLock);
delete m_block;
for (auto it : m_cachedBlocks) {
delete it.second;
}
delete m_cache;
}
@@ -124,6 +121,16 @@ void P2PServer::add_cached_block(const PoolBlock& block)
m_cachedBlocks.insert({ new_block->m_sidechainId, new_block });
}
void P2PServer::clear_cached_blocks()
{
WriteLock lock(m_cachedBlocksLock);
for (auto it : m_cachedBlocks) {
delete it.second;
}
m_cachedBlocks.clear();
}
void P2PServer::store_in_cache(const PoolBlock& block)
{
if (m_cache && block.m_verified && !block.m_invalid) {