From 43bde5aa99f147c0af1dcc7c5e90b3b0b5ab2a92 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 22 May 2025 15:50:18 +0300 Subject: [PATCH] fixed a rare race condition in get_coinbase_hash_cached() 2 --- src/currency_core/blockchain_storage_basic.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/currency_core/blockchain_storage_basic.h b/src/currency_core/blockchain_storage_basic.h index 292d2b17..a72c573e 100644 --- a/src/currency_core/blockchain_storage_basic.h +++ b/src/currency_core/blockchain_storage_basic.h @@ -203,7 +203,7 @@ namespace currency if (bei.m_cache_coinbase_state == 2) { // state is 2, cache must be ready, access the cache - std::shared_ptr local_coinbase_id = bei.m_cache_coinbase_id; + std::shared_ptr local_coinbase_id = std::atomic_load(&bei.m_cache_coinbase_id); CHECK_AND_ASSERT_THROW_MES(local_coinbase_id, "internal error: m_cache_coinbase_id is empty"); return *local_coinbase_id; } @@ -213,7 +213,7 @@ namespace currency { // state has just been 0, now 1, we're calculating std::shared_ptr ptr_h = std::make_shared(get_transaction_hash(bei.bl.miner_tx)); - std::atomic_store(&bei.m_cache_coinbase_id, ptr_h); + std::atomic_store(&bei.m_cache_coinbase_id, ptr_h); // when moving to C++20 consider to change this to atomic shared ptr -- sowle bei.m_cache_coinbase_state.store(2); return *ptr_h; }