diff --git a/src/chainlock/chainlock.cpp b/src/chainlock/chainlock.cpp index b12b02879d99..1b376e90cea8 100644 --- a/src/chainlock/chainlock.cpp +++ b/src/chainlock/chainlock.cpp @@ -4,12 +4,27 @@ #include -#include +#include #include #include namespace chainlock { +ChainLockSig::ChainLockSig() = default; +ChainLockSig::~ChainLockSig() = default; + +ChainLockSig::ChainLockSig(int32_t nHeight, const uint256& blockHash, const CBLSSignature& sig) : + nHeight{nHeight}, + blockHash{blockHash}, + sig{sig} +{ +} + +std::string ChainLockSig::ToString() const +{ + return strprintf("ChainLockSig(nHeight=%d, blockHash=%s)", nHeight, blockHash.ToString()); +} + Chainlocks::Chainlocks(const CSporkManager& sporkman) : m_sporks(sporkman) { diff --git a/src/chainlock/chainlock.h b/src/chainlock/chainlock.h index e6d34ad9aa60..3ee131264ad2 100644 --- a/src/chainlock/chainlock.h +++ b/src/chainlock/chainlock.h @@ -5,19 +5,45 @@ #ifndef BITCOIN_CHAINLOCK_CHAINLOCK_H #define BITCOIN_CHAINLOCK_CHAINLOCK_H -#include -#include +#include #include +#include #include #include +class CBlockIndex; class CSporkManager; +class uint256; namespace chainlock { //! Depth of block including transactions before it's considered safe static constexpr int32_t TX_CONFIRM_THRESHOLD{5}; +struct ChainLockSig { +private: + int32_t nHeight{-1}; + uint256 blockHash; + CBLSSignature sig; + +public: + ChainLockSig(); + ~ChainLockSig(); + + ChainLockSig(int32_t nHeight, const uint256& blockHash, const CBLSSignature& sig); + + [[nodiscard]] int32_t getHeight() const { return nHeight; } + [[nodiscard]] const uint256& getBlockHash() const { return blockHash; } + [[nodiscard]] const CBLSSignature& getSig() const { return sig; } + [[nodiscard]] bool IsNull() const { return nHeight == -1 && blockHash == uint256(); } + [[nodiscard]] std::string ToString() const; + + SERIALIZE_METHODS(ChainLockSig, obj) + { + READWRITE(obj.nHeight, obj.blockHash, obj.sig); + } +}; + class Chainlocks { private: diff --git a/src/chainlock/clsig.cpp b/src/chainlock/clsig.cpp index 573331bba610..980be33a3750 100644 --- a/src/chainlock/clsig.cpp +++ b/src/chainlock/clsig.cpp @@ -4,30 +4,27 @@ #include -#include +#include +#include +#include #include namespace chainlock { static constexpr std::string_view CLSIG_REQUESTID_PREFIX{"clsig"}; -ChainLockSig::ChainLockSig() = default; -ChainLockSig::~ChainLockSig() = default; - -ChainLockSig::ChainLockSig(int32_t nHeight, const uint256& blockHash, const CBLSSignature& sig) : - nHeight{nHeight}, - blockHash{blockHash}, - sig{sig} +uint256 GenSigRequestId(const int32_t nHeight) { + return ::SerializeHash(std::make_pair(CLSIG_REQUESTID_PREFIX, nHeight)); } -std::string ChainLockSig::ToString() const +llmq::VerifyRecSigStatus VerifyChainLock(const Consensus::Params& params, const CChain& chain, + const llmq::CQuorumManager& qman, const chainlock::ChainLockSig& clsig) { - return strprintf("ChainLockSig(nHeight=%d, blockHash=%s)", nHeight, blockHash.ToString()); -} + const auto llmqType = params.llmqTypeChainLocks; + const uint256 request_id = GenSigRequestId(clsig.getHeight()); -uint256 GenSigRequestId(const int32_t nHeight) -{ - return ::SerializeHash(std::make_pair(CLSIG_REQUESTID_PREFIX, nHeight)); + return llmq::VerifyRecoveredSig(llmqType, chain, qman, clsig.getHeight(), request_id, clsig.getBlockHash(), + clsig.getSig()); } } // namespace chainlock diff --git a/src/chainlock/clsig.h b/src/chainlock/clsig.h index 3800f2f813cb..7ff6c7fee67a 100644 --- a/src/chainlock/clsig.h +++ b/src/chainlock/clsig.h @@ -5,40 +5,28 @@ #ifndef BITCOIN_CHAINLOCK_CLSIG_H #define BITCOIN_CHAINLOCK_CLSIG_H -#include -#include +#include -#include +class CChain; +class uint256; -#include +namespace Consensus { +struct Params; +} // namespace Consensus + +namespace llmq { +class CQuorumManager; +enum class VerifyRecSigStatus : uint8_t; +} // namespace llmq namespace chainlock { -struct ChainLockSig { -private: - int32_t nHeight{-1}; - uint256 blockHash; - CBLSSignature sig; - -public: - ChainLockSig(); - ~ChainLockSig(); - - ChainLockSig(int32_t nHeight, const uint256& blockHash, const CBLSSignature& sig); - - [[nodiscard]] int32_t getHeight() const { return nHeight; } - [[nodiscard]] const uint256& getBlockHash() const { return blockHash; } - [[nodiscard]] const CBLSSignature& getSig() const { return sig; } - [[nodiscard]] bool IsNull() const { return nHeight == -1 && blockHash == uint256(); } - [[nodiscard]] std::string ToString() const; - - SERIALIZE_METHODS(ChainLockSig, obj) - { - READWRITE(obj.nHeight, obj.blockHash, obj.sig); - } -}; +struct ChainLockSig; //! Generate clsig request ID with block height uint256 GenSigRequestId(const int32_t nHeight); + +llmq::VerifyRecSigStatus VerifyChainLock(const Consensus::Params& params, const CChain& chain, + const llmq::CQuorumManager& qman, const ChainLockSig& clsig); } // namespace chainlock #endif // BITCOIN_CHAINLOCK_CLSIG_H diff --git a/src/chainlock/handler.cpp b/src/chainlock/handler.cpp index 4e1392406bb3..b62a92b3d39c 100644 --- a/src/chainlock/handler.cpp +++ b/src/chainlock/handler.cpp @@ -4,20 +4,20 @@ #include +#include #include +#include +#include +#include #include #include #include #include -#include -#include - -#include -#include -#include #include #include +#include #include +#include #include #include #include @@ -325,13 +325,4 @@ void ChainlockHandler::Cleanup() } } -llmq::VerifyRecSigStatus VerifyChainLock(const Consensus::Params& params, const CChain& chain, - const llmq::CQuorumManager& qman, const chainlock::ChainLockSig& clsig) -{ - const auto llmqType = params.llmqTypeChainLocks; - const uint256 request_id = chainlock::GenSigRequestId(clsig.getHeight()); - - return llmq::VerifyRecoveredSig(llmqType, chain, qman, clsig.getHeight(), request_id, clsig.getBlockHash(), - clsig.getSig()); -} } // namespace chainlock diff --git a/src/chainlock/handler.h b/src/chainlock/handler.h index e024ca539876..140325c007c6 100644 --- a/src/chainlock/handler.h +++ b/src/chainlock/handler.h @@ -24,20 +24,14 @@ class CBlock; class CBlockIndex; -class CChain; class CMasternodeSync; class ChainstateManager; class CScheduler; class CTxMemPool; struct MessageProcessingResult; -namespace Consensus { -struct Params; -} // namespace Consensus - namespace llmq { class CQuorumManager; -enum class VerifyRecSigStatus : uint8_t; } // namespace llmq namespace chainlock { @@ -107,9 +101,6 @@ class ChainlockHandler final : public CValidationInterface private: void Cleanup() EXCLUSIVE_LOCKS_REQUIRED(!cs); }; - -llmq::VerifyRecSigStatus VerifyChainLock(const Consensus::Params& params, const CChain& chain, - const llmq::CQuorumManager& qman, const chainlock::ChainLockSig& clsig); } // namespace chainlock #endif // BITCOIN_CHAINLOCK_HANDLER_H diff --git a/src/chainlock/signing.h b/src/chainlock/signing.h index f19659727f72..e23a8b32305f 100644 --- a/src/chainlock/signing.h +++ b/src/chainlock/signing.h @@ -6,7 +6,6 @@ #define BITCOIN_CHAINLOCK_SIGNING_H #include -#include #include #include #include diff --git a/src/evo/deterministicmns.cpp b/src/evo/deterministicmns.cpp index 55b86c240647..9c70869382c3 100644 --- a/src/evo/deterministicmns.cpp +++ b/src/evo/deterministicmns.cpp @@ -4,6 +4,10 @@ #include +#include +#include +#include +#include #include #include #include @@ -11,25 +15,19 @@ #include #include #include -#include -#include - -#include -#include -#include -#include -#include #include #include