Skip to content

Commit

Permalink
Staking Enhanced
Browse files Browse the repository at this point in the history
Select inputs by time rather than depth in a block chain (-stakemintime).

-minstakinginput renamed to -stakeminvalue.

Defaults for -minersleep, -stakecombine and -stakesplit adjusted.
  • Loading branch information
ghostlander committed Apr 16, 2016
1 parent d58a296 commit 7108583
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 36 deletions.
44 changes: 26 additions & 18 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ unsigned int nNodeLifespan;
unsigned int nDerivationMethodIndex;
unsigned int nMsgSleep;
unsigned int nMinerSleep;
unsigned int nStakeMinDepth;
bool fUseFastStakeMiner;
uint nStakeMinTime;
uint nStakeMinDepth;
enum Checkpoints::CPMode CheckpointsMode;

/* Assembly level processor optimisation features */
Expand Down Expand Up @@ -331,10 +331,11 @@ std::string HelpMessage()

"\n" + _("Staking options:") + "\n" +
" -stakegen=<n> " + _("Generate coin stakes (default: 1 = enabled)") + "\n" +
" -stakemindepth=<n> " + _("Set the min. stake input depth value in confirmations (default: 10000 or testnet: 100)") + "\n" +
" -minstakinginput=<n> " + _("Set the min. stake input amount in coins (default: 1.0)") + "\n" +
" -stakecombine=<n> " + _("Try to combine inputs while staking up to this limit in coins (20 < n < 50; default: 20)") + "\n";
" -stakesplit=<n> " + _("Don't split outputs while staking below this limit in coins (40 < n < 100; default: 40)") + "\n";
" -stakemintime=<n> " + _("Set the min. stake input block chain time in hours (default: 48 or testnet: 1)") + "\n" +
" -stakemindepth=<n> " + _("Set the min. stake input block chain depth in confirmations (default: follow -stakeminage)") + "\n" +
" -stakeminvalue=<n> " + _("Set the min. stake input value in coins (default: 1.0)") + "\n" +
" -stakecombine=<n> " + _("Try to combine inputs while staking up to this limit in coins (20 < n < 200; default: 20)") + "\n";
" -stakesplit=<n> " + _("Don't split outputs while staking below this limit in coins (40 < n < 400; default: 80)") + "\n";

return strUsage;
}
Expand Down Expand Up @@ -414,10 +415,17 @@ bool AppInit2()
/* Polling delay for message handling, in milliseconds */
nMsgSleep = GetArg("-msgsleep", 20);
/* Polling delay for stake mining, in milliseconds */
nMinerSleep = GetArg("-minersleep", 500);
/* Minimal input depth (age) for stake mining, in confirmations */
if(fTestNet) nStakeMinDepth = GetArg("-stakemindepth", 100);
else nStakeMinDepth = GetArg("-stakemindepth", 10000);
nMinerSleep = GetArg("-minersleep", 2000);
/* Minimal input time or depth in block chain for stake mining, in hours or confirmations */
if(fTestNet) {
nStakeMinTime = GetArg("-stakemintime", 1);
nStakeMinDepth = GetArg("-stakemindepth", 0);
} else {
nStakeMinTime = GetArg("-stakemintime", 48);
nStakeMinDepth = GetArg("-stakemindepth", 0);
}
/* Reset time if depth is specified */
if(nStakeMinDepth) nStakeMinTime = 0;

CheckpointsMode = Checkpoints::STRICT;
std::string strCpMode = GetArg("-cppolicy", "strict");
Expand Down Expand Up @@ -523,10 +531,10 @@ bool AppInit2()
}

