Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <consensus/validation.h>
#include <deploymentstatus.h>
#include <messagesigner.h>
#include <node/blockstorage.h>
#include <script/standard.h>
#include <stats/client.h>
#include <uint256.h>
Expand Down Expand Up @@ -778,6 +779,23 @@ CDeterministicMNList CDeterministicMNManager::GetListForBlockInternal(gsl::not_n
for (const auto& diffIndex : listDiffIndexes) {
const auto& diff = mnListDiffsCache.at(diffIndex->GetBlockHash());
snapshot.ApplyDiff(diffIndex, diff);

static constexpr int MINI_SNAPSHOT_INTERVAL = 32;
if (!node::fReindex && snapshot.GetHeight() % MINI_SNAPSHOT_INTERVAL == 0) {
// Add this temporary mini-snapshot to the cache.
// Persistent masternode list snapshots are stored in evo-db every 576 blocks.
// To answer GetListForBlock() between these snapshots, the node must rebuild
// state by applying up to 575 diffs from the nearest persistent snapshot.
// If GetListForBlock() is called repeatedly in that range, the work multiplies
// (up to 575 diffs * number of calls).
// Mini-snapshots reduce this overhead by caching intermediate states
// every MINI_SNAPSHOT_INTERVAL blocks. Unlike persistent snapshots, these live
// only in memory and are cleaned up after a short time by the scheduled cleanup().
// There is also separate in-memory caching for the current tip and active quorums,
// but this mini-snapshot cache specifically speeds up repeated requests
// for nearby historical blocks.
mnListsCache.emplace(snapshot.GetBlockHash(), snapshot);
}
}

if (tipIndex) {
Expand Down
Loading