LCOV - code coverage report
Current view: top level - src/chainlock - chainlock.h (source / functions) Hit Total Coverage
Test: test_dash_coverage.info Lines: 7 7 100.0 %
Date: 2026-06-25 07:23:51 Functions: 15 21 71.4 %

          Line data    Source code
       1             : // Copyright (c) 2019-2026 The Dash Core developers
       2             : // Distributed under the MIT/X11 software license, see the accompanying
       3             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4             : 
       5             : #ifndef BITCOIN_CHAINLOCK_CHAINLOCK_H
       6             : #define BITCOIN_CHAINLOCK_CHAINLOCK_H
       7             : 
       8             : #include <bls/bls.h>
       9             : #include <gsl/pointers.h>
      10             : #include <serialize.h>
      11             : #include <sync.h>
      12             : #include <uint256.h>
      13             : 
      14             : class CBlockIndex;
      15             : class CSporkManager;
      16             : class uint256;
      17             : 
      18             : namespace chainlock {
      19             : 
      20             : //! Depth of block including transactions before it's considered safe
      21             : static constexpr int32_t TX_CONFIRM_THRESHOLD{5};
      22             : 
      23             : struct ChainLockSig {
      24             : private:
      25             :     int32_t nHeight{-1};
      26             :     uint256 blockHash;
      27             :     CBLSSignature sig;
      28             : 
      29             : public:
      30             :     ChainLockSig();
      31             :     ~ChainLockSig();
      32             : 
      33             :     ChainLockSig(int32_t nHeight, const uint256& blockHash, const CBLSSignature& sig);
      34             : 
      35       79489 :     [[nodiscard]] int32_t getHeight() const { return nHeight; }
      36           8 :     [[nodiscard]] const uint256& getBlockHash() const { return blockHash; }
      37           6 :     [[nodiscard]] const CBLSSignature& getSig() const { return sig; }
      38        7639 :     [[nodiscard]] bool IsNull() const { return nHeight == -1 && blockHash == uint256(); }
      39             :     [[nodiscard]] std::string ToString() const;
      40             : 
      41          63 :     SERIALIZE_METHODS(ChainLockSig, obj)
      42             :     {
      43          21 :         READWRITE(obj.nHeight, obj.blockHash, obj.sig);
      44          21 :     }
      45             : };
      46             : 
      47             : class Chainlocks
      48             : {
      49             : private:
      50             :     const CSporkManager& m_sporks;
      51             : 
      52             :     mutable Mutex cs;
      53             :     const CBlockIndex* bestChainLockBlockIndex GUARDED_BY(cs){nullptr};
      54             : 
      55             :     uint256 bestChainLockHash GUARDED_BY(cs);
      56             :     chainlock::ChainLockSig bestChainLock GUARDED_BY(cs);
      57             : 
      58             :     chainlock::ChainLockSig bestChainLockWithKnownBlock GUARDED_BY(cs);
      59             : 
      60             : public:
      61             :     Chainlocks(const CSporkManager& sporkman);
      62             : 
      63             :     [[nodiscard]] bool IsEnabled() const;
      64             :     [[nodiscard]] bool IsSigningEnabled() const;
      65             : 
      66             :     [[nodiscard]] chainlock::ChainLockSig GetBestChainLock() const EXCLUSIVE_LOCKS_REQUIRED(!cs);
      67             : 
      68             :     [[nodiscard]] int32_t GetBestChainLockHeight() const EXCLUSIVE_LOCKS_REQUIRED(!cs);
      69             : 
      70             :     [[nodiscard]] bool HasChainLock(int nHeight, const uint256& blockHash) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
      71             : 
      72             :     [[nodiscard]] bool HasConflictingChainLock(int nHeight, const uint256& blockHash) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
      73             : 
      74             :     bool UpdateBestChainlock(const uint256& hash, const chainlock::ChainLockSig& clsig, const CBlockIndex* pindex)
      75             :         EXCLUSIVE_LOCKS_REQUIRED(!cs);
      76             : 
      77             :     std::pair<chainlock::ChainLockSig, const CBlockIndex*> GetBestChainlockWithPindex() const
      78             :         EXCLUSIVE_LOCKS_REQUIRED(!cs);
      79             : 
      80             :     bool GetChainLockByHash(const uint256& hash, chainlock::ChainLockSig& ret) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
      81             : 
      82             :     void AcceptedBlockHeader(gsl::not_null<const CBlockIndex*> pindexNew) EXCLUSIVE_LOCKS_REQUIRED(!cs);
      83             : 
      84             :     void ResetChainlock() EXCLUSIVE_LOCKS_REQUIRED(!cs);
      85             : };
      86             : 
      87             : } // namespace chainlock
      88             : 
      89             : #endif // BITCOIN_CHAINLOCK_CHAINLOCK_H

Generated by: LCOV version 1.16