Litecoin: s/BitcoinMiner/LitecoinMiner/ and detect scrypt implementation

This commit is contained in:
Warren Togami 2013-11-01 21:40:54 -10:00
parent d4c56161ae
commit 892b16f07a

View File

@ -4096,7 +4096,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// //
// BitcoinMiner // LitecoinMiner
// //
int static FormatHashBlocks(void* pbuffer, unsigned int len) int static FormatHashBlocks(void* pbuffer, unsigned int len)
@ -4503,7 +4503,7 @@ bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
return false; return false;
//// debug print //// debug print
printf("BitcoinMiner:\n"); printf("LitecoinMiner:\n");
printf("proof-of-work found \n hash: %s \ntarget: %s\n", hash.GetHex().c_str(), hashTarget.GetHex().c_str()); printf("proof-of-work found \n hash: %s \ntarget: %s\n", hash.GetHex().c_str(), hashTarget.GetHex().c_str());
pblock->print(); pblock->print();
printf("generated %s\n", FormatMoney(pblock->vtx[0].vout[0].nValue).c_str()); printf("generated %s\n", FormatMoney(pblock->vtx[0].vout[0].nValue).c_str());
@ -4512,7 +4512,7 @@ bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
{ {
LOCK(cs_main); LOCK(cs_main);
if (pblock->hashPrevBlock != hashBestChain) if (pblock->hashPrevBlock != hashBestChain)
return error("BitcoinMiner : generated block is stale"); return error("LitecoinMiner : generated block is stale");
// Remove key from key pool // Remove key from key pool
reservekey.KeepKey(); reservekey.KeepKey();
@ -4526,17 +4526,17 @@ bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
// Process this block the same as if we had received it from another node // Process this block the same as if we had received it from another node
CValidationState state; CValidationState state;
if (!ProcessBlock(state, NULL, pblock)) if (!ProcessBlock(state, NULL, pblock))
return error("BitcoinMiner : ProcessBlock, block not accepted"); return error("LitecoinMiner : ProcessBlock, block not accepted");
} }
return true; return true;
} }
void static BitcoinMiner(CWallet *pwallet) void static LitecoinMiner(CWallet *pwallet)
{ {
printf("BitcoinMiner started\n"); printf("LitecoinMiner started\n");
SetThreadPriority(THREAD_PRIORITY_LOWEST); SetThreadPriority(THREAD_PRIORITY_LOWEST);
RenameThread("bitcoin-miner"); RenameThread("litecoin-miner");
// Each thread has its own key and counter // Each thread has its own key and counter
CReserveKey reservekey(pwallet); CReserveKey reservekey(pwallet);
@ -4558,7 +4558,7 @@ void static BitcoinMiner(CWallet *pwallet)
CBlock *pblock = &pblocktemplate->block; CBlock *pblock = &pblocktemplate->block;
IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
printf("Running BitcoinMiner with %"PRIszu" transactions in block (%u bytes)\n", pblock->vtx.size(), printf("Running LitecoinMiner with %"PRIszu" transactions in block (%u bytes)\n", pblock->vtx.size(),
::GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION)); ::GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION));
// //
@ -4572,7 +4572,7 @@ void static BitcoinMiner(CWallet *pwallet)
unsigned int& nBlockTime = *(unsigned int*)(pdata + 64 + 4); unsigned int& nBlockTime = *(unsigned int*)(pdata + 64 + 4);
unsigned int& nBlockBits = *(unsigned int*)(pdata + 64 + 8); unsigned int& nBlockBits = *(unsigned int*)(pdata + 64 + 8);
unsigned int& nBlockNonce = *(unsigned int*)(pdata + 64 + 12); //unsigned int& nBlockNonce = *(unsigned int*)(pdata + 64 + 12);
// //
@ -4588,7 +4588,20 @@ void static BitcoinMiner(CWallet *pwallet)
char scratchpad[SCRYPT_SCRATCHPAD_SIZE]; char scratchpad[SCRYPT_SCRATCHPAD_SIZE];
loop loop
{ {
#if defined(USE_SSE2)
// Detection would work, but in cases where we KNOW it always has SSE2,
// it is faster to use directly than to use a function pointer or conditional.
#if defined(_M_X64) || defined(__x86_64__) || defined(_M_AMD64) || (defined(MAC_OSX) && defined(__i386__))
// Always SSE2: x86_64 or Intel MacOS X
scrypt_1024_1_1_256_sp_sse2(BEGIN(pblock->nVersion), BEGIN(thash), scratchpad);
#else
// Detect SSE2: 32bit x86 Linux or Windows
scrypt_1024_1_1_256_sp(BEGIN(pblock->nVersion), BEGIN(thash), scratchpad); scrypt_1024_1_1_256_sp(BEGIN(pblock->nVersion), BEGIN(thash), scratchpad);
#endif
#else
// Generic scrypt
scrypt_1024_1_1_256_sp_generic(BEGIN(pblock->nVersion), BEGIN(thash), scratchpad);
#endif
if (thash <= hashTarget) if (thash <= hashTarget)
{ {
@ -4657,7 +4670,7 @@ void static BitcoinMiner(CWallet *pwallet)
} } } }
catch (boost::thread_interrupted) catch (boost::thread_interrupted)
{ {
printf("BitcoinMiner terminated\n"); printf("LitecoinMiner terminated\n");
throw; throw;
} }
} }
@ -4682,7 +4695,7 @@ void GenerateBitcoins(bool fGenerate, CWallet* pwallet)
minerThreads = new boost::thread_group(); minerThreads = new boost::thread_group();
for (int i = 0; i < nThreads; i++) for (int i = 0; i < nThreads; i++)
minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet)); minerThreads->create_thread(boost::bind(&LitecoinMiner, pwallet));
} }
// Amount compression: // Amount compression: