From 54fe6c3b09a8bc1b95e3c1dde951420cc2cfb2e3 Mon Sep 17 00:00:00 2001 From: wowario Date: Sat, 26 May 2018 09:40:23 +0300 Subject: [PATCH] adjust FTL, timestamp check window --- src/cryptonote_config.h | 2 ++ src/cryptonote_core/blockchain.cpp | 17 ++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index fbb57fe4a..65c5da036 100755 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -44,10 +44,12 @@ #define CURRENT_TRANSACTION_VERSION 2 #define CURRENT_BLOCK_MAJOR_VERSION 7 #define CURRENT_BLOCK_MINOR_VERSION 7 +#define CRYPTONOTE_BLOCK_FUTURE_TIME_LIMIT_V3 420 #define CRYPTONOTE_BLOCK_FUTURE_TIME_LIMIT_V2 300*2 #define CRYPTONOTE_BLOCK_FUTURE_TIME_LIMIT 60*60*2 #define CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE 4 +#define BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW_V2 11 #define BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW 60 // MONEY_SUPPLY - total number coins to be generated diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index b73a90c0f..933a3b282 100755 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -1334,11 +1334,12 @@ bool Blockchain::complete_timestamps_vector(uint64_t start_top_height, std::vect { LOG_PRINT_L3("Blockchain::" << __func__); - if(timestamps.size() >= BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW) + uint64_t blockchain_timestamp_check_window = get_current_hard_fork_version() < 9 ? BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW : BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW_V2; + if(timestamps.size() >= blockchain_timestamp_check_window) return true; CRITICAL_REGION_LOCAL(m_blockchain_lock); - size_t need_elements = BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW - timestamps.size(); + size_t need_elements = blockchain_timestamp_check_window - timestamps.size(); CHECK_AND_ASSERT_MES(start_top_height < m_db->height(), false, "internal error: passed start_height not < " << " m_db->height() -- " << start_top_height << " >= " << m_db->height()); size_t stop_offset = start_top_height > need_elements ? start_top_height - need_elements : 0; while (start_top_height != stop_offset) @@ -3195,9 +3196,10 @@ bool Blockchain::check_block_timestamp(std::vector& timestamps, const LOG_PRINT_L3("Blockchain::" << __func__); uint64_t median_ts = epee::misc_utils::median(timestamps); + uint64_t blockchain_timestamp_check_window = get_current_hard_fork_version() < 9 ? BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW : BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW_V2; if(b.timestamp < median_ts) { - MERROR_VER("Timestamp of block with id: " << get_block_hash(b) << ", " << b.timestamp << ", less than median of last " << BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW << " blocks, " << median_ts); + MERROR_VER("Timestamp of block with id: " << get_block_hash(b) << ", " << b.timestamp << ", less than median of last " << blockchain_timestamp_check_window << " blocks, " << median_ts); return false; } @@ -3214,15 +3216,16 @@ bool Blockchain::check_block_timestamp(std::vector& timestamps, const bool Blockchain::check_block_timestamp(const block& b) const { LOG_PRINT_L3("Blockchain::" << __func__); - uint64_t cryptonote_block_future_time_limit = get_current_hard_fork_version() < 7 ? CRYPTONOTE_BLOCK_FUTURE_TIME_LIMIT : CRYPTONOTE_BLOCK_FUTURE_TIME_LIMIT_V2; + uint64_t cryptonote_block_future_time_limit = get_current_hard_fork_version() < 9 ? CRYPTONOTE_BLOCK_FUTURE_TIME_LIMIT_V2 : CRYPTONOTE_BLOCK_FUTURE_TIME_LIMIT_V3; + uint64_t blockchain_timestamp_check_window = get_current_hard_fork_version() < 9 ? BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW : BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW_V2; if(b.timestamp > get_adjusted_time() + cryptonote_block_future_time_limit) { - MERROR_VER("Timestamp of block with id: " << get_block_hash(b) << ", " << b.timestamp << ", bigger than adjusted time + 2 hours"); + MERROR_VER("Timestamp of block with id: " << get_block_hash(b) << ", " << b.timestamp << ", bigger than adjusted time + 7 minutes"); return false; } // if not enough blocks, no proper median yet, return true - if(m_db->height() < BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW) + if(m_db->height() < blockchain_timestamp_check_window) { return true; } @@ -3231,7 +3234,7 @@ bool Blockchain::check_block_timestamp(const block& b) const auto h = m_db->height(); // need most recent 60 blocks, get index of first of those - size_t offset = h - BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW; + size_t offset = h - blockchain_timestamp_check_window; for(;offset < h; ++offset) { timestamps.push_back(m_db->get_block_timestamp(offset));