MCPcopy Create free account
hub / github.com/LUX-Core/lux / GetMasternodeRank

Function GetMasternodeRank

src/masternode.cpp:511–689  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

509}
510
511int GetMasternodeRank(CTxIn& vin, int64_t nBlockHeight, int minProtocol) {
512 //LOCK(cs_masternodes);
513 std::vector< pair<unsigned int, CTxIn> > vecMasternodeScores;
514
515 for (CMasterNode & mn : vecMasternodes) {
516 mn.Check();
517
518 if (mn.protocolVersion < minProtocol) continue;
519 if (!mn.IsEnabled()) {
520 continue;
521 }
522
523 uint256 n = mn.CalculateScore(1, nBlockHeight);
524 unsigned int n2 = 0;
525 memcpy(&n2, &n, sizeof(n2));
526
527 vecMasternodeScores.push_back(make_pair(n2, mn.vin));
528 }
529
530 sort(vecMasternodeScores.rbegin(), vecMasternodeScores.rend(), CompareValueOnly());
531
532 unsigned int rank = 0;
533 for (PAIRTYPE(unsigned int, CTxIn) &s : vecMasternodeScores) {
534 rank++;
535 if (s.second == vin) {
536 return rank;
537 }
538 }
539
540 return -1;
541}
542
543//Get the last hash that matches the modulus given. Processed in reverse order
544bool GetBlockHash(uint256& hash, int nBlockHeight) {
545 if (chainActive.Tip() == NULL) return false;
546
547 if (nBlockHeight == 0)
548 nBlockHeight = chainActive.Height();
549
550 if (mapCacheBlockHashes.count(nBlockHeight)) {
551 hash = mapCacheBlockHashes[nBlockHeight];
552 return true;
553 }
554
555 const CBlockIndex* BlockLastSolved = chainActive.Tip();
556 const CBlockIndex* BlockReading = chainActive.Tip();
557
558 if (BlockLastSolved == NULL || BlockLastSolved->nHeight == 0 || chainActive.Height() + 1 < nBlockHeight) return false;
559
560 int nBlocksAgo = 0;
561 if (nBlockHeight > 0) nBlocksAgo = (chainActive.Height() + 1) - nBlockHeight;
562 assert(nBlocksAgo >= 0);
563
564 int n = 0;
565 for (unsigned int i = 1; BlockReading && BlockReading->nHeight > 0; i++) {
566 if (n >= nBlocksAgo) {
567 hash = BlockReading->GetBlockHash();
568 mapCacheBlockHashes[nBlockHeight] = hash;

Callers 5

DoConsensusVoteFunction · 0.85
ProcessConsensusVoteFunction · 0.85
SignaturesValidMethod · 0.85
masternodeFunction · 0.85
updateNodeListMethod · 0.85

Calls 15

memcpyFunction · 0.85
ifFunction · 0.85
CheckFunction · 0.85
GetTimeFunction · 0.85
GetMNCollateralFunction · 0.85
AcceptableInputsFunction · 0.85
IsEnabledMethod · 0.80
CalculateScoreMethod · 0.80
rbeginMethod · 0.80
rendMethod · 0.80
TipMethod · 0.80
HeightMethod · 0.80

Tested by

no test coverage detected