diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 108 |
1 files changed, 12 insertions, 96 deletions
@@ -3,7 +3,7 @@ // file license.txt or http://www.opensource.org/licenses/mit-license.php. #include "headers.h" -#include "sha.h" +#include "cryptopp/sha.h" @@ -1369,6 +1369,8 @@ bool CBlock::AcceptBlock() return error("AcceptBlock() : rejected by checkpoint lockin at 33333"); if (pindexPrev->nHeight+1 == 68555 && hash != uint256("0x00000000001e1b4903550a0b96e9a9405c8a95f387162e4944e8d9fbe501cd6a")) return error("AcceptBlock() : rejected by checkpoint lockin at 68555"); + if (pindexPrev->nHeight+1 == 70567 && hash != uint256("0x00000000006a49b14bcf27462068f1264c961f11fa2e0eddd2be0791e1d4124a")) + return error("AcceptBlock() : rejected by checkpoint lockin at 70567"); // Write block to history file if (!CheckDiskSpace(::GetSerializeSize(*this, SER_DISK))) @@ -2551,82 +2553,11 @@ using CryptoPP::ByteReverse; static const unsigned int pSHA256InitState[8] = {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19}; -static const unsigned int SHA256_K[64] = { - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, - 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, - 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, - 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, - 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, - 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, - 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, - 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, - 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, - 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, - 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, - 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, - 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 -}; - -#define blk0(i) (W[i] = dat[i]) - -#define blk2(i) (W[i&15]+=s1(W[(i-2)&15])+W[(i-7)&15]+s0(W[(i-15)&15])) - -#define Ch(x,y,z) (z^(x&(y^z))) -#define Maj(x,y,z) ((x&y)|(z&(x|y))) - -#define a(i) T[(0-i)&7] -#define b(i) T[(1-i)&7] -#define c(i) T[(2-i)&7] -#define d(i) T[(3-i)&7] -#define e(i) T[(4-i)&7] -#define f(i) T[(5-i)&7] -#define g(i) T[(6-i)&7] -#define h(i) T[(7-i)&7] - -#define R(i,j) h(i)+=S1(e(i))+Ch(e(i),f(i),g(i))+SHA256_K[i+j]+(j?blk2(i):blk0(i));\ - d(i)+=h(i);h(i)+=S0(a(i))+Maj(a(i),b(i),c(i)) - -#define rotrFixed(x,y) ((x>>y) | (x<<(sizeof(unsigned int)*8-y))) - -// for SHA256 -#define S0(x) (rotrFixed(x,2)^rotrFixed(x,13)^rotrFixed(x,22)) -#define S1(x) (rotrFixed(x,6)^rotrFixed(x,11)^rotrFixed(x,25)) -#define s0(x) (rotrFixed(x,7)^rotrFixed(x,18)^(x>>3)) -#define s1(x) (rotrFixed(x,17)^rotrFixed(x,19)^(x>>10)) - -#if 1 -inline void SHA256Transform(void* pout, const void* pin, const void* pinit) -{ - memcpy(pout, pinit, 32); - unsigned int* dat = (unsigned int*)pin; - unsigned int* T = (unsigned int*)pout; - unsigned int* initstate = (unsigned int*)pinit; - unsigned int W[16]; - - R( 0, 0); R( 1, 0); R( 2, 0); R( 3, 0); R( 4, 0); R( 5, 0); R( 6, 0); R( 7, 0); R( 8, 0); R( 9, 0); R(10, 0); R(11, 0); R(12, 0); R(13, 0); R(14, 0); R(15, 0); - R( 0, 16); R( 1, 16); R( 2, 16); R( 3, 16); R( 4, 16); R( 5, 16); R( 6, 16); R( 7, 16); R( 8, 16); R( 9, 16); R(10, 16); R(11, 16); R(12, 16); R(13, 16); R(14, 16); R(15, 16); - R( 0, 32); R( 1, 32); R( 2, 32); R( 3, 32); R( 4, 32); R( 5, 32); R( 6, 32); R( 7, 32); R( 8, 32); R( 9, 32); R(10, 32); R(11, 32); R(12, 32); R(13, 32); R(14, 32); R(15, 32); - R( 0, 48); R( 1, 48); R( 2, 48); R( 3, 48); R( 4, 48); R( 5, 48); R( 6, 48); R( 7, 48); R( 8, 48); R( 9, 48); R(10, 48); R(11, 48); R(12, 48); R(13, 48); R(14, 48); R(15, 48); - - T[0] += initstate[0]; - T[1] += initstate[1]; - T[2] += initstate[2]; - T[3] += initstate[3]; - T[4] += initstate[4]; - T[5] += initstate[5]; - T[6] += initstate[6]; - T[7] += initstate[7]; -} -#else inline void SHA256Transform(void* pstate, void* pinput, const void* pinit) { memcpy(pstate, pinit, 32); CryptoPP::SHA256::Transform((CryptoPP::word32*)pstate, (CryptoPP::word32*)pinput); } -#endif @@ -2645,7 +2576,7 @@ void BitcoinMiner() Sleep(50); if (fShutdown) return; - while (vNodes.empty()) + while (vNodes.empty() || IsInitialBlockDownload()) { Sleep(1000); if (fShutdown) @@ -2728,7 +2659,7 @@ void BitcoinMiner() // // Prebuild hash buffer // - struct unnamed1 + struct tmpworkspace { struct unnamed2 { @@ -2743,8 +2674,9 @@ void BitcoinMiner() unsigned char pchPadding0[64]; uint256 hash1; unsigned char pchPadding1[64]; - } - tmp; + }; + char tmpbuf[sizeof(tmpworkspace)+16]; + tmpworkspace& tmp = *(tmpworkspace*)alignup<16>(tmpbuf); tmp.block.nVersion = pblock->nVersion; tmp.block.hashPrevBlock = pblock->hashPrevBlock = (pindexPrev ? pindexPrev->GetBlockHash() : 0); @@ -2761,7 +2693,8 @@ void BitcoinMiner() ((unsigned int*)&tmp)[i] = ByteReverse(((unsigned int*)&tmp)[i]); // Precalc the first half of the first hash, which stays constant - uint256 midstate; + uint256 midstatebuf[2]; + uint256& midstate = *alignup<16>(midstatebuf); SHA256Transform(&midstate, &tmp.block, pSHA256InitState); @@ -2770,7 +2703,8 @@ void BitcoinMiner() // int64 nStart = GetTime(); uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256(); - uint256 hash; + uint256 hashbuf[2]; + uint256& hash = *alignup<16>(hashbuf); loop { SHA256Transform(&tmp.hash1, (char*)&tmp.block + 64, &midstate); @@ -2868,25 +2802,7 @@ void BitcoinMiner() if (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60) break; if (pindexPrev != pindexBest) - { - // Pause generating during initial download - if (GetTime() - nStart < 20) - { - CBlockIndex* pindexTmp; - do - { - pindexTmp = pindexBest; - for (int i = 0; i < 10; i++) - { - Sleep(1000); - if (fShutdown) - return; - } - } - while (pindexTmp != pindexBest); - } break; - } pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); tmp.block.nTime = ByteReverse(pblock->nTime); |