From baf101ef4a05ae4d24ed717c16be929456775969 Mon Sep 17 00:00:00 2001 From: Javier Smooth Date: Fri, 13 Nov 2015 00:24:47 -0800 Subject: More changes for 2-min blocks Use the correct block time for realtime fuzz on locktime Use the correct block time to calculate next_difficulty on alt chains (will not work as-is with voting) Lock unit tests to original block time for now --- src/cryptonote_config.h | 3 ++- src/cryptonote_core/blockchain.cpp | 11 +++++++---- src/cryptonote_core/blockchain.h | 2 ++ src/cryptonote_core/blockchain_storage.cpp | 6 +++--- src/cryptonote_core/difficulty.cpp | 4 ---- src/cryptonote_core/difficulty.h | 1 - 6 files changed, 14 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index 94ead558f..6053387ac 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -75,11 +75,12 @@ #define DIFFICULTY_BLOCKS_COUNT DIFFICULTY_WINDOW + DIFFICULTY_LAG +#define CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V1 DIFFICULTY_TARGET_V1 * CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS #define CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS DIFFICULTY_TARGET * CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS #define CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS 1 -#define DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN DIFFICULTY_TARGET //just alias +#define DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN DIFFICULTY_TARGET_V1 //just alias; used by tests #define BLOCKS_IDS_SYNCHRONIZING_DEFAULT_COUNT 10000 //by default, blocks ids count in synchronizing diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index a24ef8283..e6a233868 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -674,8 +674,8 @@ difficulty_type Blockchain::get_difficulty_for_next_block() m_timestamps = timestamps; m_difficulties = difficulties; } - - return next_difficulty(timestamps, difficulties); + size_t target = get_current_hard_fork_version() < 2 ? DIFFICULTY_TARGET_V1 : DIFFICULTY_TARGET; + return next_difficulty(timestamps, difficulties, target); } //------------------------------------------------------------------ // This function removes blocks from the blockchain until it gets to the @@ -865,8 +865,11 @@ difficulty_type Blockchain::get_next_difficulty_for_alternative_chain(const std: } } + // FIXME: This will fail if fork activation heights are subject to voting + size_t target = get_ideal_hard_fork_version(bei.height) < 2 ? DIFFICULTY_TARGET_V1 : DIFFICULTY_TARGET; + // calculate the difficulty target for the block and return it - return next_difficulty(timestamps, cumulative_difficulties); + return next_difficulty(timestamps, cumulative_difficulties, target); } //------------------------------------------------------------------ // This function does a sanity check on basic things that all miner @@ -2194,7 +2197,7 @@ bool Blockchain::is_tx_spendtime_unlocked(uint64_t unlock_time) const { //interpret as time uint64_t current_time = static_cast(time(NULL)); - if(current_time + CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS >= unlock_time) + if(current_time + (get_current_hard_fork_version() < 2 ? CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V1 : CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS) >= unlock_time) return true; else return false; diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h index 00670c6d3..c83314634 100644 --- a/src/cryptonote_core/blockchain.h +++ b/src/cryptonote_core/blockchain.h @@ -160,6 +160,8 @@ namespace cryptonote HardFork::State get_hard_fork_state() const; uint8_t get_current_hard_fork_version() const { return m_hardfork->get_current_version(); } uint8_t get_ideal_hard_fork_version() const { return m_hardfork->get_ideal_version(); } + uint8_t get_ideal_hard_fork_version(uint64_t height) const { return m_hardfork->get_ideal_version(height); } + bool get_hard_fork_voting_info(uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint8_t &voting) const; bool for_all_key_images(std::function) const; diff --git a/src/cryptonote_core/blockchain_storage.cpp b/src/cryptonote_core/blockchain_storage.cpp index fb06da48a..f7c9ffb78 100644 --- a/src/cryptonote_core/blockchain_storage.cpp +++ b/src/cryptonote_core/blockchain_storage.cpp @@ -430,7 +430,7 @@ difficulty_type blockchain_storage::get_difficulty_for_next_block() const timestamps.push_back(m_blocks[offset].bl.timestamp); commulative_difficulties.push_back(m_blocks[offset].cumulative_difficulty); } - return next_difficulty(timestamps, commulative_difficulties); + return next_difficulty(timestamps, commulative_difficulties,DIFFICULTY_TARGET_V1); } //------------------------------------------------------------------ bool blockchain_storage::rollback_blockchain_switching(std::list& original_chain, size_t rollback_height) @@ -571,7 +571,7 @@ difficulty_type blockchain_storage::get_next_difficulty_for_alternative_chain(co break; } } - return next_difficulty(timestamps, commulative_difficulties); + return next_difficulty(timestamps, commulative_difficulties,DIFFICULTY_TARGET_V1); } //------------------------------------------------------------------ bool blockchain_storage::prevalidate_miner_transaction(const block& b, uint64_t height) const @@ -1505,7 +1505,7 @@ bool blockchain_storage::is_tx_spendtime_unlocked(uint64_t unlock_time) const { //interpret as time uint64_t current_time = static_cast(time(NULL)); - if(current_time + CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS >= unlock_time) + if(current_time + CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V1 >= unlock_time) return true; else return false; diff --git a/src/cryptonote_core/difficulty.cpp b/src/cryptonote_core/difficulty.cpp index 2b5466791..3c3f1dec1 100644 --- a/src/cryptonote_core/difficulty.cpp +++ b/src/cryptonote_core/difficulty.cpp @@ -157,8 +157,4 @@ namespace cryptonote { return (low + time_span - 1) / time_span; } - difficulty_type next_difficulty(vector timestamps, vector cumulative_difficulties) - { - return next_difficulty(std::move(timestamps), std::move(cumulative_difficulties), DIFFICULTY_TARGET); - } } diff --git a/src/cryptonote_core/difficulty.h b/src/cryptonote_core/difficulty.h index 42d2df500..6e06dd702 100644 --- a/src/cryptonote_core/difficulty.h +++ b/src/cryptonote_core/difficulty.h @@ -40,6 +40,5 @@ namespace cryptonote typedef std::uint64_t difficulty_type; bool check_hash(const crypto::hash &hash, difficulty_type difficulty); - difficulty_type next_difficulty(std::vector timestamps, std::vector cumulative_difficulties); difficulty_type next_difficulty(std::vector timestamps, std::vector cumulative_difficulties, size_t target_seconds); } -- cgit v1.2.3