Skip to content

Commit 9558cc7

Browse files
committed
Remove duplicated code block and add desired UTXO size
1 parent 8935c0c commit 9558cc7

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

src/miner.cpp

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ bool GetSideStakingStatusAndAlloc(SideStakeAlloc& vSideStakeAlloc)
12831283

12841284
// This function parses the config file for the directives for stake splitting. It is used
12851285
// in StakeMiner for the miner loop and also called by rpc getmininginfo.
1286-
bool GetStakeSplitStatusAndParams(int64_t& nMinStakeSplitValue, double& dEfficiency)
1286+
bool GetStakeSplitStatusAndParams(int64_t& nMinStakeSplitValue, double& dEfficiency, int64_t& nDesiredStakeOutputValue)
12871287
{
12881288
// Parse StakeSplit and SideStaking flags.
12891289
bool fEnableStakeSplit = GetBoolArg("-enablestakesplit");
@@ -1306,6 +1306,18 @@ bool GetStakeSplitStatusAndParams(int64_t& nMinStakeSplitValue, double& dEfficie
13061306
nMinStakeSplitValue = max(GetArg("-minstakesplitvalue", MIN_STAKE_SPLIT_VALUE_GRC), MIN_STAKE_SPLIT_VALUE_GRC) * COIN;
13071307

13081308
LogPrintf("StakeMiner: nMinStakeSplitValue = %f", CoinToDouble(nMinStakeSplitValue));
1309+
1310+
// For the definition of the constant G, please see
1311+
// https://docs.google.com/document/d/1OyuTwdJx1Ax2YZ42WYkGn_UieN0uY13BTlA5G5IAN00/edit?usp=sharing
1312+
// Refer to page 5 for G. This link is a draft of an upcoming bluepaper section.
1313+
const double G = 9942.2056;
1314+
1315+
// Desired UTXO size post stake based on passed in efficiency and difficulty, but do not allow to go below
1316+
// passed in MinStakeSplitValue. Note that we use GetAverageDifficulty over a 4 hour (160 block period) rather than
1317+
// StakeKernelDiff, because the block to block difficulty has too much scatter. Please refer to the above link,
1318+
// equation (27) on page 10 as a reference for the below formula.
1319+
nDesiredStakeOutputValue = G * GetAverageDifficulty(160) * (3.0 / 2.0) * (1 / dEfficiency - 1) * COIN;
1320+
nDesiredStakeOutputValue = max(nMinStakeSplitValue, nDesiredStakeOutputValue);
13091321
}
13101322

13111323
return fEnableStakeSplit;
@@ -1328,25 +1340,6 @@ void StakeMiner(CWallet *pwallet)
13281340
// vSideStakeAlloc is an out parameter.
13291341
bool fEnableSideStaking = GetSideStakingStatusAndAlloc(vSideStakeAlloc);
13301342

1331-
// If stake output splitting is enabled, determine efficiency and minimum stake split value.
1332-
if (fEnableStakeSplit)
1333-
{
1334-
// Pull efficiency for UTXO staking from config, but constrain to the interval [0.75, 0.98]. Use default of 0.90.
1335-
dEfficiency = (double)GetArg("-stakingefficiency", 90) / 100;
1336-
if (dEfficiency > 0.98)
1337-
dEfficiency = 0.98;
1338-
else if (dEfficiency < 0.75)
1339-
dEfficiency = 0.75;
1340-
1341-
LogPrintf("StakeMiner: dEfficiency = %f", dEfficiency);
1342-
1343-
// Pull Minimum Post Stake UTXO Split Value from config or command line parameter.
1344-
// Default to 800 and do not allow it to be specified below 800 GRC.
1345-
nMinStakeSplitValue = max(GetArg("-minstakesplitvalue", MIN_STAKE_SPLIT_VALUE_GRC), MIN_STAKE_SPLIT_VALUE_GRC) * COIN;
1346-
1347-
LogPrintf("StakeMiner: nMinStakeSplitValue = %f", CoinToDouble(nMinStakeSplitValue));
1348-
}
1349-
13501343
supercfwd::fEnable= GetBoolArg("-supercfwd",true);
13511344
if(fDebug) LogPrintf("supercfwd::fEnable= %d",supercfwd::fEnable);
13521345

src/miner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ static const int64_t MIN_STAKE_SPLIT_VALUE_GRC = 800;
4949
void SplitCoinStakeOutput(CBlock &blocknew, int64_t &nReward, bool &fEnableStakeSplit, bool &fEnableSideStaking, SideStakeAlloc &vSideStakeAlloc, double &dEfficiency);
5050
unsigned int GetNumberOfStakeOutputs(int64_t &nValue, int64_t &nMinStakeSplitValue, double &dEfficiency);
5151
bool GetSideStakingStatusAndAlloc(SideStakeAlloc& vSideStakeAlloc);
52-
bool GetStakeSplitStatusAndParams(int64_t& nMinStakeSplitValue, double& dEfficiency);
52+
bool GetStakeSplitStatusAndParams(int64_t& nMinStakeSplitValue, double& dEfficiency, int64_t& nDesiredStakeOutputValue);
5353

5454
#endif // NOVACOIN_MINER_H

src/rpcmining.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ UniValue getmininginfo(const UniValue& params, bool fHelp)
6969

7070
int64_t nMinStakeSplitValue = 0;
7171
double dEfficiency = 0;
72+
int64_t nDesiredStakeSplitValue = 0;
7273
SideStakeAlloc vSideStakeAlloc;
7374

74-
// nMinStakeSplitValue and dEfficiency are out parameters.
75-
bool fEnableStakeSplit = GetStakeSplitStatusAndParams(nMinStakeSplitValue, dEfficiency);
75+
// nMinStakeSplitValue, dEfficiency, and nDesiredStakeSplitValue are out parameters.
76+
bool fEnableStakeSplit = GetStakeSplitStatusAndParams(nMinStakeSplitValue, dEfficiency, nDesiredStakeSplitValue);
7677

7778
// vSideStakeAlloc is an out parameter.
7879
bool fEnableSideStaking = GetSideStakingStatusAndAlloc(vSideStakeAlloc);
@@ -82,6 +83,7 @@ UniValue getmininginfo(const UniValue& params, bool fHelp)
8283
{
8384
stakesplittingparam.pushKV("min-stake-split-value", nMinStakeSplitValue / COIN);
8485
stakesplittingparam.pushKV("efficiency", dEfficiency);
86+
stakesplittingparam.pushKV("stake-split-UTXO-size-for-target-efficiency", nDesiredStakeSplitValue / COIN);
8587
stakesplitting.pushKV("stake-splitting-params", stakesplittingparam);
8688
}
8789
obj.pushKV("stake-splitting", stakesplitting);

0 commit comments

Comments
 (0)