PIVX Core  5.6.99
P2P Digital Currency
masternode.cpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2015 The Dash developers
2 // Copyright (c) 2015-2022 The PIVX Core developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include "masternode.h"
7 
8 #include "addrman.h"
9 #include "masternodeman.h"
10 #include "netbase.h"
11 #include "sync.h"
13 #include "wallet/wallet.h"
14 
15 #define MASTERNODE_MIN_MNP_SECONDS_REGTEST 90
16 #define MASTERNODE_MIN_MNB_SECONDS_REGTEST 25
17 #define MASTERNODE_PING_SECONDS_REGTEST 25
18 #define MASTERNODE_EXPIRATION_SECONDS_REGTEST 12 * 60
19 #define MASTERNODE_REMOVAL_SECONDS_REGTEST 13 * 60
20 
21 #define MASTERNODE_MIN_MNP_SECONDS (10 * 60)
22 #define MASTERNODE_MIN_MNB_SECONDS (5 * 60)
23 #define MASTERNODE_PING_SECONDS (5 * 60)
24 #define MASTERNODE_EXPIRATION_SECONDS (120 * 60)
25 #define MASTERNODE_REMOVAL_SECONDS (130 * 60)
26 #define MASTERNODE_CHECK_SECONDS 5
27 
29 {
31 }
32 
34 {
36 }
37 
39 {
41 }
42 
44 {
46 }
47 
49 {
51 }
52 
53 // Used for sigTime < maxTimeWindow
55 {
56  return GetAdjustedTime() + 60 * 2;
57 }
58 
59 
62 {
63  LOCK(cs);
64  vin = CTxIn();
65  addr = CService();
68  sigTime = 0;
70  protocolVersion = PROTOCOL_VERSION;
74 }
75 
77  CSignedMessage(other)
78 {
79  LOCK(cs);
80  vin = other.vin;
81  addr = other.addr;
84  sigTime = other.sigTime;
85  lastPing = other.lastPing;
90 }
91 
92 CMasternode::CMasternode(const CDeterministicMNCPtr& dmn, int64_t registeredTime, const uint256& registeredHash) :
94 {
95  LOCK(cs);
96  vin = CTxIn(dmn->collateralOutpoint);
97  addr = dmn->pdmnState->addr;
100  sigTime = registeredTime;
101  lastPing = CMasternodePing(vin, registeredHash, registeredTime);
102  protocolVersion = PROTOCOL_VERSION;
105  mnPayeeScript = dmn->pdmnState->scriptPayout;
106 }
107 
109 {
110  int version = !addr.IsAddrV1Compatible() ? PROTOCOL_VERSION | ADDRV2_FORMAT : PROTOCOL_VERSION;
111  CHashWriter ss(SER_GETHASH, version);
112  ss << nMessVersion;
113  ss << addr;
114  ss << sigTime;
116  ss << pubKeyMasternode;
117  ss << protocolVersion;
118  return ss.GetHash();
119 }
120 
121 std::string CMasternode::GetStrMessage() const
122 {
123  return (addr.ToString() +
124  std::to_string(sigTime) +
127  std::to_string(protocolVersion)
128  );
129 }
130 
131 //
132 // When a new masternode broadcast is sent, update our information
133 //
135 {
136  if (mnb.sigTime > sigTime) {
137  // TODO: lock cs. Need to be careful as mnb.lastPing.CheckAndUpdate locks cs_main internally.
141  sigTime = mnb.sigTime;
142  vchSig = mnb.vchSig;
144  addr = mnb.addr;
145  int nDoS = 0;
146  if (mnb.lastPing.IsNull() || (!mnb.lastPing.IsNull() && mnb.lastPing.CheckAndUpdate(nDoS, false))) {
147  lastPing = mnb.lastPing;
149  }
150  return true;
151  }
152  return false;
153 }
154 
155 //
156 // Deterministically calculate a given "score" for a Masternode depending on how close it's hash is to
157 // the proof of work for that block. The further away they are the better, the furthest will win the election
158 // and get paid this block
159 //
161 {
162  CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
163  ss << hash;
164  const arith_uint256& hash2 = UintToArith256(ss.GetHash());
165 
166  CHashWriter ss2(SER_GETHASH, PROTOCOL_VERSION);
167  ss2 << hash;
169  ss2 << aux;
170  const arith_uint256& hash3 = UintToArith256(ss2.GetHash());
171 
172  return (hash3 > hash2 ? hash3 - hash2 : hash2 - hash3);
173 }
174 
176 {
177  LOCK(cs);
178  if (fCollateralSpent) {
179  return MASTERNODE_VIN_SPENT;
180  }
182  return MASTERNODE_REMOVE;
183  }
185  return MASTERNODE_EXPIRED;
186  }
188  return MASTERNODE_PRE_ENABLED;
189  }
190  return MASTERNODE_ENABLED;
191 }
192 
194 {
195  // TODO: regtest is fine with any addresses for now,
196  // should probably be a bit smarter if one day we start to implement tests for this
197  return Params().IsRegTestNet() ||
199 }
200 
202  CMasternode()
203 { }
204 
205 CMasternodeBroadcast::CMasternodeBroadcast(CService newAddr, CTxIn newVin, CPubKey pubKeyCollateralAddressNew, CPubKey pubKeyMasternodeNew, int protocolVersionIn, const CMasternodePing& _lastPing) :
206  CMasternode()
207 {
208  vin = newVin;
209  addr = newAddr;
210  pubKeyCollateralAddress = pubKeyCollateralAddressNew;
211  pubKeyMasternode = pubKeyMasternodeNew;
212  protocolVersion = protocolVersionIn;
213  lastPing = _lastPing;
215 }
216 
218  CMasternode(mn)
219 { }
220 
221 bool CMasternodeBroadcast::Create(const std::string& strService,
222  const std::string& strKeyMasternode,
223  const std::string& strTxHash,
224  const std::string& strOutputIndex,
225  std::string& strErrorRet,
226  CMasternodeBroadcast& mnbRet,
227  bool fOffline,
228  int chainHeight)
229 {
230  CPubKey pubKeyCollateralAddressNew;
231  CKey keyCollateralAddressNew;
232  CPubKey pubKeyMasternodeNew;
233  CKey keyMasternodeNew;
234 
235  //need correct blocks to send ping
236  if (!fOffline && !g_tiertwo_sync_state.IsBlockchainSynced()) {
237  strErrorRet = "Sync in progress. Must wait until sync is complete to start Masternode";
238  LogPrint(BCLog::MASTERNODE,"CMasternodeBroadcast::Create -- %s\n", strErrorRet);
239  return false;
240  }
241 
242  std::string strError;
243  if (strTxHash.empty() || strOutputIndex.empty()) {
244  strError = "Invalid masternode collateral hash or output index";
245  return error("%s: %s", __func__, strError);
246  }
247 
248  const uint256 collateralHash = uint256S(strTxHash);
249  int collateralOutputIndex;
250  try {
251  collateralOutputIndex = std::stoi(strOutputIndex.c_str());
252  } catch (const std::exception& e) {
253  strError = "Invalid masternode output index";
254  return error("%s: %s on strOutputIndex", __func__, e.what());
255  }
256 
257  if (!CMessageSigner::GetKeysFromSecret(strKeyMasternode, keyMasternodeNew, pubKeyMasternodeNew)) {
258  strErrorRet = strprintf("Invalid masternode key %s", strKeyMasternode);
259  LogPrint(BCLog::MASTERNODE,"CMasternodeBroadcast::Create -- %s\n", strErrorRet);
260  return false;
261  }
262 
263  // Use wallet-0 here. Legacy mnb creation can be removed after transition to DMN
264  COutPoint collateralOut(collateralHash, collateralOutputIndex);
265  if (vpwallets.empty() || !vpwallets[0]->GetMasternodeVinAndKeys(pubKeyCollateralAddressNew,
266  keyCollateralAddressNew,
267  collateralOut,
268  true, // fValidateCollateral
269  strError)) {
270  strErrorRet = strError; // GetMasternodeVinAndKeys logs this error. Only returned for GUI error notification.
271  LogPrint(BCLog::MASTERNODE,"CMasternodeBroadcast::Create -- %s\n", strprintf("Could not allocate txin %s:%s for masternode %s", strTxHash, strOutputIndex, strService));
272  return false;
273  }
274 
275  int nPort = 0;
276  int nDefaultPort = Params().GetDefaultPort();
277  std::string strHost;
278  SplitHostPort(strService, nPort, strHost);
279  if (nPort == 0) nPort = nDefaultPort;
280  CService _service(LookupNumeric(strHost.c_str(), nPort));
281 
282  // The service needs the correct default port to work properly
283  if (!CheckDefaultPort(_service, strErrorRet, "CMasternodeBroadcast::Create"))
284  return false;
285 
286  CTxIn txin(collateralOut.hash, collateralOut.n);
287  return Create(txin, _service, keyCollateralAddressNew, pubKeyCollateralAddressNew, keyMasternodeNew, pubKeyMasternodeNew, strErrorRet, mnbRet);
288 }
289 
291  const CService& service,
292  const CKey& keyCollateralAddressNew,
293  const CPubKey& pubKeyCollateralAddressNew,
294  const CKey& keyMasternodeNew,
295  const CPubKey& pubKeyMasternodeNew,
296  std::string& strErrorRet,
297  CMasternodeBroadcast& mnbRet)
298 {
299  // wait for reindex and/or import to finish
300  if (fImporting || fReindex) return false;
301 
302  LogPrint(BCLog::MASTERNODE, "CMasternodeBroadcast::Create -- pubKeyCollateralAddressNew = %s, pubKeyMasternodeNew.GetID() = %s\n",
303  EncodeDestination(pubKeyCollateralAddressNew.GetID()),
304  pubKeyMasternodeNew.GetID().ToString());
305 
306  // Get block hash to ping (TODO: move outside of this function)
307  const uint256& nBlockHashToPing = mnodeman.GetBlockHashToPing();
308  CMasternodePing mnp(txin, nBlockHashToPing, GetAdjustedTime());
309  if (!mnp.Sign(keyMasternodeNew, pubKeyMasternodeNew.GetID())) {
310  strErrorRet = strprintf("Failed to sign ping, masternode=%s", txin.prevout.hash.ToString());
311  LogPrint(BCLog::MASTERNODE,"CMasternodeBroadcast::Create -- %s\n", strErrorRet);
312  mnbRet = CMasternodeBroadcast();
313  return false;
314  }
315 
316  mnbRet = CMasternodeBroadcast(service, txin, pubKeyCollateralAddressNew, pubKeyMasternodeNew, PROTOCOL_VERSION, mnp);
317 
318  if (!mnbRet.IsValidNetAddr()) {
319  strErrorRet = strprintf("Invalid IP address %s, masternode=%s", mnbRet.addr.ToStringIP (), txin.prevout.hash.ToString());
320  LogPrint(BCLog::MASTERNODE,"CMasternodeBroadcast::Create -- %s\n", strErrorRet);
321  mnbRet = CMasternodeBroadcast();
322  return false;
323  }
324 
325  if (!mnbRet.Sign(keyCollateralAddressNew, pubKeyCollateralAddressNew)) {
326  strErrorRet = strprintf("Failed to sign broadcast, masternode=%s", txin.prevout.hash.ToString());
327  LogPrint(BCLog::MASTERNODE,"CMasternodeBroadcast::Create -- %s\n", strErrorRet);
328  mnbRet = CMasternodeBroadcast();
329  return false;
330  }
331 
332  return true;
333 }
334 
335 bool CMasternodeBroadcast::Sign(const CKey& key, const CPubKey& pubKey)
336 {
337  std::string strError = "";
339  const std::string strMessage = GetSignatureHash().GetHex();
340 
341  if (!CMessageSigner::SignMessage(strMessage, vchSig, key)) {
342  return error("%s : SignMessage() (nMessVersion=%d) failed", __func__, nMessVersion);
343  }
344 
345  if (!CMessageSigner::VerifyMessage(pubKey, vchSig, strMessage, strError)) {
346  return error("%s : VerifyMessage() (nMessVersion=%d) failed, error: %s\n",
347  __func__, nMessVersion, strError);
348  }
349 
350  return true;
351 }
352 
354 {
355  std::string strError = "";
356  std::string strMessage = (
359  GetStrMessage()
360  );
361 
363  return error("%s : VerifyMessage (nMessVersion=%d) failed: %s", __func__, nMessVersion, strError);
364 
365  return true;
366 }
367 
368 bool CMasternodeBroadcast::CheckDefaultPort(CService service, std::string& strErrorRet, const std::string& strContext)
369 {
370  int nDefaultPort = Params().GetDefaultPort();
371 
372  if (service.GetPort() != nDefaultPort && !Params().IsRegTestNet()) {
373  strErrorRet = strprintf("Invalid port %u for masternode %s, only %d is supported on %s-net.",
374  service.GetPort(), service.ToString(), nDefaultPort, Params().NetworkIDString());
375  LogPrintf("%s - %s\n", strContext, strErrorRet);
376  return false;
377  }
378 
379  return true;
380 }
381 
383 {
384  // make sure signature isn't in the future (past is OK)
385  if (sigTime > GetMaxTimeWindow()) {
386  LogPrint(BCLog::MASTERNODE,"mnb - Signature rejected, too far into the future %s\n", vin.prevout.hash.ToString());
387  nDos = 1;
388  return false;
389  }
390 
391  // reject old signature version
393  LogPrint(BCLog::MASTERNODE, "mnb - rejecting old message version for mn %s\n", vin.prevout.hash.ToString());
394  nDos = 30;
395  return false;
396  }
397 
399  LogPrint(BCLog::MASTERNODE,"mnb - ignoring outdated Masternode %s protocol version %d\n", vin.prevout.hash.ToString(), protocolVersion);
400  return false;
401  }
402 
403  CScript pubkeyScript;
405 
406  if (pubkeyScript.size() != 25) {
407  LogPrint(BCLog::MASTERNODE,"mnb - pubkey the wrong size\n");
408  nDos = 100;
409  return false;
410  }
411 
412  CScript pubkeyScript2;
414 
415  if (pubkeyScript2.size() != 25) {
416  LogPrint(BCLog::MASTERNODE,"mnb - pubkey2 the wrong size\n");
417  nDos = 100;
418  return false;
419  }
420 
421  if (!vin.scriptSig.empty()) {
422  LogPrint(BCLog::MASTERNODE,"mnb - Ignore Not Empty ScriptSig %s\n", vin.prevout.hash.ToString());
423  return false;
424  }
425 
426  std::string strError = "";
427  if (!CheckSignature()) {
428  // For now (till v6.0), let's be "naive" and not fully ban nodes when the node is syncing
429  // This could be a bad parsed BIP155 address that got stored on db on an old software version.
430  nDos = g_tiertwo_sync_state.IsSynced() ? 100 : 5;
431  return error("%s : Got bad Masternode address signature", __func__);
432  }
433 
434  if (Params().NetworkIDString() == CBaseChainParams::MAIN) {
435  if (addr.GetPort() != 51472) return false;
436  } else if (addr.GetPort() == 51472)
437  return false;
438 
439  // incorrect ping or its sigTime
440  if(lastPing.IsNull() || !lastPing.CheckAndUpdate(nDos, false, true)) {
441  return false;
442  }
443 
444  //search existing Masternode list, this is where we update existing Masternodes with new mnb broadcasts
446 
447  // no such masternode, nothing to update
448  if (pmn == nullptr) return true;
449 
450  // this broadcast is older or equal than the one that we already have - it's bad and should never happen
451  // unless someone is doing something fishy
452  // (mapSeenMasternodeBroadcast in CMasternodeMan::ProcessMessage should filter legit duplicates)
453  if(pmn->sigTime >= sigTime) {
454  return error("%s : Bad sigTime %d for Masternode %20s %105s (existing broadcast is at %d)",
455  __func__, sigTime, addr.ToString(), vin.ToString(), pmn->sigTime);
456  }
457 
458  // masternode is not enabled yet/already, nothing to update
459  if (!pmn->IsEnabled()) return true;
460 
461  // mn.pubkey = pubkey, IsVinAssociatedWithPubkey is validated once below,
462  // after that they just need to match
464  //take the newest entry
465  LogPrint(BCLog::MASTERNODE,"mnb - Got updated entry for %s\n", vin.prevout.hash.ToString());
466  if (pmn->UpdateFromNewBroadcast((*this))) {
467  if (pmn->IsEnabled()) Relay();
468  }
470  }
471 
472  return true;
473 }
474 
476 {
478  g_connman->RelayInv(inv);
479 }
480 
482 {
483  CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
484  ss << sigTime;
486  return ss.GetHash();
487 }
488 
490  CSignedMessage(),
491  vin(),
492  blockHash(),
493  sigTime(0)
494 { }
495 
496 CMasternodePing::CMasternodePing(const CTxIn& newVin, const uint256& nBlockHash, uint64_t _sigTime) :
497  CSignedMessage(),
498  vin(newVin),
499  blockHash(nBlockHash),
500  sigTime(_sigTime)
501 { }
502 
504 {
505  CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
506  ss << vin;
508  ss << sigTime;
509  return ss.GetHash();
510 }
511 
513 {
514  return vin.ToString() + blockHash.ToString() + std::to_string(sigTime);
515 }
516 
517 bool CMasternodePing::CheckAndUpdate(int& nDos, bool fRequireAvailable, bool fCheckSigTimeOnly)
518 {
519  if (sigTime > GetMaxTimeWindow()) {
520  LogPrint(BCLog::MNPING,"%s: Signature rejected, too far into the future %s\n", __func__, vin.prevout.hash.ToString());
521  nDos = 30;
522  return false;
523  }
524 
525  if (sigTime <= GetAdjustedTime() - 60 * 60) {
526  LogPrint(BCLog::MNPING,"%s: Signature rejected, too far into the past %s - %d %d \n", __func__, vin.prevout.hash.ToString(), sigTime, GetAdjustedTime());
527  nDos = 30;
528  return false;
529  }
530 
531  // reject old signature version
533  LogPrint(BCLog::MNPING, "mnp - rejecting old message version for mn %s\n", vin.prevout.hash.ToString());
534  nDos = 30;
535  return false;
536  }
537 
538  // Check if the ping block hash exists and it's within 24 blocks from the tip
539  if (!mnodeman.IsWithinDepth(blockHash, 2 * MNPING_DEPTH)) {
540  LogPrint(BCLog::MNPING,"%s: Masternode %s block hash %s is too old or has an invalid block hash\n",
541  __func__, vin.prevout.hash.ToString(), blockHash.ToString());
542  // don't ban peers relaying stale data before the active protocol enforcement
543  nDos = 33;
544  return false;
545  }
546 
547  // see if we have this Masternode
549  const bool isMasternodeFound = (pmn != nullptr);
550  const bool isSignatureValid = (isMasternodeFound && CheckSignature(pmn->pubKeyMasternode.GetID()));
551 
552  if(fCheckSigTimeOnly) {
553  if (isMasternodeFound && !isSignatureValid) {
554  nDos = 33;
555  return false;
556  }
557  return true;
558  }
559 
560  LogPrint(BCLog::MNPING, "%s: New Ping - %s - %s - %lli\n", __func__, GetHash().ToString(), blockHash.ToString(), sigTime);
561 
562  if (isMasternodeFound && pmn->protocolVersion >= ActiveProtocol()) {
563 
564  // Update ping only if the masternode is in available state (pre-enabled or enabled)
565  if (fRequireAvailable && !pmn->IsAvailableState()) {
566  nDos = 20;
567  return false;
568  }
569 
570  // update only if there is no known ping for this masternode or
571  // last ping was more then MASTERNODE_MIN_MNP_SECONDS-60 ago comparing to this one
572  if (!pmn->IsPingedWithin(MasternodeMinPingSeconds() - 60, sigTime)) {
573  if (!isSignatureValid) {
574  nDos = 33;
575  return false;
576  }
577 
578  // ping have passed the basic checks, can be updated now
579  mnodeman.mapSeenMasternodePing.emplace(GetHash(), *this);
580 
581  // SetLastPing locks masternode cs. Be careful with the lock ordering.
582  pmn->SetLastPing(*this);
583 
584  //mnodeman.mapSeenMasternodeBroadcast.lastPing is probably outdated, so we'll update it
585  CMasternodeBroadcast mnb(*pmn);
586  const uint256& hash = mnb.GetHash();
587  if (mnodeman.mapSeenMasternodeBroadcast.count(hash)) {
588  mnodeman.mapSeenMasternodeBroadcast[hash].lastPing = *this;
589  }
590 
591  if (!pmn->IsEnabled()) return false;
592 
593  LogPrint(BCLog::MNPING, "%s: Masternode ping accepted, vin: %s\n", __func__, vin.prevout.hash.ToString());
594 
595  Relay();
596  return true;
597  }
598  LogPrint(BCLog::MNPING, "%s: Masternode ping arrived too early, vin: %s\n", __func__, vin.prevout.hash.ToString());
599  //nDos = 1; //disable, this is happening frequently and causing banned peers
600  return false;
601  }
602  LogPrint(BCLog::MNPING, "%s: Couldn't find compatible Masternode entry, vin: %s\n", __func__, vin.prevout.hash.ToString());
603 
604  return false;
605 }
606 
608 {
610  g_connman->RelayInv(inv);
611 }
612 
614 {
615  // create legacy masternode for DMN
616  int refHeight = std::max(dmn->pdmnState->nRegisteredHeight, dmn->pdmnState->nPoSeRevivedHeight);
617  const CBlockIndex* pindex = WITH_LOCK(cs_main, return mapBlockIndex.at(chainActive[refHeight]->GetBlockHash()); );
618  return std::make_shared<CMasternode>(CMasternode(dmn, pindex->GetBlockTime(), pindex->GetBlockHash()));
619 }
arith_uint256 UintToArith256(const uint256 &a)
#define ss2(x)
Definition: bmw.c:142
const CChainParams & Params()
Return the currently selected parameters.
uint256 hash
Definition: transaction.h:35
uint32_t n
Definition: transaction.h:36
static const std::string MAIN
Chain name strings.
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:139
uint256 GetBlockHash() const
Definition: chain.h:215
int64_t GetBlockTime() const
Definition: chain.h:216
int GetDefaultPort() const
Definition: chainparams.h:74
bool IsRegTestNet() const
Definition: chainparams.h:98
A writer stream (for serialization) that computes a 256-bit hash.
Definition: hash.h:216
uint256 GetHash()
Definition: hash.h:236
inv message data
Definition: protocol.h:466
An encapsulated private key.
Definition: key.h:30
static bool CheckDefaultPort(CService service, std::string &strErrorRet, const std::string &strContext)
Definition: masternode.cpp:368
static bool Create(const CTxIn &vin, const CService &service, const CKey &keyCollateralAddressNew, const CPubKey &pubKeyCollateralAddressNew, const CKey &keyMasternodeNew, const CPubKey &pubKeyMasternodeNew, std::string &strErrorRet, CMasternodeBroadcast &mnbRet)
Create Masternode broadcast, needs to be relayed manually after that.
Definition: masternode.cpp:290
bool CheckAndUpdate(int &nDoS)
Definition: masternode.cpp:382
uint256 GetHash() const
Definition: masternode.cpp:481
bool CheckSignature() const
Definition: masternode.cpp:353
bool Sign(const CKey &key, const CPubKey &pubKey)
Definition: masternode.cpp:335
uint256 GetSignatureHash() const override
Definition: masternode.cpp:108
int nLastScanningErrorBlockHeight
Definition: masternode.h:103
CMasternodePing lastPing
Definition: masternode.h:104
arith_uint256 CalculateScore(const uint256 &hash) const
Definition: masternode.cpp:160
bool fCollateralSpent
Definition: masternode.h:85
CService addr
Definition: masternode.h:97
bool IsAvailableState() const
Definition: masternode.h:203
RecursiveMutex cs
Definition: masternode.h:84
void SetLastPing(const CMasternodePing &_lastPing)
Definition: masternode.h:118
CTxIn vin
Definition: masternode.h:96
CPubKey pubKeyMasternode
Definition: masternode.h:99
int nScanningErrorCount
Definition: masternode.h:102
CScript mnPayeeScript
Definition: masternode.h:230
bool IsBroadcastedWithin(int seconds)
Definition: masternode.h:169
int protocolVersion
Definition: masternode.h:101
std::string GetStrMessage() const override
Definition: masternode.cpp:121
int64_t sigTime
Definition: masternode.h:100
@ MASTERNODE_ENABLED
Definition: masternode.h:90
@ MASTERNODE_REMOVE
Definition: masternode.h:92
@ MASTERNODE_VIN_SPENT
Definition: masternode.h:93
@ MASTERNODE_EXPIRED
Definition: masternode.h:91
@ MASTERNODE_PRE_ENABLED
Definition: masternode.h:89
bool UpdateFromNewBroadcast(CMasternodeBroadcast &mnb)
Definition: masternode.cpp:134
bool IsValidNetAddr() const
Definition: masternode.cpp:193
bool IsPingedWithin(int seconds, int64_t now=-1) const
Definition: masternode.h:174
CMasternode::state GetActiveState() const
Definition: masternode.cpp:175
bool IsEnabled() const
Definition: masternode.h:193
CPubKey pubKeyCollateralAddress
Definition: masternode.h:98
std::map< uint256, CMasternodeBroadcast > mapSeenMasternodeBroadcast
Definition: masternodeman.h:93
uint256 GetBlockHashToPing() const
bool IsWithinDepth(const uint256 &nHash, int depth) const
std::map< uint256, CMasternodePing > mapSeenMasternodePing
Definition: masternodeman.h:95
CMasternode * Find(const COutPoint &collateralOut)
Find an entry.
bool IsNull() const
Definition: masternode.h:59
int64_t sigTime
Definition: masternode.h:46
bool CheckAndUpdate(int &nDos, bool fRequireAvailable=true, bool fCheckSigTimeOnly=false)
Definition: masternode.cpp:517
uint256 blockHash
Definition: masternode.h:45
uint256 GetHash() const
Definition: masternode.cpp:503
std::string GetStrMessage() const override
Definition: masternode.cpp:512
static bool SignMessage(const std::string &strMessage, std::vector< unsigned char > &vchSigRet, const CKey &key)
Sign the message, returns true if successful.
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 successful.
static bool GetKeysFromSecret(const std::string &strSecret, CKey &keyRet, CPubKey &pubkeyRet)
Set the private/public key values, returns true if successful.
std::string ToStringIP() const
Definition: netaddress.cpp:516
bool IsRoutable() const
Definition: netaddress.cpp:454
bool IsAddrV1Compatible() const
Check if the current object can be serialized in pre-ADDRv2/BIP155 format.
Definition: netaddress.cpp:469
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:72
An encapsulated public key.
Definition: pubkey.h:44
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Definition: pubkey.h:167
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:381
void clear()
Definition: script.h:659
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:484
std::string ToString() const
Definition: netaddress.cpp:954
uint16_t GetPort() const
Definition: netaddress.cpp:882
Base Class for all signed messages on the network.
Definition: messagesigner.h:63
bool Sign(const CKey &key, const CKeyID &keyID)
CSignedMessage Class Functions inherited by network signed-messages.
bool CheckSignature(const CKeyID &keyID) const
std::vector< unsigned char > vchSig
Definition: messagesigner.h:65
An input of a transaction.
Definition: transaction.h:94
std::string ToString() const
Definition: transaction.cpp:53
CScript scriptSig
Definition: transaction.h:97
COutPoint prevout
Definition: transaction.h:96
bool IsBlockchainSynced() const
void AddedMasternodeList(const uint256 &hash)
bool IsSynced() const
256-bit unsigned big integer.
std::string ToString() const
Definition: uint256.cpp:65
std::string GetHex() const
Definition: uint256.cpp:21
bool empty() const
Definition: prevector.h:281
size_type size() const
Definition: prevector.h:277
256-bit opaque blob.
Definition: uint256.h:138
std::shared_ptr< const CDeterministicMN > CDeterministicMNCPtr
std::unique_ptr< CConnman > g_connman
Definition: init.cpp:90
@ LOCK
Definition: lockunlock.h:16
#define LogPrint(category,...)
Definition: logging.h:163
int MasternodeMinPingSeconds()
Definition: masternode.cpp:28
#define MASTERNODE_EXPIRATION_SECONDS_REGTEST
Definition: masternode.cpp:18
int MasternodeBroadcastSeconds()
Definition: masternode.cpp:33
int64_t GetMaxTimeWindow()
Definition: masternode.cpp:54
#define MASTERNODE_REMOVAL_SECONDS
Definition: masternode.cpp:25
int MasternodeExpirationSeconds()
Definition: masternode.cpp:43
int MasternodeRemovalSeconds()
Definition: masternode.cpp:48
#define MASTERNODE_PING_SECONDS
Definition: masternode.cpp:23
#define MASTERNODE_MIN_MNB_SECONDS
Definition: masternode.cpp:22
#define MASTERNODE_PING_SECONDS_REGTEST
Definition: masternode.cpp:17
#define MASTERNODE_MIN_MNB_SECONDS_REGTEST
Definition: masternode.cpp:16
#define MASTERNODE_REMOVAL_SECONDS_REGTEST
Definition: masternode.cpp:19
#define MASTERNODE_MIN_MNP_SECONDS_REGTEST
Definition: masternode.cpp:15
#define MASTERNODE_MIN_MNP_SECONDS
Definition: masternode.cpp:21
#define MASTERNODE_EXPIRATION_SECONDS
Definition: masternode.cpp:24
int MasternodePingSeconds()
Definition: masternode.cpp:38
MasternodeRef MakeMasternodeRefForDMN(const CDeterministicMNCPtr &dmn)
Definition: masternode.cpp:613
std::shared_ptr< CMasternode > MasternodeRef
Definition: masternode.h:24
CMasternodeMan mnodeman
Masternode manager.
@ MESS_VER_HASH
Definition: messagesigner.h:17
@ MASTERNODE
Definition: logging.h:59
@ MNPING
Definition: logging.h:61
std::string EncodeDestination(const CWDestination &address, const CChainParams::Base58Type addrType)
bool IsReachable(enum Network net)
Definition: net.cpp:253
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:80
void SplitHostPort(std::string in, int &portOut, std::string &hostOut)
Definition: netbase.cpp:71
CService LookupNumeric(const std::string &name, int portDefault)
Definition: netbase.cpp:209
@ MSG_MASTERNODE_ANNOUNCE
Definition: protocol.h:451
@ MSG_MASTERNODE_PING
Definition: protocol.h:452
@ collateralHash
Definition: rpcevo.cpp:38
@ SER_GETHASH
Definition: serialize.h:176
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a PIVX scriptPubKey for the given CTxDestination.
Definition: standard.cpp:278
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:247
bool error(const char *fmt, const Args &... args)
Definition: system.h:77
TierTwoSyncState g_tiertwo_sync_state
int64_t GetAdjustedTime()
Definition: timedata.cpp:36
#define strprintf
Definition: tinyformat.h:1056
uint256 uint256S(const char *str)
Definition: uint256.h:157
int ActiveProtocol()
See whether the protocol update is enforced for connected nodes.
std::atomic< bool > fImporting
Definition: validation.cpp:94
BlockMap mapBlockIndex
Definition: validation.cpp:82
std::atomic< bool > fReindex
Definition: validation.cpp:95
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
Definition: validation.cpp:84
std::vector< CWalletRef > vpwallets
Definition: wallet.cpp:33