From f7e64b9164b8995574a75e991e9ccd09097c0c79 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 24 Oct 2024 14:44:15 +0200 Subject: [PATCH] don't populate cache in get_last_n_blocks_timestamps_median() if the resulted num of blocks isn't equal to window size --- src/currency_core/blockchain_storage.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 3dcbaed8..0d6d41f8 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -5709,7 +5709,8 @@ uint64_t blockchain_storage::get_last_n_blocks_timestamps_median(size_t n) const std::vector timestamps = get_last_n_blocks_timestamps(n); uint64_t median_res = epee::misc_utils::median(timestamps); - m_timestamps_median_cache[n] = median_res; + if (timestamps.size() == n) + m_timestamps_median_cache[n] = median_res; return median_res; } //------------------------------------------------------------------