MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / GetTopVoteDelegates

Method GetTopVoteDelegates

src/persistence/delegatedb.cpp:31–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29}
30
31bool CDelegateDBCache::GetTopVoteDelegates(uint32_t delegateNum, uint64_t BpMinVote,
32 VoteDelegateVector &topVoteDelegates, bool isR3Fork) {
33
34 topVoteDelegates.clear();
35 topVoteDelegates.reserve(delegateNum);
36 auto spIt = CreateTopDelegateIterator();
37 for (spIt->First(); spIt->IsValid() && topVoteDelegates.size() < delegateNum; spIt->Next()) {
38 uint64_t vote = spIt->GetVote();
39 if (isR3Fork && vote < BpMinVote) {
40 LogPrint(BCLog::INFO, "[WARN] the %lluTH delegate vote=%llu less than %llu!"
41 " dest_delegate_num=%d\n",
42 topVoteDelegates.size(), spIt->GetVote(), BpMinVote, delegateNum);
43 break;
44 }
45 topVoteDelegates.emplace_back(spIt->GetRegId(), spIt->GetVote());
46 }
47
48 if (topVoteDelegates.empty())
49 return ERRORMSG("[WARN] topVoteDelegates is empty! expected size=%d\n", delegateNum);
50
51 if (topVoteDelegates.size() != delegateNum) {
52 LogPrint(BCLog::INFO, "[WARN] the top delegates size=%d is less than %d"
53 " expected_delegates_size=%d\n",
54 topVoteDelegates.size(), BpMinVote, delegateNum);
55 }
56
57 return true;
58}
59
60bool CDelegateDBCache::SetDelegateVotes(const CRegID &regId, const uint64_t votes) {
61 // If CRegID is empty, ignore received votes for forward compatibility.

Callers 1

GenPendingDelegatesFunction · 0.80

Calls 10

reserveMethod · 0.80
GetVoteMethod · 0.80
emplace_backMethod · 0.80
clearMethod · 0.45
FirstMethod · 0.45
IsValidMethod · 0.45
sizeMethod · 0.45
NextMethod · 0.45
GetRegIdMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected