Skip to content

Commit

Permalink
Respect reserve balance.
Browse files Browse the repository at this point in the history
Debug output adjust.
  • Loading branch information
tomasbrod committed Jun 1, 2017
1 parent d023860 commit 3948628
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1001,17 +1001,16 @@ bool CreateCoinStake( CBlock &blocknew, CKey &key,

int64_t BalanceToStake = wallet.GetBalance();
int64_t nValueIn = 0;
//if( GetBoolArg("-stakeall",
//BalanceToStake -= nReserveBalance;
BalanceToStake*=2;
//Request all the coins here, check reserve later

if ( BalanceToStake<=0
|| !wallet.SelectCoinsForStaking(BalanceToStake, txnew.nTime, CoinsToStake, nValueIn) )
|| !wallet.SelectCoinsForStaking(BalanceToStake*2, txnew.nTime, CoinsToStake, nValueIn) )
{
msMiningErrors5+="No coins to stake; ";
if (fDebug) printf("CreateCoinStake: %s",msMiningErrors5.c_str());
return false;
}
BalanceToStake -= nReserveBalance;

if(fDebug) printf("\nCreateCoinStake: Staking nTime/16= %d Bits= %u\n",
txnew.nTime/16,blocknew.nBits);
Expand Down Expand Up @@ -1039,6 +1038,9 @@ bool CreateCoinStake( CBlock &blocknew, CKey &key,
if (CoinBlock.GetBlockTime() + nStakeMinAge > txnew.nTime)
continue;

if (CoinTx.vout[CoinTxN].nValue > BalanceToStake)
continue;

NetworkTimer();
int64_t CoinWeight = CalculateStakeWeightV3(CoinTx,CoinTxN,GlobalCPUMiningCPID);
CBigNum StakeTarget;
Expand All @@ -1047,7 +1049,7 @@ bool CreateCoinStake( CBlock &blocknew, CKey &key,
StakeWeightSum += CoinWeight;
CBigNum StakeKernelHash= CalculateStakeHashV3(CoinBlock,CoinTx,CoinTxN,txnew.nTime,GlobalCPUMiningCPID,mdPORNonce);

printf(
if (fDebug) printf(
"CreateCoinStake: Time %.f, Por_Nonce %.f, Bits %jd, Weight %jd\n"
" Stk %72s\n"
" Trg %72s\n",
Expand Down Expand Up @@ -1136,7 +1138,7 @@ bool SignStakeBlock(CBlock &block, CKey &key, vector<const CWalletTx*> &StakeInp
if (!SignSignature(*pwallet, *pcoin, block.vtx[1], nIn++))
{
msMiningErrors5+="Failed to sign coinstake; ";
return error("CreateCoinStake: failed to sign coinstake");
return error("SignStakeBlock: failed to sign coinstake");
}
}

Expand All @@ -1145,7 +1147,7 @@ bool SignStakeBlock(CBlock &block, CKey &key, vector<const CWalletTx*> &StakeInp
if( !key.Sign(block.GetHash(), block.vchBlockSig) )
{
msMiningErrors5+="Failed to sign block; ";
return error("CreateCoinStake: failed to sign block");
return error("SignStakeBlock: failed to sign block");
}

return true;
Expand Down Expand Up @@ -1205,20 +1207,20 @@ bool CreateGridcoinReward(CBlock &blocknew, uint64_t &nCoinAge, CBlockIndex* pin
std::string SerializedBoincData = SerializeBoincBlock(miningcpid);
GlobalCPUMiningCPID.lastblockhash = miningcpid.lastblockhash;

if (fDebug) printf("CreateCoinStakeHashboinc: %s\r\n",SerializedBoincData.c_str());
if (fDebug) printf("CreateGridcoinReward: %s\r\n",SerializedBoincData.c_str());

double mint = CoinToDouble(nReward);
double PORDiff = GetBlockDifficulty(blocknew.nBits);
double mintlimit = MintLimiter(PORDiff,RSA_WEIGHT,miningcpid.cpid,blocknew.nTime);

printf("Creating POS Reward for %s mint %f {RSAWeight %f} Research %f, Interest %f \r\n",
printf("CreateGridcoinReward: for %s mint %f {RSAWeight %f} Research %f, Interest %f \r\n",
miningcpid.cpid.c_str(), mint, (double)RSA_WEIGHT,miningcpid.ResearchSubsidy,miningcpid.InterestSubsidy);

//INVESTORS
if (nReward == 0 || mint < mintlimit)
{
msMiningErrors5+="Mint "+RoundToString(mint,6)+" too small (min "+RoundToString(mintlimit,6)+"); ";
return error("CreateCoinStake: Mint %f of %f too small",(double)mint,(double)mintlimit);
return error("CreateGridcoinReward: Mint %f of %f too small",(double)mint,(double)mintlimit);
}

//fill in reward and boinc
Expand Down Expand Up @@ -1263,13 +1265,12 @@ bool IsMiningAllowed(CWallet *pwallet)
return false;
}

/*if (OutOfSyncByAgeWithChanceOfMining())
if (OutOfSyncByAgeWithChanceOfMining())
{
msMiningErrors7="Out of Sync";
printf("Wallet out of sync - unable to stake..\r\n");
MilliSleep(1);
if(fDebug) printf("Wallet out of sync - unable to stake.\n");
return false;
}*/
}


return true;
Expand Down Expand Up @@ -1311,31 +1312,31 @@ void StakeMiner(CWallet *pwallet)
if( !CreateCoinStake( StakeBlock, BlockKey, StakeInputs, StakeCoinAge, *pwallet ) )
continue;
StakeBlock.nTime= StakeTX.nTime;
printf("created coin stake\n");
printf("StakeMiner: created coin stake\n");

// * create rest of the block
if( !CreateRestOfTheBlock(StakeBlock,pindexPrev) )
continue;
printf("created rest of the block\n");
printf("StakeMiner: created rest of the block\n");

// * add gridcoin reward to coinstake
if( !CreateGridcoinReward(StakeBlock,StakeCoinAge,pindexPrev) )
continue;
printf("added gridcoin reward to coinstake\n");
printf("StakeMiner: added gridcoin reward to coinstake\n");

// * sign boinchash, coinstake, wholeblock
if( !SignStakeBlock(StakeBlock,BlockKey,StakeInputs,pwallet) )
continue;
printf("signed boinchash, coinstake, wholeblock\n");
printf("StakeMiner: signed boinchash, coinstake, wholeblock\n");

// * delegate to ProcessBlock
if (!ProcessBlock(NULL, &StakeBlock, true))
{
msMiningErrors5+="Block vehemently rejected; ";
error("CreateCoinStake: Block vehemently rejected");
error("StakeMiner: Block vehemently rejected");
continue;
}
printf("block processed\n");
printf("StakeMiner: block processed\n");

} //end while(!fShutdown)
}
Expand Down

0 comments on commit 3948628

Please sign in to comment.