Skip to content

Commit cf47f14

Browse files
committed
chore: apply most clang-format suggestions
1 parent 63371e0 commit cf47f14

File tree

6 files changed

+77
-66
lines changed

6 files changed

+77
-66
lines changed

src/instantsend/db.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ static const std::string_view DB_VERSION = "is_v";
1919

2020
namespace instantsend {
2121
namespace {
22-
static std::tuple<std::string, uint32_t, uint256> BuildInversedISLockKey(std::string_view k, int nHeight, const uint256& islockHash)
22+
static std::tuple<std::string, uint32_t, uint256> BuildInversedISLockKey(std::string_view k, int nHeight,
23+
const uint256& islockHash)
2324
{
2425
return std::make_tuple(std::string{k}, htobe32_internal(std::numeric_limits<uint32_t>::max() - nHeight), islockHash);
2526
}
@@ -221,7 +222,8 @@ void CInstantSendDb::WriteBlockInstantSendLocks(const gsl::not_null<std::shared_
221222
db->WriteBatch(batch);
222223
}
223224

224-
void CInstantSendDb::RemoveBlockInstantSendLocks(const gsl::not_null<std::shared_ptr<const CBlock>>& pblock, gsl::not_null<const CBlockIndex*> pindexDisconnected)
225+
void CInstantSendDb::RemoveBlockInstantSendLocks(const gsl::not_null<std::shared_ptr<const CBlock>>& pblock,
226+
gsl::not_null<const CBlockIndex*> pindexDisconnected)
225227
{
226228
LOCK(cs_db);
227229
CDBBatch batch(*db);
@@ -241,7 +243,8 @@ void CInstantSendDb::RemoveBlockInstantSendLocks(const gsl::not_null<std::shared
241243
bool CInstantSendDb::KnownInstantSendLock(const uint256& islockHash) const
242244
{
243245
LOCK(cs_db);
244-
return GetInstantSendLockByHashInternal(islockHash) != nullptr || db->Exists(std::make_tuple(DB_ARCHIVED_BY_HASH, islockHash));
246+
return GetInstantSendLockByHashInternal(islockHash) != nullptr ||
247+
db->Exists(std::make_tuple(DB_ARCHIVED_BY_HASH, islockHash));
245248
}
246249

247250
size_t CInstantSendDb::GetInstantSendLockCount() const
@@ -354,7 +357,8 @@ std::vector<uint256> CInstantSendDb::GetInstantSendLocksByParent(const uint256&
354357
return result;
355358
}
356359

357-
std::vector<uint256> CInstantSendDb::RemoveChainedInstantSendLocks(const uint256& islockHash, const uint256& txid, int nHeight)
360+
std::vector<uint256> CInstantSendDb::RemoveChainedInstantSendLocks(const uint256& islockHash, const uint256& txid,
361+
int nHeight)
358362
{
359363
LOCK(cs_db);
360364
std::vector<uint256> result;

src/instantsend/db.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ class CInstantSendDb
3333

3434
static constexpr int CURRENT_VERSION{1};
3535

36-
int best_confirmed_height GUARDED_BY(cs_db) {0};
36+
int best_confirmed_height GUARDED_BY(cs_db){0};
3737

38-
std::unique_ptr<CDBWrapper> db GUARDED_BY(cs_db) {nullptr};
38+
std::unique_ptr<CDBWrapper> db GUARDED_BY(cs_db){nullptr};
3939
mutable unordered_lru_cache<uint256, InstantSendLockPtr, StaticSaltedHasher, 10000> islockCache GUARDED_BY(cs_db);
4040
mutable unordered_lru_cache<uint256, uint256, StaticSaltedHasher, 10000> txidCache GUARDED_BY(cs_db);
4141

src/instantsend/instantsend.cpp

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,16 @@ PeerMsgRet CInstantSendManager::ProcessMessageInstantSendLock(const CNode& pfrom
142142
return tl::unexpected{100};
143143
}
144144

145-
if (WITH_LOCK(cs_pendingLocks, return pendingInstantSendLocks.count(hash) || pendingNoTxInstantSendLocks.count(hash))
146-
|| db.KnownInstantSendLock(hash)) {
145+
if (WITH_LOCK(cs_pendingLocks, return pendingInstantSendLocks.count(hash) || pendingNoTxInstantSendLocks.count(hash)) ||
146+
db.KnownInstantSendLock(hash)) {
147147
return {};
148148
}
149149

150150
LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, islock=%s: received islock, peer=%d\n", __func__,
151-
islock->txid.ToString(), hash.ToString(), pfrom.GetId());
151+
islock->txid.ToString(), hash.ToString(), pfrom.GetId());
152152

153153
if (ShouldReportISLockTiming()) {
154-
auto time_diff = [&] () -> int64_t {
154+
auto time_diff = [&]() -> int64_t {
155155
LOCK(cs_timingsTxSeen);
156156
if (auto it = timingsTxSeen.find(islock->txid); it != timingsTxSeen.end()) {
157157
// This is the normal case where we received the TX before the islock
@@ -164,7 +164,7 @@ PeerMsgRet CInstantSendManager::ProcessMessageInstantSendLock(const CNode& pfrom
164164
}();
165165
::g_stats_client->timing("islock_ms", time_diff);
166166
LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, islock took %dms\n", __func__,
167-
islock->txid.ToString(), time_diff);
167+
islock->txid.ToString(), time_diff);
168168
}
169169

170170
LOCK(cs_pendingLocks);
@@ -209,7 +209,7 @@ bool CInstantSendManager::ProcessPendingInstantSendLocks(PeerManager& peerman)
209209
return false;
210210
}
211211

212-
//TODO Investigate if leaving this is ok
212+
// TODO Investigate if leaving this is ok
213213
auto llmqType = Params().GetConsensus().llmqTypeDIP0024InstantSend;
214214
const auto& llmq_params_opt = Params().GetLLMQ(llmqType);
215215
assert(llmq_params_opt);
@@ -222,7 +222,7 @@ bool CInstantSendManager::ProcessPendingInstantSendLocks(PeerManager& peerman)
222222
LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- doing verification on old active set\n", __func__);
223223

224224
// filter out valid IS locks from "pend"
225-
for (auto it = pend.begin(); it != pend.end(); ) {
225+
for (auto it = pend.begin(); it != pend.end();) {
226226
if (!badISLocks.count(it->first)) {
227227
it = pend.erase(it);
228228
} else {
@@ -238,7 +238,8 @@ bool CInstantSendManager::ProcessPendingInstantSendLocks(PeerManager& peerman)
238238

239239
std::unordered_set<uint256, StaticSaltedHasher> CInstantSendManager::ProcessPendingInstantSendLocks(
240240
const Consensus::LLMQParams& llmq_params, PeerManager& peerman, int signOffset,
241-
const std::unordered_map<uint256, std::pair<NodeId, instantsend::InstantSendLockPtr>, StaticSaltedHasher>& pend, bool ban)
241+
const std::unordered_map<uint256, std::pair<NodeId, instantsend::InstantSendLockPtr>, StaticSaltedHasher>& pend,
242+
bool ban)
242243
{
243244
CBLSBatchVerifier<NodeId, uint256> batchVerifier(false, true, 8);
244245
std::unordered_map<uint256, CRecoveredSig, StaticSaltedHasher> recSigs;
@@ -295,7 +296,8 @@ std::unordered_set<uint256, StaticSaltedHasher> CInstantSendManager::ProcessPend
295296
// avoids unnecessary double-verification of the signature. We however only do this when verification here
296297
// turns out to be good (which is checked further down)
297298
if (!sigman.HasRecoveredSigForId(llmq_params.type, id)) {
298-
recSigs.try_emplace(hash, CRecoveredSig(llmq_params.type, quorum->qc->quorumHash, id, islock->txid, islock->sig));
299+
recSigs.try_emplace(hash,
300+
CRecoveredSig(llmq_params.type, quorum->qc->quorumHash, id, islock->txid, islock->sig));
299301
}
300302
}
301303

@@ -322,8 +324,8 @@ std::unordered_set<uint256, StaticSaltedHasher> CInstantSendManager::ProcessPend
322324
const auto& islock = p.second.second;
323325

324326
if (batchVerifier.badMessages.count(hash)) {
325-
LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, islock=%s: invalid sig in islock, peer=%d\n", __func__,
326-
islock->txid.ToString(), hash.ToString(), nodeId);
327+
LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, islock=%s: invalid sig in islock, peer=%d\n",
328+
__func__, islock->txid.ToString(), hash.ToString(), nodeId);
327329
badISLocks.emplace(hash);
328330
continue;
329331
}
@@ -349,8 +351,8 @@ std::unordered_set<uint256, StaticSaltedHasher> CInstantSendManager::ProcessPend
349351
void CInstantSendManager::ProcessInstantSendLock(NodeId from, PeerManager& peerman, const uint256& hash,
350352
const instantsend::InstantSendLockPtr& islock)
351353
{
352-
LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, islock=%s: processing islock, peer=%d\n", __func__,
353-
islock->txid.ToString(), hash.ToString(), from);
354+
LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, islock=%s: processing islock, peer=%d\n",
355+
__func__, islock->txid.ToString(), hash.ToString(), from);
354356
if (m_signer) {
355357
m_signer->ClearLockFromQueue(islock);
356358
}
@@ -418,7 +420,7 @@ void CInstantSendManager::ProcessInstantSendLock(NodeId from, PeerManager& peerm
418420
if (tx != nullptr) {
419421
RemoveMempoolConflictsForLock(peerman, hash, *islock);
420422
LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- notify about lock %s for tx %s\n", __func__,
421-
hash.ToString(), tx->GetHash().ToString());
423+
hash.ToString(), tx->GetHash().ToString());
422424
GetMainSignals().NotifyTransactionLock(tx, islock);
423425
// bump mempool counter to make sure newly locked txes are picked up by getblocktemplate
424426
mempool.AddTransactionsUpdated(1);
@@ -474,7 +476,8 @@ void CInstantSendManager::TransactionRemovedFromMempool(const CTransactionRef& t
474476
return;
475477
}
476478

477-
LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- transaction %s was removed from mempool\n", __func__, tx->GetHash().ToString());
479+
LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- transaction %s was removed from mempool\n", __func__,
480+
tx->GetHash().ToString());
478481
RemoveConflictingLock(::SerializeHash(*islock), *islock);
479482
}
480483

@@ -508,7 +511,8 @@ void CInstantSendManager::BlockConnected(const std::shared_ptr<const CBlock>& pb
508511
db.WriteBlockInstantSendLocks(pblock, pindex);
509512
}
510513

511-
void CInstantSendManager::BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexDisconnected)
514+
void CInstantSendManager::BlockDisconnected(const std::shared_ptr<const CBlock>& pblock,
515+
const CBlockIndex* pindexDisconnected)
512516
{
513517
db.RemoveBlockInstantSendLocks(pblock, pindexDisconnected);
514518
}
@@ -523,7 +527,7 @@ void CInstantSendManager::AddNonLockedTx(const CTransactionRef& tx, const CBlock
523527

524528
if (did_insert) {
525529
nonLockedTxInfo.tx = tx;
526-
for (const auto &in: tx->vin) {
530+
for (const auto& in : tx->vin) {
527531
nonLockedTxs[in.prevout.hash].children.emplace(tx->GetHash());
528532
nonLockedTxsByOutpoints.emplace(in.prevout, tx->GetHash());
529533
}
@@ -591,8 +595,8 @@ void CInstantSendManager::RemoveNonLockedTx(const uint256& txid, bool retryChild
591595

592596
nonLockedTxs.erase(it);
593597

594-
LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, retryChildren=%d, retryChildrenCount=%d\n", __func__,
595-
txid.ToString(), retryChildren, retryChildrenCount);
598+
LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, retryChildren=%d, retryChildrenCount=%d\n",
599+
__func__, txid.ToString(), retryChildren, retryChildrenCount);
596600
}
597601

598602
void CInstantSendManager::RemoveConflictedTx(const CTransaction& tx)
@@ -614,7 +618,8 @@ void CInstantSendManager::TruncateRecoveredSigsForInputs(const instantsend::Inst
614618
}
615619
}
616620

617-
void CInstantSendManager::TryEmplacePendingLock(const uint256& hash, const NodeId id, const instantsend::InstantSendLockPtr& islock)
621+
void CInstantSendManager::TryEmplacePendingLock(const uint256& hash, const NodeId id,
622+
const instantsend::InstantSendLockPtr& islock)
618623
{
619624
if (db.KnownInstantSendLock(hash)) return;
620625
LOCK(cs_pendingLocks);
@@ -673,7 +678,7 @@ void CInstantSendManager::HandleFullyConfirmedBlock(const CBlockIndex* pindex)
673678
std::vector<uint256> toRemove;
674679
{
675680
LOCK(cs_nonLocked);
676-
for (const auto& p: nonLockedTxs) {
681+
for (const auto& p : nonLockedTxs) {
677682
const auto* pindexMined = p.second.pindexMined;
678683

679684
if (pindexMined && pindex->GetAncestor(pindexMined->nHeight) == pindexMined) {
@@ -704,7 +709,7 @@ void CInstantSendManager::RemoveMempoolConflictsForLock(PeerManager& peerman, co
704709
toDelete.emplace(it->second->GetHash(), mempool.get(it->second->GetHash()));
705710

706711
LogPrintf("CInstantSendManager::%s -- txid=%s, islock=%s: mempool TX %s with input %s conflicts with islock\n", __func__,
707-
islock.txid.ToString(), hash.ToString(), it->second->GetHash().ToString(), in.ToStringShort());
712+
islock.txid.ToString(), hash.ToString(), it->second->GetHash().ToString(), in.ToStringShort());
708713
}
709714
}
710715

@@ -761,16 +766,17 @@ void CInstantSendManager::ResolveBlockConflicts(const uint256& islockHash, const
761766

762767
// If a conflict was mined into a ChainLocked block, then we have no other choice and must prune the ISLOCK and all
763768
// chained ISLOCKs that build on top of this one. The probability of this is practically zero and can only happen
764-
// when large parts of the masternode network are controlled by an attacker. In this case we must still find consensus
765-
// and its better to sacrifice individual ISLOCKs then to sacrifice whole ChainLocks.
769+
// when large parts of the masternode network are controlled by an attacker. In this case we must still find
770+
// consensus and its better to sacrifice individual ISLOCKs then to sacrifice whole ChainLocks.
766771
if (hasChainLockedConflict) {
767-
LogPrintf("CInstantSendManager::%s -- txid=%s, islock=%s: at least one conflicted TX already got a ChainLock\n", __func__,
768-
islock.txid.ToString(), islockHash.ToString());
772+
LogPrintf("CInstantSendManager::%s -- txid=%s, islock=%s: at least one conflicted TX already got a ChainLock\n",
773+
__func__, islock.txid.ToString(), islockHash.ToString());
769774
RemoveConflictingLock(islockHash, islock);
770775
return;
771776
}
772777

773-
bool isLockedTxKnown = WITH_LOCK(cs_pendingLocks, return pendingNoTxInstantSendLocks.find(islockHash) == pendingNoTxInstantSendLocks.end());
778+
bool isLockedTxKnown = WITH_LOCK(cs_pendingLocks, return pendingNoTxInstantSendLocks.find(islockHash) ==
779+
pendingNoTxInstantSendLocks.end());
774780

775781
bool activateBestChain = false;
776782
for (const auto& p : conflicts) {
@@ -828,8 +834,9 @@ bool CInstantSendManager::AlreadyHave(const CInv& inv) const
828834
return true;
829835
}
830836

831-
return WITH_LOCK(cs_pendingLocks, return pendingInstantSendLocks.count(inv.hash) != 0 || pendingNoTxInstantSendLocks.count(inv.hash) != 0)
832-
|| db.KnownInstantSendLock(inv.hash);
837+
return WITH_LOCK(cs_pendingLocks, return pendingInstantSendLocks.count(inv.hash) != 0 ||
838+
pendingNoTxInstantSendLocks.count(inv.hash) != 0) ||
839+
db.KnownInstantSendLock(inv.hash);
833840
}
834841

835842
bool CInstantSendManager::GetInstantSendLockByHash(const uint256& hash, instantsend::InstantSendLock& ret) const
@@ -885,8 +892,8 @@ bool CInstantSendManager::IsWaitingForTx(const uint256& txHash) const
885892
auto it = pendingNoTxInstantSendLocks.begin();
886893
while (it != pendingNoTxInstantSendLocks.end()) {
887894
if (it->second.second->txid == txHash) {
888-
LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, islock=%s\n", __func__,
889-
txHash.ToString(), it->first.ToString());
895+
LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, islock=%s\n", __func__, txHash.ToString(),
896+
it->first.ToString());
890897
return true;
891898
}
892899
++it;
@@ -967,5 +974,4 @@ bool CInstantSendManager::RejectConflictingBlocks() const
967974
}
968975
return true;
969976
}
970-
971977
} // namespace llmq

src/instantsend/instantsend.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include <primitives/transaction.h>
1010
#include <protocol.h>
1111
#include <sync.h>
12-
#include <util/threadinterrupt.h>
1312
#include <threadsafety.h>
13+
#include <util/threadinterrupt.h>
1414

1515
#include <instantsend/db.h>
1616
#include <instantsend/lock.h>
@@ -67,8 +67,8 @@ class CInstantSendManager
6767
// Tried to verify but there is no tx yet
6868
std::unordered_map<uint256, std::pair<NodeId, instantsend::InstantSendLockPtr>, StaticSaltedHasher> pendingNoTxInstantSendLocks GUARDED_BY(cs_pendingLocks);
6969

70-
// TXs which are neither IS locked nor ChainLocked. We use this to determine for which TXs we need to retry IS locking
71-
// of child TXs
70+
// TXs which are neither IS locked nor ChainLocked. We use this to determine for which TXs we need to retry IS
71+
// locking of child TXs
7272
struct NonLockedTxInfo {
7373
const CBlockIndex* pindexMined;
7474
CTransactionRef tx;

0 commit comments

Comments
 (0)