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

Function ShuffleDelegates

src/miner/miner.cpp:164–185  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

162}
163
164void ShuffleDelegates(const int32_t curHeight, const int64_t blockTime, VoteDelegateVector &delegates) {
165
166 int64_t oriSeed = GetShuffleOriginSeed( curHeight,blockTime );
167 auto totalDelegateNum = delegates.size();
168
169 string seedSource = strprintf("%u", oriSeed / totalDelegateNum + (oriSeed % totalDelegateNum > 0 ? 1 : 0));
170 CHashWriter ss(SER_GETHASH, 0);
171 ss << seedSource;
172 uint256 currentSeed = ss.GetHash();
173 uint64_t newIndexSource = 0;
174 for (uint32_t i = 0; i < totalDelegateNum; i++) {
175 for (uint32_t x = 0; x < 4 && i < totalDelegateNum; i++, x++) {
176 memcpy(&newIndexSource, currentSeed.begin() + (x * 8), 8);
177 uint32_t newIndex = newIndexSource % totalDelegateNum;
178 VoteDelegate delegate = delegates[newIndex];
179 delegates[newIndex] = delegates[i];
180 delegates[i] = delegate;
181 }
182 ss << currentSeed;
183 currentSeed = ss.GetHash();
184 }
185}
186
187
188bool VerifyRewardTx(const CBlock *pBlock, CCacheWrapper &cwIn, VoteDelegate &curDelegateOut, uint32_t& totalDelegateNumOut) {

Callers 3

getminerbyblocktimeFunction · 0.85
VerifyRewardTxFunction · 0.85
GetMinerFunction · 0.85

Calls 5

GetShuffleOriginSeedFunction · 0.85
memcpyFunction · 0.85
sizeMethod · 0.45
GetHashMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected