Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

deterministicmns.h
Go to the documentation of this file.
1 // Copyright (c) 2018-2020 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 DASH_DETERMINISTICMNS_H
6 #define DASH_DETERMINISTICMNS_H
7 
8 #include <arith_uint256.h>
9 #include <bls/bls.h>
10 #include <dbwrapper.h>
11 #include <evo/evodb.h>
12 #include <evo/providertx.h>
13 #include <evo/simplifiedmns.h>
14 #include <saltedhasher.h>
15 #include <sync.h>
16 
17 #include <immer/map.hpp>
18 #include <immer/map_transient.hpp>
19 
20 #include <unordered_map>
21 
22 class CBlock;
23 class CBlockIndex;
24 class CValidationState;
25 
26 namespace llmq
27 {
28  class CFinalCommitment;
29 } // namespace llmq
30 
32 {
33 public:
36  int nPoSePenalty{0};
38  int nPoSeBanHeight{-1};
40 
41  // the block hash X blocks after registration, used in quorum calculations
43  // sha256(proTxHash, confirmedHash) to speed up quorum calculations
44  // please note that this is NOT a double-sha256 hash
46 
53 
54 public:
56  explicit CDeterministicMNState(const CProRegTx& proTx)
57  {
58  keyIDOwner = proTx.keyIDOwner;
60  keyIDVoting = proTx.keyIDVoting;
61  addr = proTx.addr;
62  scriptPayout = proTx.scriptPayout;
63  }
64  template <typename Stream>
66  {
67  s >> *this;
68  }
69 
71 
72  template <typename Stream, typename Operation>
73  inline void SerializationOp(Stream& s, Operation ser_action)
74  {
86  READWRITE(addr);
89  }
90 
92  {
94  addr = CService();
97  }
98  void BanIfNotBanned(int height)
99  {
100  if (nPoSeBanHeight == -1) {
101  nPoSeBanHeight = height;
102  }
103  }
104  void UpdateConfirmedHash(const uint256& _proTxHash, const uint256& _confirmedHash)
105  {
106  confirmedHash = _confirmedHash;
107  CSHA256 h;
108  h.Write(_proTxHash.begin(), _proTxHash.size());
109  h.Write(_confirmedHash.begin(), _confirmedHash.size());
111  }
112 
113 public:
114  std::string ToString() const;
115  void ToJson(UniValue& obj) const;
116 };
117 typedef std::shared_ptr<CDeterministicMNState> CDeterministicMNStatePtr;
118 typedef std::shared_ptr<const CDeterministicMNState> CDeterministicMNStateCPtr;
119 
121 {
122 public:
123  enum Field : uint32_t {
135  Field_addr = 0x0800,
138  };
139 
140 #define DMN_STATE_DIFF_ALL_FIELDS \
141  DMN_STATE_DIFF_LINE(nRegisteredHeight) \
142  DMN_STATE_DIFF_LINE(nLastPaidHeight) \
143  DMN_STATE_DIFF_LINE(nPoSePenalty) \
144  DMN_STATE_DIFF_LINE(nPoSeRevivedHeight) \
145  DMN_STATE_DIFF_LINE(nPoSeBanHeight) \
146  DMN_STATE_DIFF_LINE(nRevocationReason) \
147  DMN_STATE_DIFF_LINE(confirmedHash) \
148  DMN_STATE_DIFF_LINE(confirmedHashWithProRegTxHash) \
149  DMN_STATE_DIFF_LINE(keyIDOwner) \
150  DMN_STATE_DIFF_LINE(pubKeyOperator) \
151  DMN_STATE_DIFF_LINE(keyIDVoting) \
152  DMN_STATE_DIFF_LINE(addr) \
153  DMN_STATE_DIFF_LINE(scriptPayout) \
154  DMN_STATE_DIFF_LINE(scriptOperatorPayout)
155 
156 public:
157  uint32_t fields{0};
158  // we reuse the state class, but only the members as noted by fields are valid
160 
161 public:
164  {
165 #define DMN_STATE_DIFF_LINE(f) if (a.f != b.f) { state.f = b.f; fields |= Field_##f; }
167 #undef DMN_STATE_DIFF_LINE
168  }
169 
171 
172  template <typename Stream, typename Operation>
173  inline void SerializationOp(Stream& s, Operation ser_action)
174  {
176 #define DMN_STATE_DIFF_LINE(f) if (fields & Field_##f) READWRITE(state.f);
178 #undef DMN_STATE_DIFF_LINE
179  }
180 
182  {
183 #define DMN_STATE_DIFF_LINE(f) if (fields & Field_##f) target.f = state.f;
185 #undef DMN_STATE_DIFF_LINE
186  }
187 };
188 
190 {
191 private:
192  uint64_t internalId{std::numeric_limits<uint64_t>::max()};
193 
194 public:
195  CDeterministicMN() = delete; // no default constructor, must specify internalId
196  CDeterministicMN(uint64_t _internalId) : internalId(_internalId)
197  {
198  // only non-initial values
199  assert(_internalId != std::numeric_limits<uint64_t>::max());
200  }
201  // TODO: can be removed in a future version
202  CDeterministicMN(const CDeterministicMN& mn, uint64_t _internalId) : CDeterministicMN(mn) {
203  // only non-initial values
204  assert(_internalId != std::numeric_limits<uint64_t>::max());
205  internalId = _internalId;
206  }
207 
208  template <typename Stream>
210  {
211  s >> *this;
212  }
213 
216  uint16_t nOperatorReward;
218 
219 public:
220  template <typename Stream, typename Operation>
221  inline void SerializationOp(Stream& s, Operation ser_action, bool oldFormat)
222  {
224  if (!oldFormat) {
226  }
230  }
231 
232  template<typename Stream>
233  void Serialize(Stream& s) const
234  {
235  NCONST_PTR(this)->SerializationOp(s, CSerActionSerialize(), false);
236  }
237 
238  template<typename Stream>
239  void Unserialize(Stream& s, bool oldFormat = false)
240  {
241  SerializationOp(s, CSerActionUnserialize(), oldFormat);
242  }
243 
244  uint64_t GetInternalId() const;
245 
246  std::string ToString() const;
247  void ToJson(UniValue& obj) const;
248 };
249 typedef std::shared_ptr<const CDeterministicMN> CDeterministicMNCPtr;
250 
252 
253 template <typename Stream, typename K, typename T, typename Hash, typename Equal>
255 {
256  WriteCompactSize(os, m.size());
257  for (typename immer::map<K, T, Hash, Equal>::const_iterator mi = m.begin(); mi != m.end(); ++mi)
258  Serialize(os, (*mi));
259 }
260 
261 template <typename Stream, typename K, typename T, typename Hash, typename Equal>
263 {
265  unsigned int nSize = ReadCompactSize(is);
266  for (unsigned int i = 0; i < nSize; i++) {
267  std::pair<K, T> item;
268  Unserialize(is, item);
269  m = m.set(item.first, item.second);
270  }
271 }
272 
273 // For some reason the compiler is not able to choose the correct Serialize/Deserialize methods without a specialized
274 // version of SerReadWrite. It otherwise always chooses the version that calls a.Serialize()
275 template<typename Stream, typename K, typename T, typename Hash, typename Equal>
276 inline void SerReadWrite(Stream& s, const immer::map<K, T, Hash, Equal>& m, CSerActionSerialize ser_action)
277 {
278  ::SerializeImmerMap(s, m);
279 }
280 
281 template<typename Stream, typename K, typename T, typename Hash, typename Equal>
282 inline void SerReadWrite(Stream& s, immer::map<K, T, Hash, Equal>& obj, CSerActionUnserialize ser_action)
283 {
284  ::UnserializeImmerMap(s, obj);
285 }
286 
287 
289 {
290 public:
294 
295 private:
297  int nHeight{-1};
301 
302  // map of unique properties like address and keys
303  // we keep track of this as checking for duplicates would otherwise be painfully slow
305 
306 public:
308  explicit CDeterministicMNList(const uint256& _blockHash, int _height, uint32_t _totalRegisteredCount) :
309  blockHash(_blockHash),
310  nHeight(_height),
311  nTotalRegisteredCount(_totalRegisteredCount)
312  {
313  }
314 
315  template <typename Stream, typename Operation>
316  inline void SerializationOpBase(Stream& s, Operation ser_action)
317  {
321  }
322 
323  template<typename Stream>
324  void Serialize(Stream& s) const
325  {
326  NCONST_PTR(this)->SerializationOpBase(s, CSerActionSerialize());
327  // Serialize the map as a vector
329  for (const auto& p : mnMap) {
330  s << *p.second;
331  }
332  }
333 
334  template<typename Stream>
335  void Unserialize(Stream& s) {
336  mnMap = MnMap();
339 
341 
342  size_t cnt = ReadCompactSize(s);
343  for (size_t i = 0; i < cnt; i++) {
344  AddMN(std::make_shared<CDeterministicMN>(deserialize, s), false);
345  }
346  }
347 
348 public:
349  size_t GetAllMNsCount() const
350  {
351  return mnMap.size();
352  }
353 
354  size_t GetValidMNsCount() const
355  {
356  size_t count = 0;
357  for (const auto& p : mnMap) {
358  if (IsMNValid(p.second)) {
359  count++;
360  }
361  }
362  return count;
363  }
364 
365  template <typename Callback>
366  void ForEachMN(bool onlyValid, Callback&& cb) const
367  {
368  for (const auto& p : mnMap) {
369  if (!onlyValid || IsMNValid(p.second)) {
370  cb(p.second);
371  }
372  }
373  }
374 
375 public:
376  const uint256& GetBlockHash() const
377  {
378  return blockHash;
379  }
380  void SetBlockHash(const uint256& _blockHash)
381  {
382  blockHash = _blockHash;
383  }
384  int GetHeight() const
385  {
386  return nHeight;
387  }
388  void SetHeight(int _height)
389  {
390  nHeight = _height;
391  }
392  uint32_t GetTotalRegisteredCount() const
393  {
394  return nTotalRegisteredCount;
395  }
396 
397  bool IsMNValid(const uint256& proTxHash) const;
398  bool IsMNPoSeBanned(const uint256& proTxHash) const;
399  bool IsMNValid(const CDeterministicMNCPtr& dmn) const;
400  bool IsMNPoSeBanned(const CDeterministicMNCPtr& dmn) const;
401 
402  bool HasMN(const uint256& proTxHash) const
403  {
404  return GetMN(proTxHash) != nullptr;
405  }
406  bool HasMNByCollateral(const COutPoint& collateralOutpoint) const
407  {
408  return GetMNByCollateral(collateralOutpoint) != nullptr;
409  }
410  bool HasValidMNByCollateral(const COutPoint& collateralOutpoint) const
411  {
412  return GetValidMNByCollateral(collateralOutpoint) != nullptr;
413  }
414  CDeterministicMNCPtr GetMN(const uint256& proTxHash) const;
415  CDeterministicMNCPtr GetValidMN(const uint256& proTxHash) const;
417  CDeterministicMNCPtr GetMNByCollateral(const COutPoint& collateralOutpoint) const;
418  CDeterministicMNCPtr GetValidMNByCollateral(const COutPoint& collateralOutpoint) const;
419  CDeterministicMNCPtr GetMNByService(const CService& service) const;
420  CDeterministicMNCPtr GetMNByInternalId(uint64_t internalId) const;
422 
429  std::vector<CDeterministicMNCPtr> GetProjectedMNPayees(int nCount) const;
430 
437  std::vector<CDeterministicMNCPtr> CalculateQuorum(size_t maxSize, const uint256& modifier) const;
438  std::vector<std::pair<arith_uint256, CDeterministicMNCPtr>> CalculateScores(const uint256& modifier) const;
439 
445  int CalcMaxPoSePenalty() const;
446 
455  int CalcPenalty(int percent) const;
456 
464  void PoSePunish(const uint256& proTxHash, int penalty, bool debugLogs);
465 
471  void PoSeDecrease(const uint256& proTxHash);
472 
475  CDeterministicMNList ApplyDiff(const CBlockIndex* pindex, const CDeterministicMNListDiff& diff) const;
476 
477  void AddMN(const CDeterministicMNCPtr& dmn, bool fBumpTotalCount = true);
478  void UpdateMN(const CDeterministicMNCPtr& oldDmn, const CDeterministicMNStateCPtr& pdmnState);
479  void UpdateMN(const uint256& proTxHash, const CDeterministicMNStateCPtr& pdmnState);
480  void UpdateMN(const CDeterministicMNCPtr& oldDmn, const CDeterministicMNStateDiff& stateDiff);
481  void RemoveMN(const uint256& proTxHash);
482 
483  template <typename T>
484  bool HasUniqueProperty(const T& v) const
485  {
486  return mnUniquePropertyMap.count(::SerializeHash(v)) != 0;
487  }
488  template <typename T>
490  {
491  auto p = mnUniquePropertyMap.find(::SerializeHash(v));
492  if (!p) {
493  return nullptr;
494  }
495  return GetMN(p->first);
496  }
497 
498 private:
499  template <typename T>
500  void AddUniqueProperty(const CDeterministicMNCPtr& dmn, const T& v)
501  {
502  static const T nullValue;
503  assert(v != nullValue);
504 
505  auto hash = ::SerializeHash(v);
506  auto oldEntry = mnUniquePropertyMap.find(hash);
507  assert(!oldEntry || oldEntry->first == dmn->proTxHash);
508  std::pair<uint256, uint32_t> newEntry(dmn->proTxHash, 1);
509  if (oldEntry) {
510  newEntry.second = oldEntry->second + 1;
511  }
512  mnUniquePropertyMap = mnUniquePropertyMap.set(hash, newEntry);
513  }
514  template <typename T>
515  void DeleteUniqueProperty(const CDeterministicMNCPtr& dmn, const T& oldValue)
516  {
517  static const T nullValue;
518  assert(oldValue != nullValue);
519 
520  auto oldHash = ::SerializeHash(oldValue);
521  auto p = mnUniquePropertyMap.find(oldHash);
522  assert(p && p->first == dmn->proTxHash);
523  if (p->second == 1) {
525  } else {
526  mnUniquePropertyMap = mnUniquePropertyMap.set(oldHash, std::make_pair(dmn->proTxHash, p->second - 1));
527  }
528  }
529  template <typename T>
530  void UpdateUniqueProperty(const CDeterministicMNCPtr& dmn, const T& oldValue, const T& newValue)
531  {
532  if (oldValue == newValue) {
533  return;
534  }
535  static const T nullValue;
536 
537  if (oldValue != nullValue) {
538  DeleteUniqueProperty(dmn, oldValue);
539  }
540 
541  if (newValue != nullValue) {
542  AddUniqueProperty(dmn, newValue);
543  }
544  }
545 };
546 
548 {
549 public:
550  int nHeight{-1}; //memory only
551 
552  std::vector<CDeterministicMNCPtr> addedMNs;
553  // keys are all relating to the internalId of MNs
554  std::map<uint64_t, CDeterministicMNStateDiff> updatedMNs;
555  std::set<uint64_t> removedMns;
556 
557 public:
558  template<typename Stream>
559  void Serialize(Stream& s) const
560  {
561  s << addedMNs;
562  WriteCompactSize(s, updatedMNs.size());
563  for (const auto& p : updatedMNs) {
564  WriteVarInt(s, p.first);
565  s << p.second;
566  }
567  WriteCompactSize(s, removedMns.size());
568  for (const auto& p : removedMns) {
569  WriteVarInt(s, p);
570  }
571  }
572 
573  template<typename Stream>
574  void Unserialize(Stream& s)
575  {
576  updatedMNs.clear();
577  removedMns.clear();
578 
579  size_t tmp;
580  uint64_t tmp2;
581  s >> addedMNs;
582  tmp = ReadCompactSize(s);
583  for (size_t i = 0; i < tmp; i++) {
585  tmp2 = ReadVarInt<Stream, uint64_t>(s);
586  s >> diff;
587  updatedMNs.emplace(tmp2, std::move(diff));
588  }
589  tmp = ReadCompactSize(s);
590  for (size_t i = 0; i < tmp; i++) {
591  tmp2 = ReadVarInt<Stream, uint64_t>(s);
592  removedMns.emplace(tmp2);
593  }
594  }
595 
596 public:
597  bool HasChanges() const
598  {
599  return !addedMNs.empty() || !updatedMNs.empty() || !removedMns.empty();
600  }
601 };
602 
603 // TODO can be removed in a future version
605 {
606 public:
609  int nHeight{-1};
610  std::map<uint256, CDeterministicMNCPtr> addedMNs;
611  std::map<uint256, CDeterministicMNStateCPtr> updatedMNs;
612  std::set<uint256> removedMns;
613 
614 public:
615  template<typename Stream>
616  void Unserialize(Stream& s) {
617  addedMNs.clear();
618  s >> prevBlockHash;
619  s >> blockHash;
620  s >> nHeight;
621  size_t cnt = ReadCompactSize(s);
622  for (size_t i = 0; i < cnt; i++) {
623  uint256 proTxHash;
624  // NOTE: This is a hack and "0" is just a dummy id. The actual internalId is assigned to a copy
625  // of this dmn via corresponding ctor when we convert the diff format to a new one in UpgradeDiff
626  // thus the logic that we must set internalId before dmn is used in any meaningful way is preserved.
627  auto dmn = std::make_shared<CDeterministicMN>(0);
628  s >> proTxHash;
629  dmn->Unserialize(s, true);
630  addedMNs.emplace(proTxHash, dmn);
631  }
632  s >> updatedMNs;
633  s >> removedMns;
634  }
635 };
636 
638 {
639  static const int DISK_SNAPSHOT_PERIOD = 576; // once per day
640  static const int DISK_SNAPSHOTS = 3; // keep cache for 3 disk snapshots to have 2 full days covered
642 
643 public:
645 
646 private:
648 
649  std::unordered_map<uint256, CDeterministicMNList, StaticSaltedHasher> mnListsCache;
650  std::unordered_map<uint256, CDeterministicMNListDiff, StaticSaltedHasher> mnListDiffsCache;
651  const CBlockIndex* tipIndex{nullptr};
652 
653 public:
654  explicit CDeterministicMNManager(CEvoDB& _evoDb);
655 
656  bool ProcessBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& state, bool fJustCheck);
657  bool UndoBlock(const CBlock& block, const CBlockIndex* pindex);
658 
659  void UpdatedBlockTip(const CBlockIndex* pindex);
660 
661  // the returned list will not contain the correct block hash (we can't know it yet as the coinbase TX is not updated yet)
662  bool BuildNewListFromBlock(const CBlock& block, const CBlockIndex* pindexPrev, CValidationState& state, CDeterministicMNList& mnListRet, bool debugLogs);
663  void HandleQuorumCommitment(llmq::CFinalCommitment& qc, const CBlockIndex* pindexQuorum, CDeterministicMNList& mnList, bool debugLogs);
665 
668 
669  // Test if given TX is a ProRegTx which also contains the collateral at index n
670  bool IsProTxWithCollateral(const CTransactionRef& tx, uint32_t n);
671 
672  bool IsDIP3Enforced(int nHeight = -1);
673 
674 public:
675  // TODO these can all be removed in a future version
676  void UpgradeDiff(CDBBatch& batch, const CBlockIndex* pindexNext, const CDeterministicMNList& curMNList, CDeterministicMNList& newMNList);
677  bool UpgradeDBIfNeeded();
678 
679 private:
680  void CleanupCache(int nHeight);
681 };
682 
683 extern std::unique_ptr<CDeterministicMNManager> deterministicMNManager;
684 
685 #endif //DASH_DETERMINISTICMNS_H
int CalcMaxPoSePenalty() const
Calculates the maximum penalty which is allowed at the height of this MN list.
CDeterministicMNList GetListAtChainTip()
CSHA256 & Write(const unsigned char *data, size_t len)
Definition: sha256.cpp:648
#define VARINT(obj)
Definition: serialize.h:375
CDeterministicMNManager(CEvoDB &_evoDb)
CDeterministicMNCPtr GetValidMN(const uint256 &proTxHash) const
std::string ToString() const
void SetBlockHash(const uint256 &_blockHash)
void PoSePunish(const uint256 &proTxHash, int penalty, bool debugLogs)
Punishes a MN for misbehavior.
void SerializationOp(Stream &s, Operation ser_action)
void UpdatedBlockTip(const CBlockIndex *pindex)
CDeterministicMNCPtr GetUniquePropertyMN(const T &v) const
void Serialize(Stream &s) const
Definition: evodb.h:32
CDeterministicMNStateDiff(const CDeterministicMNState &a, const CDeterministicMNState &b)
CDeterministicMNList(const uint256 &_blockHash, int _height, uint32_t _totalRegisteredCount)
#define READWRITE(obj)
Definition: serialize.h:165
Batch of changes queued to be written to a CDBWrapper.
Definition: dbwrapper.h:49
void UnserializeImmerMap(Stream &is, immer::map< K, T, Hash, Equal > &m)
Definition: block.h:72
void Serialize(Stream &s) const
uint64_t ReadCompactSize(Stream &is)
Definition: serialize.h:261
void WriteVarInt(CSizeComputer &os, I n)
Definition: serialize.h:1284
CDeterministicMNCPtr GetMN(const uint256 &proTxHash) const
void WriteCompactSize(CSizeComputer &os, uint64_t nSize)
Definition: serialize.h:1289
size_t GetValidMNsCount() const
void BanIfNotBanned(int height)
void SerializeImmerMap(Stream &os, const immer::map< K, T, Hash, Equal > &m)
void UpdateMN(const CDeterministicMNCPtr &oldDmn, const CDeterministicMNStateCPtr &pdmnState)
uint64_t GetInternalId() const
void ApplyToState(CDeterministicMNState &target) const
std::shared_ptr< const CDeterministicMNState > CDeterministicMNStateCPtr
map set(key_type k, mapped_type v) const
Definition: map.hpp:263
std::vector< CDeterministicMNCPtr > GetProjectedMNPayees(int nCount) const
Calculates the projected MN payees for the next count blocks.
constexpr deserialize_type deserialize
Definition: serialize.h:43
void UpgradeDiff(CDBBatch &batch, const CBlockIndex *pindexNext, const CDeterministicMNList &curMNList, CDeterministicMNList &newMNList)
void AddMN(const CDeterministicMNCPtr &dmn, bool fBumpTotalCount=true)
uint256 confirmedHashWithProRegTxHash
CKeyID keyIDVoting
Definition: providertx.h:32
const T * find(const K &k) const
Definition: map.hpp:236
static const int DISK_SNAPSHOTS
size_t GetAllMNsCount() const
bool IsMNValid(const uint256 &proTxHash) const
std::shared_ptr< const CDeterministicMN > CDeterministicMNCPtr
void Unserialize(Stream &s, bool oldFormat=false)
CDeterministicMNListDiff BuildDiff(const CDeterministicMNList &to) const
bool IsDIP3Enforced(int nHeight=-1)
void SerializationOp(Stream &s, Operation ser_action)
size_type count(const K &k) const
Definition: map.hpp:184
void AddUniqueProperty(const CDeterministicMNCPtr &dmn, const T &v)
std::unique_ptr< CDeterministicMNManager > deterministicMNManager
void ForEachMN(bool onlyValid, Callback &&cb) const
unsigned char * begin()
Definition: uint256.h:57
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:345
CDeterministicMN(const CDeterministicMN &mn, uint64_t _internalId)
std::shared_ptr< CDeterministicMNState > CDeterministicMNStatePtr
CDeterministicMNStateCPtr pdmnState
Dummy data type to identify deserializing constructors.
Definition: serialize.h:42
void ToJson(UniValue &obj) const
void Serialize(Stream &s, char a)
Definition: serialize.h:184
void SerializationOp(Stream &s, Operation ser_action, bool oldFormat)
std::vector< CDeterministicMNCPtr > CalculateQuorum(size_t maxSize, const uint256 &modifier) const
Calculate a quorum based on the modifier.
CDeterministicMNCPtr GetMNByInternalId(uint64_t internalId) const
uint256 SerializeHash(const T &obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
Compute the 256-bit hash of an object&#39;s serialization.
Definition: hash.h:254
MnUniquePropertyMap mnUniquePropertyMap
immer::map< uint256, CDeterministicMNCPtr > MnMap
CDeterministicMNCPtr GetValidMNByCollateral(const COutPoint &collateralOutpoint) const
void Unserialize(Stream &s)
Definition: uint256.h:102
CDeterministicMNCPtr GetMNPayee() const
static const int DISK_SNAPSHOT_PERIOD
const uint256 & GetBlockHash() const
std::unordered_map< uint256, CDeterministicMNList, StaticSaltedHasher > mnListsCache
CDeterministicMN(uint64_t _internalId)
CDeterministicMNState(deserialize_type, Stream &s)
iterator begin() const
Definition: map.hpp:165
void HandleQuorumCommitment(llmq::CFinalCommitment &qc, const CBlockIndex *pindexQuorum, CDeterministicMNList &mnList, bool debugLogs)
void UpdateUniqueProperty(const CDeterministicMNCPtr &dmn, const T &oldValue, const T &newValue)
iterator end() const
Definition: map.hpp:171
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:143
static const int LIST_DIFFS_CACHE_SIZE
void PoSeDecrease(const uint256 &proTxHash)
Decrease penalty score of MN by 1.
CDeterministicMN()=delete
void Finalize(unsigned char hash[OUTPUT_SIZE])
Definition: sha256.cpp:674
CKeyID keyIDOwner
Definition: providertx.h:30
uint32_t GetTotalRegisteredCount() const
void Serialize(Stream &s) const
std::string ToString() const
#define DMN_STATE_DIFF_ALL_FIELDS
void UpdateConfirmedHash(const uint256 &_proTxHash, const uint256 &_confirmedHash)
unsigned int size() const
Definition: uint256.h:77
void Unserialize(Stream &s)
CScript scriptPayout
Definition: providertx.h:34
CDeterministicMNState state
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:26
bool BuildNewListFromBlock(const CBlock &block, const CBlockIndex *pindexPrev, CValidationState &state, CDeterministicMNList &mnListRet, bool debugLogs)
bool IsProTxWithCollateral(const CTransactionRef &tx, uint32_t n)
Support for ADD_SERIALIZE_METHODS and READWRITE macro.
Definition: serialize.h:1159
void Set(const BLSObject &_obj)
Definition: bls.h:394
bool IsMNPoSeBanned(const uint256 &proTxHash) const
immer::map< uint256, std::pair< uint256, uint32_t > > MnUniquePropertyMap
void DeleteUniqueProperty(const CDeterministicMNCPtr &dmn, const T &oldValue)
Capture information about block/transaction validation.
Definition: validation.h:22
256-bit opaque blob.
Definition: uint256.h:123
size_type size() const
Definition: map.hpp:177
CBLSLazyPublicKey pubKeyOperator
std::map< uint256, CDeterministicMNStateCPtr > updatedMNs
CDeterministicMNCPtr GetMNByOperatorKey(const CBLSPublicKey &pubKey)
void SerializationOpBase(Stream &s, Operation ser_action)
void CleanupCache(int nHeight)
bool HasMN(const uint256 &proTxHash) const
CSimplifiedMNListDiff BuildSimplifiedDiff(const CDeterministicMNList &to) const
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:170
COutPoint collateralOutpoint
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:389
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:20
const CBlockIndex * tipIndex
void DecreasePoSePenalties(CDeterministicMNList &mnList)
CDeterministicMN(deserialize_type, Stream &s)
static int count
Definition: tests.c:45
bool HasUniqueProperty(const T &v) const
void Unserialize(Stream &s, char &a)
Definition: serialize.h:196
bool ProcessBlock(const CBlock &block, const CBlockIndex *pindex, CValidationState &state, bool fJustCheck)
MnInternalIdMap mnInternalIdMap
void SerReadWrite(Stream &s, const immer::map< K, T, Hash, Equal > &m, CSerActionSerialize ser_action)
std::vector< CDeterministicMNCPtr > addedMNs
immer::map< uint64_t, uint256 > MnInternalIdMap
void ToJson(UniValue &obj) const
CDeterministicMNList ApplyDiff(const CBlockIndex *pindex, const CDeterministicMNListDiff &diff) const
bool UndoBlock(const CBlock &block, const CBlockIndex *pindex)
T * NCONST_PTR(const T *val)
Used to acquire a non-const pointer "this" to generate bodies of const serialization operations from ...
Definition: serialize.h:60
CDeterministicMNList GetListForBlock(const CBlockIndex *pindex)
void SetHeight(int _height)
std::set< uint64_t > removedMns
std::map< uint256, CDeterministicMNCPtr > addedMNs
int CalcPenalty(int percent) const
Returns a the given percentage from the max penalty for this MN list.
bool HasValidMNByCollateral(const COutPoint &collateralOutpoint) const
std::vector< std::pair< arith_uint256, CDeterministicMNCPtr > > CalculateScores(const uint256 &modifier) const
A hasher class for SHA-256.
Definition: sha256.h:13
CDeterministicMNCPtr GetMNByCollateral(const COutPoint &collateralOutpoint) const
std::map< uint64_t, CDeterministicMNStateDiff > updatedMNs
CBLSPublicKey pubKeyOperator
Definition: providertx.h:31
void RemoveMN(const uint256 &proTxHash)
std::unordered_map< uint256, CDeterministicMNListDiff, StaticSaltedHasher > mnListDiffsCache
CDeterministicMNState(const CProRegTx &proTx)
Wrapped mutex: supports recursive locking, but no waiting TODO: We should move away from using the re...
Definition: sync.h:94
map erase(const K &k) const
Definition: map.hpp:286
CService addr
Definition: providertx.h:29
bool HasMNByCollateral(const COutPoint &collateralOutpoint) const
CDeterministicMNCPtr GetMNByService(const CService &service) const
Released under the MIT license