19 #define MN_WINNER_MINIMUM_AGE 8000 // Age in seconds. This should be > MASTERNODE_REMOVAL_SECONDS to avoid misconfigured new nodes in the list.
28 const std::pair<int64_t, CTxIn>& t2)
const
30 return t1.first < t2.first;
36 const std::pair<int64_t, CTxIn>& t2)
const
38 return t1.first < t2.first;
43 bool operator()(
const std::pair<int64_t, CMasternode>& t1,
44 const std::pair<int64_t, CMasternode>& t2)
const
46 return t1.first < t2.first;
68 ssMasternodes << mnodemanToSave;
70 ssMasternodes << hash;
76 return error(
"%s : Failed to open file %s", __func__,
pathMN.string());
80 fileout << ssMasternodes;
81 }
catch (
const std::exception& e) {
82 return error(
"%s : Serialize or I/O error - %s", __func__, e.what());
100 error(
"%s : Failed to open file %s", __func__,
pathMN.string());
105 int fileSize = fs::file_size(
pathMN);
106 int dataSize = fileSize -
sizeof(
uint256);
110 std::vector<unsigned char> vchData;
111 vchData.resize(dataSize);
116 filein.
read((
char*)&vchData[0], dataSize);
118 }
catch (
const std::exception& e) {
119 error(
"%s : Deserialize or I/O error - %s", __func__, e.what());
128 if (hashIn != hashTmp) {
129 error(
"%s : Checksum mismatch, data corrupted", __func__);
133 unsigned char pchMsgTmp[4];
134 std::string strMagicMessageTmp;
138 ssMasternodes >> strMagicMessageTmp;
142 error(
"%s : Invalid masternode cache magic message", __func__);
147 ssMasternodes >>
FLATDATA(pchMsgTmp);
150 if (memcmp(pchMsgTmp,
Params().MessageStart(),
sizeof(pchMsgTmp))) {
151 error(
"%s : Invalid network magic number", __func__);
155 ssMasternodes >> mnodemanToLoad;
156 }
catch (
const std::exception& e) {
157 mnodemanToLoad.
Clear();
158 error(
"%s : Deserialize or I/O error - %s", __func__, e.what());
227 int64_t t = (*i).second;
257 std::vector<CMasternode>::iterator it =
vMasternodes.begin();
270 if ((*it3).second.vin == (*it).vin) {
281 if ((*it2).first == (*it).vin.prevout) {
297 if ((*it1).second <
GetTime()) {
307 if ((*it1).second <
GetTime()) {
317 if ((*it2).second <
GetTime()) {
360 int nStable_size = 0;
363 int64_t nMasternode_Age = 0;
366 if (mn.protocolVersion < nMinProtocol) {
370 if (!mn.IsEnabled ())
386 if (mn.protocolVersion < protocolVersion || !mn.IsEnabled())
continue;
427 if (
GetTime() < (*it).second) {
458 if (mn.vin.prevout == vin.
prevout)
470 if (mn.pubKeyMasternode == pubKeyMasternode)
484 std::vector<std::pair<int64_t, CTxIn> > vecMasternodeLastPaid;
493 if (!mn.IsEnabled())
continue;
502 if (fFilterSigTime && mn.sigTime + (nMnCount * 2.6 * 60) >
GetAdjustedTime())
continue;
505 if (mn.GetMasternodeInputAge() < nMnCount)
continue;
507 vecMasternodeLastPaid.push_back(std::make_pair(mn.SecondsSincePayment(), mn.vin));
510 nCount = (int)vecMasternodeLastPaid.size();
516 sort(vecMasternodeLastPaid.rbegin(), vecMasternodeLastPaid.rend(),
CompareLastPaid());
532 pBestMasternode = pmn;
535 if (nCountTenth >= nTenthNetwork)
break;
537 return pBestMasternode;
548 if (mn.protocolVersion < minProtocol || !mn.IsEnabled())
continue;
551 uint256 n = mn.CalculateScore(mod, nBlockHeight);
566 std::vector<std::pair<int64_t, CTxIn> > vecMasternodeScores;
568 int64_t nMasternode_Age = 0;
576 if (mn.protocolVersion < minProtocol) {
583 if (!mn.IsEnabled())
continue;
585 uint256 n = mn.CalculateScore(1, nBlockHeight);
588 vecMasternodeScores.push_back(std::make_pair(n2, mn.vin));
591 sort(vecMasternodeScores.rbegin(), vecMasternodeScores.rend(),
CompareScoreTxIn());
596 if (s.second.prevout == vin.
prevout) {
606 std::vector<std::pair<int64_t, CMasternode> > vecMasternodeScores;
607 std::vector<std::pair<int, CMasternode> > vecMasternodeRanks;
611 if (!
GetBlockHash(hash, nBlockHeight))
return vecMasternodeRanks;
617 if (mn.protocolVersion < minProtocol)
continue;
619 if (!mn.IsEnabled()) {
620 vecMasternodeScores.push_back(std::make_pair(9999, mn));
624 uint256 n = mn.CalculateScore(1, nBlockHeight);
627 vecMasternodeScores.push_back(std::make_pair(n2, mn));
630 sort(vecMasternodeScores.rbegin(), vecMasternodeScores.rend(),
CompareScoreMN());
635 vecMasternodeRanks.push_back(std::make_pair(rank, s.second));
638 return vecMasternodeRanks;
643 std::vector<std::pair<int64_t, CTxIn> > vecMasternodeScores;
647 if (mn.protocolVersion < minProtocol)
continue;
650 if (!mn.IsEnabled())
continue;
653 uint256 n = mn.CalculateScore(1, nBlockHeight);
656 vecMasternodeScores.push_back(std::make_pair(n2, mn.vin));
659 sort(vecMasternodeScores.rbegin(), vecMasternodeScores.rend(),
CompareScoreTxIn());
665 return Find(s.second);
689 if (!mnb.CheckAndUpdate(nDoS)) {
700 if (!mnb.IsInputAssociatedWithPubkey(mnb.vin, mnb.pubKeyCollateralAddress)) {
701 LogPrintf(
"CMasternodeMan::ProcessMessage() : mnb - Got mismatched pubkey and vin\n");
709 if (mnb.CheckInputsAndAdd(nDoS)) {
733 if (mnp.CheckAndUpdate(nDoS))
return;
743 if (pmn != NULL)
return;
754 if (vin ==
CTxIn()) {
761 int64_t t = (*i).second;
763 LogPrintf(
"CMasternodeMan::ProcessMessage() : dseg - peer already asked me for the list\n");
777 if (mn.addr.IsRFC1918())
continue;
779 if (mn.IsEnabled()) {
781 if (vin ==
CTxIn() || vin == mn.vin) {
797 if (vin ==
CTxIn()) {
808 std::vector<CMasternode>::iterator it =
vMasternodes.begin();
810 if ((*it).vin == vin) {
840 std::ostringstream info;
853 LogPrintf(
"Masternodes thread started\n");