X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=blobdiff_plain;f=src%2Fminer.cpp;h=aae9589b92937585b8d001786a2fec434f909e3a;hp=f9bdf80334eef3f792fce3effab6ae61cc25befb;hb=a0bfbd64a8dc93eb87a452843f76dbb9dec9f30b;hpb=ac0d0a1cdff8d9493c11c29bca6ed7c82377ab2f diff --git a/src/miner.cpp b/src/miner.cpp index f9bdf80..aae9589 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -7,6 +7,7 @@ #include "txdb.h" #include "miner.h" #include "kernel.h" +#include "kernel_worker.h" using namespace std; @@ -69,14 +70,6 @@ public: ptx = ptxIn; dPriority = dFeePerKb = 0; } - - void print() const - { - printf("COrphan(hash=%s, dPriority=%.1f, dFeePerKb=%.1f)\n", - ptx->GetHash().ToString().substr(0,10).c_str(), dPriority, dFeePerKb); - BOOST_FOREACH(uint256 hash, setDependsOn) - printf(" setDependsOn %s\n", hash.ToString().substr(0,10).c_str()); - } }; @@ -146,18 +139,18 @@ CBlock* CreateNewBlock(CWallet* pwallet, CTransaction *txCoinStake) } // Largest block you're willing to create: - unsigned int nBlockMaxSize = GetArg("-blockmaxsize", MAX_BLOCK_SIZE_GEN/2); + unsigned int nBlockMaxSize = GetArgUInt("-blockmaxsize", MAX_BLOCK_SIZE_GEN/2); // Limit to betweeen 1K and MAX_BLOCK_SIZE-1K for sanity: - nBlockMaxSize = std::max((unsigned int)1000, std::min((unsigned int)(MAX_BLOCK_SIZE-1000), nBlockMaxSize)); + nBlockMaxSize = std::max(1000u, std::min(MAX_BLOCK_SIZE-1000u, nBlockMaxSize)); // How much of the block should be dedicated to high-priority transactions, // included regardless of the fees they pay - unsigned int nBlockPrioritySize = GetArg("-blockprioritysize", 27000); + unsigned int nBlockPrioritySize = GetArgUInt("-blockprioritysize", 27000); nBlockPrioritySize = std::min(nBlockMaxSize, nBlockPrioritySize); // Minimum block size you want to create; block will be filled with free transactions // until there are no more or the block reaches this size: - unsigned int nBlockMinSize = GetArg("-blockminsize", 0); + unsigned int nBlockMinSize = GetArgUInt("-blockminsize", 0); nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize); // Fee-per-kilobyte amount considered the same as "free" @@ -530,8 +523,8 @@ bool CheckStake(CBlock* pblock, CWallet& wallet) } // Precalculated SHA256 contexts and metadata -// (txid, vout.n) => (SHA256_CTX, (tx.nTime, nAmount)) -typedef std::map, std::pair > > MidstateMap; +// (txid, vout.n) => (kernel, (tx.nTime, nAmount)) +typedef std::map, std::pair, std::pair > > MidstateMap; // Fill the inputs map with precalculated contexts and metadata bool FillMap(CWallet *pwallet, uint32_t nUpperTime, MidstateMap &inputsMap) @@ -598,16 +591,9 @@ bool FillMap(CWallet *pwallet, uint32_t nUpperTime, MidstateMap &inputsMap) CDataStream ssKernel(SER_GETHASH, 0); ssKernel << nStakeModifier; ssKernel << block.nTime << (txindex.pos.nTxPos - txindex.pos.nBlockPos) << pcoin->first->nTime << pcoin->second; - CDataStream::const_iterator itK = ssKernel.begin(); - - // Init new sha256 context and update it - // with first 24 bytes of kernel - SHA256_CTX ctx; - SHA256_Init(&ctx); - SHA256_Update(&ctx, (unsigned char*)&itK[0], 8 + 16); - // (txid, vout.n) => (SHA256_CTX, (tx.nTime, nAmount)) - inputsMap[key] = make_pair(ctx, make_pair(pcoin->first->nTime, pcoin->first->vout[pcoin->second].nValue)); + // (txid, vout.n) => (kernel, (tx.nTime, nAmount)) + inputsMap[key] = make_pair(std::vector(ssKernel.begin(), ssKernel.end()), make_pair(pcoin->first->nTime, pcoin->first->vout[pcoin->second].nValue)); } nStakeInputsMapSize = inputsMap.size(); @@ -633,13 +619,13 @@ bool ScanMap(const MidstateMap &inputsMap, uint32_t nBits, MidstateMap::key_type interval.first = nSearchTime; interval.second = nSearchTime - min(nSearchTime-nLastCoinStakeSearchTime, nMaxStakeSearchInterval); - // (txid, nout) => (SHA256_CTX, (tx.nTime, nAmount)) + // (txid, nout) => (kernel, (tx.nTime, nAmount)) for(MidstateMap::const_iterator input = inputsMap.begin(); input != inputsMap.end(); input++) { - SHA256_CTX ctx = input->second.first; + unsigned char *kernel = (unsigned char *) &input->second.first[0]; // scan(State, Bits, Time, Amount, ...) - if (ScanContextBackward(ctx, nBits, input->second.second.first, input->second.second.second, interval, solution)) + if (ScanKernelBackward(kernel, nBits, input->second.second.first, input->second.second.second, interval, solution)) { // Solution found LuckyInput = input->first; // (txid, nout)