Try using cache in GetListForBlock before reading from disk (#2253)

* Try using cache in GetListForBlock before reading from disk

* Use std::list for vecDiff
This commit is contained in:
Alexander Block 2018-09-03 12:17:41 +02:00 committed by UdjinM6
parent 2900760dac
commit 88e7888de9

View File

@ -506,9 +506,16 @@ CDeterministicMNList CDeterministicMNManager::GetListForBlock(const uint256& blo
uint256 blockHashTmp = blockHash;
CDeterministicMNList snapshot;
std::vector<CDeterministicMNListDiff> vecDiff;
std::list<CDeterministicMNListDiff> listDiff;
while(true) {
// try using cache before reading from disk
it = mnListsCache.find(blockHashTmp);
if (it != mnListsCache.end()) {
snapshot = it->second;
break;
}
if (evoDb.Read(std::make_pair(DB_LIST_SNAPSHOT, blockHashTmp), snapshot)) {
break;
}
@ -519,11 +526,11 @@ CDeterministicMNList CDeterministicMNManager::GetListForBlock(const uint256& blo
break;
}
vecDiff.emplace(vecDiff.begin(), diff);
listDiff.emplace_front(diff);
blockHashTmp = diff.prevBlockHash;
}
for (const auto& diff : vecDiff) {
for (const auto& diff : listDiff) {
if (diff.HasChanges()) {
snapshot = snapshot.ApplyDiff(diff);
} else {