@@ -207,6 +207,7 @@ void CDKGSessionManager::WriteVerifiedSkContribution(Consensus::LLMQType llmqTyp
207
207
208
208
bool CDKGSessionManager::GetVerifiedContributions (Consensus::LLMQType llmqType, const CBlockIndex* pindexQuorum, const std::vector<bool >& validMembers, std::vector<uint16_t >& memberIndexesRet, std::vector<BLSVerificationVectorPtr>& vvecsRet, BLSSecretKeyVector& skContributionsRet)
209
209
{
210
+ LOCK (contributionsCacheCs);
210
211
auto members = CLLMQUtils::GetAllQuorumMembers (llmqType, pindexQuorum);
211
212
212
213
memberIndexesRet.clear ();
@@ -217,47 +218,28 @@ bool CDKGSessionManager::GetVerifiedContributions(Consensus::LLMQType llmqType,
217
218
skContributionsRet.reserve (members.size ());
218
219
for (size_t i = 0 ; i < members.size (); i++) {
219
220
if (validMembers[i]) {
220
- BLSVerificationVectorPtr vvec;
221
- CBLSSecretKey skContribution;
222
- if (!GetVerifiedContribution (llmqType, pindexQuorum, members[i]->proTxHash , vvec, skContribution)) {
223
- return false ;
221
+ const uint256& proTxHash = members[i]->proTxHash ;
222
+ ContributionsCacheKey cacheKey = {llmqType, pindexQuorum->GetBlockHash (), proTxHash};
223
+ auto it = contributionsCache.find (cacheKey);
224
+ if (it == contributionsCache.end ()) {
225
+ BLSVerificationVectorPtr vvecPtr = std::make_shared<BLSVerificationVector>();
226
+ CBLSSecretKey skContribution;
227
+ if (!llmqDb.Read (std::make_tuple (DB_VVEC, llmqType, pindexQuorum->GetBlockHash (), proTxHash), *vvecPtr)) {
228
+ return false ;
229
+ }
230
+ llmqDb.Read (std::make_tuple (DB_SKCONTRIB, llmqType, pindexQuorum->GetBlockHash (), proTxHash), skContribution);
231
+
232
+ it = contributionsCache.emplace (cacheKey, ContributionsCacheEntry{GetTimeMillis (), vvecPtr, skContribution}).first ;
224
233
}
225
234
226
235
memberIndexesRet.emplace_back (i);
227
- vvecsRet.emplace_back (vvec);
228
- skContributionsRet.emplace_back (skContribution);
236
+ vvecsRet.emplace_back (it-> second . vvec );
237
+ skContributionsRet.emplace_back (it-> second . skContribution );
229
238
}
230
239
}
231
240
return true ;
232
241
}
233
242
234
- bool CDKGSessionManager::GetVerifiedContribution (Consensus::LLMQType llmqType, const CBlockIndex* pindexQuorum, const uint256& proTxHash, BLSVerificationVectorPtr& vvecRet, CBLSSecretKey& skContributionRet)
235
- {
236
- LOCK (contributionsCacheCs);
237
- ContributionsCacheKey cacheKey = {llmqType, pindexQuorum->GetBlockHash (), proTxHash};
238
- auto it = contributionsCache.find (cacheKey);
239
- if (it != contributionsCache.end ()) {
240
- vvecRet = it->second .vvec ;
241
- skContributionRet = it->second .skContribution ;
242
- return true ;
243
- }
244
-
245
- BLSVerificationVector vvec;
246
- BLSVerificationVectorPtr vvecPtr;
247
- CBLSSecretKey skContribution;
248
- if (llmqDb.Read (std::make_tuple (DB_VVEC, llmqType, pindexQuorum->GetBlockHash (), proTxHash), vvec)) {
249
- vvecPtr = std::make_shared<BLSVerificationVector>(std::move (vvec));
250
- }
251
- llmqDb.Read (std::make_tuple (DB_SKCONTRIB, llmqType, pindexQuorum->GetBlockHash (), proTxHash), skContribution);
252
-
253
- it = contributionsCache.emplace (cacheKey, ContributionsCacheEntry{GetTimeMillis (), vvecPtr, skContribution}).first ;
254
-
255
- vvecRet = it->second .vvec ;
256
- skContributionRet = it->second .skContribution ;
257
-
258
- return true ;
259
- }
260
-
261
243
void CDKGSessionManager::CleanupCache ()
262
244
{
263
245
LOCK (contributionsCacheCs);
0 commit comments