/* Inputs below this limit in value don't participate in staking */
if(mapArgs.count("-minstakinginput")) {
if(!ParseMoney(mapArgs["-minstakinginput"], nMinStakingInputValue))
return(InitError(strprintf(_("Invalid amount for -minstakinginput=<amount>: '%s'"),
mapArgs["-minstakinginput"].c_str())));
if(mapArgs.count("-stakeminvalue")) {
if(!ParseMoney(mapArgs["-stakeminvalue"], nStakeMinValue))
return(InitError(strprintf(_("Invalid amount for -stakeminvalue=<amount>: '%s'"),
mapArgs["-stakeminvalue"].c_str())));
}

/* Try to combine inputs while staking up to this limit */
Expand All @@ -536,8 +544,8 @@ bool AppInit2()
mapArgs["-stakecombine"].c_str())));
if(nCombineThreshold < MIN_STAKE_AMOUNT)
nCombineThreshold = MIN_STAKE_AMOUNT;
if(nCombineThreshold > 2.5 * MIN_STAKE_AMOUNT)
nCombineThreshold = 2.5 * MIN_STAKE_AMOUNT;
if(nCombineThreshold > 10 * MIN_STAKE_AMOUNT)
nCombineThreshold = 10 * MIN_STAKE_AMOUNT;
}

/* Don't split outputs while staking below this limit */
Expand All @@ -547,8 +555,8 @@ bool AppInit2()
mapArgs["-stakesplit"].c_str())));
if(nSplitThreshold < 2 * MIN_STAKE_AMOUNT)
nSplitThreshold = 2 * MIN_STAKE_AMOUNT;
if(nSplitThreshold > 5 * MIN_STAKE_AMOUNT)
nSplitThreshold = 5 * MIN_STAKE_AMOUNT;
if(nSplitThreshold > 20 * MIN_STAKE_AMOUNT)
nSplitThreshold = 20 * MIN_STAKE_AMOUNT;
}

/* Controls proof-of-stake generation */
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const string strMessageMagic = "Orbitcoin Signed Message:\n";
// Settings
int64 nTransactionFee = MIN_TX_FEE;
int64 nMinimumInputValue = TX_DUST;
int64 nMinStakingInputValue = 1 * COIN;
int64 nStakeMinValue = 1 * COIN;

extern enum Checkpoints::CPMode CheckpointsMode;

Expand Down
2 changes: 1 addition & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ extern std::map<uint256, CBlock*> mapOrphanBlocks;
// Settings
extern int64 nTransactionFee;
extern int64 nMinimumInputValue;
extern int64 nMinStakingInputValue;
extern int64 nStakeMinValue;
extern int64 nCombineThreshold;
extern int64 nSplitThreshold;
extern uint nStakeMinAgeOne;
Expand Down
7 changes: 5 additions & 2 deletions src/rpcmining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ Value getmininginfo(const Array& params, bool fHelp)
obj.push_back(Pair("minweightinputs", (boost::uint64_t)nMinWeightInputs));
obj.push_back(Pair("avgweightinputs", (boost::uint64_t)nAvgWeightInputs));
obj.push_back(Pair("maxweightinputs", (boost::uint64_t)nMaxWeightInputs));
obj.push_back(Pair("stakemindepth", (int)nStakeMinDepth));
obj.push_back(Pair("minstakinginput", ValueFromAmount(nMinStakingInputValue)));
if(nStakeMinTime)
obj.push_back(Pair("stakemintime", (int)nStakeMinTime));
else
obj.push_back(Pair("stakemindepth", (int)nStakeMinDepth));
obj.push_back(Pair("stakeminvalue", ValueFromAmount(nStakeMinValue)));
obj.push_back(Pair("stakecombine", ValueFromAmount(nCombineThreshold)));
obj.push_back(Pair("stakesplit", ValueFromAmount(nSplitThreshold)));
obj.push_back(Pair("pooledtx", (boost::uint64_t)mempool.size()));
Expand Down
3 changes: 2 additions & 1 deletion src/test/test_orbitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
/* All unresolved externs of init.cpp */
unsigned int nMsgSleep = 20;
unsigned int nMinerSleep = 2000;
unsigned int nStakeMinDepth = 5000;
uint nStakeMinTime = 48;
uint nStakeMinDepth = 0;
unsigned int nNodeLifespan = 7;
unsigned int nDerivationMethodIndex = 0;

Expand Down
1 change: 1 addition & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ extern uint64 nModifierCacheMisses;
extern uint64 nInputCacheHits;
extern uint64 nInputCacheMisses;

