PIVX Core  5.6.99
P2P Digital Currency
net_masternodes.h
Go to the documentation of this file.
1 // Copyright (c) 2020 The Dash developers
2 // Copyright (c) 2021-2022 The PIVX Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or https://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef PIVX_TIERTWO_NET_MASTERNODES_H
7 #define PIVX_TIERTWO_NET_MASTERNODES_H
8 
9 #include "consensus/params.h"
10 #include "net.h"
11 #include "sync.h"
12 #include "threadinterrupt.h"
13 #include "uint256.h"
14 
15 #include <thread>
16 
17 class CAddress;
18 class CConnman;
19 class CChainParams;
20 class CNode;
21 class CScheduler;
22 
24 {
25 public:
26  struct Options {
28  };
29 
30  explicit TierTwoConnMan(CConnman* _connman);
32 
33  // Add or update quorum nodes
34  void setQuorumNodes(Consensus::LLMQType llmqType,
35  const uint256& quorumHash,
36  const std::set<uint256>& proTxHashes);
37 
38  // Return quorum nodes for a given llmqType
39  std::set<uint256> getQuorumNodes(Consensus::LLMQType llmqType);
40 
41  // Return quorum nodes for a given llmqType and hash
42  std::set<NodeId> getQuorumNodes(Consensus::LLMQType llmqType, uint256 quorumHash);
43 
44  // Return true if the quorum was already registered
45  bool hasQuorumNodes(Consensus::LLMQType llmqType, const uint256& quorumHash);
46 
47  // Remove the registered quorum from the pending/protected MN connections
48  void removeQuorumNodes(Consensus::LLMQType llmqType, const uint256& quorumHash);
49 
50  // Add MNs to the active quorum relay members map and push QSENDRECSIGS to the verified connected peers that are part of this new quorum.
51  void setMasternodeQuorumRelayMembers(Consensus::LLMQType llmqType, const uint256& quorumHash, const std::set<uint256>& proTxHashes);
52 
53  // Returns true if the node has the same address as a MN.
54  bool isMasternodeQuorumNode(const CNode* pnode);
55 
56  // Whether protxHash an active quorum relay member
57  bool isMasternodeQuorumRelayMember(const uint256& protxHash);
58 
59  // Add DMN to the pending connection list
61 
62  // Adds the DMNs to the pending to probe list
63  void addPendingProbeConnections(const std::set<uint256>& proTxHashes);
64 
65  // Set the local DMN so the node does not try to connect to himself
66  void setLocalDMN(const uint256& pro_tx_hash) { WITH_LOCK(cs_vPendingMasternodes, local_dmn_pro_tx_hash = pro_tx_hash;); }
67 
68  // Clear connections cache
69  void clear();
70 
71  // Manages the MN connections
73  void start(CScheduler& scheduler, const TierTwoConnMan::Options& options);
74  void stop();
75  void interrupt();
76 
77 private:
80 
82  std::vector<uint256> vPendingMasternodes GUARDED_BY(cs_vPendingMasternodes);
83  typedef std::pair<Consensus::LLMQType, uint256> QuorumTypeAndHash;
84  std::map<QuorumTypeAndHash, std::set<uint256>> masternodeQuorumNodes GUARDED_BY(cs_vPendingMasternodes);
85  std::map<QuorumTypeAndHash, std::set<uint256>> masternodeQuorumRelayMembers GUARDED_BY(cs_vPendingMasternodes);
86  std::set<uint256> masternodePendingProbes GUARDED_BY(cs_vPendingMasternodes);
87 
88  // The local DMN
89  Optional<uint256> local_dmn_pro_tx_hash GUARDED_BY(cs_vPendingMasternodes){nullopt};
90 
91  // parent connections manager
93 
94  void openConnection(const CAddress& addrConnect, bool isProbe);
95  void doMaintenance();
96 };
97 
98 #endif // PIVX_TIERTWO_NET_MASTERNODES_H
A CService with information about it as peer.
Definition: protocol.h:338
CChainParams defines various tweakable parameters of a given instance of the PIVX system.
Definition: chainparams.h:43
Definition: net.h:145
Information about a peer.
Definition: net.h:669
bool hasQuorumNodes(Consensus::LLMQType llmqType, const uint256 &quorumHash)
std::thread threadOpenMasternodeConnections
void addPendingProbeConnections(const std::set< uint256 > &proTxHashes)
void ThreadOpenMasternodeConnections()
RecursiveMutex cs_vPendingMasternodes
bool isMasternodeQuorumRelayMember(const uint256 &protxHash)
void start(CScheduler &scheduler, const TierTwoConnMan::Options &options)
CConnman * connman
std::map< QuorumTypeAndHash, std::set< uint256 > > masternodeQuorumNodes GUARDED_BY(cs_vPendingMasternodes)
Optional< uint256 > local_dmn_pro_tx_hash GUARDED_BY(cs_vPendingMasternodes)
std::map< QuorumTypeAndHash, std::set< uint256 > > masternodeQuorumRelayMembers GUARDED_BY(cs_vPendingMasternodes)
std::pair< Consensus::LLMQType, uint256 > QuorumTypeAndHash
void openConnection(const CAddress &addrConnect, bool isProbe)
void setMasternodeQuorumRelayMembers(Consensus::LLMQType llmqType, const uint256 &quorumHash, const std::set< uint256 > &proTxHashes)
TierTwoConnMan(CConnman *_connman)
bool isMasternodeQuorumNode(const CNode *pnode)
std::vector< uint256 > vPendingMasternodes GUARDED_BY(cs_vPendingMasternodes)
void setLocalDMN(const uint256 &pro_tx_hash)
void setQuorumNodes(Consensus::LLMQType llmqType, const uint256 &quorumHash, const std::set< uint256 > &proTxHashes)
std::set< uint256 > masternodePendingProbes GUARDED_BY(cs_vPendingMasternodes)
CThreadInterrupt interruptNet
std::set< uint256 > getQuorumNodes(Consensus::LLMQType llmqType)
bool addPendingMasternode(const uint256 &proTxHash)
void removeQuorumNodes(Consensus::LLMQType llmqType, const uint256 &quorumHash)
256-bit opaque blob.
Definition: uint256.h:138
LLMQType
Definition: params.h:90
boost::optional< T > Optional
Substitute for C++17 std::optional.
Definition: optional.h:12
@ proTxHash
Definition: rpcevo.cpp:50
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:247
CScheduler scheduler