@@ -779,11 +779,21 @@ CDeterministicMNList CDeterministicMNManager::GetListForBlockInternal(gsl::not_n
779779 for (const auto & diffIndex : listDiffIndexes) {
780780 const auto & diff = mnListDiffsCache.at (diffIndex->GetBlockHash ());
781781 snapshot.ApplyDiff (diffIndex, diff);
782- if (!fReindex && snapshot.GetHeight () % 32 == 0 ) {
783- // Add this temporary mini-snapshot to cache.
784- // This extra cached mn-list helps to improve performance of GetListForBlock
785- // for close blocks, because in the worst cases each of them requires to retrieve
786- // and apply up to 575 diffs
782+
783+ static constexpr int MINI_SNAPSHOT_INTERVAL = 32 ;
784+ if (!node::fReindex && snapshot.GetHeight () % MINI_SNAPSHOT_INTERVAL == 0 ) {
785+ // Add this temporary mini-snapshot to the cache.
786+ // Persistent masternode list snapshots are stored in evo-db every 576 blocks.
787+ // To answer GetListForBlock() between these snapshots, the node must rebuild
788+ // state by applying up to 575 diffs from the nearest persistent snapshot.
789+ // If GetListForBlock() is called repeatedly in that range, the work multiplies
790+ // (up to 575 diffs * number of calls).
791+ // Mini-snapshots reduce this overhead by caching intermediate states
792+ // every MINI_SNAPSHOT_INTERVAL blocks. Unlike persistent snapshots, these live
793+ // only in memory and are cleaned up after a short time by the scheduled cleanup().
794+ // There is also separate in-memory caching for the current tip and active quorums,
795+ // but this mini-snapshot cache specifically speeds up repeated requests
796+ // for nearby historical blocks.
787797 mnListsCache.emplace (snapshot.GetBlockHash (), snapshot);
788798 }
789799 }
0 commit comments