|
|
|
@ -898,7 +898,8 @@ start:
|
|
|
|
|
// of doing 735 (DIFFICULTY_BLOCKS_COUNT).
|
|
|
|
|
bool check = false;
|
|
|
|
|
uint8_t version = get_current_hard_fork_version();
|
|
|
|
|
uint64_t difficulty_blocks_count = version >= 20 ? DIFFICULTY_BLOCKS_COUNT_V4 : version <= 17 && version >= 11 ? DIFFICULTY_BLOCKS_COUNT_V3 : version <= 10 && version >= 8 ? DIFFICULTY_BLOCKS_COUNT_V2 : DIFFICULTY_BLOCKS_COUNT;
|
|
|
|
|
uint64_t difficulty_blocks_count = version >= 21 ? DIFFICULTY_BLOCKS_COUNT_V5 :
|
|
|
|
|
version >= 20 ? DIFFICULTY_BLOCKS_COUNT_V4 : version <= 17 && version >= 11 ? DIFFICULTY_BLOCKS_COUNT_V3 : version <= 10 && version >= 8 ? DIFFICULTY_BLOCKS_COUNT_V2 : DIFFICULTY_BLOCKS_COUNT;
|
|
|
|
|
if (m_reset_timestamps_and_difficulties_height)
|
|
|
|
|
m_timestamps_and_difficulties_height = 0;
|
|
|
|
|
if (m_timestamps_and_difficulties_height != 0 && ((height - m_timestamps_and_difficulties_height) == 1) && m_timestamps.size() >= difficulty_blocks_count)
|
|
|
|
@ -970,7 +971,9 @@ start:
|
|
|
|
|
size_t target = get_difficulty_target();
|
|
|
|
|
uint64_t HEIGHT = m_db->height();
|
|
|
|
|
difficulty_type diff;
|
|
|
|
|
if (version >= 20) {
|
|
|
|
|
if (version >= 21) {
|
|
|
|
|
diff = next_difficulty_v7(timestamps, difficulties, target);
|
|
|
|
|
} else if (version >= 20) {
|
|
|
|
|
diff = next_difficulty_v6(timestamps, difficulties, target);
|
|
|
|
|
} else if (version <= 17 && version >= 11) {
|
|
|
|
|
diff = next_difficulty_v5(timestamps, difficulties, HEIGHT);
|
|
|
|
@ -1042,7 +1045,8 @@ size_t Blockchain::recalculate_difficulties(boost::optional<uint64_t> start_heig
|
|
|
|
|
std::vector<uint64_t> timestamps;
|
|
|
|
|
std::vector<difficulty_type> difficulties;
|
|
|
|
|
uint8_t version = get_current_hard_fork_version();
|
|
|
|
|
uint64_t difficulty_blocks_count = version >= 20 ? DIFFICULTY_BLOCKS_COUNT_V4 : version <= 17 && version >= 11 ? DIFFICULTY_BLOCKS_COUNT_V3 : version <= 10 && version >= 8 ? DIFFICULTY_BLOCKS_COUNT_V2 : DIFFICULTY_BLOCKS_COUNT;
|
|
|
|
|
uint64_t difficulty_blocks_count = version >= 21 ? DIFFICULTY_BLOCKS_COUNT_V5 :
|
|
|
|
|
version >= 20 ? DIFFICULTY_BLOCKS_COUNT_V4 : version <= 17 && version >= 11 ? DIFFICULTY_BLOCKS_COUNT_V3 : version <= 10 && version >= 8 ? DIFFICULTY_BLOCKS_COUNT_V2 : DIFFICULTY_BLOCKS_COUNT;
|
|
|
|
|
timestamps.reserve(difficulty_blocks_count + 1);
|
|
|
|
|
difficulties.reserve(difficulty_blocks_count + 1);
|
|
|
|
|
if (start_height > 1)
|
|
|
|
@ -1064,7 +1068,9 @@ size_t Blockchain::recalculate_difficulties(boost::optional<uint64_t> start_heig
|
|
|
|
|
size_t target = get_ideal_hard_fork_version(height) < 2 ? DIFFICULTY_TARGET_V1 : DIFFICULTY_TARGET_V2;
|
|
|
|
|
uint64_t HEIGHT = m_db->height();
|
|
|
|
|
difficulty_type recalculated_diff;
|
|
|
|
|
if (version >= 20) {
|
|
|
|
|
if (version >= 21) {
|
|
|
|
|
recalculated_diff = next_difficulty_v7(timestamps, difficulties, target);
|
|
|
|
|
} else if (version >= 20) {
|
|
|
|
|
recalculated_diff = next_difficulty_v6(timestamps, difficulties, target);
|
|
|
|
|
} else if (version <= 17 && version >= 11) {
|
|
|
|
|
recalculated_diff = next_difficulty_v5(timestamps, difficulties, HEIGHT);
|
|
|
|
@ -1332,7 +1338,8 @@ difficulty_type Blockchain::get_next_difficulty_for_alternative_chain(const std:
|
|
|
|
|
std::vector<uint64_t> timestamps;
|
|
|
|
|
std::vector<difficulty_type> cumulative_difficulties;
|
|
|
|
|
uint8_t version = get_current_hard_fork_version();
|
|
|
|
|
uint64_t difficulty_blocks_count = version >= 20 ? DIFFICULTY_BLOCKS_COUNT_V4 : version <= 17 && version >= 11 ? DIFFICULTY_BLOCKS_COUNT_V3 : version <= 10 && version >= 8 ? DIFFICULTY_BLOCKS_COUNT_V2 : DIFFICULTY_BLOCKS_COUNT;
|
|
|
|
|
uint64_t difficulty_blocks_count = version >= 21 ? DIFFICULTY_BLOCKS_COUNT_V5 :
|
|
|
|
|
version >= 20 ? DIFFICULTY_BLOCKS_COUNT_V4 : version <= 17 && version >= 11 ? DIFFICULTY_BLOCKS_COUNT_V3 : version <= 10 && version >= 8 ? DIFFICULTY_BLOCKS_COUNT_V2 : DIFFICULTY_BLOCKS_COUNT;
|
|
|
|
|
|
|
|
|
|
// if the alt chain isn't long enough to calculate the difficulty target
|
|
|
|
|
// based on its blocks alone, need to get more blocks from the main chain
|
|
|
|
@ -1390,7 +1397,9 @@ difficulty_type Blockchain::get_next_difficulty_for_alternative_chain(const std:
|
|
|
|
|
// calculate the difficulty target for the block and return it
|
|
|
|
|
uint64_t HEIGHT = m_db->height();
|
|
|
|
|
difficulty_type next_diff;
|
|
|
|
|
if (version >= 20) {
|
|
|
|
|
if (version >= 21) {
|
|
|
|
|
next_diff = next_difficulty_v7(timestamps, cumulative_difficulties, target);
|
|
|
|
|
} else if (version >= 20) {
|
|
|
|
|
next_diff = next_difficulty_v6(timestamps, cumulative_difficulties, target);
|
|
|
|
|
} else if (version <= 17 && version >= 11) {
|
|
|
|
|
next_diff = next_difficulty_v5(timestamps, cumulative_difficulties, HEIGHT);
|
|
|
|
|