Skip to content

Commit 88e7888

Browse files
codablockUdjinM6
authored andcommitted
Try using cache in GetListForBlock before reading from disk (#2253)
* Try using cache in GetListForBlock before reading from disk * Use std::list for vecDiff
1 parent 2900760 commit 88e7888

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/evo/deterministicmns.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,16 @@ CDeterministicMNList CDeterministicMNManager::GetListForBlock(const uint256& blo
506506

507507
uint256 blockHashTmp = blockHash;
508508
CDeterministicMNList snapshot;
509-
std::vector<CDeterministicMNListDiff> vecDiff;
509+
std::list<CDeterministicMNListDiff> listDiff;
510510

511511
while(true) {
512+
// try using cache before reading from disk
513+
it = mnListsCache.find(blockHashTmp);
514+
if (it != mnListsCache.end()) {
515+
snapshot = it->second;
516+
break;
517+
}
518+
512519
if (evoDb.Read(std::make_pair(DB_LIST_SNAPSHOT, blockHashTmp), snapshot)) {
513520
break;
514521
}
@@ -519,11 +526,11 @@ CDeterministicMNList CDeterministicMNManager::GetListForBlock(const uint256& blo
519526
break;
520527
}
521528

522-
vecDiff.emplace(vecDiff.begin(), diff);
529+
listDiff.emplace_front(diff);
523530
blockHashTmp = diff.prevBlockHash;
524531
}
525532

526-
for (const auto& diff : vecDiff) {
533+
for (const auto& diff : listDiff) {
527534
if (diff.HasChanges()) {
528535
snapshot = snapshot.ApplyDiff(diff);
529536
} else {

0 commit comments

Comments
 (0)