Line data Source code
1 : // Copyright (c) 2018-2025 The Dash Core developers 2 : // Distributed under the MIT software license, see the accompanying 3 : // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 : 5 : #ifndef BITCOIN_LLMQ_UTILS_H 6 : #define BITCOIN_LLMQ_UTILS_H 7 : 8 : #include <bls/bls.h> 9 : #include <evo/types.h> 10 : #include <llmq/params.h> 11 : #include <saltedhasher.h> 12 : 13 : #include <chainparams.h> 14 : #include <sync.h> 15 : #include <uint256.h> 16 : 17 : #include <gsl/pointers.h> 18 : 19 : #include <unordered_set> 20 : #include <vector> 21 : 22 : class CBlockIndex; 23 : class CDeterministicMNManager; 24 : class ChainstateManager; 25 : class CSporkManager; 26 : namespace llmq { 27 : class CQuorumSnapshotManager; 28 : } // namespace llmq 29 : 30 : namespace llmq { 31 : struct UtilParameters { 32 : CDeterministicMNManager& m_dmnman; 33 : CQuorumSnapshotManager& m_qsnapman; 34 : const ChainstateManager& m_chainman; 35 : gsl::not_null<const CBlockIndex*> m_base_index; 36 : 37 : public: 38 12500 : UtilParameters replace_index(gsl::not_null<const CBlockIndex*> base_index) const 39 : { 40 12500 : return {m_dmnman, m_qsnapman, m_chainman, base_index}; 41 : } 42 : }; 43 : 44 : namespace utils { 45 1130 : struct BlsCheck { 46 : CBLSSignature m_sig; 47 : std::vector<CBLSPublicKey> m_pubkeys; 48 : uint256 m_msg_hash; 49 : std::string m_id_string; 50 : 51 : public: 52 : BlsCheck(); 53 : BlsCheck(CBLSSignature sig, std::vector<CBLSPublicKey> pubkeys, uint256 msg_hash, std::string id_string); 54 : ~BlsCheck(); 55 : 56 : bool operator()(); 57 : void swap(BlsCheck& obj); 58 : }; 59 : 60 : uint256 DeterministicOutboundConnection(const uint256& proTxHash1, const uint256& proTxHash2); 61 : 62 : std::unordered_set<size_t> CalcDeterministicWatchConnections(Consensus::LLMQType llmqType, 63 : gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex, 64 : size_t memberCount, size_t connectionCount); 65 : 66 : // includes members which failed DKG 67 : std::vector<CDeterministicMNCPtr> GetAllQuorumMembers(Consensus::LLMQType llmqType, const UtilParameters& util_params, 68 : bool reset_cache = false); 69 : 70 : Uint256HashSet GetQuorumConnections(const Consensus::LLMQParams& llmqParams, const CSporkManager& sporkman, 71 : const UtilParameters& util_params, const uint256& forMember, bool onlyOutbound); 72 : 73 : Uint256HashSet GetQuorumRelayMembers(const Consensus::LLMQParams& llmqParams, const UtilParameters& util_params, 74 : const uint256& forMember, bool onlyOutbound); 75 : 76 : template <typename CacheType> 77 9447 : inline void InitQuorumsCache(CacheType& cache, const Consensus::Params& consensus_params, bool limit_by_connections = true) 78 : { 79 56726 : for (const auto& llmq : consensus_params.llmqs) { 80 94558 : cache.emplace(std::piecewise_construct, std::forward_as_tuple(llmq.type), 81 47279 : std::forward_as_tuple(limit_by_connections ? llmq.keepOldConnections : llmq.keepOldKeys)); 82 : } 83 9447 : } 84 : } // namespace utils 85 : } // namespace llmq 86 : 87 : #endif // BITCOIN_LLMQ_UTILS_H