@@ -71,15 +71,17 @@ void CChainLocksHandler::Start(const llmq::CInstantSendManager& isman)
7171 if (m_signer) {
7272 m_signer->Start ();
7373 }
74- scheduler->scheduleEvery ([&]() {
75- CheckActiveState ();
76- EnforceBestChainLock ();
77- Cleanup ();
78- // regularly retry signing the current chaintip as it might have failed before due to missing islocks
79- if (m_signer) {
80- m_signer->TrySignChainTip (isman);
81- }
82- }, std::chrono::seconds{5 });
74+ scheduler->scheduleEvery (
75+ [&]() {
76+ CheckActiveState ();
77+ EnforceBestChainLock ();
78+ Cleanup ();
79+ // regularly retry signing the current chaintip as it might have failed before due to missing islocks
80+ if (m_signer) {
81+ m_signer->TrySignChainTip (isman);
82+ }
83+ },
84+ std::chrono::seconds{5 });
8385}
8486
8587void CChainLocksHandler::Stop ()
@@ -142,7 +144,8 @@ MessageProcessingResult CChainLocksHandler::ProcessNewChainLock(const NodeId fro
142144 }
143145
144146 if (const auto ret = VerifyChainLock (clsig); ret != VerifyRecSigStatus::Valid) {
145- LogPrint (BCLog::CHAINLOCKS, " CChainLocksHandler::%s -- invalid CLSIG (%s), status=%d peer=%d\n " , __func__, clsig.ToString (), ToUnderlying (ret), from);
147+ LogPrint (BCLog::CHAINLOCKS, " CChainLocksHandler::%s -- invalid CLSIG (%s), status=%d peer=%d\n " , __func__,
148+ clsig.ToString (), ToUnderlying (ret), from);
146149 if (from != -1 ) {
147150 return MisbehavingError{10 };
148151 }
@@ -157,11 +160,10 @@ MessageProcessingResult CChainLocksHandler::ProcessNewChainLock(const NodeId fro
157160 bestChainLock = clsig;
158161
159162 if (pindex != nullptr ) {
160-
161163 if (pindex->nHeight != clsig.getHeight ()) {
162164 // Should not happen, same as the conflict check from above.
163165 LogPrintf (" CChainLocksHandler::%s -- height of CLSIG (%s) does not match the specified block's height (%d)\n " ,
164- __func__, clsig.ToString (), pindex->nHeight );
166+ __func__, clsig.ToString (), pindex->nHeight );
165167 // Note: not relaying clsig here
166168 return {};
167169 }
@@ -181,13 +183,15 @@ MessageProcessingResult CChainLocksHandler::ProcessNewChainLock(const NodeId fro
181183 return clsigInv;
182184 }
183185
184- scheduler->scheduleFromNow ([&]() {
185- CheckActiveState ();
186- EnforceBestChainLock ();
187- }, std::chrono::seconds{0 });
186+ scheduler->scheduleFromNow (
187+ [&]() {
188+ CheckActiveState ();
189+ EnforceBestChainLock ();
190+ },
191+ std::chrono::seconds{0 });
188192
189- LogPrint (BCLog::CHAINLOCKS, " CChainLocksHandler::%s -- processed new CLSIG (%s), peer=%d\n " ,
190- __func__, clsig.ToString (), from);
193+ LogPrint (BCLog::CHAINLOCKS, " CChainLocksHandler::%s -- processed new CLSIG (%s), peer=%d\n " , __func__,
194+ clsig.ToString (), from);
191195 return clsigInv;
192196}
193197
@@ -196,7 +200,8 @@ void CChainLocksHandler::AcceptedBlockHeader(gsl::not_null<const CBlockIndex*> p
196200 LOCK (cs);
197201
198202 if (pindexNew->GetBlockHash () == bestChainLock.getBlockHash ()) {
199- LogPrint (BCLog::CHAINLOCKS, " CChainLocksHandler::%s -- block header %s came in late, updating and enforcing\n " , __func__, pindexNew->GetBlockHash ().ToString ());
203+ LogPrint (BCLog::CHAINLOCKS, " CChainLocksHandler::%s -- block header %s came in late, updating and enforcing\n " ,
204+ __func__, pindexNew->GetBlockHash ().ToString ());
200205
201206 if (bestChainLock.getHeight () != pindexNew->nHeight ) {
202207 // Should not happen, same as the conflict check from ProcessNewChainLock.
@@ -220,15 +225,17 @@ void CChainLocksHandler::UpdatedBlockTip(const llmq::CInstantSendManager& isman)
220225 // EnforceBestChainLock switching chains.
221226 // atomic[If tryLockChainTipScheduled is false, do (set it to true] and schedule signing).
222227 if (bool expected = false ; tryLockChainTipScheduled.compare_exchange_strong (expected, true )) {
223- scheduler->scheduleFromNow ([&]() {
224- CheckActiveState ();
225- EnforceBestChainLock ();
226- Cleanup ();
227- if (m_signer) {
228- m_signer->TrySignChainTip (isman);
229- }
230- tryLockChainTipScheduled = false ;
231- }, std::chrono::seconds{0 });
228+ scheduler->scheduleFromNow (
229+ [&]() {
230+ CheckActiveState ();
231+ EnforceBestChainLock ();
232+ Cleanup ();
233+ if (m_signer) {
234+ m_signer->TrySignChainTip (isman);
235+ }
236+ tryLockChainTipScheduled = false ;
237+ },
238+ std::chrono::seconds{0 });
232239 }
233240}
234241
@@ -281,7 +288,8 @@ void CChainLocksHandler::BlockConnected(const std::shared_ptr<const CBlock>& pbl
281288 }
282289}
283290
284- void CChainLocksHandler::BlockDisconnected (const std::shared_ptr<const CBlock>& pblock, gsl::not_null<const CBlockIndex*> pindexDisconnected)
291+ void CChainLocksHandler::BlockDisconnected (const std::shared_ptr<const CBlock>& pblock,
292+ gsl::not_null<const CBlockIndex*> pindexDisconnected)
285293{
286294 if (m_signer) {
287295 m_signer->EraseFromBlockHashTxidMap (pindexDisconnected->GetBlockHash ());
@@ -340,17 +348,21 @@ void CChainLocksHandler::EnforceBestChainLock()
340348 // Go backwards through the chain referenced by clsig until we find a block that is part of the main chain.
341349 // For each of these blocks, check if there are children that are NOT part of the chain referenced by clsig
342350 // and mark all of them as conflicting.
343- LogPrint (BCLog::CHAINLOCKS, " CChainLocksHandler::%s -- enforcing block %s via CLSIG (%s)\n " , __func__, pindex->GetBlockHash ().ToString (), clsig->ToString ());
351+ LogPrint (BCLog::CHAINLOCKS, " CChainLocksHandler::%s -- enforcing block %s via CLSIG (%s)\n " , __func__,
352+ pindex->GetBlockHash ().ToString (), clsig->ToString ());
344353 m_chainstate.EnforceBlock (dummy_state, pindex);
345354
346355
347- if (/* activateNeeded =*/ WITH_LOCK (::cs_main, return m_chainstate.m_chain .Tip ()->GetAncestor (currentBestChainLockBlockIndex->nHeight )) != currentBestChainLockBlockIndex) {
356+ if (/* activateNeeded =*/ WITH_LOCK (::cs_main, return m_chainstate.m_chain .Tip ()->GetAncestor (
357+ currentBestChainLockBlockIndex->nHeight )) !=
358+ currentBestChainLockBlockIndex) {
348359 if (!m_chainstate.ActivateBestChain (dummy_state)) {
349360 LogPrintf (" CChainLocksHandler::%s -- ActivateBestChain failed: %s\n " , __func__, dummy_state.ToString ());
350361 return ;
351362 }
352363 LOCK (::cs_main);
353- if (m_chainstate.m_chain .Tip ()->GetAncestor (currentBestChainLockBlockIndex->nHeight ) != currentBestChainLockBlockIndex) {
364+ if (m_chainstate.m_chain .Tip ()->GetAncestor (currentBestChainLockBlockIndex->nHeight ) !=
365+ currentBestChainLockBlockIndex) {
354366 return ;
355367 }
356368 }
@@ -371,7 +383,8 @@ VerifyRecSigStatus CChainLocksHandler::VerifyChainLock(const chainlock::ChainLoc
371383 const auto llmqType = Params ().GetConsensus ().llmqTypeChainLocks ;
372384 const uint256 nRequestId = ::SerializeHash (std::make_pair (chainlock::CLSIG_REQUESTID_PREFIX, clsig.getHeight ()));
373385
374- return llmq::VerifyRecoveredSig (llmqType, m_chainstate.m_chain , qman, clsig.getHeight (), nRequestId, clsig.getBlockHash (), clsig.getSig ());
386+ return llmq::VerifyRecoveredSig (llmqType, m_chainstate.m_chain , qman, clsig.getHeight (), nRequestId,
387+ clsig.getBlockHash (), clsig.getSig ());
375388}
376389
377390bool CChainLocksHandler::HasChainLock (int nHeight, const uint256& blockHash) const
@@ -438,7 +451,7 @@ void CChainLocksHandler::Cleanup()
438451
439452 {
440453 LOCK (cs);
441- for (auto it = seenChainLocks.begin (); it != seenChainLocks.end (); ) {
454+ for (auto it = seenChainLocks.begin (); it != seenChainLocks.end ();) {
442455 if (TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now ()) - it->second >= CLEANUP_SEEN_TIMEOUT) {
443456 it = seenChainLocks.erase (it);
444457 } else {
@@ -459,14 +472,15 @@ void CChainLocksHandler::Cleanup()
459472
460473 LOCK (::cs_main);
461474 LOCK2 (mempool.cs , cs); // need mempool.cs due to GetTransaction calls
462- for (auto it = txFirstSeenTime.begin (); it != txFirstSeenTime.end (); ) {
475+ for (auto it = txFirstSeenTime.begin (); it != txFirstSeenTime.end ();) {
463476 uint256 hashBlock;
464477 if (auto tx = GetTransaction (nullptr , &mempool, it->first , Params ().GetConsensus (), hashBlock); !tx) {
465478 // tx has vanished, probably due to conflicts
466479 it = txFirstSeenTime.erase (it);
467480 } else if (!hashBlock.IsNull ()) {
468481 const auto * pindex = m_chainstate.m_blockman .LookupBlockIndex (hashBlock);
469- if (m_chainstate.m_chain .Tip ()->GetAncestor (pindex->nHeight ) == pindex && m_chainstate.m_chain .Height () - pindex->nHeight >= 6 ) {
482+ if (m_chainstate.m_chain .Tip ()->GetAncestor (pindex->nHeight ) == pindex &&
483+ m_chainstate.m_chain .Height () - pindex->nHeight >= 6 ) {
470484 // tx got confirmed >= 6 times, so we can stop keeping track of it
471485 it = txFirstSeenTime.erase (it);
472486 } else {
0 commit comments