Skip to content

Commit 89823cc

Browse files
committed
fix coinstake size fee allowance
1 parent 1d3e82d commit 89823cc

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/wallet/wallet.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3787,7 +3787,7 @@ bool CWallet::CreateCoinStake(ChainstateManager& chainman, const CWallet* pwalle
37873787
double difficulty = GetDifficulty(GetLastBlockIndex(chainman.ActiveChain().Tip(), true), chainman.ActiveChain().Tip());
37883788
CAmount supply = chainman.ActiveChain().Tip()->nMoneySupply;
37893789
int maxDayWeight = (params.nStakeMaxAge - params.nStakeMinAge) / (60*60*24);
3790-
double securityLevel = (long(2) << 31)*difficulty / maxDayWeight / (supply/COIN) / params.nStakeTargetSpacing;
3790+
double securityLevel = (uint64_t(2) << 31)*difficulty / maxDayWeight / (supply/COIN) / params.nStakeTargetSpacing;
37913791
bool isTestnet = Params().NetworkIDString() != CBaseChainParams::MAIN;
37923792
CAmount nTargetOutputAmount = SecurityToOptimalFraction(securityLevel, isTestnet)*supply;
37933793

@@ -3826,8 +3826,8 @@ bool CWallet::CreateCoinStake(ChainstateManager& chainman, const CWallet* pwalle
38263826
if (((pcoin->txout.scriptPubKey == scriptPubKeyKernel || pcoin->txout.scriptPubKey == txNew.vout[1].scriptPubKey))
38273827
&& pcoin->outpoint.hash != txNew.vin[0].prevout.hash)
38283828
{
3829-
// Stop adding more inputs if already too many inputs and we are above target
3830-
if ((txNew.vin.size() >= MAX_COINSTAKE_INPUTS) && (nCredit > nTargetOutputAmount))
3829+
// Stop adding more inputs if already too many inputs and we are above target or have minter key to add
3830+
if ((txNew.vin.size() >= MAX_COINSTAKE_INPUTS) && (bMinterKey || nCredit > nTargetOutputAmount))
38313831
break;
38323832
// Stop adding more inputs if we are below target but about to exceed 1kb
38333833
if ((txNew.vin.size() >= 8) && (nCredit < nTargetOutputAmount))
@@ -3861,7 +3861,7 @@ bool CWallet::CreateCoinStake(ChainstateManager& chainman, const CWallet* pwalle
38613861

38623862
CAmount nMinFee = 0;
38633863
int maxOutputs = 30;
3864-
CAmount nMinFeeBase = (IsProtocolV07(txNew.nTime) ? MIN_TX_FEE : MIN_TX_FEE_PREV7);
3864+
CAmount nSubsidizedFee = PERKB_TX_FEE;
38653865
while(true)
38663866
{
38673867
// Clear outputs
@@ -3891,7 +3891,9 @@ bool CWallet::CreateCoinStake(ChainstateManager& chainman, const CWallet* pwalle
38913891
// Add remainder to first output
38923892
txNew.vout.push_back(CTxOut(outValue + (i == 0 ? remainder : 0), scriptPubKeyOut));
38933893
// make sure transaction below 1kb
3894-
if (::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION) > 1024) {
3894+
if (::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION) > 1000) {
3895+
if (!i)
3896+
return error("CreateCoinStake : failed to create coinstake");
38953897
// Remove output that goes over max size and set maxOutputs so that the logic can be re-run
38963898
txNew.vout.pop_back();
38973899
outputsOk = false;
@@ -3935,7 +3937,12 @@ bool CWallet::CreateCoinStake(ChainstateManager& chainman, const CWallet* pwalle
39353937
return error("CreateCoinStake : exceeded coinstake size limit");
39363938

39373939
// Check enough fee is paid
3938-
CAmount nNeededFee = GetMinFee(CTransaction(txNew), txNew.nTime) - nMinFeeBase;
3940+
CAmount nTxnFee = GetMinFee(CTransaction(txNew), txNew.nTime);
3941+
CAmount nNeededFee = 0;
3942+
3943+
if (nTxnFee > nSubsidizedFee)
3944+
nNeededFee = nTxnFee - nSubsidizedFee;
3945+
39393946
// If not enough fee paid or max outputs have changed requiring a new split and fee, run again
39403947
if (nMinFee < nNeededFee || !outputsOk) {
39413948
nMinFee = nNeededFee;

0 commit comments

Comments
 (0)