From 964968ded097afd27aea65b910df2b1866478600 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 2 Nov 2023 16:47:18 +0100 Subject: [PATCH] get_actual_timestamp() -> get_block_timestamp_from_miner_tx_extra(), corresponding check in pos block validation has been adjusted --- src/currency_core/blockchain_storage.cpp | 20 ++++++++++++-------- src/currency_core/currency_format_utils.cpp | 5 ++--- src/currency_core/currency_format_utils.h | 4 +--- tests/core_tests/chaingen.cpp | 2 +- tests/core_tests/emission_test.cpp | 2 +- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 1048c9b1..fa41923f 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -5705,15 +5705,19 @@ bool blockchain_storage::validate_pos_block(const block& b, CHECK_AND_ASSERT_MES(!have_tx_keyimg_as_spent(stake_key_image), false, "stake key image has been already spent in blockchain: " << stake_key_image); } - // the following check is de-facto not applicable since 2021-10, but left intact to avoid consensus issues - // PoS blocks don't use etc_tx_time anymore to store actual timestamp; instead, they use tx_service_attachment in mining tx extra - uint64_t actual_ts = get_actual_timestamp(b); - if ((actual_ts > b.timestamp && actual_ts - b.timestamp > POS_MAX_ACTUAL_TIMESTAMP_TO_MINED) || - (actual_ts < b.timestamp && b.timestamp - actual_ts > POS_MAX_ACTUAL_TIMESTAMP_TO_MINED) - ) + if (!is_hardfork_active(ZANO_HARDFORK_04_ZARCANUM)) { - LOG_PRINT_L0("PoS block actual timestamp " << actual_ts << " differs from b.timestamp " << b.timestamp << " by " << ((int64_t)actual_ts - (int64_t)b.timestamp) << " s, it's more than allowed " << POS_MAX_ACTUAL_TIMESTAMP_TO_MINED << " s."); - return false; + // the following check is de-facto not applicable since 2021-10, but left intact to avoid consensus issues + // PoS blocks don't use etc_tx_time anymore to store actual timestamp; instead, they use tx_service_attachment in mining tx extra + // TODO: remove this entire section after HF4 -- sowle + uint64_t actual_ts = get_block_timestamp_from_miner_tx_extra(b); + if ((actual_ts > b.timestamp && actual_ts - b.timestamp > POS_MAX_ACTUAL_TIMESTAMP_TO_MINED) || + (actual_ts < b.timestamp && b.timestamp - actual_ts > POS_MAX_ACTUAL_TIMESTAMP_TO_MINED) + ) + { + LOG_PRINT_L0("PoS block actual timestamp " << actual_ts << " differs from b.timestamp " << b.timestamp << " by " << ((int64_t)actual_ts - (int64_t)b.timestamp) << " s, it's more than allowed " << POS_MAX_ACTUAL_TIMESTAMP_TO_MINED << " s."); + return false; + } } // build kernel and calculate hash diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 87bd14bb..3c63c21b 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -3396,9 +3396,8 @@ namespace currency return median_fee * 10; } //--------------------------------------------------------------- - // NOTE: this function is obsolete and depricated - [[deprecated("PoS block real timestamp is set using a service attachment in mining tx extra since 2021-10")]] - uint64_t get_actual_timestamp(const block& b) + // TODO: remove this function after HF4 -- sowle + uint64_t get_block_timestamp_from_miner_tx_extra(const block& b) { uint64_t tes_ts = b.timestamp; if (is_pos_block(b)) diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index e30c40dd..f1b6d6f9 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -413,7 +413,7 @@ namespace currency // prints amount in format "3.14", "0.0" std::string print_money_brief(uint64_t amount, size_t decimal_point = CURRENCY_DISPLAY_DECIMAL_POINT); - uint64_t get_actual_timestamp(const block& b); // obsolete and depricated, use get_block_datetime + uint64_t get_block_timestamp_from_miner_tx_extra(const block& b); // remove this function after HF4 -- sowle uint64_t get_block_datetime(const block& b); void set_block_datetime(uint64_t datetime, block& b); @@ -425,8 +425,6 @@ namespace currency bool does_tx_have_only_mixin_inputs(const transaction& tx); bool is_showing_sender_addres(const transaction& tx); bool check_native_coins_amount_burnt_in_outs(const transaction& tx, const uint64_t amount, uint64_t* p_amount_burnt = nullptr); - [[deprecated("Use check_native_coins_amount_burnt_in_outs instead")]] uint64_t get_amount_for_zero_pubkeys(const transaction& tx); - //std::string get_comment_from_tx(const transaction& tx); std::string print_stake_kernel_info(const stake_kernel& sk); std::string dump_ring_sig_data(const crypto::hash& hash_for_sig, const crypto::key_image& k_image, const std::vector& output_keys_ptrs, const std::vector& sig); diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index a158e044..fde7294e 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -1458,7 +1458,7 @@ bool fill_tx_sources(std::vector& sources, const std: } } - uint64_t head_block_ts = get_actual_timestamp(blk_head); + uint64_t head_block_ts = get_block_datetime(blk_head); uint64_t next_block_height = blockchain.size(); // Iterate in reverse is more efficiency diff --git a/tests/core_tests/emission_test.cpp b/tests/core_tests/emission_test.cpp index f5aca21b..035726ca 100644 --- a/tests/core_tests/emission_test.cpp +++ b/tests/core_tests/emission_test.cpp @@ -118,7 +118,7 @@ bool emission_test::c1(currency::core& c, size_t ev_index, const std::vector(pb.m_block.miner_tx.vin[1]).amount; already_generated_coins += gen_coins; CHECK_AND_ASSERT_MES(already_generated_coins == bcs.total_coins(), false, "total coins missmatch: BCS has: " << bcs.total_coins() << ", expected: " << already_generated_coins);