diff --git a/src/cryptonote_basic/difficulty.cpp b/src/cryptonote_basic/difficulty.cpp index f3ff538c8..39e97695d 100644 --- a/src/cryptonote_basic/difficulty.cpp +++ b/src/cryptonote_basic/difficulty.cpp @@ -243,33 +243,35 @@ namespace cryptonote { // LWMA-2 difficulty algorithm // Copyright (c) 2017-2018 Zawy, MIT License -// See commented version in https://github.com/zawy12/difficulty-algorithms/issues/3 -// for required config file changes. +// https://github.com/zawy12/difficulty-algorithms/issues/3 +// See commented version for required config file changes. -difficulty_type next_difficulty_v3(std::vector timestamps, std::vector cumulative_difficulties) { +difficulty_type next_difficulty_v3(std::vector timestamps, std::vector cumulative_difficulties) { int64_t T = DIFFICULTY_TARGET_V2; int64_t N = DIFFICULTY_WINDOW_V2; int64_t FTL = CRYPTONOTE_BLOCK_FUTURE_TIME_LIMIT_V3; int64_t L(0), ST, sum_3_ST(0), next_D, prev_D; + assert(timestamps.size() == cumulative_difficulties.size() && timestamps.size() <= static_cast(N+1) ); + // TODO: change initial_difficulty_guess before v9 mainnet hard fork // if ( height >= fork_height && height <= fork_height+N ) { return difficulty_guess; } - uint64_t initial_difficulty_guess = 100; - if (timestamps.size() <= 6 ) { return initial_difficulty_guess; } - else if ( timestamps.size() < static_cast(N +1) ) { N=timestamps.size()-1; } + uint64_t difficulty_guess = 100; + if (timestamps.size() <= 10 ) { return difficulty_guess; } + if ( timestamps.size() < static_cast(N +1) ) { N = timestamps.size()-1; } for ( int64_t i = 1; i <= N; i++) { - ST = std::max(-FTL, std::min( (int64_t)(timestamps[i]) - (int64_t)(timestamps[i-1]), 6*T)); - L += ST * i ; + ST = std::max(-FTL, std::min( static_cast(timestamps[i]) - static_cast(timestamps[i-1]), 6*T)); + L += ST * i ; if ( i > N-3 ) { sum_3_ST += ST; } } - next_D = ((int64_t)(cumulative_difficulties[N] - cumulative_difficulties[0])*T*(N+1)*99)/(100*2*L); + next_D = (static_cast(cumulative_difficulties[N] - cumulative_difficulties[0])*T*(N+1)*99)/(100*2*L); prev_D = cumulative_difficulties[N] - cumulative_difficulties[N-1]; next_D = std::max((prev_D*67)/100, std::min( next_D, (prev_D*150)/100)); - if ( sum_3_ST < (8*T)/10) { next_D = (prev_D*110)/100; } + if ( sum_3_ST < (8*T)/10) { next_D = std::max(next_D,(prev_D*110)/100); } return static_cast(next_D); } diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index a7a87cbd5..68a36efd2 100755 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -9141,7 +9141,7 @@ uint64_t wallet2::get_daemon_blockchain_target_height(string &err) uint64_t wallet2::get_approximate_blockchain_height() const { // time of v8 fork - const time_t fork_time = m_nettype == TESTNET ? 1530634467 : m_nettype == STAGENET ? 1530635153 : 1524622167; + const time_t fork_time = m_nettype == TESTNET ? 1532756009 : m_nettype == STAGENET ? 1530635153 : 1524622167; // v8 fork block const uint64_t fork_block = m_nettype == TESTNET ? 10 : m_nettype == STAGENET ? 10 : 6969; // avg seconds per block