Skip to content

Commit

Permalink
Adjustable combine threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
Crestington committed Jun 22, 2015
1 parent cdd4058 commit 885ecda
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ std::string HelpMessage()
" -upgradewallet " + _("Upgrade wallet to latest format") + "\n" +
" -keypool=<n> " + _("Set key pool size to <n> (default: 100)") + "\n" +
" -rescan " + _("Rescan the block chain for missing wallet transactions") + "\n" +
" -combinethreshold=<n> " + _("Set stake combine threshold after 14 days within range (default: 30, max: 1000)") + "\n" +
" -salvagewallet " + _("Attempt to recover private keys from a corrupt wallet.dat") + "\n" +
" -checkblocks=<n> " + _("How many blocks to check at startup (default: 2500, 0 = all)") + "\n" +
" -checklevel=<n> " + _("How thorough the block verification is (0-6, default: 1)") + "\n" +
Expand Down Expand Up @@ -571,6 +572,18 @@ bool AppInit2()
}

// ********************************************************* Step 6: network initialization

// Combine threshold
if (mapArgs.count("-combinethreshold"))
{
if (!ParseMoney(mapArgs["-combinethreshold"], nCombineThreshold))
return InitError(strprintf(_("Invalid amount for -combinethreshold=<amount>: '%s'"), mapArgs["-combinethreshold"].c_str()));
else {
if (nCombineThreshold > MAX_COMBINE_AMOUNT)
nCombineThreshold = MAX_COMBINE_AMOUNT;
}
printf("combinethreshold set to %"PRId64"\n",nCombineThreshold);
}

int nSocksVersion = GetArg("-socks", 5);

Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const string strMessageMagic = "PayCon Signed Message:\n";
int64_t nTransactionFee = MIN_TX_FEE;
int64_t nReserveBalance = 0;
int64_t nMinimumInputValue = 0;
int64_t nCombineThreshold = DEF_COMBINE_AMOUNT;

extern enum Checkpoints::CPMode CheckpointsMode;

Expand Down
5 changes: 5 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ static const int MODIFIER_INTERVAL_SWITCH = 7200; // start POS 500 blocks before
inline bool MoneyRange(int64_t nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
// Threshold for nLockTime: below this value it is interpreted as block number, otherwise as UNIX timestamp.
static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC
/** Combine Threshold Default */
static const int64_t DEF_COMBINE_AMOUNT = 30 * COIN;
/** Combine Threshold Max */
static const int64_t MAX_COMBINE_AMOUNT = 1000 * COIN;

#ifdef USE_UPNP
static const int fHaveUPnP = true;
Expand Down Expand Up @@ -97,6 +101,7 @@ extern std::map<unsigned int, unsigned int> mapHashedBlocks; // for liteStake

// Settings
extern int64_t nTransactionFee;
extern int64_t nCombineThreshold;
extern int64_t nReserveBalance;
extern int64_t nMinimumInputValue;
extern bool fUseFastIndex;
Expand Down
1 change: 1 addition & 0 deletions src/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Value getinfo(const Array& params, bool fHelp)
obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance())));
obj.push_back(Pair("newmint", ValueFromAmount(pwalletMain->GetNewMint())));
obj.push_back(Pair("stake", ValueFromAmount(pwalletMain->GetStake())));
obj.push_back(Pair("combine threshold", ValueFromAmount(nCombineThreshold)));
obj.push_back(Pair("blocks", (int)nBestHeight));
obj.push_back(Pair("timeoffset", (boost::int64_t)GetTimeOffset()));
obj.push_back(Pair("moneysupply", ValueFromAmount(pindexBest->nMoneySupply)));
Expand Down
9 changes: 4 additions & 5 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
using namespace std;
extern unsigned int nStakeMaxAge;

unsigned int nStakeSplitAge = 14 * 24 * 60 * 60;
int64_t nStakeCombineThreshold = 200 * COIN;
unsigned int nStakeCombineAge = 14 * 24 * 60 * 60;

int64_t gcd(int64_t n,int64_t m) { return m == 0 ? n : gcd(m, n % m); }
static uint64_t CoinWeightCost(const COutput &out)
Expand Down Expand Up @@ -2206,16 +2205,16 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
if (txNew.vin.size() >= 100)
break;
// Stop adding more inputs if value is already pretty significant
if (nCredit >= nStakeCombineThreshold)
if (nCredit >= nCombineThreshold)
break;
// Stop adding inputs if reached reserve limit
if (nCredit + pcoin.first->vout[pcoin.second].nValue > nBalance - nReserveBalance)
break;
// Do not add additional significant input
if (pcoin.first->vout[pcoin.second].nValue >= nStakeCombineThreshold)
if (pcoin.first->vout[pcoin.second].nValue >= nCombineThreshold)
continue;
// Do not add input that is still too young
if (nTimeWeight < nStakeSplitAge)
if (nTimeWeight < nStakeCombineAge)
continue;

txNew.vin.push_back(CTxIn(pcoin.first->GetHash(), pcoin.second));
Expand Down

0 comments on commit 885ecda

Please sign in to comment.