From a3933fac781e9fbc673021756c6a972cff2575f5 Mon Sep 17 00:00:00 2001 From: pasta Date: Wed, 11 Nov 2026 12:03:23 -0600 Subject: [PATCH] fix(llmq): races in watch-connection seed, partial sig-share batches, and ChainLock shutdown --- src/chainlock/handler.cpp | 11 ++++++++--- src/llmq/signing_shares.cpp | 2 ++ src/llmq/utils.cpp | 10 +--------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/chainlock/handler.cpp b/src/chainlock/handler.cpp index 69f2efb47067..cadce2a74dc8 100644 --- a/src/chainlock/handler.cpp +++ b/src/chainlock/handler.cpp @@ -57,8 +57,7 @@ ChainlockHandler::ChainlockHandler(chainlock::Chainlocks& chainlocks, Chainstate ChainlockHandler::~ChainlockHandler() { - scheduler->stop(); - scheduler_thread->join(); + Stop(); } void ChainlockHandler::Start() @@ -72,7 +71,13 @@ void ChainlockHandler::Start() std::chrono::seconds{5}); } -void ChainlockHandler::Stop() { scheduler->stop(); } +void ChainlockHandler::Stop() +{ + scheduler->stop(); + if (scheduler_thread->joinable()) { + scheduler_thread->join(); + } +} bool ChainlockHandler::AlreadyHave(const CInv& inv) const { diff --git a/src/llmq/signing_shares.cpp b/src/llmq/signing_shares.cpp index d1998ffced08..a1af7093be9b 100644 --- a/src/llmq/signing_shares.cpp +++ b/src/llmq/signing_shares.cpp @@ -596,6 +596,8 @@ bool CSigSharesManager::CollectPendingSigSharesToVerify( if (!quorum) { LogPrintf("%s: ERROR! Unexpected missing quorum with llmqType=%d, quorumHash=%s\n", __func__, std23::to_underlying(llmqType), sigShare.getQuorumHash().ToString()); + retSigShares.clear(); + retQuorums.clear(); return false; } retQuorums.try_emplace(k, quorum); diff --git a/src/llmq/utils.cpp b/src/llmq/utils.cpp index 541de71ed982..a27c86d9b64f 100644 --- a/src/llmq/utils.cpp +++ b/src/llmq/utils.cpp @@ -21,7 +21,6 @@ #include #include -#include #include #include #include @@ -902,14 +901,7 @@ std::unordered_set CalcDeterministicWatchConnections(Consensus::LLMQType gsl::not_null pQuorumBaseBlockIndex, size_t memberCount, size_t connectionCount) { - static uint256 qwatchConnectionSeed; - static std::atomic qwatchConnectionSeedGenerated{false}; - static RecursiveMutex qwatchConnectionSeedCs; - if (!qwatchConnectionSeedGenerated) { - LOCK(qwatchConnectionSeedCs); - qwatchConnectionSeed = GetRandHash(); - qwatchConnectionSeedGenerated = true; - } + static const uint256 qwatchConnectionSeed = GetRandHash(); std::unordered_set result; uint256 rnd = qwatchConnectionSeed;