From 66e7e3ca93ec48647a8072f9124128cb1234f65c Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 20 Jan 2014 02:41:14 +0400 Subject: [PATCH] Add previous block checking in the proof-of-stake miner This should help against orphans. --- src/miner.cpp | 4 +--- src/wallet.cpp | 48 +++--------------------------------------------- 2 files changed, 4 insertions(+), 48 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index f9d23cb..d5ace13 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -381,7 +381,7 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& } ++nExtraNonce; - unsigned int nHeight = pindexPrev->nHeight+1; // Height first in coinbase required for block.version=2 + unsigned int nHeight = pindexPrev->nHeight+1; // Height first in coinbase required pblock->vtx[0].vin[0].scriptSig = (CScript() << nHeight << CBigNum(nExtraNonce)) + COINBASE_FLAGS; assert(pblock->vtx[0].vin[0].scriptSig.size() <= 100); @@ -564,7 +564,5 @@ void StakeMiner(CWallet *pwallet) } else Sleep(nMinerSleep); - - continue; } } diff --git a/src/wallet.cpp b/src/wallet.cpp index 12799fd..7ee94f1 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -15,7 +15,7 @@ using namespace std; extern int nStakeMaxAge; - +extern unsigned int nTransactionsUpdated; ////////////////////////////////////////////////////////////////////////////// // @@ -1438,27 +1438,6 @@ bool CWallet::GetStakeWeight(const CKeyStore& keystore, uint64& nMinWeight, uint return false; vector vwtxPrev; - -/* - * TODO: performance comparison - - static set > setCoins; - static uint256 hashPrevBlock; - static int64 nValueIn = 0; - - // Cache outputs unless best block changed - if (hashPrevBlock != pindexBest->GetBlockHash()) - { - if (!SelectCoinsSimple(nBalance - nReserveBalance, GetAdjustedTime(), nCoinbaseMaturity * 10, setCoins, nValueIn)) - return false; - - if (setCoins.empty()) - return false; - - hashPrevBlock == pindexBest->GetBlockHash(); - } -*/ - set > setCoins; int64 nValueIn = 0; @@ -1508,7 +1487,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int // The following combine threshold is important to security // Should not be adjusted if you don't understand the consequences int64 nCombineThreshold = GetProofOfWorkReward(GetLastBlockIndex(pindexBest, false)->nBits) / 3; - + CBlockIndex* pindexPrev = pindexBest; CBigNum bnTargetPerCoinDay; bnTargetPerCoinDay.SetCompact(nBits); @@ -1531,27 +1510,6 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int return false; vector vwtxPrev; - -/* - * TODO: performance comparison - - static set > setCoins; - static uint256 hashPrevBlock; - static int64 nValueIn = 0; - - // Cache outputs unless best block changed - if (hashPrevBlock != pindexBest->GetBlockHash()) - { - if (!SelectCoinsSimple(nBalance - nReserveBalance, txNew.nTime, nCoinbaseMaturity * 10, setCoins, nValueIn)) - return false; - - if (setCoins.empty()) - return false; - - hashPrevBlock == pindexBest->GetBlockHash(); - } -*/ - set > setCoins; int64 nValueIn = 0; @@ -1600,7 +1558,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int bool fKernelFound = false; - for (unsigned int n=0; n