From 296a6c6211169139193f1f251f7a49ee966bcb28 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 22 May 2025 16:58:34 +0300 Subject: [PATCH] fixed a rare race condition in get_coinbase_hash_cached() 3 --- src/currency_core/blockchain_storage_basic.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/currency_core/blockchain_storage_basic.h b/src/currency_core/blockchain_storage_basic.h index a72c573e..643ba527 100644 --- a/src/currency_core/blockchain_storage_basic.h +++ b/src/currency_core/blockchain_storage_basic.h @@ -204,8 +204,13 @@ namespace currency { // state is 2, cache must be ready, access the cache 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; + if (local_coinbase_id) + return *local_coinbase_id; + + // this branch is considered to be a rare case with possible race condition during state 1, reset state to 0 + bei.m_cache_coinbase_state.store(0); + crypto::hash h = get_transaction_hash(bei.bl.miner_tx); + return h; } uint8_t state = 0;