From d8f8f174c096770fea1dc6da9d09431d9f4d494b Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Wed, 28 Oct 2020 22:01:29 +0300 Subject: [PATCH] Avoid accessing pendingContributionVerifications from VerifyPendingContributions while ReceiveMessage is still doing its job (#3782) --- src/llmq/quorums_dkgsession.cpp | 9 ++++++++- src/llmq/quorums_dkgsession.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/llmq/quorums_dkgsession.cpp b/src/llmq/quorums_dkgsession.cpp index 4859497f1d..8871071187 100644 --- a/src/llmq/quorums_dkgsession.cpp +++ b/src/llmq/quorums_dkgsession.cpp @@ -260,6 +260,8 @@ bool CDKGSession::PreVerifyMessage(const uint256& hash, const CDKGContribution& void CDKGSession::ReceiveMessage(const uint256& hash, const CDKGContribution& qc, bool& retBan) { + LOCK(cs_pending); + CDKGLogger logger(*this, __func__); retBan = false; @@ -359,6 +361,8 @@ void CDKGSession::ReceiveMessage(const uint256& hash, const CDKGContribution& qc // See CBLSWorker::VerifyContributionShares for more details. void CDKGSession::VerifyPendingContributions() { + AssertLockHeld(cs_pending); + CDKGLogger logger(*this, __func__); cxxtimer::Timer t1(true); @@ -412,7 +416,10 @@ void CDKGSession::VerifyAndComplain(CDKGPendingMessages& pendingMessages) return; } - VerifyPendingContributions(); + { + LOCK(cs_pending); + VerifyPendingContributions(); + } CDKGLogger logger(*this, __func__); diff --git a/src/llmq/quorums_dkgsession.h b/src/llmq/quorums_dkgsession.h index b70f7d7942..6525f6eb89 100644 --- a/src/llmq/quorums_dkgsession.h +++ b/src/llmq/quorums_dkgsession.h @@ -277,6 +277,7 @@ private: std::map justifications; std::map prematureCommitments; + mutable CCriticalSection cs_pending; std::vector pendingContributionVerifications; // filled by ReceivePrematureCommitment and used by FinalizeCommitments