PRCYCoin  2.0.0.7rc1
P2P Digital Currency
masternode.cpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2015 The Dash developers
2 // Copyright (c) 2015-2018 The PIVX developers
3 // Copyright (c) 2018-2020 The DAPS Project developers
4 // Distributed under the MIT/X11 software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #include "masternode.h"
8 
9 #include "addrman.h"
10 #include "masternode-payments.h"
11 #include "masternode-sync.h"
12 #include "masternodeman.h"
13 #include "messagesigner.h"
14 #include "netbase.h"
15 #include "sync.h"
16 #include "util.h"
17 #include "streams.h"
18 #include "wallet/wallet.h"
19 
20 // keep track of the scanning errors I've seen
21 std::map<uint256, int> mapSeenMasternodeScanningErrors;
22 // cache block hashes as we calculate them
23 std::map<int64_t, uint256> mapCacheBlockHashes;
24 
25 //Get the last hash that matches the modulus given. Processed in reverse order
26 bool GetBlockHash(uint256& hash, int nBlockHeight)
27 {
28  int tipHeight;
29  const CBlockIndex* tipIndex;
30  {
31  LOCK(cs_main);
32  CBlockIndex *pindex = chainActive.Tip();
33  if (!pindex) return false;
34  tipHeight = pindex->nHeight;
35  tipIndex = mapBlockIndex[pindex->GetBlockHash()];
36  }
37 
38  if (nBlockHeight == 0)
39  nBlockHeight = tipHeight;
40 
41  if (mapCacheBlockHashes.count(nBlockHeight)) {
42  hash = mapCacheBlockHashes[nBlockHeight];
43  return true;
44  }
45 
46  const CBlockIndex* BlockLastSolved = tipIndex;
47  const CBlockIndex* BlockReading = tipIndex;
48 
49  if (BlockLastSolved == nullptr || BlockLastSolved->nHeight == 0 || tipHeight + 1 < nBlockHeight) return false;
50 
51  int nBlocksAgo = 0;
52  if (nBlockHeight > 0) nBlocksAgo = (tipHeight + 1) - nBlockHeight;
53  assert(nBlocksAgo >= 0);
54 
55  int n = 0;
56  for (unsigned int i = 1; BlockReading && BlockReading->nHeight > 0; i++) {
57  if (n >= nBlocksAgo) {
58  hash = BlockReading->GetBlockHash();
59  mapCacheBlockHashes[nBlockHeight] = hash;
60  return true;
61  }
62  n++;
63 
64  if (BlockReading->pprev == NULL) {
65  assert(BlockReading);
66  break;
67  }
68  BlockReading = BlockReading->pprev;
69  }
70 
71  return false;
72 }
73 
75 {
76  LOCK(cs);
77  vin = CTxIn();
78  addr = CService();
81  sig = std::vector<unsigned char>();
85  cacheInputAge = 0;
87  unitTest = false;
88  allowFreeTx = true;
90  protocolVersion = PROTOCOL_VERSION;
91  nLastDsq = 0;
94  lastTimeChecked = 0;
95 }
96 
98 {
99  LOCK(cs);
100  vin = other.vin;
101  addr = other.addr;
104  sig = other.sig;
105  activeState = other.activeState;
106  sigTime = other.sigTime;
107  lastPing = other.lastPing;
110  unitTest = other.unitTest;
111  allowFreeTx = other.allowFreeTx;
114  nLastDsq = other.nLastDsq;
117  lastTimeChecked = 0;
118 }
119 
121 {
122  LOCK(cs);
123  vin = mnb.vin;
124  addr = mnb.addr;
127  sig = mnb.sig;
129  sigTime = mnb.sigTime;
130  lastPing = mnb.lastPing;
131  cacheInputAge = 0;
132  cacheInputAgeBlock = 0;
133  unitTest = false;
134  allowFreeTx = true;
137  nLastDsq = mnb.nLastDsq;
140  lastTimeChecked = 0;
141 }
142 
143 //
144 // When a new masternode broadcast is sent, update our information
145 //
147 {
148  if (mnb.sigTime > sigTime) {
151  sigTime = mnb.sigTime;
152  sig = mnb.sig;
154  addr = mnb.addr;
155  lastTimeChecked = 0;
156  int nDoS = 0;
157  if (mnb.lastPing == CMasternodePing() || (mnb.lastPing != CMasternodePing() && mnb.lastPing.CheckAndUpdate(nDoS, false))) {
158  lastPing = mnb.lastPing;
159  mnodeman.mapSeenMasternodePing.insert(std::make_pair(lastPing.GetHash(), lastPing));
160  }
161  return true;
162  }
163  return false;
164 }
165 
166 //
167 // Deterministically calculate a given "score" for a Masternode depending on how close it's hash is to
168 // the proof of work for that block. The further away they are the better, the furthest will win the election
169 // and get paid this block
170 //
171 uint256 CMasternode::CalculateScore(int mod, int64_t nBlockHeight)
172 {
173  {
174  LOCK(cs_main);
175  if (chainActive.Tip() == nullptr) return UINT256_ZERO;
176  }
177 
178  uint256 hash;
179  uint256 aux = vin.prevout.hash + vin.prevout.n;
180 
181  if (!GetBlockHash(hash, nBlockHeight)) {
182  LogPrint(BCLog::MASTERNODE,"CalculateScore ERROR - nHeight %d - Returned 0\n", nBlockHeight);
183  return UINT256_ZERO;
184  }
185 
186  CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
187  ss << hash;
188  uint256 hash2 = ss.GetHash();
189 
190  CHashWriter ss2(SER_GETHASH, PROTOCOL_VERSION);
191  ss2 << hash;
192  ss2 << aux;
193  uint256 hash3 = ss2.GetHash();
194 
195  uint256 r = (hash3 > hash2 ? hash3 - hash2 : hash2 - hash3);
196 
197  return r;
198 }
199 
200 void CMasternode::Check(bool forceCheck)
201 {
202  if (ShutdownRequested()) return;
203  if (!forceCheck && (GetTime() - lastTimeChecked < MASTERNODE_CHECK_SECONDS)) return;
205 
206  //once spent, stop doing the checks
207  if (activeState == MASTERNODE_VIN_SPENT) return;
208 
211  return;
212  }
213 
216  return;
217  }
218 
219  if (!unitTest) {
220  {
221  TRY_LOCK(cs_main, lockMain);
222  if (!lockMain) return;
223 
224  CCoins coins;
225  if (!pcoinsTip->GetCoins(vin.prevout.hash, coins) ||
226  (unsigned int)vin.prevout.n>=coins.vout.size() ||
227  coins.vout[vin.prevout.n].IsNull()) {
229  LogPrint(BCLog::MASTERNODE, "CMasternode::Check -- Failed to find Masternode UTXO, masternode=%s\n", vin.prevout.ToStringShort());
230  return;
231  }
234  return;
235  }
236  }
237  }
239 }
240 
242 {
243  CScript pubkeyScript;
245 
246  int64_t sec = (GetAdjustedTime() - GetLastPaid());
247  int64_t month = 60 * 60 * 24 * 30;
248  if (sec < month) return sec; //if it's less than 30 days, give seconds
249 
250  CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
251  ss << vin;
252  ss << sigTime;
253  uint256 hash = ss.GetHash();
254 
255  // return some deterministic value for unknown/unpaid but force it to be more than 30 days old
256  return month + hash.GetCompact(false);
257 }
258 
260 {
261  CBlockIndex* pindexPrev = chainActive.Tip();
262  if (pindexPrev == NULL) return false;
263 
264  std::vector<unsigned char> mnpayee;
265  mnpayee = vin.masternodeStealthAddress;
266 
267  CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
268  ss << vin;
269  ss << sigTime;
270  uint256 hash = ss.GetHash();
271 
272  // use a deterministic offset to break a tie -- 2.5 minutes
273  int64_t nOffset = hash.GetCompact(false) % 150;
274 
275  if (chainActive.Tip() == NULL) return false;
276 
277  const CBlockIndex* BlockReading = chainActive.Tip();
278 
279  int nMnCount = mnodeman.CountEnabled() * 1.25;
280  int n = 0;
281  for (unsigned int i = 1; BlockReading && BlockReading->nHeight > 0; i++) {
282  if (n >= nMnCount) {
283  return 0;
284  }
285  n++;
286 
287  if (masternodePayments.mapMasternodeBlocks.count(BlockReading->nHeight)) {
288  /*
289  Search for this payee, with at least 2 votes. This will aid in consensus allowing the network
290  to converge on the same payees quickly, then keep the same schedule.
291  */
292  if (masternodePayments.mapMasternodeBlocks[BlockReading->nHeight].HasPayeeWithVotes(mnpayee, 2)) {
293  return BlockReading->nTime + nOffset;
294  }
295  }
296 
297  if (BlockReading->pprev == NULL) {
298  assert(BlockReading);
299  break;
300  }
301  BlockReading = BlockReading->pprev;
302  }
303 
304  return 0;
305 }
306 
308 {
309  switch (nActiveState) {
311  return "PRE_ENABLED";
313  return "ENABLED";
315  return "EXPIRED";
317  return "OUTPOINT_SPENT";
319  return "REMOVE";
321  return "WATCHDOG_EXPIRED";
323  return "POSE_BAN";
324  default:
325  return "UNKNOWN";
326  }
327 }
328 
330 {
331  // TODO: regtest is fine with any addresses for now,
332  // should probably be a bit smarter if one day we start to implement tests for this
333  return Params().IsRegTestNet() ||
335 }
336 
338 {
339  CScript payee2;
340  payee2 = GetScriptForDestination(pubkey);
341 
342  CTransaction txVin;
343  uint256 hash;
344  if (GetTransaction(vin.prevout.hash, txVin, hash, true)) {
345  if (vin.prevout.n >= txVin.vout.size()) return false;
346  CTxOut out = txVin.vout[vin.prevout.n];
347  CAmount amount;
348  CKey decodedMask;
349  CPubKey sharedSec(vin.encryptionKey.begin(), vin.encryptionKey.end());
350  ECDHInfo::Decode(out.maskValue.mask.begin(), out.maskValue.amount.begin(), sharedSec, decodedMask, amount);
351  std::vector<unsigned char> commitment;
352  CWallet::CreateCommitment(decodedMask.begin(), amount, commitment);
353  if (commitment != out.commitment) {
354  return false;
355  }
356 
357  if (amount == Params().MNCollateralAmt()) {
358  if (out.scriptPubKey == payee2) return true;
359  }
360  }
361 
362  return false;
363 }
364 
366 {
367  vin = CTxIn();
368  addr = CService();
371  sig = std::vector<unsigned char>();
375  cacheInputAge = 0;
376  cacheInputAgeBlock = 0;
377  unitTest = false;
378  allowFreeTx = true;
379  protocolVersion = PROTOCOL_VERSION;
380  nLastDsq = 0;
383 }
384 
385 CMasternodeBroadcast::CMasternodeBroadcast(CService newAddr, CTxIn newVin, CPubKey pubKeyCollateralAddressNew, CPubKey pubKeyMasternodeNew, int protocolVersionIn)
386 {
387  vin = newVin;
388  addr = newAddr;
389  pubKeyCollateralAddress = pubKeyCollateralAddressNew;
390  pubKeyMasternode = pubKeyMasternodeNew;
391  sig = std::vector<unsigned char>();
395  cacheInputAge = 0;
396  cacheInputAgeBlock = 0;
397  unitTest = false;
398  allowFreeTx = true;
399  protocolVersion = protocolVersionIn;
400  nLastDsq = 0;
403 }
404 
406 {
407  vin = mn.vin;
408  addr = mn.addr;
411  sig = mn.sig;
413  sigTime = mn.sigTime;
414  lastPing = mn.lastPing;
417  unitTest = mn.unitTest;
420  nLastDsq = mn.nLastDsq;
423 }
424 
425 bool CMasternodeBroadcast::Create(std::string strService, std::string strKeyMasternode, std::string strTxHash, std::string strOutputIndex, std::string& strErrorRet, CMasternodeBroadcast& mnbRet, bool fOffline)
426 {
427  CTxIn txin;
428  CPubKey pubKeyCollateralAddressNew;
429  CKey keyCollateralAddressNew;
430  CPubKey pubKeyMasternodeNew;
431  CKey keyMasternodeNew;
432 
433  //need correct blocks to send ping
434  if (!fOffline && !masternodeSync.IsBlockchainSynced()) {
435  strErrorRet = "Sync in progress. Must wait until sync is complete to start Masternode";
436  LogPrint(BCLog::MASTERNODE,"CMasternodeBroadcast::Create -- %s\n", strErrorRet);
437  return false;
438  }
439 
440  if (!CMessageSigner::GetKeysFromSecret(strKeyMasternode, keyMasternodeNew, pubKeyMasternodeNew)) {
441  strErrorRet = strprintf("Invalid masternode key %s", strKeyMasternode);
442  LogPrint(BCLog::MASTERNODE,"CMasternodeBroadcast::Create -- %s\n", strErrorRet);
443  return false;
444  }
445 
446  std::string strError;
447  if (!pwalletMain->GetMasternodeVinAndKeys(txin, pubKeyCollateralAddressNew, keyCollateralAddressNew, strTxHash, strOutputIndex, strError)) {
448  strErrorRet = strError; // GetMasternodeVinAndKeys logs this error. Only returned for GUI error notification.
449  LogPrint(BCLog::MASTERNODE,"CMasternodeBroadcast::Create -- %s\n", strprintf("Could not allocate txin %s:%s for masternode %s", strTxHash, strOutputIndex, strService));
450  return false;
451  }
452 
453  int nPort;
454  int nDefaultPort = Params().GetDefaultPort();
455  std::string strHost;
456  SplitHostPort(strService, nPort, strHost);
457  if (nPort == 0) nPort = nDefaultPort;
458  CService _service(LookupNumeric(strHost.c_str(), nPort));
459 
460  // The service needs the correct default port to work properly
461  if(!CheckDefaultPort(_service, strErrorRet, "CMasternodeBroadcast::Create"))
462  return false;
463 
464  return Create(txin, _service, keyCollateralAddressNew, pubKeyCollateralAddressNew, keyMasternodeNew, pubKeyMasternodeNew, strErrorRet, mnbRet);
465 }
466 
467 bool CMasternodeBroadcast::Create(CTxIn txin, CService service, CKey keyCollateralAddressNew, CPubKey pubKeyCollateralAddressNew, CKey keyMasternodeNew, CPubKey pubKeyMasternodeNew, std::string& strErrorRet, CMasternodeBroadcast& mnbRet)
468 {
469  // wait for reindex and/or import to finish
470  if (fImporting || fReindex) return false;
471 
472  LogPrint(BCLog::MASTERNODE, "CMasternodeBroadcast::Create -- pubKeyCollateralAddressNew = %s, pubKeyMasternodeNew.GetID() = %s\n",
473  CBitcoinAddress(pubKeyCollateralAddressNew.GetID()).ToString(),
474  pubKeyMasternodeNew.GetID().ToString());
475 
476  CMasternodePing mnp(txin);
477  if (!mnp.Sign(keyMasternodeNew, pubKeyMasternodeNew)) {
478  strErrorRet = strprintf("Failed to sign ping, masternode=%s", txin.prevout.hash.ToString());
479  LogPrint(BCLog::MASTERNODE,"CMasternodeBroadcast::Create -- %s\n", strErrorRet);
480  mnbRet = CMasternodeBroadcast();
481  return false;
482  }
483 
484  mnbRet = CMasternodeBroadcast(service, txin, pubKeyCollateralAddressNew, pubKeyMasternodeNew, PROTOCOL_VERSION);
485 
486  if (!mnbRet.IsValidNetAddr()) {
487  strErrorRet = strprintf("Invalid IP address %s, masternode=%s", mnbRet.addr.ToStringIP (), txin.prevout.hash.ToString());
488  LogPrint(BCLog::MASTERNODE,"CMasternodeBroadcast::Create -- %s\n", strErrorRet);
489  mnbRet = CMasternodeBroadcast();
490  return false;
491  }
492 
493  mnbRet.lastPing = mnp;
494  if (!mnbRet.Sign(keyCollateralAddressNew)) {
495  strErrorRet = strprintf("Failed to sign broadcast, masternode=%s", txin.prevout.hash.ToString());
496  LogPrint(BCLog::MASTERNODE,"CMasternodeBroadcast::Create -- %s\n", strErrorRet);
497  mnbRet = CMasternodeBroadcast();
498  return false;
499  }
500 
501  return true;
502 }
503 
504 
505 bool CMasternodeBroadcast::CheckDefaultPort(CService service, std::string& strErrorRet, const std::string& strContext)
506 {
507  int nDefaultPort = Params().GetDefaultPort();
508 
509  if (service.GetPort() != nDefaultPort) {
510  strErrorRet = strprintf("Invalid port %u for masternode %s, only %d is supported on %s-net.",
511  service.GetPort(), service.ToString(), nDefaultPort, Params().NetworkIDString());
512  LogPrintf("%s - %s\n", strContext, strErrorRet);
513  return false;
514  }
515 
516  return true;
517 }
518 
520 {
521  // make sure signature isn't in the future (past is OK)
522  if (sigTime > GetAdjustedTime() + 60 * 60) {
523  LogPrint(BCLog::MNPING,"%s: Signature rejected, too far into the future %s\n", __func__, vin.prevout.hash.ToString());
524  nDos = 1;
525  return false;
526  }
527 
528  // incorrect ping or its sigTime
529  if(lastPing == CMasternodePing() || !lastPing.CheckAndUpdate(nDos, false, true)) {
530  LogPrint(BCLog::MASTERNODE,"mnb - Incorrect ping or its sigTime\n");
531  return false;
532  }
533 
534  std::string vchPubKey(pubKeyCollateralAddress.begin(), pubKeyCollateralAddress.end());
535  std::string vchPubKey2(pubKeyMasternode.begin(), pubKeyMasternode.end());
536 
537  std::string strMessage = GetStrMessage();
538 
540  LogPrint(BCLog::MASTERNODE,"mnb - ignoring outdated Masternode %s protocol version %d\n", vin.prevout.hash.ToString(), protocolVersion);
541  return false;
542  }
543  std::string mstl(vin.masternodeStealthAddress.begin(), vin.masternodeStealthAddress.end());
544 
545  CScript pubkeyScript;
547  LogPrint(BCLog::MASTERNODE, "CMasternodeBroadcast::CheckAndUpdate: pubKeyCollateralAddress=%s\n", pubkeyScript.ToString());
548  if ((pubkeyScript.size() != 35) && (pubkeyScript.size() != 67)) {
549  LogPrint(BCLog::MASTERNODE,"mnb - pubkey the wrong size\n");
550  nDos = 100;
551  return false;
552  }
553 
554  CScript pubkeyScript2;
555  pubkeyScript2 = GetScriptForDestination(pubKeyMasternode);
556  if ((pubkeyScript2.size() != 35) && (pubkeyScript2.size() != 67)) {
557  LogPrint(BCLog::MASTERNODE,"mnb - pubkey2 the wrong size\n");
558  nDos = 100;
559  return false;
560  }
561 
562  if (!vin.scriptSig.empty()) {
563  LogPrint(BCLog::MASTERNODE,"mnb - Ignore Not Empty ScriptSig %s\n", vin.prevout.hash.ToString());
564  return false;
565  }
566 
567  std::string errorMessage = "";
568  //only need to verify shnorr signature
570  LogPrint(BCLog::MASTERNODE,"mnb - Got bad Masternode address signature\n");
572  nDos = 100;
573  return false;
574  }
575  if (Params().NetworkID() == CBaseChainParams::MAIN) {
576  if (addr.GetPort() != 59682) return false;
577  } else if (addr.GetPort() == 59682)
578  return false;
579 
580  //search existing Masternode list, this is where we update existing Masternodes with new mnb broadcasts
581  CMasternode* pmn = mnodeman.Find(vin);
582 
583  // no such masternode, nothing to update
584  if (pmn == NULL)
585  return true;
586  else {
587  // this broadcast older than we have, it's bad.
588  if (pmn->sigTime > sigTime) {
589  LogPrint(BCLog::MASTERNODE,"mnb - Bad sigTime %d for Masternode %s (existing broadcast is at %d)\n",
591  return false;
592  }
593  // masternode is not enabled yet/already, nothing to update
594  if (!pmn->IsEnabled()) return true;
595  }
596 
597  // mn.pubkey = pubkey, IsVinAssociatedWithPubkey is validated once below,
598  // after that they just need to match
600  //take the newest entry
601  LogPrint(BCLog::MASTERNODE,"mnb - Got updated entry for %s\n", vin.prevout.hash.ToString());
602  if (pmn->UpdateFromNewBroadcast((*this))) {
603  pmn->Check();
604  if (pmn->IsEnabled()) Relay();
605  }
607  }
608 
609  return true;
610 }
611 
613 {
614  // we are a masternode with the same vin (i.e. already activated) and this mnb is ours (matches our Masternode privkey)
615  // so nothing to do here for us
617  return true;
618 
619  // incorrect ping or its sigTime
620  if(lastPing == CMasternodePing() || !lastPing.CheckAndUpdate(nDoS, false, true)) return false;
621 
622  // search existing Masternode list
623  CMasternode* pmn = mnodeman.Find(vin);
624 
625  if (pmn != NULL) {
626  // nothing to do here if we already know about this masternode and it's enabled
627  if (pmn->IsEnabled()) return true;
628  // if it's not enabled, remove old MN first and continue
629  else
630  mnodeman.Remove(pmn->vin);
631  }
632 
633  {
634  TRY_LOCK(cs_main, lockMain);
635  if (!lockMain) {
636  // not mnb fault, let it to be checked again later
639  return false;
640  }
641 
642  CCoins coins;
643  if (!pcoinsTip->GetCoins(vin.prevout.hash, coins) ||
644  (unsigned int)vin.prevout.n>=coins.vout.size() ||
645  coins.vout[vin.prevout.n].IsNull()) {
646  LogPrint(BCLog::MASTERNODE, "CMasternodeBroadcast::CheckInputsAndAdd -- Failed to find Masternode UTXO, masternode=%s\n", vin.prevout.ToStringShort());
647  return false;
648  }
649  }
650 
651  LogPrint(BCLog::MASTERNODE, "mnb - Accepted Masternode entry\n");
652 
654  LogPrint(BCLog::MASTERNODE,"mnb - Input must have at least %d confirmations\n", MASTERNODE_MIN_CONFIRMATIONS);
655  // maybe we miss few blocks, let this mnb to be checked again later
658  return false;
659  }
660 
661  // verify that sig time is legit in past
662  // should be at least not earlier than block when 1000 PRCY tx got MASTERNODE_MIN_CONFIRMATIONS
663  uint256 hashBlock = UINT256_ZERO;
664  CTransaction tx2;
665  GetTransaction(vin.prevout.hash, tx2, hashBlock, true);
666  BlockMap::iterator mi = mapBlockIndex.find(hashBlock);
667  if (mi != mapBlockIndex.end() && (*mi).second) {
668  CBlockIndex* pMNIndex = (*mi).second; // block for 1000 PRCY tx -> 1 confirmation
669  CBlockIndex* pConfIndex = chainActive[pMNIndex->nHeight + MASTERNODE_MIN_CONFIRMATIONS - 1]; // block where tx got MASTERNODE_MIN_CONFIRMATIONS
670  if (pConfIndex->GetBlockTime() > sigTime) {
671  LogPrint(BCLog::MASTERNODE,"mnb - Bad sigTime %d for Masternode %s (%i conf block is at %d)\n",
673  return false;
674  }
675  }
676 
677  LogPrint(BCLog::MASTERNODE,"mnb - Got NEW Masternode entry - %s - %lli \n", vin.prevout.hash.ToString(), sigTime);
678  CMasternode mn(*this);
679  mnodeman.Add(mn);
680 
681  // if it matches our Masternode privkey, then we've been remotely activated
682  if (pubKeyMasternode == activeMasternode.pubKeyMasternode && protocolVersion == PROTOCOL_VERSION) {
684  }
685 
686  bool isLocal = addr.IsRFC1918() || addr.IsLocal();
687  if (Params().IsRegTestNet()) isLocal = false;
688 
689  if (!isLocal) Relay();
690 
691  return true;
692 }
693 
695 {
697  RelayInv(inv);
698 }
699 
700 bool CMasternodeBroadcast::Sign(CKey& keyCollateralAddress)
701 {
702  std::string strError = "";
703 
704  std::string vchPubKey(pubKeyCollateralAddress.begin(), pubKeyCollateralAddress.end());
705  std::string vchPubKey2(pubKeyMasternode.begin(), pubKeyMasternode.end());
706 
708  std::string ss = addr.ToString();
709  std::string strMessage = GetStrMessage();
710 
711  if (!CMessageSigner::SignMessage(strMessage, sig, keyCollateralAddress))
712  return error("CMasternodeBroadcast::Sign() - Error.");
713 
714  if (!CMessageSigner::VerifyMessage(pubKeyCollateralAddress, sig, strMessage, strError))
715  return error("CMasternodeBroadcast::Sign() - Error: %s", strError);
716 
717  return true;
718 }
719 
721 {
722  std::string strError;
723 
725  return error("CMasternodeBroadcast::VerifySignature() - Error: %s", strError);
726 
727  return true;
728 }
729 
731 {
733  std::string strMessage = HEX_STR(ser);
734 
735  return strMessage;
736 }
737 
739 {
740  vin = CTxIn();
742  sigTime = 0;
743  vchSig = std::vector<unsigned char>();
744 }
745 
747 {
748  vin = newVin;
749  blockHash = chainActive[chainActive.Height() - 12]->GetBlockHash();
751  vchSig = std::vector<unsigned char>();
752 }
753 
754 
755 bool CMasternodePing::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode)
756 {
757  std::string strError = "";
758  std::string strMasterNodeSignMessage;
759 
761  HEX_DATA_STREAM_PROTOCOL(PROTOCOL_VERSION) << vin.ToString() << blockHash.ToString() << sigTime;
762  std::string strMessage = HEX_STR(ser);
763 
764  if (!CMessageSigner::SignMessage(strMessage, vchSig, keyMasternode)) {
765  LogPrint(BCLog::MASTERNODE,"%s : SignMessage() - Error.", __func__);
766  return false;
767  }
768 
769  if (!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) {
770  LogPrint(BCLog::MASTERNODE,"%s : VerifyMessage() - Error: %s\n", __func__, strError);
771  return false;
772  }
773 
774  return true;
775 }
776 
777 bool CMasternodePing::VerifySignature(CPubKey& pubKeyMasternode, int &nDos) {
778  std::string strError = "";
779  HEX_DATA_STREAM_PROTOCOL(PROTOCOL_VERSION) << vin.ToString() << blockHash.ToString() << sigTime;
780  std::string strMessage = HEX_STR(ser);
781 
782  if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)){
783  nDos = 33;
784  return error("CMasternodePing::VerifySignature - Got bad Masternode ping signature %s Error: %s", vin.ToString(), strError);
785  }
786  return true;
787 }
788 
789 bool CMasternodePing::CheckAndUpdate(int& nDos, bool fRequireEnabled, bool fCheckSigTimeOnly)
790 {
791  if (sigTime > GetAdjustedTime() + 60 * 60) {
792  LogPrint(BCLog::MNPING, "%s: Signature rejected, too far into the future %s\n", __func__, vin.prevout.hash.ToString());
793  nDos = 1;
794  return false;
795  }
796 
797  if (sigTime <= GetAdjustedTime() - 60 * 60) {
798  LogPrint(BCLog::MNPING, "%s: Signature rejected, too far into the past %s - %d %d \n", __func__, vin.prevout.hash.ToString(), sigTime, GetAdjustedTime());
799  nDos = 1;
800  return false;
801  }
802 
803  if(fCheckSigTimeOnly) {
804  CMasternode* pmn = mnodeman.Find(vin);
805  if(pmn) return VerifySignature(pmn->pubKeyMasternode, nDos);
806  return true;
807  }
808 
809  LogPrint(BCLog::MNPING, "%s: New Ping - %s - %s - %lli\n", __func__, GetHash().ToString(), blockHash.ToString(), sigTime);
810 
811  // see if we have this Masternode
812  CMasternode* pmn = mnodeman.Find(vin);
814  if (fRequireEnabled && !pmn->IsEnabled()) return false;
815 
816  // update only if there is no known ping for this masternode or
817  // last ping was more then MASTERNODE_MIN_MNP_SECONDS-60 ago comparing to this one
819 
820  HEX_DATA_STREAM_PROTOCOL(PROTOCOL_VERSION) << vin.ToString() << blockHash.ToString() << sigTime;
821  std::string strMessage = HEX_STR(ser);
822 
823  std::string errorMessage = "";
824  if (!CMessageSigner::VerifyMessage(pmn->pubKeyMasternode, vchSig, strMessage, errorMessage)) {
825  LogPrint(BCLog::MNPING, "%s: Got bad Masternode address signature %s\n", __func__, vin.prevout.hash.ToString());
826  nDos = 33;
827  return false;
828  }
829 
830  BlockMap::iterator mi = mapBlockIndex.find(blockHash);
831  if (mi != mapBlockIndex.end() && (*mi).second) {
832  if ((*mi).second->nHeight < chainActive.Height() - 24) {
833  LogPrint(BCLog::MNPING, "%s: Masternode %s block hash %s is too old\n", __func__, vin.prevout.hash.ToString(), blockHash.ToString());
834  // Do nothing here (no Masternode update, no mnping relay)
835  // Let this node to be visible but fail to accept mnping
836 
837  return false;
838  }
839  } else {
840  LogPrint(BCLog::MNPING, "%s: Masternode %s block hash %s is unknown\n", __func__, vin.prevout.hash.ToString(), blockHash.ToString());
841  // maybe we stuck so we shouldn't ban this node, just fail to accept it
842  // TODO: or should we also request this block?
843 
844  return false;
845  }
846 
847  pmn->lastPing = *this;
848 
849  //mnodeman.mapSeenMasternodeBroadcast.lastPing is probably outdated, so we'll update it
850  CMasternodeBroadcast mnb(*pmn);
851  uint256 hash = mnb.GetHash();
852  if (mnodeman.mapSeenMasternodeBroadcast.count(hash)) {
853  mnodeman.mapSeenMasternodeBroadcast[hash].lastPing = *this;
854  }
855 
856  pmn->Check(true);
857  if (!pmn->IsEnabled()) return false;
858 
859  LogPrint(BCLog::MNPING, "%s: Masternode ping accepted, vin: %s\n", __func__, vin.prevout.hash.ToString());
860 
861  Relay();
862  return true;
863  }
864  LogPrint(BCLog::MNPING, "%s: Masternode ping arrived too early, vin: %s\n", __func__, vin.prevout.hash.ToString());
865  return false;
866  }
867  LogPrint(BCLog::MNPING, "%s: Couldn't find compatible Masternode entry, vin: %s\n", __func__, vin.prevout.hash.ToString());
868 
869  return false;
870 }
871 
873 {
875  RelayInv(inv);
876 }
CBlockIndex::GetBlockTime
int64_t GetBlockTime() const
Definition: chain.h:364
CTxIn
An input of a transaction.
Definition: transaction.h:83
CActiveMasternode::EnableHotColdMasterNode
bool EnableHotColdMasterNode(CTxIn &vin, CService &addr)
Enable cold wallet mode (run a Masternode with no funds)
Definition: activemasternode.cpp:162
CMasternode::nLastDsq
int64_t nLastDsq
Definition: masternode.h:142
CService
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:133
UINT256_ZERO
const uint256 UINT256_ZERO
constant uint256 instances
Definition: uint256.h:129
fImporting
std::atomic< bool > fImporting
Definition: main.cpp:80
CMasternodeBroadcast::Sign
bool Sign(CKey &keyCollateralAddress)
Definition: masternode.cpp:700
CMasternode::MASTERNODE_EXPIRED
@ MASTERNODE_EXPIRED
Definition: masternode.h:118
CTxIn::encryptionKey
std::vector< unsigned char > encryptionKey
Definition: transaction.h:96
SplitHostPort
void SplitHostPort(std::string in, int &portOut, std::string &hostOut)
Definition: netbase.cpp:74
CMasternodeMan::CountEnabled
int CountEnabled(int protocolVersion=-1)
Definition: masternodeman.cpp:379
CMasternode::cacheInputAgeBlock
int cacheInputAgeBlock
Definition: masternode.h:137
ShutdownRequested
bool ShutdownRequested()
Definition: init.cpp:135
GetTime
int64_t GetTime()
For unit testing.
Definition: utiltime.cpp:19
SER_GETHASH
@ SER_GETHASH
Definition: serialize.h:161
activeMasternode
CActiveMasternode activeMasternode
Keep track of the active Masternode.
Definition: masternodeman.cpp:24
CMasternodePayments::GetMinMasternodePaymentsProto
int GetMinMasternodePaymentsProto()
Definition: masternode-payments.cpp:293
CMasternodeBroadcast::CheckDefaultPort
static bool CheckDefaultPort(CService service, std::string &strErrorRet, const std::string &strContext)
Definition: masternode.cpp:505
streams.h
CMasternode::MASTERNODE_ENABLED
@ MASTERNODE_ENABLED
Definition: masternode.h:117
CMasternode::allowFreeTx
bool allowFreeTx
Definition: masternode.h:139
CMasternode::MASTERNODE_WATCHDOG_EXPIRED
@ MASTERNODE_WATCHDOG_EXPIRED
Definition: masternode.h:121
CMasternodeBroadcast::Create
static bool Create(CTxIn vin, CService service, CKey keyCollateralAddressNew, CPubKey pubKeyCollateralAddressNew, CKey keyMasternodeNew, CPubKey pubKeyMasternodeNew, std::string &strErrorRet, CMasternodeBroadcast &mnbRet)
Create Masternode broadcast, needs to be relayed manually after that.
Definition: masternode.cpp:467
base_uint::begin
unsigned char * begin()
Definition: arith_uint256.h:240
sync.h
chainActive
CChain chainActive
The currently-connected chain of blocks.
Definition: main.cpp:70
CMasternode::nScanningErrorCount
int nScanningErrorCount
Definition: masternode.h:143
COutPoint::hash
uint256 hash
Definition: transaction.h:39
GetScriptForDestination
CScript GetScriptForDestination(const CTxDestination &dest)
Definition: standard.cpp:285
CBitcoinAddress
base58-encoded PRCY addresses.
Definition: base58.h:109
CMasternodePing::CheckAndUpdate
bool CheckAndUpdate(int &nDos, bool fRequireEnabled=true, bool fCheckSigTimeOnly=false)
Definition: masternode.cpp:789
CMasternodeMan::Find
CMasternode * Find(const CScript &payee)
Find an entry.
Definition: masternodeman.cpp:440
CActiveMasternode::vin
CTxIn vin
Definition: activemasternode.h:44
CMasternodeSync::IsBlockchainSynced
bool IsBlockchainSynced()
Definition: masternode-sync.cpp:32
CBlockIndex::pprev
CBlockIndex * pprev
pointer to the index of the predecessor of this block
Definition: chain.h:169
CMasternodePing::Sign
bool Sign(CKey &keyMasternode, CPubKey &pubKeyMasternode)
Definition: masternode.cpp:755
CBlockIndex::nHeight
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:181
CMasternodeBroadcast::CheckAndUpdate
bool CheckAndUpdate(int &nDoS)
Definition: masternode.cpp:519
CMasternode::UpdateFromNewBroadcast
bool UpdateFromNewBroadcast(CMasternodeBroadcast &mnb)
Definition: masternode.cpp:146
wallet.h
CMasternodeSync::AddedMasternodeList
void AddedMasternodeList(uint256 hash)
Definition: masternode-sync.cpp:89
COutPoint::ToStringShort
std::string ToStringShort() const
Definition: transaction.cpp:26
CMasternode::SecondsSincePayment
int64_t SecondsSincePayment()
Definition: masternode.cpp:241
masternode-sync.h
CMasternode::IsValidNetAddr
bool IsValidNetAddr()
Definition: masternode.cpp:329
CMasternodeBroadcast::Relay
void Relay()
Definition: masternode.cpp:694
CMasternode::activeState
int activeState
Definition: masternode.h:134
TRY_LOCK
#define TRY_LOCK(cs, name)
Definition: sync.h:186
CMasternodePing::sigTime
int64_t sigTime
Definition: masternode.h:44
CMasternode::cs
RecursiveMutex cs
Definition: masternode.h:111
CInv
inv message data
Definition: protocol.h:358
MSG_MASTERNODE_ANNOUNCE
@ MSG_MASTERNODE_ANNOUNCE
Definition: protocol.h:402
masternodeman.h
CChainParams::IsRegTestNet
bool IsRegTestNet() const
Definition: chainparams.h:104
CMessageSigner::VerifyMessage
static bool VerifyMessage(const CPubKey &pubkey, const std::vector< unsigned char > &vchSig, const std::string &strMessage, std::string &strErrorRet)
Verify the message signature, returns true if succcessful.
Definition: messagesigner.cpp:34
CBase58Data::ToString
std::string ToString() const
Definition: base58.cpp:200
uint256::GetCompact
uint32_t GetCompact(bool fNegative=false) const
Definition: uint256.cpp:34
CMasternode::vin
CTxIn vin
Definition: masternode.h:127
fMasterNode
bool fMasterNode
Definition: util.cpp:97
CMasternodeMan::Remove
void Remove(CTxIn vin)
Definition: masternodeman.cpp:804
CPubKey::GetHex
std::string GetHex() const
Definition: pubkey.h:193
MASTERNODE_EXPIRATION_SECONDS
#define MASTERNODE_EXPIRATION_SECONDS
Definition: masternode.h:22
CTxIn::masternodeStealthAddress
std::vector< unsigned char > masternodeStealthAddress
Definition: transaction.h:99
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:269
CNetAddr::ToStringIP
std::string ToStringIP() const
Definition: netaddress.cpp:243
CMessageSigner::SignMessage
static bool SignMessage(const std::string &strMessage, std::vector< unsigned char > &vchSigRet, const CKey &key)
Sign the message, returns true if successful.
Definition: messagesigner.cpp:25
MaskValue::mask
uint256 mask
Definition: transaction.h:151
CMasternode::sigTime
int64_t sigTime
Definition: masternode.h:135
masternodeSync
CMasternodeSync masternodeSync
Definition: masternode-sync.cpp:19
r
void const uint64_t uint64_t * r
Definition: field_5x52_asm_impl.h:10
CWallet::GetMasternodeVinAndKeys
bool GetMasternodeVinAndKeys(CTxIn &txinRet, CPubKey &pubKeyRet, CKey &keyRet, std::string strTxHash, std::string strOutputIndex, std::string &strError)
Get 5000 PRCY output and keys which can be used for the Masternode.
Definition: wallet.cpp:2409
CActiveMasternode::pubKeyMasternode
CPubKey pubKeyMasternode
Definition: activemasternode.h:41
CBlockIndex::nTime
unsigned int nTime
Definition: chain.h:228
CPubKey::begin
const unsigned char * begin() const
Definition: pubkey.h:95
cs_main
RecursiveMutex cs_main
Global state.
Definition: main.cpp:65
CKey::begin
const unsigned char * begin() const
Definition: key.h:100
CCoins::vout
std::vector< CTxOut > vout
unspent transaction outputs; spent outputs are .IsNull(); spent outputs at the end of the array are d...
Definition: coins.h:85
mnodeman
CMasternodeMan mnodeman
Masternode manager.
Definition: masternodeman.cpp:22
CService::ToString
std::string ToString() const
Definition: netaddress.cpp:568
CMasternode::pubKeyMasternode1
CPubKey pubKeyMasternode1
Definition: masternode.h:132
BCLog::MNPING
@ MNPING
Definition: logging.h:64
CTxOut
An output of a transaction.
Definition: transaction.h:164
CMasternode::MASTERNODE_VIN_SPENT
@ MASTERNODE_VIN_SPENT
Definition: masternode.h:123
IsReachable
bool IsReachable(enum Network net)
check whether a given network is one we can probably connect to
Definition: net.cpp:280
GetTransaction
bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock, bool fAllowSlow, CBlockIndex *blockIndex)
Return transaction in tx, and if it was found inside a block, its hash is placed in hashBlock.
Definition: main.cpp:2010
CTransaction::vout
std::vector< CTxOut > vout
Definition: transaction.h:286
CTxOut::scriptPubKey
CScript scriptPubKey
Definition: transaction.h:168
CNetAddr::IsRoutable
bool IsRoutable() const
Definition: netaddress.cpp:224
GetBlockHash
bool GetBlockHash(uint256 &hash, int nBlockHeight)
Definition: masternode.cpp:26
CPubKey::end
const unsigned char * end() const
Definition: pubkey.h:96
CMasternode::MASTERNODE_POSE_BAN
@ MASTERNODE_POSE_BAN
Definition: masternode.h:122
MASTERNODE_CHECK_SECONDS
#define MASTERNODE_CHECK_SECONDS
Definition: masternode.h:24
CMasternode::lastTimeChecked
int64_t lastTimeChecked
Definition: masternode.h:112
RelayInv
void RelayInv(CInv &inv)
Definition: net.cpp:2077
CMasternodeBroadcast::CheckInputsAndAdd
bool CheckInputsAndAdd(int &nDos)
Definition: masternode.cpp:612
CBaseChainParams::MAIN
@ MAIN
Definition: chainparamsbase.h:19
CMasternode::CalculateScore
uint256 CalculateScore(int mod=1, int64_t nBlockHeight=0)
Definition: masternode.cpp:171
LogPrintf
#define LogPrintf(...)
Definition: logging.h:147
CAmount
int64_t CAmount
Amount in PRCY (Can be negative)
Definition: amount.h:17
pcoinsTip
CCoinsViewCache * pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
Definition: main.cpp:1130
masternodePayments
CMasternodePayments masternodePayments
Object for who's going to get paid on which blocks.
Definition: masternode-payments.cpp:19
MASTERNODE_MIN_MNP_SECONDS
#define MASTERNODE_MIN_MNP_SECONDS
Definition: masternode.h:19
mapSeenMasternodeScanningErrors
std::map< uint256, int > mapSeenMasternodeScanningErrors
Definition: masternode.cpp:21
GetInputAge
int GetInputAge(CTxIn &vin)
Definition: main.cpp:1373
CNetAddr::IsRFC1918
bool IsRFC1918() const
Definition: netaddress.cpp:90
CMasternodeMan::mapSeenMasternodeBroadcast
std::map< uint256, CMasternodeBroadcast > mapSeenMasternodeBroadcast
Definition: masternodeman.h:76
CMasternodePing::blockHash
uint256 blockHash
Definition: masternode.h:43
masternode-payments.h
uint256
256-bit unsigned big integer.
Definition: uint256.h:38
HEX_DATA_STREAM_PROTOCOL
#define HEX_DATA_STREAM_PROTOCOL(protocolVersion)
Definition: streams.h:26
CMasternode::CMasternode
CMasternode()
Definition: masternode.cpp:74
CMasternodeMan::Add
bool Add(CMasternode &mn)
Add an entry.
Definition: masternodeman.cpp:206
CWallet::CreateCommitment
static bool CreateCommitment(const CAmount val, CKey &blind, std::vector< unsigned char > &commitment)
Definition: wallet.cpp:3096
CService::GetPort
unsigned short GetPort() const
Definition: netaddress.cpp:494
mapCacheBlockHashes
std::map< int64_t, uint256 > mapCacheBlockHashes
Definition: masternode.cpp:23
LogPrint
#define LogPrint(category,...)
Definition: logging.h:162
MaskValue::amount
uint256 amount
Definition: transaction.h:150
MASTERNODE_MIN_CONFIRMATIONS
#define MASTERNODE_MIN_CONFIRMATIONS
Definition: masternode.h:18
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:363
CBlockIndex::GetBlockHash
uint256 GetBlockHash() const
Definition: chain.h:359
CMasternode::pubKeyMasternode
CPubKey pubKeyMasternode
Definition: masternode.h:130
MSG_MASTERNODE_PING
@ MSG_MASTERNODE_PING
Definition: protocol.h:403
MASTERNODE_REMOVAL_SECONDS
#define MASTERNODE_REMOVAL_SECONDS
Definition: masternode.h:23
CMasternodePayments::mapMasternodeBlocks
std::map< int, CMasternodeBlockPayees > mapMasternodeBlocks
Definition: masternode-payments.h:239
CChain::Height
int Height() const
Return the maximal height in the chain.
Definition: chain.h:641
CMessageSigner::GetKeysFromSecret
static bool GetKeysFromSecret(const std::string &strSecret, CKey &keyRet, CPubKey &pubkeyRet)
Set the private/public key values, returns true if successful.
Definition: messagesigner.cpp:13
CMasternodeBroadcast::CMasternodeBroadcast
CMasternodeBroadcast()
Definition: masternode.cpp:365
CChainParams::GetDefaultPort
int GetDefaultPort() const
Definition: chainparams.h:56
CMasternode::addr
CService addr
Definition: masternode.h:128
CMasternodeBroadcast::GetHash
uint256 GetHash()
Definition: masternode.h:322
messagesigner.h
CMasternode::sig
std::vector< unsigned char > sig
Definition: masternode.h:133
strprintf
#define strprintf
Definition: tinyformat.h:1056
ss2
#define ss2(x)
Definition: bmw.c:142
CMasternode
Definition: masternode.h:107
CMasternodePing::CMasternodePing
CMasternodePing()
Definition: masternode.cpp:738
CPubKey
An encapsulated public key.
Definition: pubkey.h:37
GetAdjustedTime
int64_t GetAdjustedTime()
Definition: timedata.cpp:30
CMasternode::nLastScanningErrorBlockHeight
int nLastScanningErrorBlockHeight
Definition: masternode.h:144
CMasternodePing::Relay
void Relay()
Definition: masternode.cpp:872
CMasternode::GetStatus
std::string GetStatus()
Definition: masternode.cpp:307
CKey
An encapsulated private key.
Definition: key.h:39
CTxOut::maskValue
MaskValue maskValue
Definition: transaction.h:176
CMasternode::MASTERNODE_OUTPOINT_SPENT
@ MASTERNODE_OUTPOINT_SPENT
Definition: masternode.h:119
BCLog::MASTERNODE
@ MASTERNODE
Definition: logging.h:62
CTxIn::ToString
std::string ToString() const
Definition: transaction.cpp:50
fReindex
std::atomic< bool > fReindex
Definition: main.cpp:81
COutPoint::n
uint32_t n
Definition: transaction.h:40
CMasternodeMan::mapSeenMasternodePing
std::map< uint256, CMasternodePing > mapSeenMasternodePing
Definition: masternodeman.h:78
CMasternode::GetLastPaid
int64_t GetLastPaid()
Definition: masternode.cpp:259
LOCK
#define LOCK(cs)
Definition: sync.h:182
CScript::ToString
std::string ToString() const
Definition: script.cpp:266
CMasternodeSync::mapSeenSyncMNB
std::map< uint256, int > mapSeenSyncMNB
Definition: masternode-sync.h:32
CTxIn::prevout
COutPoint prevout
Definition: transaction.h:86
CHashWriter
A writer stream (for serialization) that computes a 256-bit hash.
Definition: hash.h:259
prevector::size
size_type size() const
Definition: prevector.h:282
CTxIn::scriptSig
CScript scriptSig
Definition: transaction.h:87
HEX_STR
#define HEX_STR(a)
Definition: streams.h:27
LookupNumeric
CService LookupNumeric(const char *pszName, int portDefault)
Definition: netbase.cpp:234
masternode.h
Params
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:463
CMasternode::IsPingedWithin
bool IsPingedWithin(int seconds, int64_t now=-1)
Definition: masternode.h:229
CMasternode::MASTERNODE_REMOVE
@ MASTERNODE_REMOVE
Definition: masternode.h:120
VerifyShnorrKeyImageTxIn
bool VerifyShnorrKeyImageTxIn(const CTxIn &txin, uint256 ctsHash)
Definition: main.cpp:1407
prevector::empty
bool empty() const
Definition: prevector.h:286
addrman.h
CCoins
Definition: coins.h:77
CTxOut::commitment
std::vector< unsigned char > commitment
Definition: transaction.h:178
CMasternode::IsEnabled
bool IsEnabled()
Definition: masternode.h:242
CMasternode::IsBroadcastedWithin
bool IsBroadcastedWithin(int seconds)
Definition: masternode.h:224
netbase.h
CMasternode::cacheInputAge
int cacheInputAge
Definition: masternode.h:136
CChain::Tip
CBlockIndex * Tip(bool fProofOfStake=false) const
Returns the index entry for the tip of this chain, or NULL if none.
Definition: chain.h:596
CMasternodePing::vchSig
std::vector< unsigned char > vchSig
Definition: masternode.h:45
CHashWriter::GetHash
uint256 GetHash()
Definition: hash.h:277
CTxIn::keyImage
CKeyImage keyImage
Definition: transaction.h:97
GetTxInSignatureHash
uint256 GetTxInSignatureHash(const CTxIn &txin)
Definition: main.cpp:687
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:162
CMasternodeBroadcast::GetStrMessage
std::string GetStrMessage()
Definition: masternode.cpp:730
CMasternode::nActiveState
int nActiveState
Definition: masternode.h:141
CMasternodeBroadcast
Definition: masternode.h:292
pwalletMain
CWallet * pwalletMain
Definition: wallet.cpp:49
CMasternode::MASTERNODE_PRE_ENABLED
@ MASTERNODE_PRE_ENABLED
Definition: masternode.h:116
CMasternodeBroadcast::VerifySignature
bool VerifySignature()
Definition: masternode.cpp:720
CMasternode::protocolVersion
int protocolVersion
Definition: masternode.h:140
CNetAddr::IsLocal
bool IsLocal() const
Definition: netaddress.cpp:168
CMasternode::unitTest
bool unitTest
Definition: masternode.h:138
util.h
MASTERNODE_MIN_MNB_SECONDS
#define MASTERNODE_MIN_MNB_SECONDS
Definition: masternode.h:20
CCoinsViewCache::GetCoins
bool GetCoins(const uint256 &txid, CCoins &coins) const
Retrieve the CCoins (unspent transaction outputs) for a given txid.
Definition: coins.cpp:113
CMasternodePing
Definition: masternode.h:39
CMasternodePing::GetHash
uint256 GetHash()
Definition: masternode.h:67
CMasternode::Check
void Check(bool forceCheck=false)
Definition: masternode.cpp:200
CMasternodePing::VerifySignature
bool VerifySignature(CPubKey &pubKeyMasternode, int &nDos)
Definition: masternode.cpp:777
CMasternode::pubKeyCollateralAddress
CPubKey pubKeyCollateralAddress
Definition: masternode.h:129
CMasternode::lastPing
CMasternodePing lastPing
Definition: masternode.h:145
IsSpentKeyImage
bool IsSpentKeyImage(const std::string &kiHex, const uint256 &againsHash)
Definition: main.cpp:283
error
bool error(const char *fmt, const Args &... args)
Definition: util.h:61
CPubKey::GetID
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Definition: pubkey.h:143
CMasternode::IsInputAssociatedWithPubkey
bool IsInputAssociatedWithPubkey(CTxIn &vin, CPubKey &pubkey) const
Is the input associated with collateral public key? (and there is 5000 PRCY - checking if valid maste...
Definition: masternode.cpp:337
mapBlockIndex
BlockMap mapBlockIndex
Definition: main.cpp:67
CMasternodePing::vin
CTxIn vin
Definition: masternode.h:42
ECDHInfo::Decode
static void Decode(unsigned char *encodedMask, unsigned char *encodedAmount, const CPubKey &sharedSec, CKey &decodedMask, CAmount &decodedAmount)
Definition: wallet.cpp:126
base_uint::ToString
std::string ToString() const
Definition: arith_uint256.cpp:199