Line data Source code
1 : // Copyright (c) 2017-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_EVO_SMLDIFF_H 6 : #define BITCOIN_EVO_SMLDIFF_H 7 : 8 : #include <bls/bls.h> 9 : #include <evo/dmn_types.h> 10 : #include <evo/netinfo.h> 11 : #include <evo/providertx.h> 12 : #include <evo/simplifiedmns.h> 13 : 14 : #include <merkleblock.h> 15 : #include <netaddress.h> 16 : #include <pubkey.h> 17 : #include <sync.h> 18 : #include <threadsafety.h> 19 : 20 : class CBlockIndex; 21 : class CDeterministicMNManager; 22 : class UniValue; 23 : class ChainstateManager; 24 : struct RPCResult; 25 : 26 : namespace llmq { 27 : class CFinalCommitment; 28 : class CQuorumBlockProcessor; 29 : class CQuorumManager; 30 : } // namespace llmq 31 : 32 : extern RecursiveMutex cs_main; // NOLINT(readability-redundant-declaration) 33 : 34 : /// P2P messages 35 : 36 : class CGetSimplifiedMNListDiff 37 : { 38 : public: 39 : uint256 baseBlockHash; 40 : uint256 blockHash; 41 : 42 0 : SERIALIZE_METHODS(CGetSimplifiedMNListDiff, obj) { READWRITE(obj.baseBlockHash, obj.blockHash); } 43 : }; 44 : 45 22 : class CSimplifiedMNListDiff 46 : { 47 : public: 48 : static constexpr uint16_t CURRENT_VERSION = 1; 49 : 50 : uint256 baseBlockHash; 51 : uint256 blockHash; 52 : CPartialMerkleTree cbTxMerkleTree; 53 : CMutableTransaction cbTx; 54 : std::vector<uint256> deletedMNs; 55 : std::vector<CSimplifiedMNListEntry> mnList; 56 : uint16_t nVersion{CURRENT_VERSION}; 57 : 58 : std::vector<std::pair<uint8_t, uint256>> deletedQuorums; // p<LLMQType, quorumHash> 59 : std::vector<llmq::CFinalCommitment> newQuorums; 60 : 61 : // Map of Chainlock Signature used for shuffling per set of quorums 62 : // The set of quorums is the set of indexes corresponding to entries in newQuorums 63 : std::map<CBLSSignature, std::set<uint16_t>> quorumsCLSigs; 64 : 65 276 : SERIALIZE_METHODS(CSimplifiedMNListDiff, obj) 66 : { 67 92 : if ((s.GetType() & SER_NETWORK) && s.GetVersion() >= MNLISTDIFF_VERSION_ORDER) { 68 92 : READWRITE(obj.nVersion); 69 92 : } 70 92 : READWRITE(obj.baseBlockHash, obj.blockHash, obj.cbTxMerkleTree, obj.cbTx); 71 92 : if ((s.GetType() & SER_NETWORK) && s.GetVersion() >= BLS_SCHEME_PROTO_VERSION && 72 92 : s.GetVersion() < MNLISTDIFF_VERSION_ORDER) { 73 0 : READWRITE(obj.nVersion); 74 0 : } 75 92 : READWRITE(obj.deletedMNs, obj.mnList); 76 92 : READWRITE(obj.deletedQuorums, obj.newQuorums); 77 92 : if ((s.GetType() & SER_NETWORK) && s.GetVersion() >= MNLISTDIFF_CHAINLOCKS_PROTO_VERSION) { 78 92 : READWRITE(obj.quorumsCLSigs); 79 92 : } 80 92 : } 81 : 82 : CSimplifiedMNListDiff(); 83 : ~CSimplifiedMNListDiff(); 84 : 85 : bool BuildQuorumsDiff(const CBlockIndex* baseBlockIndex, const CBlockIndex* blockIndex, 86 : const llmq::CQuorumBlockProcessor& quorum_block_processor); 87 : bool BuildQuorumChainlockInfo(const llmq::CQuorumManager& qman, const CBlockIndex* blockIndex); 88 : 89 : [[nodiscard]] static RPCResult GetJsonHelp(const std::string& key, bool optional); 90 : [[nodiscard]] UniValue ToJson(bool extended = false) const; 91 : }; 92 : 93 : bool BuildSimplifiedMNListDiff(CDeterministicMNManager& dmnman, const ChainstateManager& chainman, 94 : const llmq::CQuorumBlockProcessor& qblockman, const llmq::CQuorumManager& qman, 95 : const uint256& baseBlockHash, const uint256& blockHash, CSimplifiedMNListDiff& mnListDiffRet, 96 : std::string& errorRet, bool extended = false) EXCLUSIVE_LOCKS_REQUIRED(::cs_main); 97 : 98 : #endif // BITCOIN_EVO_SMLDIFF_H