diff --git a/src/llmq/chainlocks.cpp b/src/llmq/chainlocks.cpp index 39130b5a07..0e9b13ae30 100644 --- a/src/llmq/chainlocks.cpp +++ b/src/llmq/chainlocks.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -373,27 +374,36 @@ void CChainLocksHandler::BlockConnected(const std::shared_ptr& pbl // We need this information later when we try to sign a new tip, so that we can determine if all included TXs are // safe. - LOCK(cs); + { + LOCK(cs); - auto it = blockTxs.find(pindex->GetBlockHash()); - if (it == blockTxs.end()) { - // we must create this entry even if there are no lockable transactions in the block, so that TrySignChainTip - // later knows about this block - it = blockTxs.emplace(pindex->GetBlockHash(), std::make_shared>()).first; - } - auto& txids = *it->second; - - int64_t curTime = GetTime().count(); - - for (const auto& tx : pblock->vtx) { - if (tx->IsCoinBase() || tx->vin.empty()) { - continue; + auto it = blockTxs.find(pindex->GetBlockHash()); + if (it == blockTxs.end()) { + // we must create this entry even if there are no lockable transactions in the block, so that TrySignChainTip later knows about this block + it = blockTxs + .emplace(pindex->GetBlockHash(), std::make_shared>()) + .first; } + auto& txids = *it->second; - txids.emplace(tx->GetHash()); - txFirstSeenTime.emplace(tx->GetHash(), curTime); + int64_t curTime = GetTime().count(); + + for (const auto& tx : pblock->vtx) { + if (tx->IsCoinBase() || tx->vin.empty()) { + continue; + } + + txids.emplace(tx->GetHash()); + txFirstSeenTime.emplace(tx->GetHash(), curTime); + } } + auto cbtx = GetCoinbaseTx(pindex); + auto clsig_height = pindex->nHeight - cbtx->bestCLHeightDiff; + if (clsig_height > uint32_t(WITH_LOCK(cs, return bestChainLock.getHeight()))) { + auto clsig = CChainLockSig(clsig_height, pindex->GetAncestor(clsig_height)->GetBlockHash(), cbtx->bestCLSignature); + ProcessNewChainLock(-1, clsig, ::SerializeHash(clsig)); + } } void CChainLocksHandler::BlockDisconnected(const std::shared_ptr& pblock, gsl::not_null pindexDisconnected)