From f7048fd7af3ad79887380e791cf0a7e8627724a5 Mon Sep 17 00:00:00 2001 From: "crypro.zoidberg" Date: Fri, 12 Apr 2019 00:00:36 +0200 Subject: [PATCH 1/5] connectivity_tool updated --- src/connectivity_tool/conn_tool.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/connectivity_tool/conn_tool.cpp b/src/connectivity_tool/conn_tool.cpp index 381c2c07..660de59a 100644 --- a/src/connectivity_tool/conn_tool.cpp +++ b/src/connectivity_tool/conn_tool.cpp @@ -56,6 +56,7 @@ namespace const command_line::arg_descriptor arg_get_info_flags = { "getinfo-flags-hex", "Set of bits for rpc-get-daemon-info", "", true }; const command_line::arg_descriptor arg_set_peer_log_level = { "set-peer-log-level", "Set log level for remote peer", 0, true }; const command_line::arg_descriptor arg_download_peer_log = { "download-peer-log", "Download log from remote peer (starting offset)", 0, true }; + const command_line::arg_descriptor arg_do_consloe_log = { "do-console-log", "Tool generates debug console output(debug purposes)", "", true }; } typedef COMMAND_REQUEST_STAT_INFO_T::stat_info> COMMAND_REQUEST_STAT_INFO; @@ -1004,7 +1005,7 @@ int main(int argc, char* argv[]) { string_tools::set_module_name_and_folder(argv[0]); - log_space::get_set_log_detalisation_level(true, LOG_LEVEL_4); + log_space::get_set_log_detalisation_level(true, LOG_LEVEL_2); tools::signal_handler::install_fatal([](int sig_number, void* address) { LOG_ERROR("\n\nFATAL ERROR\nsig: " << sig_number << ", address: " << address); @@ -1036,6 +1037,8 @@ int main(int argc, char* argv[]) command_line::add_arg(desc_params, arg_log_journal_len); command_line::add_arg(desc_params, arg_set_peer_log_level); command_line::add_arg(desc_params, arg_download_peer_log); + command_line::add_arg(desc_params, arg_do_consloe_log); + @@ -1059,6 +1062,11 @@ int main(int argc, char* argv[]) }); if (!r) return 1; + if (command_line::has_arg(vm, arg_do_consloe_log) && command_line::get_arg(vm, arg_do_consloe_log)) + { + log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL); + } + if (command_line::get_arg(vm, command_line::arg_version)) { From 6976ebb18df4dff4945af15a64e1709f0dad852f Mon Sep 17 00:00:00 2001 From: "crypro.zoidberg" Date: Fri, 12 Apr 2019 15:52:03 +0200 Subject: [PATCH 2/5] added seed infor to get_block_template --- src/currency_core/basic_pow_helpers.cpp | 8 ++++++++ src/currency_core/basic_pow_helpers.h | 1 + src/rpc/core_rpc_server.cpp | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/src/currency_core/basic_pow_helpers.cpp b/src/currency_core/basic_pow_helpers.cpp index 95ed6dfd..94af36d9 100644 --- a/src/currency_core/basic_pow_helpers.cpp +++ b/src/currency_core/basic_pow_helpers.cpp @@ -39,6 +39,14 @@ namespace currency return height / ETHASH_EPOCH_LENGTH; } //-------------------------------------------------------------- + crypto::hash ethash_epoch_to_seed(int epoch) + { + auto res_eth = ethash_calculate_epoch_seed(epoch); + crypto::hash result = currency::null_hash; + memcpy(&result.data, &res_eth, sizeof(res_eth)); + return result; + } + //-------------------------------------------------------------- crypto::hash get_block_longhash(uint64_t height, const crypto::hash& block_long_ash, uint64_t nonce) { int epoch = ethash_height_to_epoch(height); diff --git a/src/currency_core/basic_pow_helpers.h b/src/currency_core/basic_pow_helpers.h index ccc1a132..4bea2718 100644 --- a/src/currency_core/basic_pow_helpers.h +++ b/src/currency_core/basic_pow_helpers.h @@ -28,6 +28,7 @@ namespace currency { int ethash_height_to_epoch(uint64_t height); + crypto::hash ethash_epoch_to_seed(int epoch); crypto::hash get_block_longhash(uint64_t h, const crypto::hash& block_long_ash, 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/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 5089f054..a27ec33d 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -799,6 +799,10 @@ namespace currency res.blocktemplate_blob = string_tools::buff_to_hex_nodelimer(block_blob); res.prev_hash = string_tools::pod_to_hex(b.prev_id); + + //calculate epoch seed + res.seed = currency::ethash_epoch_to_seed(currency::ethash_height_to_epoch(res.height)); + res.status = CORE_RPC_STATUS_OK; return true; From e0e4220e79adcbb73f9b727cfb9e6ce6975910c2 Mon Sep 17 00:00:00 2001 From: "crypro.zoidberg" Date: Sun, 14 Apr 2019 14:15:24 +0200 Subject: [PATCH 3/5] added rpc command for ignoring offline status(for debug) --- src/currency_core/basic_pow_helpers.cpp | 4 ++-- src/currency_core/basic_pow_helpers.h | 2 +- src/rpc/core_rpc_server.cpp | 10 +++++++++- src/rpc/core_rpc_server.h | 1 + src/wallet/wallet_rpc_server.cpp | 1 + 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/currency_core/basic_pow_helpers.cpp b/src/currency_core/basic_pow_helpers.cpp index 94af36d9..0509ff65 100644 --- a/src/currency_core/basic_pow_helpers.cpp +++ b/src/currency_core/basic_pow_helpers.cpp @@ -47,11 +47,11 @@ namespace currency return result; } //-------------------------------------------------------------- - crypto::hash get_block_longhash(uint64_t height, const crypto::hash& block_long_ash, uint64_t nonce) + crypto::hash get_block_longhash(uint64_t height, const crypto::hash& block_header_hash, uint64_t nonce) { int epoch = ethash_height_to_epoch(height); const auto& context = progpow::get_global_epoch_context_full(static_cast(epoch)); - auto res_eth = progpow::hash(context, height, *(ethash::hash256*)&block_long_ash, nonce); + auto res_eth = progpow::hash(context, height, *(ethash::hash256*)&block_header_hash, nonce); crypto::hash result = currency::null_hash; memcpy(&result.data, &res_eth.final_hash, sizeof(res_eth.final_hash)); return result; diff --git a/src/currency_core/basic_pow_helpers.h b/src/currency_core/basic_pow_helpers.h index 4bea2718..36b2f0ad 100644 --- a/src/currency_core/basic_pow_helpers.h +++ b/src/currency_core/basic_pow_helpers.h @@ -29,7 +29,7 @@ namespace currency { int ethash_height_to_epoch(uint64_t height); crypto::hash ethash_epoch_to_seed(int epoch); - crypto::hash get_block_longhash(uint64_t h, const crypto::hash& block_long_ash, uint64_t nonce); + 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/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index a27ec33d..64a38cc2 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -24,23 +24,29 @@ namespace currency { const command_line::arg_descriptor arg_rpc_bind_ip = {"rpc-bind-ip", "", "127.0.0.1"}; const command_line::arg_descriptor arg_rpc_bind_port = {"rpc-bind-port", "", std::to_string(RPC_DEFAULT_PORT)}; + const command_line::arg_descriptor arg_rpc_ignore_status = {"rpc-ignore-offline", "Let rpc calls despite online/offline status", false, true }; } //----------------------------------------------------------------------------------- void core_rpc_server::init_options(boost::program_options::options_description& desc) { command_line::add_arg(desc, arg_rpc_bind_ip); command_line::add_arg(desc, arg_rpc_bind_port); + command_line::add_arg(desc, arg_rpc_ignore_status); } //------------------------------------------------------------------------------------------------------------------------------ core_rpc_server::core_rpc_server(core& cr, nodetool::node_server >& p2p, bc_services::bc_offers_service& of - ) :m_core(cr), m_p2p(p2p), m_of(of), m_session_counter(0) + ) :m_core(cr), m_p2p(p2p), m_of(of), m_session_counter(0), m_ignore_status(false) {} //------------------------------------------------------------------------------------------------------------------------------ bool core_rpc_server::handle_command_line(const boost::program_options::variables_map& vm) { m_bind_ip = command_line::get_arg(vm, arg_rpc_bind_ip); m_port = command_line::get_arg(vm, arg_rpc_bind_port); + if (command_line::has_arg(vm, arg_rpc_ignore_status)) + { + m_ignore_status = command_line::get_arg(vm, arg_rpc_ignore_status); + } return true; } //------------------------------------------------------------------------------------------------------------------------------ @@ -55,6 +61,8 @@ namespace currency bool core_rpc_server::check_core_ready_(const std::string& calling_method) { #ifndef TESTNET + if (m_ignore_status) + return true; if(!m_p2p.get_payload_object().is_synchronized()) { LOG_PRINT_L0("[" << calling_method << "]Core busy cz is_synchronized"); diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h index 53e723c7..c74e31b4 100644 --- a/src/rpc/core_rpc_server.h +++ b/src/rpc/core_rpc_server.h @@ -177,6 +177,7 @@ namespace currency bc_services::bc_offers_service& m_of; std::string m_port; std::string m_bind_ip; + bool m_ignore_status; //mining stuff epee::critical_section m_session_jobs_lock; std::map m_session_jobs; //session id -> blob diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 5d7846b2..53af9d91 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -28,6 +28,7 @@ namespace tools command_line::add_arg(desc, arg_rpc_bind_ip); command_line::add_arg(desc, arg_rpc_bind_port); command_line::add_arg(desc, arg_miner_text_info); + command_line::add_arg(desc, arg_rpc_ignore_status); } //------------------------------------------------------------------------------------------------------------------------------ wallet_rpc_server::wallet_rpc_server(wallet2& w):m_wallet(w), m_do_mint(false) From 44fe6ada85397f9cdbcc5919072fe4506024ec02 Mon Sep 17 00:00:00 2001 From: "crypro.zoidberg" Date: Sun, 14 Apr 2019 20:23:49 +0200 Subject: [PATCH 4/5] added nonce messge --- src/currency_core/blockchain_storage.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index a24d6b47..3dcd502e 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -4295,8 +4295,9 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt if (!check_hash(proof_hash, current_diffic)) { LOG_ERROR("Block with id: " << id << ENDL - << "PoW hash: " << proof_hash << ENDL - << "unexpected difficulty: " << current_diffic); + << "PoW hash: " << proof_hash << ENDL + << "nonce: " << bl.nonce << ENDL + << "expected difficulty: " << current_diffic); bvc.m_verification_failed = true; return false; } From 47aa684f4dab1a26680b39500beffd255255d2ef Mon Sep 17 00:00:00 2001 From: "crypro.zoidberg" Date: Sun, 14 Apr 2019 23:41:24 +0200 Subject: [PATCH 5/5] 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)