diff --git a/contrib/ethereum/libethash/ethash.cpp b/contrib/ethereum/libethash/ethash.cpp index f12faab7..10ee9c6d 100644 --- a/contrib/ethereum/libethash/ethash.cpp +++ b/contrib/ethereum/libethash/ethash.cpp @@ -145,7 +145,11 @@ epoch_context_full* create_epoch_context( char* const alloc_data = static_cast(std::calloc(1, alloc_size)); if (!alloc_data) - return nullptr; // Signal out-of-memory by returning null pointer. + { + LOG_CUSTOM_WITH_CALLSTACK("CRITICAL: std::calloc(" << alloc_size << ") failed in create_epoch_context()", 0); + return nullptr; // Signal out-of-memory by returning null pointer. + } + LOG_CUSTOM("context for epoch " << epoch_number << " allocated, size: " << alloc_size << " bytes", 0); hash512* const light_cache = reinterpret_cast(alloc_data + context_alloc_size); const hash256 epoch_seed = calculate_epoch_seed(epoch_number); @@ -373,6 +377,33 @@ search_result search(const epoch_context_full& context, const hash256& header_ha } return {}; } + +custom_log_level_function*& access_custom_log_level_function() +{ + static custom_log_level_function* p_custom_log_level_function = nullptr; + return p_custom_log_level_function; +} + +custom_log_function*& access_custom_log_function() +{ + static custom_log_function* p_custom_log_function = nullptr; + return p_custom_log_function; +} + +int get_custom_log_level() +{ + if (access_custom_log_level_function() != nullptr) + return access_custom_log_level_function()(); + return -1; +} + +void custom_log(const std::string& m, bool add_callstack) +{ + if (access_custom_log_function() != nullptr) + access_custom_log_function()(m, add_callstack); +} + + } // namespace ethash using namespace ethash; @@ -434,6 +465,8 @@ void ethash_destroy_epoch_context_full(epoch_context_full* context) noexcept void ethash_destroy_epoch_context(epoch_context* context) noexcept { + LOG_CUSTOM("context for epoch " << context->epoch_number << " is about to be freed", 0); + context->~epoch_context(); std::free(context); } diff --git a/contrib/ethereum/libethash/ethash/ethash.hpp b/contrib/ethereum/libethash/ethash/ethash.hpp index 8034090b..0f2962a5 100644 --- a/contrib/ethereum/libethash/ethash/ethash.hpp +++ b/contrib/ethereum/libethash/ethash/ethash.hpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include namespace ethash { @@ -157,4 +159,33 @@ const epoch_context& get_global_epoch_context(int epoch_number); /// Get global shared epoch context with full dataset initialized. std::shared_ptr get_global_epoch_context_full(int epoch_number); + +typedef int (custom_log_level_function)(); +typedef void (custom_log_function)(const std::string& m, bool add_callstack); + +custom_log_level_function*& access_custom_log_level_function(); +custom_log_function*& access_custom_log_function(); +int get_custom_log_level(); +void custom_log(const std::string& m, bool add_callstack); + +#define LOG_CUSTOM(msg, level) \ +{ \ + if (level <= ethash::get_custom_log_level()) \ + { \ + std::stringstream ss; \ + ss << msg << std::endl; \ + ethash::custom_log(ss.str(), false); \ + } \ +} + +#define LOG_CUSTOM_WITH_CALLSTACK(msg, level) \ +{ \ + if (level <= ethash::get_custom_log_level()) \ + { \ + std::stringstream ss; \ + ss << msg << std::endl; \ + ethash::custom_log(ss.str(), true); \ + } \ +} + } // namespace ethash diff --git a/src/currency_core/basic_pow_helpers.cpp b/src/currency_core/basic_pow_helpers.cpp index b97a1087..ddb87912 100644 --- a/src/currency_core/basic_pow_helpers.cpp +++ b/src/currency_core/basic_pow_helpers.cpp @@ -22,17 +22,31 @@ namespace currency { //-------------------------------------------------------------- - //global object -// crypto::ethash::cache_manager cache; -// void ethash_set_use_dag(bool use_dag) -// { -// cache.set_use_dag(use_dag); -// } -// //------------------------------------------------------------------ -// const uint8_t* ethash_get_dag(uint64_t epoch, uint64_t& dag_size) -// { -// return cache.get_dag(epoch, dag_size); -// } + int ethash_custom_log_get_level() + { + return epee::log_space::get_set_log_detalisation_level(); + } + //-------------------------------------------------------------- + void ethash_custom_log(const std::string& m, bool add_callstack) + { + std::string msg = epee::log_space::log_singletone::get_prefix_entry() + "[ETHASH]" + m; + if (add_callstack) + msg = msg + "callstask: " + epee::misc_utils::get_callstack(); + + epee::log_space::log_singletone::do_log_message(msg, LOG_LEVEL_0, epee::log_space::console_color_default, true, LOG_DEFAULT_TARGET); + } + //-------------------------------------------------------------- + void init_ethash_log_if_necessary() + { + static bool inited = false; + if (inited) + return; + + ethash::access_custom_log_level_function() = ðash_custom_log_get_level; + ethash::access_custom_log_function() = ðash_custom_log; + + inited = true; + } //------------------------------------------------------------------ int ethash_height_to_epoch(uint64_t height) { @@ -49,6 +63,7 @@ namespace currency //-------------------------------------------------------------- crypto::hash get_block_longhash(uint64_t height, const crypto::hash& block_header_hash, uint64_t nonce) { + init_ethash_log_if_necessary(); int epoch = ethash_height_to_epoch(height); std::shared_ptr p_context = progpow::get_global_epoch_context_full(static_cast(epoch)); CHECK_AND_ASSERT_THROW_MES(p_context, "progpow::get_global_epoch_context_full returned null"); diff --git a/src/version.h.in b/src/version.h.in index 307ec14d..d469b618 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -2,6 +2,6 @@ #define BUILD_COMMIT_ID "@VERSION@" #define PROJECT_VERSION "1.0" -#define PROJECT_VERSION_BUILD_NO 49 +#define PROJECT_VERSION_BUILD_NO 50 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]"