extern uint nStakeMinTime;
extern uint nStakeMinDepth;
extern long long nLastWalletStakeTime;
extern unsigned long long nMinWeightInputs;
Expand Down
22 changes: 12 additions & 10 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1212,9 +1212,9 @@ int64 nCoinsCacheValue = 0;
uint nCoinsCacheTime = 0;
const uint nCoinsCacheInterval = 600; /* 10 minutes */

/* Quick cacheable selection of inputs for staking at the depth specified */
bool CWallet::SelectCoinsStaking(int64 nTargetValue, int nStakeMinDepth,
set<pair<const CWalletTx*, uint> >& setCoinsRet, int64& nValueRet) const {
/* Quick cacheable selection of inputs for staking */
bool CWallet::SelectCoinsStaking(int64 nTargetValue,
set<pair<const CWalletTx *, uint> > &setCoinsRet, int64 &nValueRet) const {

uint nCurrentTime = GetTime();
if(nCurrentTime < (nCoinsCacheTime + nCoinsCacheInterval)) {
Expand Down Expand Up @@ -1245,14 +1245,16 @@ bool CWallet::SelectCoinsStaking(int64 nTargetValue, int nStakeMinDepth,
/* May be negative (failed transactions) */
nDepth = pcoin->GetDepthInMainChain();

/* Discard if the depth requirement is unmet */
if(nDepth < nStakeMinDepth)
/* Discard if the time (depth) requirement is unmet */
if(nStakeMinTime && ((nCurrentTime - nStakeMinTime * 60 * 60) < pcoin->nTime))
continue;
if(!nStakeMinTime && (nDepth < (int)nStakeMinDepth))
continue;

for(i = 0; i < pcoin->vout.size(); i++) {
/* Must be unspent and above the limit in value */
if(!(pcoin->IsSpent(i)) && IsMine(pcoin->vout[i])
&& (pcoin->vout[i].nValue >= nMinStakingInputValue))
&& (pcoin->vout[i].nValue >= nStakeMinValue))
vCoins.push_back(COutput(pcoin, i, nDepth));
}
}
Expand Down Expand Up @@ -1468,8 +1470,8 @@ bool CWallet::GetStakeWeight(const CKeyStore& keystore, uint64& nMinWeightInputs
set<pair<const CWalletTx*,unsigned int> > setCoins;
int64 nValueIn = 0;

/* Select aged coins by depth in the main chain */
if(!SelectCoinsStaking(nBalance - nReserveBalance, nStakeMinDepth, setCoins, nValueIn))
/* Select aged coins */
if(!SelectCoinsStaking(nBalance - nReserveBalance, setCoins, nValueIn))
return(false);

if(setCoins.empty()) return(false);
Expand Down Expand Up @@ -1540,8 +1542,8 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, uint nBits, int64 nSear
set<pair<const CWalletTx*, uint> > setCoins;
int64 nValueIn = 0;

/* Select aged coins by depth in the main chain */
if(!SelectCoinsStaking(nBalance - nReserveBalance, nStakeMinDepth, setCoins, nValueIn))
/* Select aged coins */
if(!SelectCoinsStaking(nBalance - nReserveBalance, setCoins, nValueIn))
return(false);

if(setCoins.empty()) return(false);
Expand Down
6 changes: 3 additions & 3 deletions src/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ class CWallet : public CCryptoKeyStore
bool SelectCoins(int64 nTargetValue, uint nSpendTime,
std::set<std::pair<const CWalletTx*, uint> >& setCoinsRet, int64& nValueRet,
const CCoinControl *coinControl=NULL) const;
/* Quick cacheable selection of inputs for staking at the depth specified */
bool SelectCoinsStaking(int64 nTargetValue, int nStakeMinDepth,
std::set<std::pair<const CWalletTx*, uint> >& setCoinsRet, int64& nValueRet) const;
/* Quick cacheable selection of inputs for staking */
bool SelectCoinsStaking(int64 nTargetValue,
std::set<std::pair<const CWalletTx *, uint> > &setCoinsRet, int64 &nValueRet) const;

CWalletDB *pwalletdbEncryption;

Expand Down

0 comments on commit 7108583

Please sign in to comment.