@ -838,8 +838,11 @@ difficulty_type Blockchain::get_difficulty_for_next_block()
else if ( version = = 8 ) {
return next_difficulty_v2 ( timestamps , difficulties , target ) ;
}
else {
else if ( version = = 9 ) {
return next_difficulty_v3 ( timestamps , difficulties , height ) ;
}
else {
return next_difficulty_v4 ( timestamps , difficulties , height ) ;
}
}
//------------------------------------------------------------------
@ -1056,9 +1059,12 @@ difficulty_type Blockchain::get_next_difficulty_for_alternative_chain(const std:
}
else if ( version = = 8 ) {
return next_difficulty_v2 ( timestamps , cumulative_difficulties , target ) ;
}
}
else if ( version = = 9 ) {
return next_difficulty_v2 ( timestamps , cumulative_difficulties , height ) ;
}
else {
return next_difficulty_v3 ( timestamps , cumulative_difficulties , height ) ;
return next_difficulty_v 4 ( timestamps , cumulative_difficulties , height ) ;
}
}
@ -1350,12 +1356,13 @@ bool Blockchain::create_block_template(block& b, const account_public_address& m
bool Blockchain : : complete_timestamps_vector ( uint64_t start_top_height , std : : vector < uint64_t > & timestamps )
{
LOG_PRINT_L3 ( " Blockchain:: " < < __func__ ) ;
if ( timestamps . size ( ) > = BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW )
const uint8_t hf_version = m_hardfork - > get_current_version ( ) ;
size_t blockchain_timestamp_check_window = hf_version > = 10 ? BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW_V2 : BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW ;
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 )
@ -3203,10 +3210,12 @@ bool Blockchain::check_block_timestamp(std::vector<uint64_t>& timestamps, const
{
LOG_PRINT_L3 ( " Blockchain:: " < < __func__ ) ;
median_ts = epee : : misc_utils : : median ( timestamps ) ;
const uint8_t hf_version = m_hardfork - > get_current_version ( ) ;
size_t blockchain_timestamp_check_window = hf_version > = 10 ? BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW_V2 : BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW ;
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 ;
}
@ -3224,6 +3233,8 @@ bool Blockchain::check_block_timestamp(const block& b, uint64_t& median_ts) cons
{
LOG_PRINT_L3 ( " Blockchain:: " < < __func__ ) ;
uint64_t cryptonote_block_future_time_limit = get_current_hard_fork_version ( ) > = 8 ? CRYPTONOTE_BLOCK_FUTURE_TIME_LIMIT_V2 : CRYPTONOTE_BLOCK_FUTURE_TIME_LIMIT ;
const uint8_t hf_version = m_hardfork - > get_current_version ( ) ;
size_t blockchain_timestamp_check_window = hf_version > = 10 ? BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW_V2 : BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW ;
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 + 10 minutes " ) ;
@ -3231,7 +3242,7 @@ bool Blockchain::check_block_timestamp(const block& b, uint64_t& median_ts) cons
}
// 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 ;
}
@ -3240,7 +3251,7 @@ bool Blockchain::check_block_timestamp(const block& b, uint64_t& median_ts) cons
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 ) ) ;