Skip to content

Commit

Permalink
Fixes proof-of-stake reward check
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanis committed Sep 23, 2015
1 parent f8320bf commit f90108e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/GetProofOfStakeReward.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "GetProofOfStakeReward.h"

money_t GetProofOfStakeReward(timestamp_t coinAge, blockheight_t height)
money_t GetProofOfStakeReward(timestamp_t coinAge, blockheight_t prevHeight)
{
if (POS_BLOCK_REWARD)
return POS_BLOCK_REWARD;
Expand All @@ -17,7 +17,7 @@ money_t GetProofOfStakeReward(timestamp_t coinAge, blockheight_t height)

static uint16_t const rewardSteps[] = { 10000, 9754, 9593, 9435, 9278, 9124, 8972, 8823, 8675, 8530, 8386, 8245, 8106, 7969, 7834, 7701, 7569, 7440, 7312, 7187, 7063, 6941, 6821, 6702, 6585, 6470, 6356, 6245, 6134, 6026, 5919, 5813, 5709, 5607, 5505, 5406, 5308, 5211, 5116, 5022, 4929, 4838, 4748, 4659, 4572, 4486, 4401, 4318, 4235, 4154, 4074, 3995, 3917, 3841, 3765, 3691, 3617, 3545, 3474, 3404, 3334, 3266, 3199, 3133, 3067, 3003, 2940, 2877, 2816, 2755, 2695, 2636, 2578, 2521, 2464, 2409, 2354, 2300, 2247, 2194, 2142, 2091, 2041, 1992, 1943, 1895, 1847, 1801, 1755, 1709, 1664, 1620, 1577, 1534, 1492, 1450, 1409, 1369, 1329, 1290, 1251, 1213, 1176, 1139, 1102, 1066, 1031, 996, 961, 928, 894, 861, 829, 797, 765, 734, 703, 673, 643, 600 };

uint32_t stepIndex = height / 43836;
uint32_t stepIndex = prevHeight / 43836;
uint32_t stepCount = sizeof( rewardSteps ) / sizeof( rewardSteps[ 0 ] );

if ( stepIndex >= stepCount )
Expand Down
6 changes: 0 additions & 6 deletions src/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,5 @@
#include "constants.h"
#include "main.h"

#define DYN_POW_TAIL GetLastBlockIndex(pindexBest, false)
#define DYN_POS_TAIL GetLastBlockIndex(pindexBest, true)

#define DYN_POW_HEIGHT DYN_POW_TAIL->nHeight
#define DYN_POS_HEIGHT DYN_POS_TAIL->nHeight

#define UNSIGNED(N) static_cast<unsigned>(N)
#define IP_ADDRESS(A, B, C, D) ((UNSIGNED(D) << 24) | (UNSIGNED(C) << 16) | (UNSIGNED(B) << 8) | UNSIGNED(A))
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, MapPrevTx inputs,
if (!GetCoinAge(txdb, nCoinAge))
return error("ConnectInputs() : %s unable to get coin age for coinstake", GetHash().ToString().substr(0,10).c_str());
int64 nStakeReward = GetValueOut() - nValueIn;
if (nStakeReward > GetProofOfStakeReward(nCoinAge, DYN_POS_HEIGHT) - GetMinFee() + MIN_TX_FEES)
if (nStakeReward > GetProofOfStakeReward(nCoinAge, pindexBlock->pprev->nHeight) - GetMinFee() + MIN_TX_FEES)
return DoS(100, error("ConnectInputs() : %s stake reward exceeded", GetHash().ToString().substr(0,10).c_str()));
}
else
Expand Down
6 changes: 2 additions & 4 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1287,9 +1287,7 @@ bool CWallet::CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& w
// ppcoin: create coin stake transaction
bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64 nSearchInterval, CTransaction& txNew)
{
CBlockIndex const * pLastBlockIndex = DYN_POW_TAIL;


CBlockIndex const * pLastBlockIndex = GetLastBlockIndex(pindexBest, false);
int64 nCombineThreshold = GetProofOfWorkReward(pLastBlockIndex->nHeight) / COMBINE_THRESHOLD;

CBigNum bnTargetPerCoinDay;
Expand Down Expand Up @@ -1475,7 +1473,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
CTxDB txdb("r");
if (!txNew.GetCoinAge(txdb, nCoinAge))
return error("CreateCoinStake : failed to calculate coin age");
nCredit += GetProofOfStakeReward(nCoinAge, DYN_POS_HEIGHT);
nCredit += GetProofOfStakeReward(nCoinAge, pindexBest->nHeight);
}

int64 nMinFee = 0;
Expand Down

0 comments on commit f90108e

Please sign in to comment.