Skip to content

Commit ef15fee

Browse files
committed
refactor: cleanup src/chainlock/clsig.*, move to dedicated namespace
1 parent 021062c commit ef15fee

25 files changed

+107
-105
lines changed

src/chainlock/chainlock.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ bool CChainLocksHandler::AlreadyHave(const CInv& inv) const
8686
return seenChainLocks.count(inv.hash) != 0;
8787
}
8888

89-
bool CChainLocksHandler::GetChainLockByHash(const uint256& hash, llmq::CChainLockSig& ret) const
89+
bool CChainLocksHandler::GetChainLockByHash(const uint256& hash, chainlock::ChainLockSig& ret) const
9090
{
9191
LOCK(cs);
9292

@@ -99,13 +99,13 @@ bool CChainLocksHandler::GetChainLockByHash(const uint256& hash, llmq::CChainLoc
9999
return true;
100100
}
101101

102-
CChainLockSig CChainLocksHandler::GetBestChainLock() const
102+
chainlock::ChainLockSig CChainLocksHandler::GetBestChainLock() const
103103
{
104104
LOCK(cs);
105105
return bestChainLock;
106106
}
107107

108-
MessageProcessingResult CChainLocksHandler::ProcessNewChainLock(const NodeId from, const llmq::CChainLockSig& clsig,
108+
MessageProcessingResult CChainLocksHandler::ProcessNewChainLock(const NodeId from, const chainlock::ChainLockSig& clsig,
109109
const uint256& hash)
110110
{
111111
CheckActiveState();
@@ -221,7 +221,7 @@ void CChainLocksHandler::CheckActiveState()
221221
// to disable spork19)
222222
LOCK(cs);
223223
bestChainLockHash = uint256();
224-
bestChainLock = bestChainLockWithKnownBlock = CChainLockSig();
224+
bestChainLock = bestChainLockWithKnownBlock = chainlock::ChainLockSig();
225225
bestChainLockBlockIndex = lastNotifyChainLockBlockIndex = nullptr;
226226
}
227227
}
@@ -325,7 +325,7 @@ void CChainLocksHandler::TrySignChainTip(const llmq::CInstantSendManager& isman)
325325
}
326326
}
327327

328-
uint256 requestId = ::SerializeHash(std::make_pair(CLSIG_REQUESTID_PREFIX, pindex->nHeight));
328+
uint256 requestId = ::SerializeHash(std::make_pair(chainlock::CLSIG_REQUESTID_PREFIX, pindex->nHeight));
329329
uint256 msgHash = pindex->GetBlockHash();
330330

331331
{
@@ -461,7 +461,7 @@ void CChainLocksHandler::EnforceBestChainLock()
461461
AssertLockNotHeld(cs);
462462
AssertLockNotHeld(cs_main);
463463

464-
std::shared_ptr<CChainLockSig> clsig;
464+
std::shared_ptr<chainlock::ChainLockSig> clsig;
465465
const CBlockIndex* pindex;
466466
const CBlockIndex* currentBestChainLockBlockIndex;
467467
{
@@ -471,7 +471,7 @@ void CChainLocksHandler::EnforceBestChainLock()
471471
return;
472472
}
473473

474-
clsig = std::make_shared<CChainLockSig>(bestChainLockWithKnownBlock);
474+
clsig = std::make_shared<chainlock::ChainLockSig>(bestChainLockWithKnownBlock);
475475
pindex = currentBestChainLockBlockIndex = this->bestChainLockBlockIndex;
476476

477477
if (currentBestChainLockBlockIndex == nullptr) {
@@ -517,7 +517,7 @@ MessageProcessingResult CChainLocksHandler::HandleNewRecoveredSig(const llmq::CR
517517
return {};
518518
}
519519

520-
CChainLockSig clsig;
520+
chainlock::ChainLockSig clsig;
521521
{
522522
LOCK(cs);
523523

@@ -531,7 +531,7 @@ MessageProcessingResult CChainLocksHandler::HandleNewRecoveredSig(const llmq::CR
531531
}
532532

533533

534-
clsig = CChainLockSig(lastSignedHeight, lastSignedMsgHash, recoveredSig.sig.Get());
534+
clsig = chainlock::ChainLockSig(lastSignedHeight, lastSignedMsgHash, recoveredSig.sig.Get());
535535
}
536536
return ProcessNewChainLock(-1, clsig, ::SerializeHash(clsig));
537537
}
@@ -543,10 +543,10 @@ bool CChainLocksHandler::HasChainLock(int nHeight, const uint256& blockHash) con
543543
}
544544

