diff options
| author | Ross Nicoll <[email protected]> | 2015-06-28 16:03:55 +0100 |
|---|---|---|
| committer | Ross Nicoll <[email protected]> | 2015-06-28 16:21:09 +0000 |
| commit | a99e717ed6860a1bf384929a4148fbf22065e39a (patch) | |
| tree | 7fd84c5100041976632011d8c7ac7b09b403581a /src | |
| parent | Litecoin: Scrypt n=1024 Pow hash based upon Colin Percival's Tarnsnap (2009) (diff) | |
| download | discoin-a99e717ed6860a1bf384929a4148fbf22065e39a.tar.xz discoin-a99e717ed6860a1bf384929a4148fbf22065e39a.zip | |
Added Scrypt mining support based on Dogecoin 1.9 work.
Diffstat (limited to 'src')
| -rw-r--r-- | src/miner.cpp | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/miner.cpp b/src/miner.cpp index f5919ca3a..04d7f5186 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -9,6 +9,7 @@ #include "chainparams.h" #include "consensus/consensus.h" #include "consensus/validation.h" +#include "crypto/scrypt.h" #include "hash.h" #include "main.h" #include "net.h" @@ -374,30 +375,34 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& // nonce is 0xffff0000 or above, the block is rebuilt and nNonce starts over at // zero. // -bool static ScanHash(const CBlockHeader *pblock, uint32_t& nNonce, uint256 *phash) +bool static ScanHash(CBlockHeader *pblock, uint32_t& nNonce, uint256 *phash, char *pscratchpad) { // Write the first 76 bytes of the block header to a double-SHA256 state. - CHash256 hasher; - CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); - ss << *pblock; - assert(ss.size() == 80); - hasher.Write((unsigned char*)&ss[0], 76); + //CHash256 hasher; + //CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); + //ss << *pblock; + //assert(ss.size() == 80); + //hasher.Write((unsigned char*)&ss[0], 76); while (true) { nNonce++; // Write the last 4 bytes of the block header (the nonce) to a copy of // the double-SHA256 state, and compute the result. - CHash256(hasher).Write((unsigned char*)&nNonce, 4).Finalize((unsigned char*)phash); + pblock->nNonce = nNonce; + scrypt_1024_1_1_256_sp(BEGIN(pblock->nVersion), (char*)phash, pscratchpad); // Return the nonce if the hash has at least some zero bits, // caller will check if it has enough to reach the target - if (((uint16_t*)phash)[15] == 0) + // TODO: I don't like having this hard-coded, it's too coarse for regtest, too fine for main + if (((uint8_t*)phash)[31] == 0) return true; // If nothing found after trying for a while, return -1 - if ((nNonce & 0xfff) == 0) + if ((nNonce & 0x1fff) == 0) return false; + if ((nNonce & 0x01ff) == 0) + boost::this_thread::interruption_point(); } } @@ -493,15 +498,16 @@ void static BitcoinMiner(CWallet *pwallet) arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits); uint256 hash; uint32_t nNonce = 0; + char scratchpad[SCRYPT_SCRATCHPAD_SIZE]; while (true) { // Check if something found - if (ScanHash(pblock, nNonce, &hash)) + if (ScanHash(pblock, nNonce, &hash, scratchpad)) { if (UintToArith256(hash) <= hashTarget) { // Found a solution pblock->nNonce = nNonce; - assert(hash == pblock->GetHash()); + assert(hash == pblock->GetPoWHash()); SetThreadPriority(THREAD_PRIORITY_NORMAL); LogPrintf("BitcoinMiner:\n"); |