mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-17 18:40:09 +00:00
Move internal miner functionality together
This commit is contained in:
parent
4a85e06750
commit
acfa03337e
105
src/miner.cpp
105
src/miner.cpp
@ -10,12 +10,6 @@
|
|||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "wallet.h"
|
#include "wallet.h"
|
||||||
|
|
||||||
#ifdef ENABLE_WALLET
|
|
||||||
// These globals are only used by the built-in miner
|
|
||||||
double dHashesPerSec = 0.0;
|
|
||||||
int64_t nHPSTimerStart = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// BitcoinMiner
|
// BitcoinMiner
|
||||||
@ -57,41 +51,6 @@ void SHA256Transform(void* pstate, void* pinput, const void* pinit)
|
|||||||
((uint32_t*)pstate)[i] = ctx.h[i];
|
((uint32_t*)pstate)[i] = ctx.h[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// ScanHash scans nonces looking for a hash with at least some zero bits.
|
|
||||||
// It operates on big endian data. Caller does the byte reversing.
|
|
||||||
// All input buffers are 16-byte aligned. nNonce is usually preserved
|
|
||||||
// between calls, but periodically or if nNonce is 0xffff0000 or above,
|
|
||||||
// the block is rebuilt and nNonce starts over at zero.
|
|
||||||
//
|
|
||||||
unsigned int static ScanHash_CryptoPP(char* pmidstate, char* pdata, char* phash1, char* phash, unsigned int& nHashesDone)
|
|
||||||
{
|
|
||||||
unsigned int& nNonce = *(unsigned int*)(pdata + 12);
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
// Crypto++ SHA256
|
|
||||||
// Hash pdata using pmidstate as the starting state into
|
|
||||||
// pre-formatted buffer phash1, then hash phash1 into phash
|
|
||||||
nNonce++;
|
|
||||||
SHA256Transform(phash1, pdata, pmidstate);
|
|
||||||
SHA256Transform(phash, phash1, pSHA256InitState);
|
|
||||||
|
|
||||||
// Return the nonce if the hash has at least some zero bits,
|
|
||||||
// caller will check if it has enough to reach the target
|
|
||||||
if (((unsigned short*)phash)[14] == 0)
|
|
||||||
return nNonce;
|
|
||||||
|
|
||||||
// If nothing found after trying for a while, return -1
|
|
||||||
if ((nNonce & 0xffff) == 0)
|
|
||||||
{
|
|
||||||
nHashesDone = 0xffff+1;
|
|
||||||
return (unsigned int) -1;
|
|
||||||
}
|
|
||||||
if ((nNonce & 0xfff) == 0)
|
|
||||||
boost::this_thread::interruption_point();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Some explaining would be appreciated
|
// Some explaining would be appreciated
|
||||||
class COrphan
|
class COrphan
|
||||||
{
|
{
|
||||||
@ -384,18 +343,6 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
return pblocktemplate.release();
|
return pblocktemplate.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_WALLET
|
|
||||||
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
|
|
||||||
{
|
|
||||||
CPubKey pubkey;
|
|
||||||
if (!reservekey.GetReservedKey(pubkey))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
CScript scriptPubKey = CScript() << pubkey << OP_CHECKSIG;
|
|
||||||
return CreateNewBlock(scriptPubKey);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce)
|
void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce)
|
||||||
{
|
{
|
||||||
// Update nExtraNonce
|
// Update nExtraNonce
|
||||||
@ -460,6 +407,58 @@ void FormatHashBuffers(CBlock* pblock, char* pmidstate, char* pdata, char* phash
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Internal miner
|
||||||
|
//
|
||||||
|
double dHashesPerSec = 0.0;
|
||||||
|
int64_t nHPSTimerStart = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
// ScanHash scans nonces looking for a hash with at least some zero bits.
|
||||||
|
// It operates on big endian data. Caller does the byte reversing.
|
||||||
|
// All input buffers are 16-byte aligned. nNonce is usually preserved
|
||||||
|
// between calls, but periodically or if nNonce is 0xffff0000 or above,
|
||||||
|
// the block is rebuilt and nNonce starts over at zero.
|
||||||
|
//
|
||||||
|
unsigned int static ScanHash_CryptoPP(char* pmidstate, char* pdata, char* phash1, char* phash, unsigned int& nHashesDone)
|
||||||
|
{
|
||||||
|
unsigned int& nNonce = *(unsigned int*)(pdata + 12);
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
// Crypto++ SHA256
|
||||||
|
// Hash pdata using pmidstate as the starting state into
|
||||||
|
// pre-formatted buffer phash1, then hash phash1 into phash
|
||||||
|
nNonce++;
|
||||||
|
SHA256Transform(phash1, pdata, pmidstate);
|
||||||
|
SHA256Transform(phash, phash1, pSHA256InitState);
|
||||||
|
|
||||||
|
// Return the nonce if the hash has at least some zero bits,
|
||||||
|
// caller will check if it has enough to reach the target
|
||||||
|
if (((unsigned short*)phash)[14] == 0)
|
||||||
|
return nNonce;
|
||||||
|
|
||||||
|
// If nothing found after trying for a while, return -1
|
||||||
|
if ((nNonce & 0xffff) == 0)
|
||||||
|
{
|
||||||
|
nHashesDone = 0xffff+1;
|
||||||
|
return (unsigned int) -1;
|
||||||
|
}
|
||||||
|
if ((nNonce & 0xfff) == 0)
|
||||||
|
boost::this_thread::interruption_point();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
|
||||||
|
{
|
||||||
|
CPubKey pubkey;
|
||||||
|
if (!reservekey.GetReservedKey(pubkey))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
CScript scriptPubKey = CScript() << pubkey << OP_CHECKSIG;
|
||||||
|
return CreateNewBlock(scriptPubKey);
|
||||||
|
}
|
||||||
|
|
||||||
bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
|
bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
|
||||||
{
|
{
|
||||||
uint256 hash = pblock->GetHash();
|
uint256 hash = pblock->GetHash();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user