Skip to content

Commit

Permalink
fix: avoid cs_vvec_shShare double-lock
Browse files Browse the repository at this point in the history
  • Loading branch information
UdjinM6 authored and PastaPastaPasta committed Mar 25, 2024
1 parent cfdb8a6 commit 804c1da
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/llmq/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ bool CQuorum::IsValidMember(const uint256& proTxHash) const
CBLSPublicKey CQuorum::GetPubKeyShare(size_t memberIdx) const
{
LOCK(cs_vvec_shShare);
if (!HasVerificationVector() || memberIdx >= members.size() || !qc->validMembers[memberIdx]) {
if (!HasVerificationVectorInternal() || memberIdx >= members.size() || !qc->validMembers[memberIdx]) {
return CBLSPublicKey();
}
const auto& m = members[memberIdx];
Expand All @@ -141,6 +141,11 @@ CBLSPublicKey CQuorum::GetPubKeyShare(size_t memberIdx) const

bool CQuorum::HasVerificationVector() const {
LOCK(cs_vvec_shShare);
return HasVerificationVectorInternal();
}

bool CQuorum::HasVerificationVectorInternal() const {
AssertLockHeld(cs_vvec_shShare);
return quorumVvec != nullptr;
}

Expand All @@ -166,7 +171,7 @@ void CQuorum::WriteContributions(CEvoDB& evoDb) const
uint256 dbKey = MakeQuorumKey(*this);

LOCK(cs_vvec_shShare);
if (HasVerificationVector()) {
if (HasVerificationVectorInternal()) {
CDataStream s(SER_DISK, CLIENT_VERSION);
WriteCompactSize(s, quorumVvec->size());
for (auto& pubkey : *quorumVvec) {
Expand Down
3 changes: 2 additions & 1 deletion src/llmq/quorums.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class CQuorum
}
bool SetSecretKeyShare(const CBLSSecretKey& secretKeyShare);

bool HasVerificationVector() const;
bool HasVerificationVector() const LOCKS_EXCLUDED(cs_vvec_shShare);
bool IsMember(const uint256& proTxHash) const;
bool IsValidMember(const uint256& proTxHash) const;
int GetMemberIndex(const uint256& proTxHash) const;
Expand All @@ -208,6 +208,7 @@ class CQuorum
CBLSSecretKey GetSkShare() const;

private:
bool HasVerificationVectorInternal() const EXCLUSIVE_LOCKS_REQUIRED(cs_vvec_shShare);
void WriteContributions(CEvoDB& evoDb) const;
bool ReadContributions(CEvoDB& evoDb);
};
Expand Down

0 comments on commit 804c1da

Please sign in to comment.