545545

546-
VerifyRecSigStatus CChainLocksHandler::VerifyChainLock(const CChainLockSig& clsig) const
546+
VerifyRecSigStatus CChainLocksHandler::VerifyChainLock(const chainlock::ChainLockSig& clsig) const
547547
{
548548
const auto llmqType = Params().GetConsensus().llmqTypeChainLocks;
549-
const uint256 nRequestId = ::SerializeHash(std::make_pair(llmq::CLSIG_REQUESTID_PREFIX, clsig.getHeight()));
549+
const uint256 nRequestId = ::SerializeHash(std::make_pair(chainlock::CLSIG_REQUESTID_PREFIX, clsig.getHeight()));
550550

551551
return llmq::VerifyRecoveredSig(llmqType, m_chainstate.m_chain, qman, clsig.getHeight(), nRequestId, clsig.getBlockHash(), clsig.getSig());
552552
}

src/chainlock/chainlock.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class CChainLocksHandler : public CRecoveredSigsListener
6161
std::atomic<bool> isEnabled{false};
6262

6363
uint256 bestChainLockHash GUARDED_BY(cs);
64-
CChainLockSig bestChainLock GUARDED_BY(cs);
64+
chainlock::ChainLockSig bestChainLock GUARDED_BY(cs);
6565

66-
CChainLockSig bestChainLockWithKnownBlock GUARDED_BY(cs);
66+
chainlock::ChainLockSig bestChainLockWithKnownBlock GUARDED_BY(cs);
6767
const CBlockIndex* bestChainLockBlockIndex GUARDED_BY(cs) {nullptr};
6868
const CBlockIndex* lastNotifyChainLockBlockIndex GUARDED_BY(cs) {nullptr};
6969

@@ -94,10 +94,10 @@ class CChainLocksHandler : public CRecoveredSigsListener
9494
void Stop();
9595

9696
bool AlreadyHave(const CInv& inv) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
97-
bool GetChainLockByHash(const uint256& hash, CChainLockSig& ret) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
98-
CChainLockSig GetBestChainLock() const EXCLUSIVE_LOCKS_REQUIRED(!cs);
97+
bool GetChainLockByHash(const uint256& hash, chainlock::ChainLockSig& ret) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
98+
chainlock::ChainLockSig GetBestChainLock() const EXCLUSIVE_LOCKS_REQUIRED(!cs);
9999

