Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shuffle vSideStakeAlloc if necessary #1532

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <memory>
#include <algorithm>
#include <tuple>
#include <random>

using namespace std;

Expand Down Expand Up @@ -637,6 +638,22 @@ void SplitCoinStakeOutput(CBlock &blocknew, int64_t &nReward, bool &fEnableStake
// Initialize nOutputUsed at 1, because one is already used for the empty coinstake flag output.
unsigned int nOutputsUsed = 1;

// If the number of sidestaking allocation entries exceeds nMaxSideStakeOutputs, then shuffle the vSideStakeAlloc
// to support sidestaking with more than six entries. This is a super simple solution but has some disadvantages.
// If the person made a mistake and has the entries in the config file add up to more than 100%, then those entries
// resulting a cumulative total over 100% will always be excluded, not just randomly excluded, because the cumulative
// check is done in the order of the entries in the config file. This is not regarded as a big issue, because
// all of the entries are supposed to add up to less than or equal to 100%. Also when there are more than
// mMaxSideStakeOutput entries, the residual returned to the coinstake will vary when the entries are shuffled,
// because the total percentage of the selected entries will be randomized. No attempt to renormalize
// the percentages is done.
if (vSideStakeAlloc.size() > nMaxSideStakeOutputs)
{
unsigned int seed = static_cast<unsigned int>(GetAdjustedTime());

std::shuffle(vSideStakeAlloc.begin(), vSideStakeAlloc.end(), std::default_random_engine(seed));
}

// Initialize remaining stake output value to the total value of output for stake, which also includes
// (interest or CBR) and research rewards.
int64_t nRemainingStakeOutputValue = blocknew.vtx[1].vout[1].nValue;
Expand Down