Skip to content

Commit

Permalink
CoinStake Updates
Browse files Browse the repository at this point in the history
Add Split Threshold (Hat tip ghostlander ORB)
Update Combine Threshold
Default both to 5.
Allow user to change these settings (within range) by startup parms.  (
-splitthreshold and -combinethreshold )
  • Loading branch information
Tranz5 committed Sep 27, 2014
1 parent 88f579b commit c9e91a0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
26 changes: 25 additions & 1 deletion src/init.cpp
Expand Up @@ -304,6 +304,8 @@ std::string HelpMessage()
" -keypool=<n> " + _("Set key pool size to <n> (default: 100)") + "\n" +
" -rescan " + _("Rescan the block chain for missing wallet transactions") + "\n" +
" -zapwallettxes " + _("Clear list of wallet transactions (diagnostic tool; implies -rescan)") + "\n" +
" -splitthreshold=<n> " + _("Set stake split threshold within range (default 5),(max 20))") + "\n" +
" -combinethreshold=<n> " + _("Set stake combine threshold within range (default 5),(max 20))") + "\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 @@ -584,7 +586,7 @@ bool AppInit2()
if (mapArgs.count("-mininput"))
{
if (!ParseMoney(mapArgs["-mininput"], nMinimumInputValue))
return InitError(strprintf(_("Invalid amount for -mininput=<amount>: '%s'"), mapArgs["-mininput"].c_str()));
return InitError(strprintf(_("Invalid amount for -mininput=<amount>: '%s'"), mapArgs["-mininput"].c_str()));
}

// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
Expand Down Expand Up @@ -674,6 +676,28 @@ bool AppInit2()
return InitError(_("wallet.dat corrupt, salvage failed"));
}

if (mapArgs.count("-splitthreshold"))
{
if (!ParseMoney(mapArgs["-splitthreshold"], nSplitThreshold))
return InitError(strprintf(_("Invalid amount for -splitthreshold=<amount>: '%s'"), mapArgs["-splitthreshold"].c_str()));
else {
if (nSplitThreshold > MAX_SPLIT_AMOUNT)
nSplitThreshold = MAX_SPLIT_AMOUNT;
}
printf("splitthreshold set to %"PRI64d"\n",nSplitThreshold);
}

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 %"PRI64d"\n",nCombineThreshold);
}

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

RegisterNodeSignals(GetNodeSignals());
Expand Down
2 changes: 2 additions & 0 deletions src/main.cpp
Expand Up @@ -78,6 +78,8 @@ int64 nHPSTimerStart;
// Settings
int64 nTransactionFee = MIN_TX_FEE;
int64 nMinimumInputValue = MIN_TX_FEE;
int64 nSplitThreshold = GetProofOfWorkReward();
int64 nCombineThreshold = GetProofOfWorkReward();
extern enum Checkpoints::CPMode CheckpointsMode;


Expand Down
6 changes: 6 additions & 0 deletions src/main.h
Expand Up @@ -55,6 +55,10 @@ static const int64 MAX_MINT_PROOF_OF_STAKE_FIX = 1000 * CENT;// Incorrect value
static const int64 MAX_MINT_PROOF_OF_STAKE_FIX2 = 100 * CENT; // Correct just right
/** Transactions smaller then this are ignored */
static const int64 MIN_TXOUT_AMOUNT = MIN_TX_FEE;
/** Split/Combine Threshold Max */
static const int64 MAX_SPLIT_AMOUNT = 20 * COIN;
static const int64 MAX_COMBINE_AMOUNT = MAX_SPLIT_AMOUNT;


/** Hard Fork Change Times */
static const unsigned int PROTOCOL_SWITCH_TIME = 1371686400; // 20 Jun 2013 00:00:00
Expand Down Expand Up @@ -111,6 +115,8 @@ extern bool fReindex;
// Settings
extern int64 nTransactionFee;
extern int64 nMinimumInputValue;
extern int64 nCombineThreshold;
extern int64 nSplitThreshold;
extern bool fUseFastIndex;

// Minimum disk space required - used in CheckDiskSpace()
Expand Down
14 changes: 9 additions & 5 deletions src/qt/bitcoingui.cpp
Expand Up @@ -685,11 +685,13 @@ void BitcoinGUI::stakingIconClicked()
"Current Wallet Version: %9\n"
"Current Wallet PoS Weight: %10\n"
"Current Wallet Reserve Balance: %11\n\n"
"Stake for Charity Address: %12\n"
"Stake for Charity Percentage: %13\n\n"
"Total Wallets Loaded: %14\n"
"Total Wallets PoS Weight: %15\n\n"
"Network Money Supply: %16\n")
"Stake Split Threshold %12\n"
"Stake Combine Threshold %13\n\n"
"Stake for Charity Address: %14\n"
"Stake for Charity Percentage: %15\n\n"
"Total Wallets Loaded: %16\n"
"Total Wallets PoS Weight: %17\n\n"
"Network Money Supply: %18\n")
.arg(clientModel->formatFullVersion())
.arg(clientModel->getProtocolVersion())
.arg(clientModel->getLastPoSBlock())
Expand All @@ -701,6 +703,8 @@ void BitcoinGUI::stakingIconClicked()
.arg(walletStack->getWalletVersion())
.arg(nWeight)
.arg(BitcoinUnits::formatWithUnit(unit, walletStack->getReserveBalance()))
.arg(BitcoinUnits::formatWithUnit(unit, nSplitThreshold, false))
.arg(BitcoinUnits::formatWithUnit(unit, nCombineThreshold, false))
.arg(walletStack->getStakeForCharityAddress())
.arg(walletStack->getStakeForCharityPercent())
.arg(walletManager->GetWalletCount())
Expand Down
4 changes: 2 additions & 2 deletions src/wallet.cpp
Expand Up @@ -1643,7 +1643,6 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
// The following split & combine thresholds are important to security
// Should not be adjusted if you don't understand the consequences
static unsigned int nStakeSplitAge = (60 * 60 * 24 * 90);
int64 nCombineThreshold = GetProofOfWorkReward() / 3;

CBlockIndex* pindexPrev = pindexBest;
CBigNum bnTargetPerCoinDay;
Expand Down Expand Up @@ -1765,7 +1764,8 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
nCredit += pcoin.first->vout[pcoin.second].nValue;
vwtxPrev.push_back(pcoin.first);
txNew.vout.push_back(CTxOut(0, scriptPubKeyOut));
if (block.GetBlockTime() + nStakeSplitAge > txNew.nTime)

if((nCredit >= nSplitThreshold) && (block.GetBlockTime() + nStakeSplitAge > txNew.nTime))
txNew.vout.push_back(CTxOut(0, scriptPubKeyOut)); // split stake
if (fDebug && fPrintCoinStake)
printf("CreateCoinStake : added kernel type=%d\n", whichType);
Expand Down

0 comments on commit c9e91a0

Please sign in to comment.