100-
[[nodiscard]] MessageProcessingResult ProcessNewChainLock(NodeId from, const CChainLockSig& clsig,
100+
[[nodiscard]] MessageProcessingResult ProcessNewChainLock(NodeId from, const chainlock::ChainLockSig& clsig,
101101
const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(!cs);
102102

103103
void AcceptedBlockHeader(gsl::not_null<const CBlockIndex*> pindexNew) EXCLUSIVE_LOCKS_REQUIRED(!cs);
@@ -113,7 +113,7 @@ class CChainLocksHandler : public CRecoveredSigsListener
113113

114114
bool HasChainLock(int nHeight, const uint256& blockHash) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
115115
bool HasConflictingChainLock(int nHeight, const uint256& blockHash) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
116-
VerifyRecSigStatus VerifyChainLock(const CChainLockSig& clsig) const;
116+
VerifyRecSigStatus VerifyChainLock(const chainlock::ChainLockSig& clsig) const;
117117

118118
bool IsTxSafeForMining(const uint256& txid) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
119119

src/chainlock/clsig.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,21 @@
66

77
#include <tinyformat.h>
88

9-
namespace llmq {
10-
const std::string CLSIG_REQUESTID_PREFIX = "clsig";
9+
namespace chainlock {
10+
const std::string CLSIG_REQUESTID_PREFIX = "clsig";
1111

12-
std::string CChainLockSig::ToString() const {
13-
return strprintf("CChainLockSig(nHeight=%d, blockHash=%s)", nHeight, blockHash.ToString());
14-
}
15-
int32_t CChainLockSig::getHeight() const {
16-
return nHeight;
17-
}
18-
const uint256& CChainLockSig::getBlockHash() const {
19-
return blockHash;
20-
}
21-
const CBLSSignature& CChainLockSig::getSig() const {
22-
return sig;
23-
}
24-
bool CChainLockSig::IsNull() const
25-
{
26-
return nHeight == -1 && blockHash == uint256();
27-
}
12+
ChainLockSig::ChainLockSig() = default;
13+
ChainLockSig::~ChainLockSig() = default;
14+
15+
ChainLockSig::ChainLockSig(int32_t nHeight, const uint256& blockHash, const CBLSSignature& sig) :
16+
nHeight{nHeight},
17+
blockHash{blockHash},
18+
sig{sig}
19+
{
20+
}
21+
22+
std::string ChainLockSig::ToString() const
23+
{
24+
return strprintf("ChainLockSig(nHeight=%d, blockHash=%s)", nHeight, blockHash.ToString());
2825
}
26+
} // namespace chainlock

src/chainlock/clsig.h

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,39 @@
55
#ifndef BITCOIN_CHAINLOCK_CLSIG_H
66
#define BITCOIN_CHAINLOCK_CLSIG_H
77

8-
#include <bls/bls.h>
98
#include <serialize.h>
109
#include <uint256.h>
1110

12-
namespace llmq
13-
{
11+
#include <bls/bls.h>
12+
13+
#include <cstdint>
1414

15+
namespace chainlock {
1516
extern const std::string CLSIG_REQUESTID_PREFIX;
1617

17-
class CChainLockSig
18-
{
18+
struct ChainLockSig {
1919
private:
2020
int32_t nHeight{-1};
2121
uint256 blockHash;
2222
CBLSSignature sig;
2323

2424
public:
25-
CChainLockSig(int32_t nHeight, const uint256& blockHash, const CBLSSignature& sig) :
26-
nHeight(nHeight),
27-
blockHash(blockHash),
28-
sig(sig)
29-
{}
30-
CChainLockSig() = default;
31-
32-
33-
[[nodiscard]] int32_t getHeight() const;
34-
[[nodiscard]] const uint256& getBlockHash() const;
35-
[[nodiscard]] const CBLSSignature& getSig() const;
36-
[[nodiscard]] bool IsNull() const;
25+
ChainLockSig();
26+
~ChainLockSig();
27+
28+
ChainLockSig(int32_t nHeight, const uint256& blockHash, const CBLSSignature& sig);
29+
30+
[[nodiscard]] int32_t getHeight() const { return nHeight; }
31+
[[nodiscard]] const uint256& getBlockHash() const { return blockHash; }
32+
[[nodiscard]] const CBLSSignature& getSig() const { return sig; }
33+
[[nodiscard]] bool IsNull() const { return nHeight == -1 && blockHash == uint256(); }
3734
[[nodiscard]] std::string ToString() const;
3835

39-
SERIALIZE_METHODS(CChainLockSig, obj)
36+
SERIALIZE_METHODS(ChainLockSig, obj)
4037
{
4138
READWRITE(obj.nHeight, obj.blockHash, obj.sig);
4239
}
4340
};
44-
} // namespace llmq
41+
} // namespace chainlock
4542

4643
#endif // BITCOIN_CHAINLOCK_CLSIG_H

src/dsnotificationinterface.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ void CDSNotificationInterface::NotifyMasternodeListChanged(bool undo, const CDet
143143
}
144144
}
145145

146-
void CDSNotificationInterface::NotifyChainLock(const CBlockIndex* pindex, const std::shared_ptr<const llmq::CChainLockSig>& clsig)
146+
void CDSNotificationInterface::NotifyChainLock(const CBlockIndex* pindex,
147+
const std::shared_ptr<const chainlock::ChainLockSig>& clsig)
147148
{
148149
assert(m_cj_ctx && m_llmq_ctx);
149150

src/dsnotificationinterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CDSNotificationInterface : public CValidationInterface
4646
void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex) override;
4747
void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexDisconnected) override;
4848
void NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff) override;
49-
void NotifyChainLock(const CBlockIndex* pindex, const std::shared_ptr<const llmq::CChainLockSig>& clsig) override;
49+
void NotifyChainLock(const CBlockIndex* pindex, const std::shared_ptr<const chainlock::ChainLockSig>& clsig) override;
5050

5151
private:
5252
CConnman& m_connman;

src/evo/specialtxman.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static bool CheckCbTxBestChainlock(const CCbTx& cbTx, const CBlockIndex* pindex,
7878
}
7979
uint256 curBlockCoinbaseCLBlockHash = pindex->GetAncestor(curBlockCoinbaseCLHeight)->GetBlockHash();
8080
if (chainlock_handler.VerifyChainLock(
81-
llmq::CChainLockSig(curBlockCoinbaseCLHeight, curBlockCoinbaseCLBlockHash, cbTx.bestCLSignature)) !=
81+
chainlock::ChainLockSig(curBlockCoinbaseCLHeight, curBlockCoinbaseCLBlockHash, cbTx.bestCLSignature)) !=
8282
llmq::VerifyRecSigStatus::Valid) {
8383
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cbtx-invalid-clsig");
8484
}

