From e07e4b0b9b237118587631208c7b291b60dc216f Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 29 Aug 2019 18:44:59 +0300 Subject: [PATCH 1/2] correctly handle null ptr that may be returned from progpow in get_block_longhash() --- contrib/ethereum/libethash/ethash/ethash.hpp | 2 +- contrib/ethereum/libethash/managed.cpp | 4 ++-- src/currency_core/basic_pow_helpers.cpp | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/contrib/ethereum/libethash/ethash/ethash.hpp b/contrib/ethereum/libethash/ethash/ethash.hpp index 03f29afd..8034090b 100644 --- a/contrib/ethereum/libethash/ethash/ethash.hpp +++ b/contrib/ethereum/libethash/ethash/ethash.hpp @@ -156,5 +156,5 @@ int find_epoch_number(const hash256& seed) noexcept; const epoch_context& get_global_epoch_context(int epoch_number); /// Get global shared epoch context with full dataset initialized. -const epoch_context_full& get_global_epoch_context_full(int epoch_number); +std::shared_ptr get_global_epoch_context_full(int epoch_number); } // namespace ethash diff --git a/contrib/ethereum/libethash/managed.cpp b/contrib/ethereum/libethash/managed.cpp index 900da7e7..82ff69b2 100644 --- a/contrib/ethereum/libethash/managed.cpp +++ b/contrib/ethereum/libethash/managed.cpp @@ -89,12 +89,12 @@ const epoch_context& get_global_epoch_context(int epoch_number) return *thread_local_context; } -const epoch_context_full& get_global_epoch_context_full(int epoch_number) +std::shared_ptr get_global_epoch_context_full(int epoch_number) { // Check if local context matches epoch number. if (!thread_local_context_full || thread_local_context_full->epoch_number != epoch_number) update_local_context_full(epoch_number); - return *thread_local_context_full; + return thread_local_context_full; } } // namespace ethash diff --git a/src/currency_core/basic_pow_helpers.cpp b/src/currency_core/basic_pow_helpers.cpp index 7c2275cc..b97a1087 100644 --- a/src/currency_core/basic_pow_helpers.cpp +++ b/src/currency_core/basic_pow_helpers.cpp @@ -50,8 +50,9 @@ namespace currency 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, static_cast(height), *(ethash::hash256*)&block_header_hash, nonce); + 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"); + auto res_eth = progpow::hash(*p_context, static_cast(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; From a8173575bb100d23903bbae5fd3a58ba374e2f07 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 29 Aug 2019 18:45:59 +0300 Subject: [PATCH 2/2] === build number: 48 -> 49 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index 351ac76a..307ec14d 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 48 +#define PROJECT_VERSION_BUILD_NO 49 #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 "]"