From 892b16f07a59d47bb678c393cfc771d2505b0679 Mon Sep 17 00:00:00 2001 From: Warren Togami Date: Fri, 1 Nov 2013 21:40:54 -1000 Subject: [PATCH] Litecoin: s/BitcoinMiner/LitecoinMiner/ and detect scrypt implementation --- src/main.cpp | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9a2aad3c66..55e24c2278 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4096,7 +4096,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) ////////////////////////////////////////////////////////////////////////////// // -// BitcoinMiner +// LitecoinMiner // int static FormatHashBlocks(void* pbuffer, unsigned int len) @@ -4503,7 +4503,7 @@ bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey) return false; //// 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()); pblock->print(); 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); if (pblock->hashPrevBlock != hashBestChain) - return error("BitcoinMiner : generated block is stale"); + return error("LitecoinMiner : generated block is stale"); // Remove key from key pool 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 CValidationState state; if (!ProcessBlock(state, NULL, pblock)) - return error("BitcoinMiner : ProcessBlock, block not accepted"); + return error("LitecoinMiner : ProcessBlock, block not accepted"); } return true; } -void static BitcoinMiner(CWallet *pwallet) +void static LitecoinMiner(CWallet *pwallet) { - printf("BitcoinMiner started\n"); + printf("LitecoinMiner started\n"); SetThreadPriority(THREAD_PRIORITY_LOWEST); - RenameThread("bitcoin-miner"); + RenameThread("litecoin-miner"); // Each thread has its own key and counter CReserveKey reservekey(pwallet); @@ -4558,7 +4558,7 @@ void static BitcoinMiner(CWallet *pwallet) CBlock *pblock = &pblocktemplate->block; 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)); // @@ -4572,7 +4572,7 @@ void static BitcoinMiner(CWallet *pwallet) unsigned int& nBlockTime = *(unsigned int*)(pdata + 64 + 4); 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]; 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); +#endif +#else + // Generic scrypt + scrypt_1024_1_1_256_sp_generic(BEGIN(pblock->nVersion), BEGIN(thash), scratchpad); +#endif if (thash <= hashTarget) { @@ -4657,7 +4670,7 @@ void static BitcoinMiner(CWallet *pwallet) } } catch (boost::thread_interrupted) { - printf("BitcoinMiner terminated\n"); + printf("LitecoinMiner terminated\n"); throw; } } @@ -4682,7 +4695,7 @@ void GenerateBitcoins(bool fGenerate, CWallet* pwallet) minerThreads = new boost::thread_group(); for (int i = 0; i < nThreads; i++) - minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet)); + minerThreads->create_thread(boost::bind(&LitecoinMiner, pwallet)); } // Amount compression: