diff --git a/src/main.cpp b/src/main.cpp index 98a214d7..d920c4d5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4839,7 +4839,7 @@ void BitcoinMiner(CWallet *pwallet, CBlockProvider *block_provider, unsigned int // Primecoin: update time and nonce //pblock->nTime = max(pblock->nTime, (unsigned int) GetAdjustedTime()); - pblock->nTime = max(pblock->nTime, (unsigned int)(((((size_t)GetAdjustedTime() + thread_num_max) / thread_num_max) * thread_num_max) + thread_id)); + pblock->nTime = max(pblock->nTime, block_provider->GetAdjustedTimeWithOffset(thread_id)); pblock->nNonce++; loop { // Fast loop diff --git a/src/main_poolminer.cpp b/src/main_poolminer.cpp index e0d959c3..c363fa85 100644 --- a/src/main_poolminer.cpp +++ b/src/main_poolminer.cpp @@ -16,10 +16,11 @@ #include "json/json_spirit_value.h" #include #include +#include #define VERSION_MAJOR 0 -#define VERSION_MINOR 6 -#define VERSION_EXT "RC3" +#define VERSION_MINOR 8 +#define VERSION_EXT "RC1" #define MAX_THREADS 32 @@ -65,6 +66,8 @@ static boost::posix_time::ptime t_start; static std::map statistics; static bool running; static volatile int submitting_share; +std::string pool_username; +std::string pool_password; /********************************* * helping functions @@ -99,16 +102,20 @@ void convertDataToBlock(unsigned char* blockData, CBlock& block) { class CBlockProviderGW : public CBlockProvider { public: - CBlockProviderGW() : CBlockProvider(), _blocks(NULL) {} + CBlockProviderGW() : CBlockProvider(), nTime_offset(0), _blocks(NULL) {} virtual ~CBlockProviderGW() { /* TODO */ } + + virtual unsigned int GetAdjustedTimeWithOffset(unsigned int thread_id) { + return nTime_offset + ((((unsigned int)GetAdjustedTime() + thread_num_max) / thread_num_max) * thread_num_max) + thread_id; + } virtual CBlock* getBlock(unsigned int thread_id, unsigned int last_time) { boost::unique_lock lock(_mutex_getwork); if (_blocks == NULL) return NULL; CBlock* block = NULL; block = new CBlock(_blocks->GetBlockHeader()); - unsigned int new_time = ((((unsigned int)GetAdjustedTime() + thread_num_max) / thread_num_max) * thread_num_max) + thread_id; + unsigned int new_time = GetAdjustedTimeWithOffset(thread_id); if (new_time == last_time) new_time += thread_num_max; block->nTime = new_time; //TODO: check if this is the same time like before!? @@ -121,6 +128,11 @@ public: //for (size_t i = 0; i < thread_num_count; ++i) // convertDataToBlock(data+i*128,blocks[i]); convertDataToBlock(data,*blocks); + // + unsigned int nTime_local = GetAdjustedTime(); + unsigned int nTime_server = blocks->nTime; + nTime_offset = nTime_local > nTime_server ? 0 : (nTime_server-nTime_local); + // CBlock* old_blocks = NULL; { boost::unique_lock lock(_mutex_getwork); @@ -160,8 +172,8 @@ public: boost::asio::write(*socket_to_server, boost::asio::buffer((unsigned char*)&blockraw, 128), boost::asio::transfer_at_least(1), submit_error); //FaF //size_t len = boost::asio::write(*socket_to_server, boost::asio::buffer((unsigned char*)&blockraw, 128), boost::asio::transfer_all(), submit_error); //socket_to_server->write_some(boost::asio::buffer((unsigned char*)&blockraw, 128), submit_error); - if (submit_error) - std::cout << submit_error << " @ write_submit" << std::endl; + //if (submit_error) + // std::cout << submit_error << " @ write_submit" << std::endl; } } --submitting_share; @@ -172,12 +184,13 @@ public: if (socket_to_server != NULL) { boost::system::error_code close_error; socket_to_server->close(close_error); - if (close_error) - std::cout << close_error << " @ close" << std::endl; + //if (close_error) + // std::cout << close_error << " @ close" << std::endl; } } protected: + unsigned int nTime_offset; boost::shared_mutex _mutex_getwork; CBlock* _blocks; }; @@ -266,24 +279,25 @@ public: } { //send hello message - std::string username = GetArg("-pooluser", ""); - char* hello = new char[username.length()+/*v0.2/0.3=*/2+/*v0.4=*/20]; - memcpy(hello+1, username.c_str(), username.length()); - *((unsigned char*)hello) = username.length(); - *((unsigned char*)(hello+username.length()+1)) = 0; //hi, i'm v0.4+ - *((unsigned char*)(hello+username.length()+2)) = VERSION_MAJOR; - *((unsigned char*)(hello+username.length()+3)) = VERSION_MINOR; - *((unsigned char*)(hello+username.length()+4)) = 1; - *((unsigned char*)(hello+username.length()+5)) = fee_to_pay; - *((unsigned short*)(hello+username.length()+6)) = miner_id; - *((unsigned int*)(hello+username.length()+8)) = nSieveExtensions; - *((unsigned int*)(hello+username.length()+12)) = nSievePercentage; - *((unsigned int*)(hello+username.length()+16)) = nSieveSize; - *((unsigned short*)(hello+username.length()+20)) = 0; //EXTENSIONS + char* hello = new char[pool_username.length()+/*v0.2/0.3=*/2+/*v0.4=*/20+/*v0.7=*/1+pool_password.length()]; + memcpy(hello+1, pool_username.c_str(), pool_username.length()); + *((unsigned char*)hello) = pool_username.length(); + *((unsigned char*)(hello+pool_username.length()+1)) = 0; //hi, i'm v0.4+ + *((unsigned char*)(hello+pool_username.length()+2)) = VERSION_MAJOR; + *((unsigned char*)(hello+pool_username.length()+3)) = VERSION_MINOR; + *((unsigned char*)(hello+pool_username.length()+4)) = thread_num_max; + *((unsigned char*)(hello+pool_username.length()+5)) = fee_to_pay; + *((unsigned short*)(hello+pool_username.length()+6)) = miner_id; + *((unsigned int*)(hello+pool_username.length()+8)) = nSieveExtensions; + *((unsigned int*)(hello+pool_username.length()+12)) = nSievePercentage; + *((unsigned int*)(hello+pool_username.length()+16)) = nSieveSize; + *((unsigned char*)(hello+pool_username.length()+20)) = pool_password.length(); + memcpy(hello+pool_username.length()+21, pool_password.c_str(), pool_password.length()); + *((unsigned short*)(hello+pool_username.length()+21+pool_password.length())) = 0; //EXTENSIONS boost::system::error_code error; - socket->write_some(boost::asio::buffer(hello, username.length()+2+20), error); - if (error) - std::cout << error << " @ write_some_hello" << std::endl; + socket->write_some(boost::asio::buffer(hello, pool_username.length()+2+20+1+pool_password.length()), error); + //if (error) + // std::cout << error << " @ write_some_hello" << std::endl; delete[] hello; } @@ -301,7 +315,7 @@ public: if (error == boost::asio::error::eof) break; // Connection closed cleanly by peer. else if (error) { - std::cout << error << " @ read_some1" << std::endl; + //std::cout << error << " @ read_some1" << std::endl; break; } type = buf; @@ -322,7 +336,7 @@ public: done = true; break; // Connection closed cleanly by peer. } else if (error) { - std::cout << error << " @ read2a" << std::endl; + //std::cout << error << " @ read2a" << std::endl; done = true; break; } @@ -349,7 +363,7 @@ public: done = true; break; // Connection closed cleanly by peer. } else if (error) { - std::cout << error << " @ read2b" << std::endl; + //std::cout << error << " @ read2b" << std::endl; done = true; break; } @@ -380,7 +394,7 @@ public: //PING-PONG EVENT, nothing to do } break; default: { - std::cout << "unknown header type = " << type << std::endl; + //std::cout << "unknown header type = " << type << std::endl; } } } @@ -582,6 +596,8 @@ int main(int argc, char **argv) thread_num_max = GetArg("-genproclimit", 1); // what about boost's hardware_concurrency() ? fee_to_pay = GetArg("-poolfee", 3); miner_id = GetArg("-minerid", 0); + pool_username = GetArg("-pooluser", ""); + pool_password = GetArg("-poolpassword", ""); if (thread_num_max == 0 || thread_num_max > MAX_THREADS) { @@ -600,6 +616,17 @@ int main(int argc, char **argv) std::cerr << "usage: " << "please use a miner id between [0 , 65535]" << std::endl; return EXIT_FAILURE; } + + { //password to sha1 + boost::uuids::detail::sha1 sha; + sha.process_bytes(pool_password.c_str(), pool_password.size()); + unsigned int digest[5]; + sha.get_digest(digest); + std::stringstream ss; + ss << std::setw(5) << std::setfill('0') << std::hex << (digest[0] ^ digest[1] ^ digest[4]) << (digest[2] ^ digest[3] ^ digest[4]); + pool_password = ss.str(); + } +std::cout << pool_username << std::endl; fPrintToConsole = true; // always on fDebug = GetBoolArg("-debug"); diff --git a/src/prime.h b/src/prime.h index 077712a6..827be9ef 100644 --- a/src/prime.h +++ b/src/prime.h @@ -25,6 +25,7 @@ public: virtual CBlock* getBlock(unsigned int thread_id, unsigned int last_time) = 0; virtual void submitBlock(CBlock* block) = 0; virtual void forceReconnect() = 0; + virtual unsigned int GetAdjustedTimeWithOffset(unsigned int thread_id) = 0; }; /**********************/