X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fminer.cpp;h=92ade153134f1171015f179091fad4ff58b78741;hb=d8f8063eda45b8dec864b28bb98839a2dd3a8170;hp=89032da0a389339b7d5ed1fe4e871d8873684111;hpb=d5c1cb354fa50539f836ea337284679d56b84c3b;p=novacoin.git diff --git a/src/miner.cpp b/src/miner.cpp index 89032da..92ade15 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -4,6 +4,7 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include "txdb.h" #include "miner.h" #include "kernel.h" @@ -14,9 +15,11 @@ using namespace std; // BitcoinMiner // -string strMintMessage = "Info: Minting suspended due to locked wallet."; +string strMintMessage = "Info: Mining suspended due to locked wallet."; string strMintWarning; +extern unsigned int nMinerSleep; + int static FormatHashBlocks(void* pbuffer, unsigned int len) { unsigned char* pdata = (unsigned char*)pbuffer; @@ -106,8 +109,7 @@ public: } }; -// CreateNewBlock: -// fProofOfStake: try (best effort) to make a proof-of-stake block +// CreateNewBlock: create new block (without proof-of-work/proof-of-stake) CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake) { // Create new block @@ -124,7 +126,7 @@ CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake) if (!fProofOfStake) { CReserveKey reservekey(pwallet); - txNew.vout[0].scriptPubKey << reservekey.GetReservedKey() << OP_CHECKSIG; + txNew.vout[0].scriptPubKey.SetDestination(reservekey.GetReservedKey().GetID()); } else txNew.vout[0].SetEmpty(); @@ -156,32 +158,9 @@ CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake) if (mapArgs.count("-mintxfee")) ParseMoney(mapArgs["-mintxfee"], nMinTxFee); - // ppcoin: if coinstake available add coinstake tx - static int64 nLastCoinStakeSearchTime = GetAdjustedTime(); // only initialized at startup CBlockIndex* pindexPrev = pindexBest; - if (fProofOfStake) // attempt to find a coinstake - { - pblock->nBits = GetNextTargetRequired(pindexPrev, true); - CTransaction txCoinStake; - int64 nSearchTime = txCoinStake.nTime; // search to current time - if (nSearchTime > nLastCoinStakeSearchTime) - { - if (pwallet->CreateCoinStake(*pwallet, pblock->nBits, nSearchTime-nLastCoinStakeSearchTime, txCoinStake)) - { - if (txCoinStake.nTime >= max(pindexPrev->GetMedianTimePast()+1, pindexPrev->GetBlockTime() - nMaxClockDrift)) - { // make sure coinstake would meet timestamp protocol - // as it would be the same as the block timestamp - pblock->vtx[0].nTime = txCoinStake.nTime; - pblock->vtx.push_back(txCoinStake); - } - } - nLastCoinStakeSearchInterval = nSearchTime - nLastCoinStakeSearchTime; - nLastCoinStakeSearchTime = nSearchTime; - } - } - - pblock->nBits = GetNextTargetRequired(pindexPrev, pblock->IsProofOfStake()); + pblock->nBits = GetNextTargetRequired(pindexPrev, fProofOfStake); // Collect memory pool transactions into the block int64 nFees = 0; @@ -296,10 +275,10 @@ CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake) continue; // Timestamp limit - if (tx.nTime > GetAdjustedTime() || (pblock->IsProofOfStake() && tx.nTime > pblock->vtx[1].nTime)) + if (tx.nTime > GetAdjustedTime() || (fProofOfStake && tx.nTime > pblock->vtx[0].nTime)) continue; - // ppcoin: simplify transaction fee - allow free = false + // Simplify transaction fee - allow free = false int64 nMinFee = tx.GetMinFee(nBlockSize, false, GMF_BLOCK); // Skip free transactions if we're past the minimum block size: @@ -375,16 +354,14 @@ CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake) if (fDebug && GetBoolArg("-printpriority")) printf("CreateNewBlock(): total size %"PRI64u"\n", nBlockSize); - if (pblock->IsProofOfWork()) + if (!fProofOfStake) pblock->vtx[0].vout[0].nValue = GetProofOfWorkReward(pblock->nBits); // Fill in header pblock->hashPrevBlock = pindexPrev->GetBlockHash(); - if (pblock->IsProofOfStake()) - pblock->nTime = pblock->vtx[1].nTime; //same as coinstake timestamp pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, pblock->GetMaxTransactionTime()); - pblock->nTime = max(pblock->GetBlockTime(), pindexPrev->GetBlockTime() - nMaxClockDrift); - if (pblock->IsProofOfWork()) + pblock->nTime = max(pblock->GetBlockTime(), PastDrift(pindexPrev->GetBlockTime())); + if (!fProofOfStake) pblock->UpdateTime(pindexPrev); pblock->nNonce = 0; } @@ -403,6 +380,7 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& hashPrevBlock = pblock->hashPrevBlock; } ++nExtraNonce; + unsigned int nHeight = pindexPrev->nHeight+1; // Height first in coinbase required for block.version=2 pblock->vtx[0].vin[0].scriptSig = (CScript() << nHeight << CBigNum(nExtraNonce)) + COINBASE_FLAGS; assert(pblock->vtx[0].vin[0].scriptSig.size() <= 100); @@ -469,7 +447,7 @@ bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey) return error("CheckWork() : proof-of-work not meeting target"); //// debug print - printf("CheckWork() : new proof-of-stake block found \n hash: %s \ntarget: %s\n", hashBlock.GetHex().c_str(), hashTarget.GetHex().c_str()); + printf("CheckWork() : new proof-of-work block found \n hash: %s \ntarget: %s\n", hashBlock.GetHex().c_str(), hashTarget.GetHex().c_str()); pblock->print(); printf("generated %s\n", FormatMoney(pblock->vtx[0].vout[0].nValue).c_str()); @@ -547,18 +525,22 @@ void StakeMiner(CWallet *pwallet) { if (fShutdown) return; - while (vNodes.empty() || IsInitialBlockDownload()) + + while (pwallet->IsLocked()) { + strMintWarning = strMintMessage; Sleep(1000); if (fShutdown) return; } - while (pwallet->IsLocked()) + while (vNodes.empty() || IsInitialBlockDownload()) { - strMintWarning = strMintMessage; Sleep(1000); + if (fShutdown) + return; } + strMintWarning = ""; // @@ -571,22 +553,18 @@ void StakeMiner(CWallet *pwallet) return; IncrementExtraNonce(pblock.get(), pindexPrev, nExtraNonce); - if(pblock->IsProofOfStake()) + // Trying to sign a block + if (pblock->SignBlock(*pwallet)) { - // Trying to sign a block - if (!pblock->SignBlock(*pwallet)) - { - strMintWarning = strMintMessage; - continue; - } - - strMintWarning = ""; + strMintWarning = _("Stake generation: new block found!"); SetThreadPriority(THREAD_PRIORITY_NORMAL); CheckStake(pblock.get(), *pwallet); SetThreadPriority(THREAD_PRIORITY_LOWEST); + Sleep(500); } + else + Sleep(nMinerSleep); - Sleep(500); continue; } }