Skip to content

Commit 1dd9573

Browse files
wip: implement automatic detection of clsigs in blocks and process them
1 parent f675fcb commit 1dd9573

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

src/llmq/chainlocks.cpp

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <llmq/quorums.h>
77
#include <llmq/instantsend.h>
88
#include <llmq/signing_shares.h>
9+
#include <evo/cbtx.h>
910

1011
#include <chain.h>
1112
#include <chainparams.h>
@@ -373,27 +374,36 @@ void CChainLocksHandler::BlockConnected(const std::shared_ptr<const CBlock>& pbl
373374
// We need this information later when we try to sign a new tip, so that we can determine if all included TXs are
374375
// safe.
375376

376-
LOCK(cs);
377+
{
378+
LOCK(cs);
377379

378-
auto it = blockTxs.find(pindex->GetBlockHash());
379-
if (it == blockTxs.end()) {
380-
// we must create this entry even if there are no lockable transactions in the block, so that TrySignChainTip
381-
// later knows about this block
382-
it = blockTxs.emplace(pindex->GetBlockHash(), std::make_shared<std::unordered_set<uint256, StaticSaltedHasher>>()).first;
383-
}
384-
auto& txids = *it->second;
380+
auto it = blockTxs.find(pindex->GetBlockHash());
381+
if (it == blockTxs.end()) {
382+
// we must create this entry even if there are no lockable transactions in the block, so that TrySignChainTip later knows about this block
383+
it = blockTxs
384+
.emplace(pindex->GetBlockHash(), std::make_shared<std::unordered_set<uint256, StaticSaltedHasher>>())
385+
.first;
386+
}
387+
auto& txids = *it->second;
385388

386-
int64_t curTime = GetTime<std::chrono::seconds>().count();
389+
int64_t curTime = GetTime<std::chrono::seconds>().count();
387390

388-
for (const auto& tx : pblock->vtx) {
389-
if (tx->IsCoinBase() || tx->vin.empty()) {
390-
continue;
391-
}
391+
for (const auto& tx : pblock->vtx) {
392+
if (tx->IsCoinBase() || tx->vin.empty()) {
393+
continue;
394+
}
392395

393-
txids.emplace(tx->GetHash());
394-
txFirstSeenTime.emplace(tx->GetHash(), curTime);
396+
txids.emplace(tx->GetHash());
397+
txFirstSeenTime.emplace(tx->GetHash(), curTime);
398+
}
395399
}
400+
auto cbtx = GetCoinbaseTx(pindex);
401+
auto clsig_height = pindex->nHeight - cbtx->bestCLHeightDiff;
396402

403+
if (clsig_height > uint32_t(WITH_LOCK(cs, return bestChainLock.getHeight()))) {
404+
auto clsig = CChainLockSig(clsig_height, pindex->GetAncestor(clsig_height)->GetBlockHash(), cbtx->bestCLSignature);
405+
ProcessNewChainLock(-1, clsig, ::SerializeHash(clsig));
406+
}
397407
}
398408

399409
void CChainLocksHandler::BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, gsl::not_null<const CBlockIndex*> pindexDisconnected)

0 commit comments

Comments
 (0)