Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

governance-object.cpp
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 
6 #include <core_io.h>
10 #include <governance/governance.h>
13 #include <messagesigner.h>
14 #include <spork.h>
15 #include <util.h>
16 #include <validation.h>
17 
18 #include <string>
19 #include <univalue.h>
20 
22  cs(),
23  nObjectType(GOVERNANCE_OBJECT_UNKNOWN),
24  nHashParent(),
25  nRevision(0),
26  nTime(0),
27  nDeletionTime(0),
28  nCollateralHash(),
29  vchData(),
30  masternodeOutpoint(),
31  vchSig(),
32  fCachedLocalValidity(false),
33  strLocalValidityError(),
34  fCachedFunding(false),
35  fCachedValid(true),
36  fCachedDelete(false),
37  fCachedEndorsed(false),
38  fDirtyCache(true),
39  fExpired(false),
40  fUnparsable(false),
41  mapCurrentMNVotes(),
42  fileVotes()
43 {
44  // PARSE JSON DATA STORAGE (VCHDATA)
45  LoadData();
46 }
47 
48 CGovernanceObject::CGovernanceObject(const uint256& nHashParentIn, int nRevisionIn, int64_t nTimeIn, const uint256& nCollateralHashIn, const std::string& strDataHexIn) :
49  cs(),
50  nObjectType(GOVERNANCE_OBJECT_UNKNOWN),
51  nHashParent(nHashParentIn),
52  nRevision(nRevisionIn),
53  nTime(nTimeIn),
54  nDeletionTime(0),
55  nCollateralHash(nCollateralHashIn),
56  vchData(ParseHex(strDataHexIn)),
57  masternodeOutpoint(),
58  vchSig(),
59  fCachedLocalValidity(false),
60  strLocalValidityError(),
61  fCachedFunding(false),
62  fCachedValid(true),
63  fCachedDelete(false),
64  fCachedEndorsed(false),
65  fDirtyCache(true),
66  fExpired(false),
67  fUnparsable(false),
68  mapCurrentMNVotes(),
69  fileVotes()
70 {
71  // PARSE JSON DATA STORAGE (VCHDATA)
72  LoadData();
73 }
74 
76  cs(),
77  nObjectType(other.nObjectType),
78  nHashParent(other.nHashParent),
79  nRevision(other.nRevision),
80  nTime(other.nTime),
81  nDeletionTime(other.nDeletionTime),
82  nCollateralHash(other.nCollateralHash),
83  vchData(other.vchData),
84  masternodeOutpoint(other.masternodeOutpoint),
85  vchSig(other.vchSig),
86  fCachedLocalValidity(other.fCachedLocalValidity),
87  strLocalValidityError(other.strLocalValidityError),
88  fCachedFunding(other.fCachedFunding),
89  fCachedValid(other.fCachedValid),
90  fCachedDelete(other.fCachedDelete),
91  fCachedEndorsed(other.fCachedEndorsed),
92  fDirtyCache(other.fDirtyCache),
93  fExpired(other.fExpired),
94  fUnparsable(other.fUnparsable),
95  mapCurrentMNVotes(other.mapCurrentMNVotes),
96  fileVotes(other.fileVotes)
97 {
98 }
99 
101  const CGovernanceVote& vote,
102  CGovernanceException& exception,
103  CConnman& connman)
104 {
105  LOCK(cs);
106 
107  // do not process already known valid votes twice
108  if (fileVotes.HasVote(vote.GetHash())) {
109  // nothing to do here, not an error
110  std::ostringstream ostr;
111  ostr << "CGovernanceObject::ProcessVote -- Already known valid vote";
112  LogPrint(BCLog::GOBJECT, "%s\n", ostr.str());
113  exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_NONE);
114  return false;
115  }
116 
117  auto mnList = deterministicMNManager->GetListAtChainTip();
118  auto dmn = mnList.GetMNByCollateral(vote.GetMasternodeOutpoint());
119 
120  if (!dmn) {
121  std::ostringstream ostr;
122  ostr << "CGovernanceObject::ProcessVote -- Masternode " << vote.GetMasternodeOutpoint().ToStringShort() << " not found";
123  exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_PERMANENT_ERROR, 20);
124  return false;
125  }
126 
127  vote_m_it it = mapCurrentMNVotes.emplace(vote_m_t::value_type(vote.GetMasternodeOutpoint(), vote_rec_t())).first;
128  vote_rec_t& voteRecordRef = it->second;
129  vote_signal_enum_t eSignal = vote.GetSignal();
130  if (eSignal == VOTE_SIGNAL_NONE) {
131  std::ostringstream ostr;
132  ostr << "CGovernanceObject::ProcessVote -- Vote signal: none";
133  LogPrint(BCLog::GOBJECT, "%s\n", ostr.str());
134  exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_WARNING);
135  return false;
136  }
137  if (eSignal > MAX_SUPPORTED_VOTE_SIGNAL) {
138  std::ostringstream ostr;
139  ostr << "CGovernanceObject::ProcessVote -- Unsupported vote signal: " << CGovernanceVoting::ConvertSignalToString(vote.GetSignal());
140  LogPrintf("%s\n", ostr.str());
141  exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_PERMANENT_ERROR, 20);
142  return false;
143  }
144  vote_instance_m_it it2 = voteRecordRef.mapInstances.emplace(vote_instance_m_t::value_type(int(eSignal), vote_instance_t())).first;
145  vote_instance_t& voteInstanceRef = it2->second;
146 
147  // Reject obsolete votes
148  if (vote.GetTimestamp() < voteInstanceRef.nCreationTime) {
149  std::ostringstream ostr;
150  ostr << "CGovernanceObject::ProcessVote -- Obsolete vote";
151  LogPrint(BCLog::GOBJECT, "%s\n", ostr.str());
152  exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_NONE);
153  return false;
154  } else if (vote.GetTimestamp() == voteInstanceRef.nCreationTime) {
155  // Someone is doing something fishy, there can be no two votes from the same masternode
156  // with the same timestamp for the same object and signal and yet different hash/outcome.
157  std::ostringstream ostr;
158  ostr << "CGovernanceObject::ProcessVote -- Invalid vote, same timestamp for the different outcome";
159  if (vote.GetOutcome() < voteInstanceRef.eOutcome) {
160  // This is an arbitrary comparison, we have to agree on some way
161  // to pick the "winning" vote.
162  ostr << ", rejected";
163  LogPrint(BCLog::GOBJECT, "%s\n", ostr.str());
164  exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_NONE);
165  return false;
166  }
167  ostr << ", accepted";
168  LogPrint(BCLog::GOBJECT, "%s\n", ostr.str());
169  }
170 
171  int64_t nNow = GetAdjustedTime();
172  int64_t nVoteTimeUpdate = voteInstanceRef.nTime;
174  int64_t nTimeDelta = nNow - voteInstanceRef.nTime;
175  if (nTimeDelta < GOVERNANCE_UPDATE_MIN) {
176  std::ostringstream ostr;
177  ostr << "CGovernanceObject::ProcessVote -- Masternode voting too often"
178  << ", MN outpoint = " << vote.GetMasternodeOutpoint().ToStringShort()
179  << ", governance object hash = " << GetHash().ToString()
180  << ", time delta = " << nTimeDelta;
181  LogPrint(BCLog::GOBJECT, "%s\n", ostr.str());
183  return false;
184  }
185  nVoteTimeUpdate = nNow;
186  }
187 
188  bool onlyVotingKeyAllowed = nObjectType == GOVERNANCE_OBJECT_PROPOSAL && vote.GetSignal() == VOTE_SIGNAL_FUNDING;
189 
190  // Finally check that the vote is actually valid (done last because of cost of signature verification)
191  if (!vote.IsValid(onlyVotingKeyAllowed)) {
192  std::ostringstream ostr;
193  ostr << "CGovernanceObject::ProcessVote -- Invalid vote"
194  << ", MN outpoint = " << vote.GetMasternodeOutpoint().ToStringShort()
195  << ", governance object hash = " << GetHash().ToString()
196  << ", vote hash = " << vote.GetHash().ToString();
197  LogPrintf("%s\n", ostr.str());
198  exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_PERMANENT_ERROR, 20);
200  return false;
201  }
202 
203  if (!mmetaman.AddGovernanceVote(dmn->proTxHash, vote.GetParentHash())) {
204  std::ostringstream ostr;
205  ostr << "CGovernanceObject::ProcessVote -- Unable to add governance vote"
206  << ", MN outpoint = " << vote.GetMasternodeOutpoint().ToStringShort()
207  << ", governance object hash = " << GetHash().ToString();
208  LogPrint(BCLog::GOBJECT, "%s\n", ostr.str());
210  return false;
211  }
212 
213  voteInstanceRef = vote_instance_t(vote.GetOutcome(), nVoteTimeUpdate, vote.GetTimestamp());
214  fileVotes.AddVote(vote);
215  fDirtyCache = true;
216  return true;
217 }
218 
220 {
221  LOCK(cs);
222 
223  auto mnList = deterministicMNManager->GetListAtChainTip();
224 
225  vote_m_it it = mapCurrentMNVotes.begin();
226  while (it != mapCurrentMNVotes.end()) {
227  if (!mnList.HasMNByCollateral(it->first)) {
229  mapCurrentMNVotes.erase(it++);
230  fDirtyCache = true;
231  } else {
232  ++it;
233  }
234  }
235 }
236 
237 std::set<uint256> CGovernanceObject::RemoveInvalidVotes(const COutPoint& mnOutpoint)
238 {
239  LOCK(cs);
240 
241  auto it = mapCurrentMNVotes.find(mnOutpoint);
242  if (it == mapCurrentMNVotes.end()) {
243  // don't even try as we don't have any votes from this MN
244  return {};
245  }
246 
247  auto removedVotes = fileVotes.RemoveInvalidVotes(mnOutpoint, nObjectType == GOVERNANCE_OBJECT_PROPOSAL);
248  if (removedVotes.empty()) {
249  return {};
250  }
251 
252  auto nParentHash = GetHash();
253  for (auto jt = it->second.mapInstances.begin(); jt != it->second.mapInstances.end(); ) {
254  CGovernanceVote tmpVote(mnOutpoint, nParentHash, (vote_signal_enum_t)jt->first, jt->second.eOutcome);
255  tmpVote.SetTime(jt->second.nCreationTime);
256  if (removedVotes.count(tmpVote.GetHash())) {
257  jt = it->second.mapInstances.erase(jt);
258  } else {
259  ++jt;
260  }
261  }
262  if (it->second.mapInstances.empty()) {
263  mapCurrentMNVotes.erase(it);
264  }
265 
266  if (!removedVotes.empty()) {
267  std::string removedStr;
268  for (auto& h : removedVotes) {
269  removedStr += strprintf(" %s\n", h.ToString());
270  }
271  LogPrintf("CGovernanceObject::%s -- Removed %d invalid votes for %s from MN %s:\n%s", __func__, removedVotes.size(), nParentHash.ToString(), mnOutpoint.ToString(), removedStr); /* Continued */
272  fDirtyCache = true;
273  }
274 
275  return removedVotes;
276 }
277 
279 {
280  // Note: doesn't match serialization
281 
282  // CREATE HASH OF ALL IMPORTANT PIECES OF DATA
283 
285  ss << nHashParent;
286  ss << nRevision;
287  ss << nTime;
288  ss << GetDataAsHexString();
289  ss << masternodeOutpoint << uint8_t{} << 0xffffffff; // adding dummy values here to match old hashing
290  ss << vchSig;
291  // fee_tx is left out on purpose
292 
293  return ss.GetHash();
294 }
295 
297 {
298  return SerializeHash(*this);
299 }
300 
302 {
303  masternodeOutpoint = outpoint;
304 }
305 
307 {
308  CBLSSignature sig = key.Sign(GetSignatureHash());
309  if (!key.IsValid()) {
310  return false;
311  }
312  sig.GetBuf(vchSig);
313  return true;
314 }
315 
317 {
318  CBLSSignature sig;
319  sig.SetBuf(vchSig);
320  if (!sig.VerifyInsecure(pubKey, GetSignatureHash())) {
321  LogPrintf("CGovernanceObject::CheckSignature -- VerifyInsecure() failed\n");
322  return false;
323  }
324  return true;
325 }
326 
333 {
335  if (vchData.empty()) {
336  return obj;
337  }
338 
339  UniValue objResult(UniValue::VOBJ);
340  GetData(objResult);
341 
342  if (objResult.isObject()) {
343  obj = objResult;
344  } else {
345  std::vector<UniValue> arr1 = objResult.getValues();
346  std::vector<UniValue> arr2 = arr1.at(0).getValues();
347  obj = arr2.at(1);
348  }
349 
350  return obj;
351 }
352 
362 {
363  if (vchData.empty()) {
364  return;
365  }
366 
367  try {
368  // ATTEMPT TO LOAD JSON STRING FROM VCHDATA
369  UniValue objResult(UniValue::VOBJ);
370  GetData(objResult);
371  LogPrint(BCLog::GOBJECT, "CGovernanceObject::LoadData -- GetDataAsPlainString = %s\n", GetDataAsPlainString());
372  UniValue obj = GetJSONObject();
373  nObjectType = obj["type"].get_int();
374  } catch (std::exception& e) {
375  fUnparsable = true;
376  std::ostringstream ostr;
377  ostr << "CGovernanceObject::LoadData Error parsing JSON"
378  << ", e.what() = " << e.what();
379  LogPrintf("%s\n", ostr.str());
380  return;
381  } catch (...) {
382  fUnparsable = true;
383  std::ostringstream ostr;
384  ostr << "CGovernanceObject::LoadData Unknown Error parsing JSON";
385  LogPrintf("%s\n", ostr.str());
386  return;
387  }
388 }
389 
399 {
401  std::string s = GetDataAsPlainString();
402  o.read(s);
403  objResult = o;
404 }
405 
413 {
414  return HexStr(vchData);
415 }
416 
418 {
419  return std::string(vchData.begin(), vchData.end());
420 }
421 
423 {
424  LOCK(cs_main);
425  // THIS DOES NOT CHECK COLLATERAL, THIS IS CHECKED UPON ORIGINAL ARRIVAL
427 };
428 
429 
430 bool CGovernanceObject::IsValidLocally(std::string& strError, bool fCheckCollateral) const
431 {
432  bool fMissingConfirmations = false;
433 
434  return IsValidLocally(strError, fMissingConfirmations, fCheckCollateral);
435 }
436 
437 bool CGovernanceObject::IsValidLocally(std::string& strError, bool& fMissingConfirmations, bool fCheckCollateral) const
438 {
439  fMissingConfirmations = false;
440 
441  if (fUnparsable) {
442  strError = "Object data unparseable";
443  return false;
444  }
445 
446  switch (nObjectType) {
448  CProposalValidator validator(GetDataAsHexString(), true);
449  // Note: It's ok to have expired proposals
450  // they are going to be cleared by CGovernanceManager::UpdateCachesAndClean()
451  // TODO: should they be tagged as "expired" to skip vote downloading?
452  if (!validator.Validate(false)) {
453  strError = strprintf("Invalid proposal data, error messages: %s", validator.GetErrorMessages());
454  return false;
455  }
456  if (fCheckCollateral && !IsCollateralValid(strError, fMissingConfirmations)) {
457  strError = "Invalid proposal collateral";
458  return false;
459  }
460  return true;
461  }
463  if (!fCheckCollateral) {
464  // nothing else we can check here (yet?)
465  return true;
466  }
467 
468  auto mnList = deterministicMNManager->GetListAtChainTip();
469 
470  std::string strOutpoint = masternodeOutpoint.ToStringShort();
471  auto dmn = mnList.GetMNByCollateral(masternodeOutpoint);
472  if (!dmn) {
473  strError = "Failed to find Masternode by UTXO, missing masternode=" + strOutpoint;
474  return false;
475  }
476 
477  // Check that we have a valid MN signature
478  if (!CheckSignature(dmn->pdmnState->pubKeyOperator.Get())) {
479  strError = "Invalid masternode signature for: " + strOutpoint + ", pubkey = " + dmn->pdmnState->pubKeyOperator.Get().ToString();
480  return false;
481  }
482 
483  return true;
484  }
485  default: {
486  strError = strprintf("Invalid object type %d", nObjectType);
487  return false;
488  }
489  }
490 }
491 
493 {
494  // Only 1 type has a fee for the moment but switch statement allows for future object types
495  switch (nObjectType) {
499  return 0;
500  default:
501  return MAX_MONEY;
502  }
503 }
504 
505 bool CGovernanceObject::IsCollateralValid(std::string& strError, bool& fMissingConfirmations) const
506 {
507  strError = "";
508  fMissingConfirmations = false;
509  CAmount nMinFee = GetMinCollateralFee();
510  uint256 nExpectedHash = GetHash();
511 
512  CTransactionRef txCollateral;
513  uint256 nBlockHash;
514 
515  // RETRIEVE TRANSACTION IN QUESTION
516 
517  if (!GetTransaction(nCollateralHash, txCollateral, Params().GetConsensus(), nBlockHash, true)) {
518  strError = strprintf("Can't find collateral tx %s", nCollateralHash.ToString());
519  LogPrintf("CGovernanceObject::IsCollateralValid -- %s\n", strError);
520  return false;
521  }
522 
523  if (nBlockHash == uint256()) {
524  strError = strprintf("Collateral tx %s is not mined yet", txCollateral->ToString());
525  LogPrintf("CGovernanceObject::IsCollateralValid -- %s\n", strError);
526  return false;
527  }
528 
529  if (txCollateral->vout.size() < 1) {
530  strError = strprintf("tx vout size less than 1 | %d", txCollateral->vout.size());
531  LogPrintf("CGovernanceObject::IsCollateralValid -- %s\n", strError);
532  return false;
533  }
534 
535  // LOOK FOR SPECIALIZED GOVERNANCE SCRIPT (PROOF OF BURN)
536 
537  CScript findScript;
538  findScript << OP_RETURN << ToByteVector(nExpectedHash);
539 
540  LogPrint(BCLog::GOBJECT, "CGovernanceObject::IsCollateralValid -- txCollateral->vout.size() = %s, findScript = %s, nMinFee = %lld\n",
541  txCollateral->vout.size(), ScriptToAsmStr(findScript, false), nMinFee);
542 
543  bool foundOpReturn = false;
544  for (const auto& output : txCollateral->vout) {
545  LogPrint(BCLog::GOBJECT, "CGovernanceObject::IsCollateralValid -- txout = %s, output.nValue = %lld, output.scriptPubKey = %s\n",
546  output.ToString(), output.nValue, ScriptToAsmStr(output.scriptPubKey, false));
547  if (!output.scriptPubKey.IsPayToPublicKeyHash() && !output.scriptPubKey.IsUnspendable()) {
548  strError = strprintf("Invalid Script %s", txCollateral->ToString());
549  LogPrintf("CGovernanceObject::IsCollateralValid -- %s\n", strError);
550  return false;
551  }
552  if (output.scriptPubKey == findScript && output.nValue >= nMinFee) {
553  foundOpReturn = true;
554  }
555  }
556 
557  if (!foundOpReturn) {
558  strError = strprintf("Couldn't find opReturn %s in %s", nExpectedHash.ToString(), txCollateral->ToString());
559  LogPrintf("CGovernanceObject::IsCollateralValid -- %s\n", strError);
560  return false;
561  }
562 
563  // GET CONFIRMATIONS FOR TRANSACTION
564 
566  int nConfirmationsIn = 0;
567  if (nBlockHash != uint256()) {
568  BlockMap::iterator mi = mapBlockIndex.find(nBlockHash);
569  if (mi != mapBlockIndex.end() && (*mi).second) {
570  CBlockIndex* pindex = (*mi).second;
571  if (chainActive.Contains(pindex)) {
572  nConfirmationsIn += chainActive.Height() - pindex->nHeight + 1;
573  }
574  }
575  }
576 
577  if ((nConfirmationsIn < GOVERNANCE_FEE_CONFIRMATIONS)) {
578  strError = strprintf("Collateral requires at least %d confirmations to be relayed throughout the network (it has only %d)", GOVERNANCE_FEE_CONFIRMATIONS, nConfirmationsIn);
579  if (nConfirmationsIn >= GOVERNANCE_MIN_RELAY_FEE_CONFIRMATIONS) {
580  fMissingConfirmations = true;
581  strError += ", pre-accepted -- waiting for required confirmations";
582  } else {
583  strError += ", rejected -- try again later";
584  }
585  LogPrintf("CGovernanceObject::IsCollateralValid -- %s\n", strError);
586 
587  return false;
588  }
589 
590  strError = "valid";
591  return true;
592 }
593 
595 {
596  LOCK(cs);
597 
598  int nCount = 0;
599  for (const auto& votepair : mapCurrentMNVotes) {
600  const vote_rec_t& recVote = votepair.second;
601  vote_instance_m_cit it2 = recVote.mapInstances.find(eVoteSignalIn);
602  if (it2 != recVote.mapInstances.end() && it2->second.eOutcome == eVoteOutcomeIn) {
603  ++nCount;
604  }
605  }
606  return nCount;
607 }
608 
614 {
615  return GetYesCount(eVoteSignalIn) - GetNoCount(eVoteSignalIn);
616 }
617 
619 {
620  return GetNoCount(eVoteSignalIn) - GetYesCount(eVoteSignalIn);
621 }
622 
624 {
625  return CountMatchingVotes(eVoteSignalIn, VOTE_OUTCOME_YES);
626 }
627 
629 {
630  return CountMatchingVotes(eVoteSignalIn, VOTE_OUTCOME_NO);
631 }
632 
634 {
635  return CountMatchingVotes(eVoteSignalIn, VOTE_OUTCOME_ABSTAIN);
636 }
637 
638 bool CGovernanceObject::GetCurrentMNVotes(const COutPoint& mnCollateralOutpoint, vote_rec_t& voteRecord) const
639 {
640  LOCK(cs);
641 
642  vote_m_cit it = mapCurrentMNVotes.find(mnCollateralOutpoint);
643  if (it == mapCurrentMNVotes.end()) {
644  return false;
645  }
646  voteRecord = it->second;
647  return true;
648 }
649 
651 {
652  // Do not relay until fully synced
653  if (!masternodeSync.IsSynced()) {
654  LogPrint(BCLog::GOBJECT, "CGovernanceObject::Relay -- won't relay until fully synced\n");
655  return;
656  }
657 
660 }
661 
663 {
664  // CALCULATE MINIMUM SUPPORT LEVELS REQUIRED
665 
666  int nMnCount = (int)deterministicMNManager->GetListAtChainTip().GetValidMNsCount();
667  if (nMnCount == 0) return;
668 
669  // CALCULATE THE MINUMUM VOTE COUNT REQUIRED FOR FULL SIGNAL
670 
671  int nAbsVoteReq = std::max(Params().GetConsensus().nGovernanceMinQuorum, nMnCount / 10);
672  int nAbsDeleteReq = std::max(Params().GetConsensus().nGovernanceMinQuorum, (2 * nMnCount) / 3);
673 
674  // SET SENTINEL FLAGS TO FALSE
675 
676  fCachedFunding = false;
677  fCachedValid = true; //default to valid
678  fCachedEndorsed = false;
679  fDirtyCache = false;
680 
681  // SET SENTINEL FLAGS TO TRUE IF MIMIMUM SUPPORT LEVELS ARE REACHED
682  // ARE ANY OF THESE FLAGS CURRENTLY ACTIVATED?
683 
684  if (GetAbsoluteYesCount(VOTE_SIGNAL_FUNDING) >= nAbsVoteReq) fCachedFunding = true;
685  if ((GetAbsoluteYesCount(VOTE_SIGNAL_DELETE) >= nAbsDeleteReq) && !fCachedDelete) {
686  fCachedDelete = true;
687  if (nDeletionTime == 0) {
689  }
690  }
691  if (GetAbsoluteYesCount(VOTE_SIGNAL_ENDORSED) >= nAbsVoteReq) fCachedEndorsed = true;
692 
693  if (GetAbsoluteNoCount(VOTE_SIGNAL_VALID) >= nAbsVoteReq) fCachedValid = false;
694 }
bool IsCollateralValid(std::string &strError, bool &fMissingConfirmations) const
Check the collateral transaction for the budget proposal/finalized budget.
bool HasVote(const uint256 &nHash) const
Return true if the vote with this hash is currently cached in memory.
bool isObject() const
Definition: univalue.h:85
const uint256 & GetParentHash() const
CMasternodeSync masternodeSync
uint256 GetHash() const
GetHash()
std::string GetDataAsHexString() const
GetData - As
const std::vector< UniValue > & getValues() const
bool GetTransaction(const uint256 &hash, CTransactionRef &txOut, const Consensus::Params &consensusParams, uint256 &hashBlock, bool fAllowSlow, CBlockIndex *blockIndex)
Return transaction in txOut, and if it was found inside a block, its hash is placed in hashBlock...
Definition: validation.cpp:950
Governance Object.
void LoadData()
LoadData
static const int64_t GOVERNANCE_FEE_CONFIRMATIONS
bool read(const char *raw, size_t len)
static const CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
Definition: amount.h:26
#define strprintf
Definition: tinyformat.h:1066
vote_instance_m_t mapInstances
void SetBuf(const void *buf, size_t size)
Definition: bls.h:99
int GetAbstainCount(vote_signal_enum_t eVoteSignalIn) const
inv message data
Definition: protocol.h:429
BlockMap & mapBlockIndex
Definition: validation.cpp:215
static const int MIN_GOVERNANCE_PEER_PROTO_VERSION
uint256 GetHash() const
bool CheckSignature(const CBLSPublicKey &pubKey) const
static const CAmount GOVERNANCE_PROPOSAL_FEE_TX
Default value, normally indicates no exception condition occurred.
int Height() const
Return the maximal height in the chain.
Definition: chain.h:484
CCriticalSection cs_main
Definition: validation.cpp:213
vote_outcome_enum_t GetOutcome() const
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
std::string strLocalValidityError
void SetMasternodeOutpoint(const COutPoint &outpoint)
static const int64_t GOVERNANCE_MIN_RELAY_FEE_CONFIRMATIONS
static const int GOVERNANCE_OBJECT_PROPOSAL
bool VerifyInsecure(const CBLSPublicKey &pubKey, const uint256 &hash) const
Definition: bls.cpp:335
false true true true
Definition: bls_dkg.cpp:176
std::string ToString() const
Definition: transaction.cpp:12
void GetData(UniValue &objResult)
GetData - Example usage:
bool fCachedLocalValidity
is valid by blockchain
uint256 nCollateralHash
fee-tx
vote_outcome_enum_t eOutcome
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:345
std::unique_ptr< CDeterministicMNManager > deterministicMNManager
Requested operation cannot be performed.
bool IsValid() const
const std::string & GetErrorMessages()
bool fCachedFunding
true == minimum network support has been reached for this object to be funded (doesn&#39;t mean it will f...
const COutPoint & GetMasternodeOutpoint() const
CMasternodeMetaMan mmetaman
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
UniValue GetJSONObject()
Return the actual object from the vchData JSON structure.
void GetBuf(void *buf, size_t size) const
Definition: bls.h:122
CGovernanceManager governance
Definition: governance.cpp:23
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
false
Definition: bls_dkg.cpp:168
bool ProcessVote(CNode *pfrom, const CGovernanceVote &vote, CGovernanceException &exception, CConnman &connman)
COutPoint masternodeOutpoint
Masternode info for signed objects.
#define LogPrintf(...)
Definition: util.h:203
int GetNoCount(vote_signal_enum_t eVoteSignalIn) const
int64_t nTime
time this object was created
Requested operation not currently possible, may resubmit later.
std::string ScriptToAsmStr(const CScript &script, const bool fAttemptSighashDecode=false)
Create the assembly string representation of a CScript object.
Definition: core_write.cpp:86
std::set< uint256 > RemoveInvalidVotes(const COutPoint &mnOutpoint)
void RemoveVotesFromMasternode(const COutPoint &outpointMasternode)
std::vector< unsigned char > vchSig
int nRevision
object revision in the system
#define LOCK(cs)
Definition: sync.h:178
bool Sign(const CBLSSecretKey &key)
bool fCachedValid
true == minimum network has been reached flagging this object as a valid and understood governance ob...
CGovernanceObjectVoteFile fileVotes
bool Validate(bool fCheckExpiration=true)
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
Definition: chain.h:471
uint256 nHashParent
parent object, 0 is root
void Relay(CConnman &connman)
static const int GOVERNANCE_OBJECT_TRIGGER
int GetAbsoluteNoCount(vote_signal_enum_t eVoteSignalIn) const
int64_t GetTimestamp() const
vote_signal_enum_t GetSignal() const
A class which encapsulates information about a governance exception condition.
Definition: net.h:136
int get_int() const
std::string ToString() const
Definition: uint256.cpp:62
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:26
uint256 GetSignatureHash() const
void SetTime(int64_t nTimeIn)
std::vector< unsigned char > vchData
Data field - can be used for anything.
#define LogPrint(category,...)
Definition: util.h:214
uint256 GetHash()
Definition: hash.h:203
bool IsValidLocally(std::string &strError, bool fCheckCollateral) const
256-bit opaque blob.
Definition: uint256.h:123
int nObjectType
Object typecode.
std::string GetDataAsPlainString() const
void AddVote(const CGovernanceVote &vote)
Add a vote to the file.
int64_t nDeletionTime
time this object was marked for deletion
void ClearMasternodeVotes()
Called when MN&#39;s which have voted on this object have been removed.
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:170
const CChainParams & Params()
Return the currently selected parameters.
int GetAbsoluteYesCount(vote_signal_enum_t eVoteSignalIn) const
Get specific vote counts for each outcome (funding, validity, etc)
static const int64_t GOVERNANCE_UPDATE_MIN
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:389
Unusual condition requiring no caller action.
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:14
bool fUnparsable
Failed to parse object data.
vote_outcome_enum_t
vote_m_t::iterator vote_m_it
int64_t GetAdjustedTime()
Definition: timedata.cpp:35
CAmount GetMinCollateralFee() const
int GetYesCount(vote_signal_enum_t eVoteSignalIn) const
vote_signal_enum_t
void RelayInv(CInv &inv, const int minProtoVersion=MIN_PEER_PROTO_VERSION, bool fAllowMasternodeConnections=false)
Definition: net.cpp:3482
static const int GOVERNANCE_OBJECT_UNKNOWN
A writer stream (for serialization) that computes a 256-bit hash.
Definition: hash.h:184
int CountMatchingVotes(vote_signal_enum_t eVoteSignalIn, vote_outcome_enum_t eVoteOutcomeIn) const
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:183
Information about a peer.
Definition: net.h:800
bool AreRateChecksEnabled() const
Definition: governance.h:392
static std::string ConvertSignalToString(vote_signal_enum_t nSignal)
bool fCachedEndorsed
true == minimum network support has been reached flagging this object as endorsed by an elected repre...
CChain & chainActive
The currently-connected chain of blocks (protected by cs_main).
Definition: validation.cpp:217
AssertLockHeld(g_cs_orphans)
std::set< uint256 > RemoveInvalidVotes(const COutPoint &outpointMasternode, bool fProposal)
vote_m_t::const_iterator vote_m_cit
static const int MAX_SUPPORTED_VOTE_SIGNAL
bool AddGovernanceVote(const uint256 &proTxHash, const uint256 &nGovernanceObjectHash)
bool IsValid() const
Definition: bls.h:94
bool fDirtyCache
object was updated and cached values should be updated soon
void AddInvalidVote(const CGovernanceVote &vote)
Definition: governance.h:406
bool fCachedDelete
true == minimum network support has been reached saying this object should be deleted from the system...
CCriticalSection cs
critical section to protect the inner data structures
bool GetCurrentMNVotes(const COutPoint &mnCollateralOutpoint, vote_rec_t &voteRecord) const
vote_instance_m_t::const_iterator vote_instance_m_cit
vote_instance_m_t::iterator vote_instance_m_it
CBLSSignature Sign(const uint256 &hash) const
Definition: bls.cpp:160
std::vector< unsigned char > ToByteVector(const T &in)
Definition: script.h:42
std::vector< unsigned char > ParseHex(const char *psz)
std::string ToStringShort() const
Definition: transaction.cpp:17
Released under the MIT license