@@ -3787,7 +3787,7 @@ bool CWallet::CreateCoinStake(ChainstateManager& chainman, const CWallet* pwalle
3787
3787
double difficulty = GetDifficulty (GetLastBlockIndex (chainman.ActiveChain ().Tip (), true ), chainman.ActiveChain ().Tip ());
3788
3788
CAmount supply = chainman.ActiveChain ().Tip ()->nMoneySupply ;
3789
3789
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 ;
3791
3791
bool isTestnet = Params ().NetworkIDString () != CBaseChainParams::MAIN;
3792
3792
CAmount nTargetOutputAmount = SecurityToOptimalFraction (securityLevel, isTestnet)*supply;
3793
3793
@@ -3826,8 +3826,8 @@ bool CWallet::CreateCoinStake(ChainstateManager& chainman, const CWallet* pwalle
3826
3826
if (((pcoin->txout .scriptPubKey == scriptPubKeyKernel || pcoin->txout .scriptPubKey == txNew.vout [1 ].scriptPubKey ))
3827
3827
&& pcoin->outpoint .hash != txNew.vin [0 ].prevout .hash )
3828
3828
{
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))
3831
3831
break ;
3832
3832
// Stop adding more inputs if we are below target but about to exceed 1kb
3833
3833
if ((txNew.vin .size () >= 8 ) && (nCredit < nTargetOutputAmount))
@@ -3861,7 +3861,7 @@ bool CWallet::CreateCoinStake(ChainstateManager& chainman, const CWallet* pwalle
3861
3861
3862
3862
CAmount nMinFee = 0 ;
3863
3863
int maxOutputs = 30 ;
3864
- CAmount nMinFeeBase = ( IsProtocolV07 (txNew. nTime ) ? MIN_TX_FEE : MIN_TX_FEE_PREV7) ;
3864
+ CAmount nSubsidizedFee = PERKB_TX_FEE ;
3865
3865
while (true )
3866
3866
{
3867
3867
// Clear outputs
@@ -3891,7 +3891,9 @@ bool CWallet::CreateCoinStake(ChainstateManager& chainman, const CWallet* pwalle
3891
3891
// Add remainder to first output
3892
3892
txNew.vout .push_back (CTxOut (outValue + (i == 0 ? remainder : 0 ), scriptPubKeyOut));
3893
3893
// 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" );
3895
3897
// Remove output that goes over max size and set maxOutputs so that the logic can be re-run
3896
3898
txNew.vout .pop_back ();
3897
3899
outputsOk = false ;
@@ -3935,7 +3937,12 @@ bool CWallet::CreateCoinStake(ChainstateManager& chainman, const CWallet* pwalle
3935
3937
return error (" CreateCoinStake : exceeded coinstake size limit" );
3936
3938
3937
3939
// 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
+
3939
3946
// If not enough fee paid or max outputs have changed requiring a new split and fee, run again
3940
3947
if (nMinFee < nNeededFee || !outputsOk) {
3941
3948
nMinFee = nNeededFee;
0 commit comments