@@ -81,8 +81,23 @@ bool CRecoveredSigsDb::HasRecoveredSigForSession(const uint256& signHash)
81
81
82
82
bool CRecoveredSigsDb::HasRecoveredSigForHash (const uint256& hash)
83
83
{
84
+ int64_t t = GetTimeMillis ();
85
+
86
+ {
87
+ LOCK (cs);
88
+ auto it = hasSigForHashCache.find (hash);
89
+ if (it != hasSigForHashCache.end ()) {
90
+ it->second .second = t;
91
+ return it->second .first ;
92
+ }
93
+ }
94
+
84
95
auto k = std::make_tuple (' h' , hash);
85
- return db.Exists (k);
96
+ bool ret = db.Exists (k);
97
+
98
+ LOCK (cs);
99
+ hasSigForHashCache.emplace (hash, std::make_pair (ret, t));
100
+ return ret;
86
101
}
87
102
88
103
bool CRecoveredSigsDb::ReadRecoveredSig (Consensus::LLMQType llmqType, const uint256& id, CRecoveredSig& ret)
@@ -154,6 +169,7 @@ void CRecoveredSigsDb::WriteRecoveredSig(const llmq::CRecoveredSig& recSig)
154
169
LOCK (cs);
155
170
hasSigForIdCache[std::make_pair ((Consensus::LLMQType)recSig.llmqType , recSig.id )] = std::make_pair (true , t);
156
171
hasSigForSessionCache[signHash] = std::make_pair (true , t);
172
+ hasSigForHashCache[recSig.GetHash ()] = std::make_pair (true , t);
157
173
}
158
174
}
159
175
@@ -239,10 +255,12 @@ void CRecoveredSigsDb::CleanupOldRecoveredSigs(int64_t maxAge)
239
255
240
256
hasSigForIdCache.erase (std::make_pair ((Consensus::LLMQType)recSig.llmqType , recSig.id ));
241
257
hasSigForSessionCache.erase (signHash);
258
+ hasSigForHashCache.erase (recSig.GetHash ());
242
259
}
243
260
244
261
TruncateCacheMap (hasSigForIdCache, MAX_CACHE_SIZE, MAX_CACHE_TRUNCATE_THRESHOLD);
245
262
TruncateCacheMap (hasSigForSessionCache, MAX_CACHE_SIZE, MAX_CACHE_TRUNCATE_THRESHOLD);
263
+ TruncateCacheMap (hasSigForHashCache, MAX_CACHE_SIZE, MAX_CACHE_TRUNCATE_THRESHOLD);
246
264
}
247
265
248
266
for (auto & e : toDelete2) {
0 commit comments