From 96291e7a0f9a363b8d55aa613898af0615b1d0e5 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Fri, 1 Mar 2019 06:45:11 +0100 Subject: [PATCH] Cheaper/Faster bailout from TrySignChainTip when already signed before --- src/llmq/quorums_chainlocks.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/llmq/quorums_chainlocks.cpp b/src/llmq/quorums_chainlocks.cpp index eed337bfd861d..eb016ed045795 100644 --- a/src/llmq/quorums_chainlocks.cpp +++ b/src/llmq/quorums_chainlocks.cpp @@ -227,9 +227,6 @@ void CChainLocksHandler::TrySignChainTip() // This will fail when multiple blocks compete, but we accept this for the initial implementation. // Later, we'll add the multiple attempts process. - uint256 requestId = ::SerializeHash(std::make_pair(CLSIG_REQUESTID_PREFIX, pindex->nHeight)); - uint256 msgHash = pindex->GetBlockHash(); - { LOCK(cs); @@ -244,6 +241,16 @@ void CChainLocksHandler::TrySignChainTip() return; } + if (pindex->nHeight == lastSignedHeight) { + // already signed this one + return; + } + + if (bestChainLock.nHeight >= pindex->nHeight) { + // already got the same CLSIG or a better one + return; + } + if (InternalHasConflictingChainLock(pindex->nHeight, pindex->GetBlockHash())) { if (!inEnforceBestChainLock) { // we accepted this block when there was no lock yet, but now a conflicting lock appeared. Invalidate it. @@ -253,14 +260,15 @@ void CChainLocksHandler::TrySignChainTip() } return; } + } - if (bestChainLock.nHeight >= pindex->nHeight) { - // already got the same CLSIG or a better one - return; - } + uint256 requestId = ::SerializeHash(std::make_pair(CLSIG_REQUESTID_PREFIX, pindex->nHeight)); + uint256 msgHash = pindex->GetBlockHash(); - if (pindex->nHeight == lastSignedHeight) { - // already signed this one + { + LOCK(cs); + if (bestChainLock.nHeight >= pindex->nHeight) { + // might have happened while we didn't hold cs return; } lastSignedHeight = pindex->nHeight;