Skip to content

Commit c6e99fb

Browse files
committed
chore: apply most clang-format suggestions
1 parent 489c5f0 commit c6e99fb

File tree

3 files changed

+61
-45
lines changed

3 files changed

+61
-45
lines changed

src/chainlock/chainlock.cpp

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -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

8587
void 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

377390
bool 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 {

src/chainlock/chainlock.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ class CChainLocksHandler final : public chainlock::ChainLockSignerParent
5858
chainlock::ChainLockSig bestChainLock GUARDED_BY(cs);
5959

6060
chainlock::ChainLockSig bestChainLockWithKnownBlock GUARDED_BY(cs);
61-
const CBlockIndex* bestChainLockBlockIndex GUARDED_BY(cs) {nullptr};
62-
const CBlockIndex* lastNotifyChainLockBlockIndex GUARDED_BY(cs) {nullptr};
61+
const CBlockIndex* bestChainLockBlockIndex GUARDED_BY(cs){nullptr};
62+
const CBlockIndex* lastNotifyChainLockBlockIndex GUARDED_BY(cs){nullptr};
6363

6464
std::unordered_map<uint256, int64_t, StaticSaltedHasher> txFirstSeenTime GUARDED_BY(cs);
6565

src/chainlock/signing.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
using node::ReadBlockFromDisk;
1616

1717
namespace chainlock {
18-
ChainLockSigner::ChainLockSigner(CChainState& chainstate, ChainLockSignerParent& clhandler, llmq::CSigningManager& sigman,
19-
llmq::CSigSharesManager& shareman, CSporkManager& sporkman,
20-
const CMasternodeSync& mn_sync) :
18+
ChainLockSigner::ChainLockSigner(CChainState& chainstate, ChainLockSignerParent& clhandler,
19+
llmq::CSigningManager& sigman, llmq::CSigSharesManager& shareman,
20+
CSporkManager& sporkman, const CMasternodeSync& mn_sync) :
2121
m_chainstate{chainstate},
2222
m_clhandler{clhandler},
2323
m_sigman{sigman},
@@ -85,7 +85,8 @@ void ChainLockSigner::TrySignChainTip(const llmq::CInstantSendManager& isman)
8585
return;
8686
}
8787

88-
LogPrint(BCLog::CHAINLOCKS, "%s -- trying to sign %s, height=%d\n", __func__, pindex->GetBlockHash().ToString(), pindex->nHeight);
88+
LogPrint(BCLog::CHAINLOCKS, "%s -- trying to sign %s, height=%d\n", __func__, pindex->GetBlockHash().ToString(),
89+
pindex->nHeight);
8990

9091
// When the new IX system is activated, we only try to ChainLock blocks which include safe transactions. A TX is
9192
// considered safe when it is islocked or at least known since 10 minutes (from mempool or block). These checks are
@@ -114,8 +115,9 @@ void ChainLockSigner::TrySignChainTip(const llmq::CInstantSendManager& isman)
114115

115116
for (const auto& txid : *txids) {
116117
if (!m_clhandler.IsTxSafeForMining(txid) && !isman.IsLocked(txid)) {
117-
LogPrint(BCLog::CHAINLOCKS, "%s -- not signing block %s due to TX %s not being islocked and not old enough.\n", __func__,
118-
pindexWalk->GetBlockHash().ToString(), txid.ToString());
118+
LogPrint(BCLog::CHAINLOCKS, /* Continued */
119+
"%s -- not signing block %s due to TX %s not being islocked and not old enough.\n",
120+
__func__, pindexWalk->GetBlockHash().ToString(), txid.ToString());
119121
return;
120122
}
121123
}
@@ -243,7 +245,7 @@ std::vector<std::shared_ptr<std::unordered_set<uint256, StaticSaltedHasher>>> Ch
243245
AssertLockNotHeld(cs_signer);
244246
std::vector<std::shared_ptr<std::unordered_set<uint256, StaticSaltedHasher>>> removed;
245247
LOCK2(::cs_main, cs_signer);
246-
for (auto it = blockTxs.begin(); it != blockTxs.end(); ) {
248+
for (auto it = blockTxs.begin(); it != blockTxs.end();) {
247249
const auto* pindex = m_chainstate.m_blockman.LookupBlockIndex(it->first);
248250
if (m_clhandler.HasChainLock(pindex->nHeight, pindex->GetBlockHash())) {
249251
removed.push_back(it->second);

0 commit comments

Comments
 (0)