Skip to content

Commit b63db6b

Browse files
committed
refactor: abstract away ChainLocks parent implementation from signer
1 parent 4ded977 commit b63db6b

File tree

5 files changed

+36
-20
lines changed

5 files changed

+36
-20
lines changed

src/chainlock/chainlock.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <validation.h>
1717
#include <validationinterface.h>
1818

19-
#include <chainlock/signing.h>
2019
#include <instantsend/instantsend.h>
2120
#include <llmq/quorums.h>
2221
#include <llmq/signing_shares.h>

src/chainlock/chainlock.h

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <saltedhasher.h>
1313
#include <sync.h>
1414

15+
#include <chainlock/signing.h>
16+
1517
#include <gsl/pointers.h>
1618

1719
#include <atomic>
@@ -25,9 +27,6 @@ class CMasternodeSync;
2527
class CScheduler;
2628
class CSporkManager;
2729
class CTxMemPool;
28-
namespace chainlock {
29-
class ChainLockSigner;
30-
} // namespace chainlock
3130

3231
using NodeId = int64_t;
3332

@@ -38,7 +37,7 @@ class CSigningManager;
3837
class CSigSharesManager;
3938
enum class VerifyRecSigStatus;
4039

41-
class CChainLocksHandler
40+
class CChainLocksHandler final : public chainlock::ChainLockSignerParent
4241
{
4342
private:
4443
CChainState& m_chainstate;
@@ -80,11 +79,12 @@ class CChainLocksHandler
8079
bool AlreadyHave(const CInv& inv) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
8180
bool GetChainLockByHash(const uint256& hash, chainlock::ChainLockSig& ret) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
8281
chainlock::ChainLockSig GetBestChainLock() const EXCLUSIVE_LOCKS_REQUIRED(!cs);
83-
void UpdateTxFirstSeenMap(const std::unordered_set<uint256, StaticSaltedHasher>& tx, const int64_t& time)
82+
void UpdateTxFirstSeenMap(const std::unordered_set<uint256, StaticSaltedHasher>& tx, const int64_t& time) override
8483
EXCLUSIVE_LOCKS_REQUIRED(!cs);
8584

8685
[[nodiscard]] MessageProcessingResult ProcessNewChainLock(NodeId from, const chainlock::ChainLockSig& clsig,
87-
const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(!cs);
86+
const uint256& hash) override
87+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
8888

8989
void AcceptedBlockHeader(gsl::not_null<const CBlockIndex*> pindexNew) EXCLUSIVE_LOCKS_REQUIRED(!cs);
9090
void UpdatedBlockTip(const llmq::CInstantSendManager& isman);
@@ -94,13 +94,17 @@ class CChainLocksHandler
9494
void CheckActiveState() EXCLUSIVE_LOCKS_REQUIRED(!cs);
9595
void EnforceBestChainLock() EXCLUSIVE_LOCKS_REQUIRED(!cs);
9696

97-
bool HasChainLock(int nHeight, const uint256& blockHash) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
98-
bool HasConflictingChainLock(int nHeight, const uint256& blockHash) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
97+
bool HasChainLock(int nHeight, const uint256& blockHash) const override
98+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
99+
bool HasConflictingChainLock(int nHeight, const uint256& blockHash) const override
100+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
99101
VerifyRecSigStatus VerifyChainLock(const chainlock::ChainLockSig& clsig) const;
100102

101-
[[nodiscard]] int32_t GetBestChainLockHeight() const EXCLUSIVE_LOCKS_REQUIRED(!cs);
102-
bool IsTxSafeForMining(const uint256& txid) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
103-
[[nodiscard]] bool IsEnabled() const { return isEnabled; }
103+
[[nodiscard]] int32_t GetBestChainLockHeight() const override
104+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
105+
bool IsTxSafeForMining(const uint256& txid) const override
106+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
107+
[[nodiscard]] bool IsEnabled() const override { return isEnabled; }
104108

105109
private:
106110
void Cleanup() EXCLUSIVE_LOCKS_REQUIRED(!cs);

src/chainlock/signing.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <node/blockstorage.h>
88
#include <validation.h>
99

10-
#include <chainlock/chainlock.h>
1110
#include <chainlock/clsig.h>
1211
#include <instantsend/instantsend.h>
1312
#include <masternode/sync.h>
@@ -16,9 +15,9 @@
1615
using node::ReadBlockFromDisk;
1716

1817
namespace chainlock {
19-
ChainLockSigner::ChainLockSigner(CChainState& chainstate, llmq::CChainLocksHandler& clhandler,
20-
llmq::CSigningManager& sigman, llmq::CSigSharesManager& shareman,
21-
CSporkManager& sporkman, const CMasternodeSync& mn_sync) :
18+
ChainLockSigner::ChainLockSigner(CChainState& chainstate, ChainLockSignerParent& clhandler, llmq::CSigningManager& sigman,
19+
llmq::CSigSharesManager& shareman, CSporkManager& sporkman,
20+
const CMasternodeSync& mn_sync) :
2221
m_chainstate{chainstate},
2322
m_clhandler{clhandler},
2423
m_sigman{sigman},

src/chainlock/signing.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef BITCOIN_CHAINLOCK_SIGNING_H
66
#define BITCOIN_CHAINLOCK_SIGNING_H
77

8+
#include <chainlock/clsig.h>
89
#include <llmq/signing.h>
910

1011
class CMasternodeSync;
@@ -19,11 +20,25 @@ class CSigSharesManager;
1920
} // namespace llmq
2021

2122
namespace chainlock {
22-
class ChainLockSigner : public llmq::CRecoveredSigsListener
23+
class ChainLockSignerParent
24+
{
25+
public:
26+
virtual ~ChainLockSignerParent() = default;
27+
28+
virtual int32_t GetBestChainLockHeight() const = 0;
29+
virtual bool HasChainLock(int nHeight, const uint256& blockHash) const = 0;
30+
virtual bool HasConflictingChainLock(int nHeight, const uint256& blockHash) const = 0;
31+
virtual bool IsEnabled() const = 0;
32+
virtual bool IsTxSafeForMining(const uint256& txid) const = 0;
33+
virtual MessageProcessingResult ProcessNewChainLock(NodeId from, const ChainLockSig& clsig, const uint256& hash) = 0;
34+
virtual void UpdateTxFirstSeenMap(const std::unordered_set<uint256, StaticSaltedHasher>& tx, const int64_t& time) = 0;
35+
};
36+
37+
class ChainLockSigner final : public llmq::CRecoveredSigsListener
2338
{
2439
private:
2540
CChainState& m_chainstate;
26-
llmq::CChainLocksHandler& m_clhandler;
41+
ChainLockSignerParent& m_clhandler;
2742
llmq::CSigningManager& m_sigman;
2843
llmq::CSigSharesManager& m_shareman;
2944
CSporkManager& m_sporkman;
@@ -45,7 +60,7 @@ class ChainLockSigner : public llmq::CRecoveredSigsListener
4560
uint256 lastSignedMsgHash GUARDED_BY(cs_signer);
4661

4762
public:
48-
explicit ChainLockSigner(CChainState& chainstate, llmq::CChainLocksHandler& clhandler, llmq::CSigningManager& sigman,
63+
explicit ChainLockSigner(CChainState& chainstate, ChainLockSignerParent& clhandler, llmq::CSigningManager& sigman,
4964
llmq::CSigSharesManager& shareman, CSporkManager& sporkman, const CMasternodeSync& mn_sync);
5065
~ChainLockSigner();
5166

test/lint/lint-circular-dependencies.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
# Dash
2626
"banman -> common/bloom -> evo/assetlocktx -> llmq/quorums -> net -> banman",
2727
"banman -> common/bloom -> evo/assetlocktx -> llmq/signing -> net_processing -> banman",
28-
"chainlock/chainlock -> chainlock/signing -> chainlock/chainlock",
2928
"chainlock/chainlock -> instantsend/instantsend -> chainlock/chainlock",
3029
"chainlock/chainlock -> instantsend/instantsend -> instantsend/signing -> chainlock/chainlock",
3130
"chainlock/chainlock -> instantsend/instantsend -> net_processing -> chainlock/chainlock",

0 commit comments

Comments
 (0)