Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

masternode-meta.h
Go to the documentation of this file.
1 // Copyright (c) 2014-2020 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 MASTERNODE_META_H
6 #define MASTERNODE_META_H
7 
8 #include <serialize.h>
9 
10 #include <evo/deterministicmns.h>
11 
12 #include <univalue.h>
13 
14 #include <memory>
15 
16 class CConnman;
17 
18 static const int MASTERNODE_MAX_MIXING_TXES = 5;
19 
20 // Holds extra (non-deterministic) information about masternodes
21 // This is mostly local information, e.g. about mixing and governance
23 {
24  friend class CMasternodeMetaMan;
25 
26 private:
28 
30 
31  //the dsq count from the last dsq broadcast of this node
32  int64_t nLastDsq = 0;
33  int nMixingTxCount = 0;
34 
35  // KEEP TRACK OF GOVERNANCE ITEMS EACH MASTERNODE HAS VOTE UPON FOR RECALCULATION
36  std::map<uint256, int> mapGovernanceObjectsVotedOn;
37 
38  int64_t lastOutboundAttempt = 0;
39  int64_t lastOutboundSuccess = 0;
40 
41 public:
43  explicit CMasternodeMetaInfo(const uint256& _proTxHash) : proTxHash(_proTxHash) {}
45  proTxHash(ref.proTxHash),
46  nLastDsq(ref.nLastDsq),
51  {
52  }
53 
55  template <typename Stream, typename Operation>
56  inline void SerializationOp(Stream& s, Operation ser_action)
57  {
58  LOCK(cs);
65  }
66 
67  UniValue ToJson() const;
68 
69 public:
70  const uint256& GetProTxHash() const { LOCK(cs); return proTxHash; }
71  int64_t GetLastDsq() const { LOCK(cs); return nLastDsq; }
72  int GetMixingTxCount() const { LOCK(cs); return nMixingTxCount; }
73 
75 
76  // KEEP TRACK OF EACH GOVERNANCE ITEM INCASE THIS NODE GOES OFFLINE, SO WE CAN RECALC THEIR STATUS
77  void AddGovernanceVote(const uint256& nGovernanceObjectHash);
78 
79  void RemoveGovernanceObject(const uint256& nGovernanceObjectHash);
80 
82  int64_t GetLastOutboundAttempt() const { LOCK(cs); return lastOutboundAttempt; }
84  int64_t GetLastOutboundSuccess() const { LOCK(cs); return lastOutboundSuccess; }
85 };
86 typedef std::shared_ptr<CMasternodeMetaInfo> CMasternodeMetaInfoPtr;
87 
89 {
90 private:
91  static const std::string SERIALIZATION_VERSION_STRING;
92 
94 
95  std::map<uint256, CMasternodeMetaInfoPtr> metaInfos;
96  std::vector<uint256> vecDirtyGovernanceObjectHashes;
97 
98  // keep track of dsq count to prevent masternodes from gaming privatesend queue
99  int64_t nDsqCount = 0;
100 
101 public:
103 
104  template <typename Stream, typename Operation>
105  inline void SerializationOp(Stream& s, Operation ser_action)
106  {
107  LOCK(cs);
108 
109  std::string strVersion;
110  if(ser_action.ForRead()) {
111  Clear();
112  READWRITE(strVersion);
113  if (strVersion != SERIALIZATION_VERSION_STRING) {
114  return;
115  }
116  }
117  else {
118  strVersion = SERIALIZATION_VERSION_STRING;
119  READWRITE(strVersion);
120  }
121 
122  std::vector<CMasternodeMetaInfo> tmpMetaInfo;
123  if (ser_action.ForRead()) {
124  READWRITE(tmpMetaInfo);
125  metaInfos.clear();
126  for (auto& mm : tmpMetaInfo) {
127  metaInfos.emplace(mm.GetProTxHash(), std::make_shared<CMasternodeMetaInfo>(std::move(mm)));
128  }
129  } else {
130  for (auto& p : metaInfos) {
131  tmpMetaInfo.emplace_back(*p.second);
132  }
133  READWRITE(tmpMetaInfo);
134  }
135 
137  }
138 
139 public:
140  CMasternodeMetaInfoPtr GetMetaInfo(const uint256& proTxHash, bool fCreate = true);
141 
142  int64_t GetDsqCount() { LOCK(cs); return nDsqCount; }
143  int64_t GetDsqThreshold(const uint256& proTxHash, int nMnCount);
144 
145  void AllowMixing(const uint256& proTxHash);
146  void DisallowMixing(const uint256& proTxHash);
147 
148  bool AddGovernanceVote(const uint256& proTxHash, const uint256& nGovernanceObjectHash);
149  void RemoveGovernanceObject(const uint256& nGovernanceObjectHash);
150 
151  std::vector<uint256> GetAndClearDirtyGovernanceObjectHashes();
152 
153  void Clear();
154  void CheckAndRemove();
155 
156  std::string ToString() const;
157 };
158 
160 
161 #endif//MASTERNODE_META_H
void DisallowMixing(const uint256 &proTxHash)
ADD_SERIALIZE_METHODS void SerializationOp(Stream &s, Operation ser_action)
#define READWRITE(obj)
Definition: serialize.h:165
CMasternodeMetaInfo(const CMasternodeMetaInfo &ref)
void SetLastOutboundAttempt(int64_t t)
int64_t GetDsqThreshold(const uint256 &proTxHash, int nMnCount)
int GetMixingTxCount() const
UniValue ToJson() const
static const std::string SERIALIZATION_VERSION_STRING
std::map< uint256, int > mapGovernanceObjectsVotedOn
void SetLastOutboundSuccess(int64_t t)
static const int MASTERNODE_MAX_MIXING_TXES
int64_t GetLastDsq() const
void RemoveGovernanceObject(const uint256 &nGovernanceObjectHash)
CMasternodeMetaMan mmetaman
std::vector< uint256 > GetAndClearDirtyGovernanceObjectHashes()
CCriticalSection cs
void AddGovernanceVote(const uint256 &nGovernanceObjectHash)
#define LOCK(cs)
Definition: sync.h:178
#define ADD_SERIALIZE_METHODS
Implement three methods for serializable objects.
Definition: serialize.h:174
std::shared_ptr< CMasternodeMetaInfo > CMasternodeMetaInfoPtr
bool IsValidForMixingTxes() const
int64_t GetLastOutboundAttempt() const
Definition: net.h:136
CMasternodeMetaInfo(const uint256 &_proTxHash)
std::map< uint256, CMasternodeMetaInfoPtr > metaInfos
ADD_SERIALIZE_METHODS void SerializationOp(Stream &s, Operation ser_action)
256-bit opaque blob.
Definition: uint256.h:123
void AllowMixing(const uint256 &proTxHash)
int64_t GetLastOutboundSuccess() const
std::string ToString() const
const uint256 & GetProTxHash() const
CCriticalSection cs
std::vector< uint256 > vecDirtyGovernanceObjectHashes
bool AddGovernanceVote(const uint256 &proTxHash, const uint256 &nGovernanceObjectHash)
CMasternodeMetaInfoPtr GetMetaInfo(const uint256 &proTxHash, bool fCreate=true)
Wrapped mutex: supports recursive locking, but no waiting TODO: We should move away from using the re...
Definition: sync.h:94
void RemoveGovernanceObject(const uint256 &nGovernanceObjectHash)
Released under the MIT license