From 47aa684f4dab1a26680b39500beffd255255d2ef Mon Sep 17 00:00:00 2001 From: "crypro.zoidberg" Date: Sun, 14 Apr 2019 23:41:24 +0200 Subject: [PATCH] added more debug info to pow verification --- src/currency_core/basic_pow_helpers.cpp | 14 +++++++++----- src/currency_core/basic_pow_helpers.h | 1 + src/currency_core/blockchain_storage.cpp | 1 + src/stratum/stratum_server.cpp | 4 ++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/currency_core/basic_pow_helpers.cpp b/src/currency_core/basic_pow_helpers.cpp index 0509ff65..6b3e53f1 100644 --- a/src/currency_core/basic_pow_helpers.cpp +++ b/src/currency_core/basic_pow_helpers.cpp @@ -57,6 +57,14 @@ namespace currency return result; } //--------------------------------------------------------------- + crypto::hash get_block_header_mining_hash(const block& b) + { + blobdata bd = get_block_hashing_blob(b); + + access_nonce_in_block_blob(bd) = 0; + return crypto::cn_fast_hash(bd.data(), bd.size()); + } + //--------------------------------------------------------------- void get_block_longhash(const block& b, crypto::hash& res) { /* @@ -65,11 +73,7 @@ namespace currency To achieve the same effect we make blob of data from block in normal way, but then set to zerro nonce inside serialized buffer, and then pass this nonce to ethash algo as a second argument, as it expected. */ - blobdata bd = get_block_hashing_blob(b); - - access_nonce_in_block_blob(bd) = 0; - crypto::hash bl_hash = crypto::cn_fast_hash(bd.data(), bd.size()); - + crypto::hash bl_hash = get_block_header_mining_hash(b); res = get_block_longhash(get_block_height(b), bl_hash, b.nonce); } //--------------------------------------------------------------- diff --git a/src/currency_core/basic_pow_helpers.h b/src/currency_core/basic_pow_helpers.h index 36b2f0ad..32ded457 100644 --- a/src/currency_core/basic_pow_helpers.h +++ b/src/currency_core/basic_pow_helpers.h @@ -29,6 +29,7 @@ namespace currency { int ethash_height_to_epoch(uint64_t height); crypto::hash ethash_epoch_to_seed(int epoch); + crypto::hash get_block_header_mining_hash(const block& b); crypto::hash get_block_longhash(uint64_t h, const crypto::hash& block_header_hash, uint64_t nonce); void get_block_longhash(const block& b, crypto::hash& res); crypto::hash get_block_longhash(const block& b); diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 3dcd502e..51c082bd 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -4297,6 +4297,7 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt LOG_ERROR("Block with id: " << id << ENDL << "PoW hash: " << proof_hash << ENDL << "nonce: " << bl.nonce << ENDL + << "header_mining_hash: " << get_block_header_mining_hash(bl) << ENDL << "expected difficulty: " << current_diffic); bvc.m_verification_failed = true; return false; diff --git a/src/stratum/stratum_server.cpp b/src/stratum/stratum_server.cpp index 28c802dc..28c10299 100644 --- a/src/stratum/stratum_server.cpp +++ b/src/stratum/stratum_server.cpp @@ -821,7 +821,7 @@ namespace } m_json_helper.feed(str, data_size); - LP_CC_WORKER(m_context, "data received: " << data_size << " bytes:" << ENDL << std::string(str, data_size), LOG_LEVEL_4); + LP_CC_WORKER(m_context, "DATA received <<<<<<<<<<<<< " << data_size << " bytes:" << ENDL << std::string(str, data_size), LOG_LEVEL_0); if (m_json_helper.has_objects()) { @@ -975,7 +975,7 @@ namespace void send(const std::string& data) { static_cast(m_p_connection)->do_send(data.c_str(), data.size()); - LOG_PRINT_CC(m_context, "DATA sent >>>>>>>>>>>>> " << ENDL << data, LOG_LEVEL_4); + LOG_PRINT_CC(m_context, "DATA sent >>>>>>>>>>>>> " << ENDL << data, LOG_LEVEL_0); } void send_notification(const std::string& json)