src/interfaces/chain.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ enum class MemPoolRemovalReason;
3131
struct bilingual_str;
3232
struct CBlockLocator;
3333
struct FeeCalculation;
34+
namespace chainlock {
35+
struct ChainLockSig;
36+
} // namespace chainlock
3437
namespace instantsend {
3538
struct InstantSendLock;
3639
} // namespace instantsend
37-
namespace llmq {
38-
class CChainLockSig;
39-
} // namespace llmq
4040
namespace node {
4141
struct NodeContext;
4242
} // namespace node
@@ -267,7 +267,7 @@ class Chain
267267
virtual void blockDisconnected(const CBlock& block, int height) {}
268268
virtual void updatedBlockTip() {}
269269
virtual void chainStateFlushed(const CBlockLocator& locator) {}
270-
virtual void notifyChainLock(const CBlockIndex* pindexChainLock, const std::shared_ptr<const llmq::CChainLockSig>& clsig) {}
270+
virtual void notifyChainLock(const CBlockIndex* pindexChainLock, const std::shared_ptr<const chainlock::ChainLockSig>& clsig) {}
271271
virtual void notifyTransactionLock(const CTransactionRef &tx, const std::shared_ptr<const instantsend::InstantSendLock>& islock) {}
272272
};
273273

src/net_processing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2858,7 +2858,7 @@ void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic
28582858
}
28592859

28602860
if (!push && (inv.type == MSG_CLSIG)) {
2861-
llmq::CChainLockSig o;
2861+
chainlock::ChainLockSig o;
28622862
if (m_llmq_ctx->clhandler->GetChainLockByHash(inv.hash, o)) {
28632863
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::CLSIG, o));
28642864
push = true;
@@ -5282,7 +5282,7 @@ void PeerManagerImpl::ProcessMessage(
52825282

52835283
if (msg_type == NetMsgType::CLSIG) {
52845284
if (llmq::AreChainLocksEnabled(m_sporkman)) {
5285-
llmq::CChainLockSig clsig;
5285+
chainlock::ChainLockSig clsig;
52865286
vRecv >> clsig;
52875287
const uint256& hash = ::SerializeHash(clsig);
52885288
WITH_LOCK(::cs_main, EraseObjectRequest(pfrom.GetId(), CInv{MSG_CLSIG, hash}));

src/node/interfaces.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ class NotificationsProxy : public CValidationInterface
653653
m_notifications->updatedBlockTip();
654654
}
655655
void ChainStateFlushed(const CBlockLocator& locator) override { m_notifications->chainStateFlushed(locator); }
656-
void NotifyChainLock(const CBlockIndex* pindexChainLock, const std::shared_ptr<const llmq::CChainLockSig>& clsig) override
656+
void NotifyChainLock(const CBlockIndex* pindexChainLock, const std::shared_ptr<const chainlock::ChainLockSig>& clsig) override
657657
{
658658
m_notifications->notifyChainLock(pindexChainLock, clsig);
659659
}

0 commit comments

Comments
 (0)