1
0
Fork 0
forked from lthn/blockchain

correctly handle null ptr that may be returned from progpow in get_block_longhash()

This commit is contained in:
sowle 2019-08-29 18:44:59 +03:00
parent 6d173d7077
commit e07e4b0b9b
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
3 changed files with 6 additions and 5 deletions

View file

@ -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<epoch_context_full> get_global_epoch_context_full(int epoch_number);
} // namespace ethash

View file

@ -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<epoch_context_full> 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

View file

@ -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<int>(epoch));
auto res_eth = progpow::hash(context, static_cast<int>(height), *(ethash::hash256*)&block_header_hash, nonce);
std::shared_ptr<ethash::epoch_context_full> p_context = progpow::get_global_epoch_context_full(static_cast<int>(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<int>(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;