diff --git a/hash/hasher.cpp b/hash/hasher.cpp index 05d3ced..c1c2f7d 100755 --- a/hash/hasher.cpp +++ b/hash/hasher.cpp @@ -23,11 +23,16 @@ hasher::hasher() { __argon2profile = argon2profile_default; __hash_rate = 0; - __avg_hash_rate = 0; - __hash_count = 0; - __total_hash_count = 0; + __avg_hash_rate_cblocks = 0; + __avg_hash_rate_gblocks = 0; + __hash_count_cblocks = 0; + __hash_count_gblocks = 0; + __total_hash_count_cblocks = 0; + __total_hash_count_gblocks = 0; - __begin_time = __hashrate_time = microseconds(); + __begin_round_time = __hashrate_time = microseconds(); + __cblocks_time = 0; + __gblocks_time = 0; if(__registered_hashers == NULL) { __registered_hashers = new vector(); @@ -48,14 +53,23 @@ string hasher::get_info() { } void hasher::set_input(const string &public_key, const string &blk, const string &difficulty, const string &argon2profile_string, const string &recommendation) { + uint64_t timestamp = microseconds(); __input_mutex.lock(); __public_key = public_key; __blk = blk; __difficulty = difficulty; if(argon2profile_string == "4_4_16384") { + if(strcmp(__argon2profile->profile_name, "1_1_524288") == 0) { + __cblocks_time += (timestamp - __begin_round_time); + __begin_round_time = timestamp; + } __argon2profile = &argon2profile_4_4_16384; } else { + if(strcmp(__argon2profile->profile_name, "4_4_16384") == 0) { + __gblocks_time += (timestamp - __begin_round_time); + __begin_round_time = timestamp; + } __argon2profile = &argon2profile_1_1_524288; } __pause = (recommendation == "pause"); @@ -76,6 +90,7 @@ hash_data hasher::get_input() { new_hash.nonce = __make_nonce(); new_hash.base = tmp_public_key + "-" + new_hash.nonce + "-" + tmp_blk + "-" + tmp_difficulty; new_hash.salt = ""; + new_hash.profile_name = __argon2profile->profile_name; // new_hash.base = "PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCy7AEg3h9oYjeR74yj73q3gPxbxq9R3nxSSUV4KKgu1sQZu9Qj9v2q2HhT5H3LTHwW7HzAA28SjWFdzkNoovBMncD-sauULo1zM4tt9DhGEnO8qPe5nlzItJwwIKiIcAUDg-4KhqbBhShBf36zYeen943tS6KhgFmQixtUoVbf2egtBmD6j3NQtcueEBite2zjzdpK2ShaA28icRfJM9yPUQ6azN-56262626"; // new_hash.salt = "NSHFFAg.iATJ0sfM"; return new_hash; @@ -89,22 +104,34 @@ double hasher::get_current_hash_rate() { __hashes_mutex.lock(); uint64_t timestamp = microseconds(); if(timestamp - __hashrate_time > 5000000) { //we calculate hashrate every 5 seconds - __hash_rate = __hash_count / ((timestamp - __hashrate_time) / 1000000.0); - __avg_hash_rate = (__total_hash_count) / ((timestamp - __begin_time) / 1000000.0); + __hash_rate = (__hash_count_cblocks + __hash_count_gblocks) / ((timestamp - __hashrate_time) / 1000000.0); + uint64_t cblocks_time = __cblocks_time != 0 ? __cblocks_time : (timestamp - __begin_round_time); + uint64_t gblocks_time = __gblocks_time != 0 ? __gblocks_time : (timestamp - __begin_round_time); + __avg_hash_rate_cblocks = (__total_hash_count_cblocks) / (cblocks_time / 1000000.0); + __avg_hash_rate_gblocks = (__total_hash_count_gblocks) / (gblocks_time / 1000000.0); __hashrate_time = timestamp; - __hash_count = 0; + __hash_count_cblocks = 0; + __hash_count_gblocks = 0; } __hashes_mutex.unlock(); return __hash_rate; } -double hasher::get_avg_hash_rate() { - return __avg_hash_rate; +double hasher::get_avg_hash_rate_cblocks() { + return __avg_hash_rate_cblocks; +} + +double hasher::get_avg_hash_rate_gblocks() { + return __avg_hash_rate_gblocks; +} + +uint32_t hasher::get_hash_count_cblocks() { + return __total_hash_count_cblocks; } -uint32_t hasher::get_hash_count() { - return __total_hash_count; +uint32_t hasher::get_hash_count_gblocks() { + return __total_hash_count_gblocks; } vector hasher::get_hashes() { @@ -120,8 +147,14 @@ void hasher::_store_hash(const hash_data &hash) { // LOG(hash.hash); __hashes_mutex.lock(); __hashes.push_back(hash); - __hash_count++; - __total_hash_count++; + if(hash.profile_name == "1_1_524288") { + __hash_count_cblocks++; + __total_hash_count_cblocks++; + } + else { + __hash_count_gblocks++; + __total_hash_count_gblocks++; + } __hashes_mutex.unlock(); } diff --git a/hash/hasher.h b/hash/hasher.h index 1aeabcd..6a375cc 100755 --- a/hash/hasher.h +++ b/hash/hasher.h @@ -16,6 +16,7 @@ struct hash_data { string salt; string base; string hash; + string profile_name; bool *realloc_flag; }; @@ -38,8 +39,11 @@ class hasher { int get_intensity(); double get_current_hash_rate(); - double get_avg_hash_rate(); - uint32_t get_hash_count(); + double get_avg_hash_rate_cblocks(); + double get_avg_hash_rate_gblocks(); + + uint32_t get_hash_count_cblocks(); + uint32_t get_hash_count_gblocks(); vector get_hashes(); @@ -59,9 +63,12 @@ class hasher { static vector *__registered_hashers; double __hash_rate; - double __avg_hash_rate; - uint32_t __total_hash_count; - uint32_t __hash_count; + double __avg_hash_rate_cblocks; + double __avg_hash_rate_gblocks; + uint32_t __total_hash_count_cblocks; + uint32_t __total_hash_count_gblocks; + uint32_t __hash_count_cblocks; + uint32_t __hash_count_gblocks; mutex __input_mutex; string __public_key; @@ -73,7 +80,9 @@ class hasher { mutex __hashes_mutex; vector __hashes; - uint64_t __begin_time; + uint64_t __begin_round_time; + uint64_t __cblocks_time; + uint64_t __gblocks_time; uint64_t __hashrate_time; }; diff --git a/http/client.cpp b/http/client.cpp index 0fb404a..8d482b8 100755 --- a/http/client.cpp +++ b/http/client.cpp @@ -15,21 +15,31 @@ ariopool_client::ariopool_client(const string &pool_address, const string &worke __pool_address = pool_address; __worker_id = worker_id; __client_wallet_address = __used_wallet_address = wallet_address; - __timestamp = microseconds(); + __timestamp = __last_hash_report = microseconds(); + __force_hashrate_report = false; } -ariopool_update_result ariopool_client::update(double hash_rate) { +ariopool_update_result ariopool_client::update(double hash_rate_cblocks, double hash_rate_gblocks) { ariopool_update_result result; result.success = false; string wallet = __get_wallet_address(); #ifndef DEVELOPER_OWN_BUILD - if(wallet == DEV_WALLET_ADDRESS) - hash_rate = hash_rate / 100; + if(wallet == DEV_WALLET_ADDRESS) { + hash_rate_cblocks = hash_rate_cblocks / 100; + hash_rate_gblocks = hash_rate_gblocks / 100; + } #endif - string url = __pool_address + "/mine.php?q=info&worker=" + __worker_id + "&address=" + __get_wallet_address() + "&hashrate=" + to_string(hash_rate); + uint64_t current_timestamp = microseconds(); + string hash_report_query = ""; + if(__force_hashrate_report || (current_timestamp - __last_hash_report) > 600000000) { + hash_report_query = "&hashrate=" + to_string(hash_rate_cblocks) + "&hrgpu=" + to_string(hash_rate_gblocks); + __last_hash_report = current_timestamp; + __force_hashrate_report = false; + } + string url = __pool_address + "/mine.php?q=info&worker=" + __worker_id + "&address=" + __get_wallet_address() + hash_report_query; string response = __http_get(url); @@ -101,6 +111,7 @@ string ariopool_client::__get_wallet_address() { if(__used_wallet_address != DEV_WALLET_ADDRESS) { LOG("--> Switching to dev wallet for 1 minute."); __used_wallet_address = DEV_WALLET_ADDRESS; + __force_hashrate_report = true; } } else { diff --git a/http/client.h b/http/client.h index abdff96..d027dd9 100755 --- a/http/client.h +++ b/http/client.h @@ -29,7 +29,7 @@ class ariopool_client : public http { public: ariopool_client(const string &pool_address, const string &worker_id, const string &wallet_address); - ariopool_update_result update(double hash_rate); + ariopool_update_result update(double hash_rate_cblocks, double hash_rate_gblocks); ariopool_submit_result submit(const string &hash, const string &nonce, const string &public_key); private: @@ -41,7 +41,10 @@ class ariopool_client : public http { string __client_wallet_address; string __used_wallet_address; + bool __force_hashrate_report; + uint64_t __timestamp; + uint64_t __last_hash_report; }; #endif //PROJECT_CLIENT_H diff --git a/miner/miner.cpp b/miner/miner.cpp index 794456e..1fd090e 100755 --- a/miner/miner.cpp +++ b/miner/miner.cpp @@ -155,12 +155,14 @@ uint64_t miner::__calc_compare(const string &duration) { bool miner::__update_pool_data() { vector hashers = hasher::get_active_hashers(); - double hash_rate = 0; + double hash_rate_cblocks = 0; + double hash_rate_gblocks = 0; for(vector::iterator it = hashers.begin();it != hashers.end();++it) { - hash_rate += (*it)->get_current_hash_rate(); + hash_rate_cblocks += (*it)->get_avg_hash_rate_cblocks(); + hash_rate_gblocks += (*it)->get_avg_hash_rate_gblocks(); } - ariopool_update_result new_settings = __client.update(hash_rate); + ariopool_update_result new_settings = __client.update(hash_rate_cblocks, hash_rate_gblocks); if (new_settings.success && (new_settings.block != __blk || new_settings.difficulty != __difficulty || @@ -196,44 +198,53 @@ void miner::__display_report() { stringstream ss; double hash_rate = 0; - double avg_hash_rate = 0; - uint32_t hash_count = 0; + double avg_hash_rate_cblocks = 0; + double avg_hash_rate_gblocks = 0; + uint32_t hash_count_cblocks = 0; + uint32_t hash_count_gblocks = 0; if(!__args.is_verbose() || hashers.size() == 1) { for (vector::iterator it = hashers.begin(); it != hashers.end(); ++it) { hash_rate += (*it)->get_current_hash_rate(); - avg_hash_rate += (*it)->get_avg_hash_rate(); - hash_count += (*it)->get_hash_count(); + avg_hash_rate_cblocks += (*it)->get_avg_hash_rate_cblocks(); + hash_count_cblocks += (*it)->get_hash_count_cblocks(); + avg_hash_rate_gblocks += (*it)->get_avg_hash_rate_gblocks(); + hash_count_gblocks += (*it)->get_hash_count_gblocks(); } - ss << fixed << setprecision(2) << "--> Last hash rate: " << setw(6) << hash_rate << " H/s " << - "Average: " << setw(6) << avg_hash_rate << " H/s " << - "Total hashes: " << setw(6) << hash_count << " " << - "Mining Time: " << setw(6) << __total_time << " " << - "Shares: " << setw(4) << __confirmed << " " << - "Finds: " << setw(4) << __found << " " << - "Rejected: " << setw(4) << __rejected; + ss << fixed << setprecision(2) << "--> Hash Rate: " << setw(6) << hash_rate << " H/s " << + "Avg. (CPU): " << setw(6) << avg_hash_rate_cblocks << " H/s " << + "Avg. (GPU): " << setw(6) << avg_hash_rate_gblocks << " H/s " << + "Count: " << setw(4) << (hash_count_cblocks + hash_count_gblocks) << " " << + "Time: " << setw(4) << __total_time << " " << + "Shares: " << setw(3) << __confirmed << " " << + "Finds: " << setw(3) << __found << " " << + "Rejected: " << setw(3) << __rejected; } else { - ss << fixed << setprecision(2) << "--> Mining Time: " << setw(6) << __total_time << " " << - "Shares: " << setw(4) << __confirmed << " " << - "Finds: " << setw(4) << __found << " " << - "Rejected: " << setw(4) << __rejected << endl; + ss << fixed << setprecision(2) << "--> Time: " << setw(4) << __total_time << " " << + "Shares: " << setw(3) << __confirmed << " " << + "Finds: " << setw(3) << __found << " " << + "Rejected: " << setw(3) << __rejected << endl; for (vector::iterator it = hashers.begin(); it != hashers.end(); ++it) { if((*it)->get_intensity() == 0) continue; hash_rate += (*it)->get_current_hash_rate(); - avg_hash_rate += (*it)->get_avg_hash_rate(); - hash_count += (*it)->get_hash_count(); + avg_hash_rate_cblocks += (*it)->get_avg_hash_rate_cblocks(); + hash_count_cblocks += (*it)->get_hash_count_cblocks(); + avg_hash_rate_gblocks += (*it)->get_avg_hash_rate_gblocks(); + hash_count_gblocks += (*it)->get_hash_count_gblocks(); ss << fixed << setprecision(2) << "--> " << (*it)->get_type() << " " << - "Last hash rate: " << setw(6)<< (*it)->get_current_hash_rate() << " H/s " << - "Average: " << setw(6) << (*it)->get_avg_hash_rate() << " H/s " << - "Total hashes: " << setw(6) << (*it)->get_hash_count() << endl; + "Hash rate: " << setw(6)<< (*it)->get_current_hash_rate() << " H/s " << + "Avg. (CPU): " << setw(6) << (*it)->get_avg_hash_rate_cblocks() << " H/s " << + "Avg. (GPU): " << setw(6) << (*it)->get_avg_hash_rate_gblocks() << " " << + "Count: " << setw(4) << ((*it)->get_hash_count_cblocks() + (*it)->get_hash_count_gblocks()) << endl; } ss << fixed << setprecision(2) << "--> ALL " << - "Last hash rate: " << setw(6) << hash_rate << " H/s " << - "Average: " << setw(6) << avg_hash_rate << " H/s " << - "Total hashes: " << setw(6) << hash_count; + "Hash rate: " << setw(6) << hash_rate << " H/s " << + "Avg. (CPU): " << setw(6) << avg_hash_rate_cblocks << " H/s " << + "Avg. (GPU): " << setw(6) << avg_hash_rate_gblocks << " " << + "Count: " << setw(4) << (hash_count_cblocks + hash_count_gblocks); } LOG(ss.str());