diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index 9ab8a12f..6f226878 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -42,6 +42,7 @@ #include "misc_language.h" #include "block_flags.h" #include "etc_custom_serialization.h" +#include "difficulty.h" namespace currency { @@ -56,6 +57,10 @@ namespace currency const static crypto::hash gdefault_genesis = epee::string_tools::hex_to_pod("CC608F59F8080E2FBFE3C8C80EB6E6A953D47CF2D6AEBD345BADA3A1CAB99852"); const static crypto::hash ffff_hash = epee::string_tools::hex_to_pod("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); + const static wide_difficulty_type global_difficulty_pow_starter = DIFFICULTY_POW_STARTER; + const static wide_difficulty_type global_difficulty_pos_starter = DIFFICULTY_POS_STARTER; + const static uint64_t global_difficulty_pos_target = DIFFICULTY_POS_TARGET; + const static uint64_t global_difficulty_pow_target = DIFFICULTY_POW_TARGET; typedef std::string payment_id_t; diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index 5318bc33..e48ca6a3 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -65,7 +65,7 @@ #define CURRENCY_MINER_TX_MAX_OUTS CURRENCY_TX_MAX_ALLOWED_OUTS #define CURRENCY_TX_OUTS_RND_SPLIT_DIGITS_TO_KEEP 3 -#define DIFFICULTY_STARTER 1 +#define DIFFICULTY_POW_STARTER 1 #define DIFFICULTY_POS_TARGET 120 // seconds #define DIFFICULTY_POW_TARGET 120 // seconds #define DIFFICULTY_TOTAL_TARGET ((DIFFICULTY_POS_TARGET + DIFFICULTY_POW_TARGET) / 4) @@ -110,6 +110,7 @@ #define STRATUM_DEFAULT_PORT 11777 #define P2P_NETWORK_ID_TESTNET_FLAG 0 #define P2P_MAINTAINERS_PUB_KEY "8f138bb73f6d663a3746a542770781a09579a7b84cb4125249e95530824ee607" +#define DIFFICULTY_POS_STARTER 1 #else #define P2P_DEFAULT_PORT (11112 + CURRENCY_FORMATION_VERSION) #define RPC_DEFAULT_PORT 12111 @@ -117,6 +118,7 @@ #define STRARUM_DEFAULT_PORT 51113 #define P2P_NETWORK_ID_TESTNET_FLAG 1 #define P2P_MAINTAINERS_PUB_KEY "aaa2d7aabc8d383fd53a3ae898697b28f236ceade6bafc1eecff413a6a02272a" +#define DIFFICULTY_POS_STARTER 625000000000 #endif #define P2P_NETWORK_ID_VER (CURRENCY_FORMATION_VERSION+0) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 2512a41c..9adeb482 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -4005,11 +4005,12 @@ namespace currency const difficulties& a_diff, const difficulties& b_diff ) { - static const wide_difficulty_type difficulty_starter = DIFFICULTY_STARTER; - const wide_difficulty_type& a_pos_cumulative_difficulty = a_diff.pos_diff > 0 ? a_diff.pos_diff : difficulty_starter; - const wide_difficulty_type& b_pos_cumulative_difficulty = b_diff.pos_diff > 0 ? b_diff.pos_diff : difficulty_starter; - const wide_difficulty_type& a_pow_cumulative_difficulty = a_diff.pow_diff > 0 ? a_diff.pow_diff : difficulty_starter; - const wide_difficulty_type& b_pow_cumulative_difficulty = b_diff.pow_diff > 0 ? b_diff.pow_diff : difficulty_starter; + static const wide_difficulty_type difficulty_pos_starter = DIFFICULTY_POS_STARTER; + static const wide_difficulty_type difficulty_pow_starter = DIFFICULTY_POW_STARTER; + const wide_difficulty_type& a_pos_cumulative_difficulty = a_diff.pos_diff > 0 ? a_diff.pos_diff : difficulty_pos_starter; + const wide_difficulty_type& b_pos_cumulative_difficulty = b_diff.pos_diff > 0 ? b_diff.pos_diff : difficulty_pos_starter; + const wide_difficulty_type& a_pow_cumulative_difficulty = a_diff.pow_diff > 0 ? a_diff.pow_diff : difficulty_pow_starter; + const wide_difficulty_type& b_pow_cumulative_difficulty = b_diff.pow_diff > 0 ? b_diff.pow_diff : difficulty_pow_starter; boost::multiprecision::uint1024_t basic_sum = boost::multiprecision::uint1024_t(a_pow_cumulative_difficulty) + (boost::multiprecision::uint1024_t(a_pos_cumulative_difficulty)*difficulty_pow_at_split_point) / difficulty_pos_at_split_point; boost::multiprecision::uint1024_t res = diff --git a/src/currency_core/difficulty.cpp b/src/currency_core/difficulty.cpp index 68d82c15..b0bdfac0 100644 --- a/src/currency_core/difficulty.cpp +++ b/src/currency_core/difficulty.cpp @@ -179,7 +179,7 @@ namespace currency { return res.convert_to(); } - wide_difficulty_type next_difficulty_1(vector& timestamps, vector& cumulative_difficulties, size_t target_seconds) + wide_difficulty_type next_difficulty_1(vector& timestamps, vector& cumulative_difficulties, size_t target_seconds, const wide_difficulty_type& difficulty_starter) { // timestamps - first is latest, back - is oldest timestamps @@ -194,7 +194,7 @@ namespace currency { CHECK_AND_ASSERT_MES(length == cumulative_difficulties.size(), 0, "Check \"length == cumulative_difficulties.size()\" failed"); if (length <= 1) { - return DIFFICULTY_STARTER; + return difficulty_starter; } static_assert(DIFFICULTY_WINDOW >= 2, "Window is too small"); @@ -221,7 +221,7 @@ namespace currency { return summ / devider; } - wide_difficulty_type next_difficulty_2(vector& timestamps, vector& cumulative_difficulties, size_t target_seconds) + wide_difficulty_type next_difficulty_2(vector& timestamps, vector& cumulative_difficulties, size_t target_seconds, const wide_difficulty_type& difficulty_starter) { // timestamps - first is latest, back - is oldest timestamps @@ -236,7 +236,7 @@ namespace currency { CHECK_AND_ASSERT_MES(length == cumulative_difficulties.size(), 0, "Check \"length == cumulative_difficulties.size()\" failed"); if (length <= 1) { - return DIFFICULTY_STARTER; + return difficulty_starter; } static_assert(DIFFICULTY_WINDOW >= 2, "Window is too small"); diff --git a/src/currency_core/difficulty.h b/src/currency_core/difficulty.h index ab97f142..731fb26f 100644 --- a/src/currency_core/difficulty.h +++ b/src/currency_core/difficulty.h @@ -19,8 +19,8 @@ namespace currency typedef boost::multiprecision::uint128_t wide_difficulty_type; bool check_hash(const crypto::hash &hash, wide_difficulty_type difficulty); - wide_difficulty_type next_difficulty_1(std::vector& timestamps, std::vector& cumulative_difficulties, size_t target_seconds); - wide_difficulty_type next_difficulty_2(std::vector& timestamps, std::vector& cumulative_difficulties, size_t target_seconds); + wide_difficulty_type next_difficulty_1(std::vector& timestamps, std::vector& cumulative_difficulties, size_t target_seconds, const wide_difficulty_type& difficulty_starter); + wide_difficulty_type next_difficulty_2(std::vector& timestamps, std::vector& cumulative_difficulties, size_t target_seconds, const wide_difficulty_type& difficulty_starter); uint64_t difficulty_to_boundary(wide_difficulty_type difficulty); void difficulty_to_boundary_long(wide_difficulty_type difficulty, crypto::hash& result); } diff --git a/tests/core_tests/block_validation.cpp b/tests/core_tests/block_validation.cpp index c7d55c21..85e9aa1f 100644 --- a/tests/core_tests/block_validation.cpp +++ b/tests/core_tests/block_validation.cpp @@ -21,7 +21,7 @@ namespace for (size_t i = 0; i < new_block_count; ++i) { block blk_next; - wide_difficulty_type diffic = next_difficulty_1(timestamps, cummulative_difficulties, DIFFICULTY_POW_TARGET); + wide_difficulty_type diffic = next_difficulty_1(timestamps, cummulative_difficulties, DIFFICULTY_POW_TARGET, DIFFICULTY_POW_STARTER); if (!generator.construct_block_manually(blk_next, blk_prev, miner_account, test_generator::bf_timestamp | test_generator::bf_diffic, 0, 0, blk_prev.timestamp, crypto::hash(), diffic)) return false; @@ -152,7 +152,7 @@ bool gen_block_invalid_nonce::generate(std::vector& events) co return false; // Create invalid nonce - wide_difficulty_type diffic = next_difficulty_1(timestamps, commulative_difficulties, DIFFICULTY_POW_TARGET); + wide_difficulty_type diffic = next_difficulty_1(timestamps, commulative_difficulties, DIFFICULTY_POW_TARGET, DIFFICULTY_POW_STARTER); CHECK_AND_ASSERT_MES(diffic > 1, false, "diffic > 1 validation failed"); const block& blk_last = boost::get(events.back()); uint64_t timestamp = blk_last.timestamp; diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index 0e5270de..18d33a06 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -766,7 +766,7 @@ bool test_generator::get_params_for_next_pos_block(const crypto::hash& head_id, std::vector timestamps; std::vector commulative_difficulties; if (!blocks.size()) - return DIFFICULTY_STARTER; + return DIFFICULTY_POW_STARTER; for (size_t i = blocks.size() - 1; i != 0; --i) { @@ -775,7 +775,7 @@ bool test_generator::get_params_for_next_pos_block(const crypto::hash& head_id, timestamps.push_back(blocks[i]->b.timestamp); commulative_difficulties.push_back(blocks[i]->cumul_difficulty); } - return next_difficulty_1(timestamps, commulative_difficulties, pow ? DIFFICULTY_POW_TARGET : DIFFICULTY_POS_TARGET); + return next_difficulty_1(timestamps, commulative_difficulties, pow ? global_difficulty_pow_target : global_difficulty_pos_target, pow ? global_difficulty_pow_starter : global_difficulty_pos_starter); } currency::wide_difficulty_type test_generator::get_cumul_difficulty_for_next_block(const crypto::hash& head_id, bool pow) const diff --git a/tests/core_tests/wallet_tests.cpp b/tests/core_tests/wallet_tests.cpp index 3d891568..a1744253 100644 --- a/tests/core_tests/wallet_tests.cpp +++ b/tests/core_tests/wallet_tests.cpp @@ -2769,7 +2769,7 @@ bool premine_wallet_test::generate(std::vector& events) const currency::generate_genesis_block(blk_0_info.b); blk_0_info.already_generated_coins = get_outs_money_amount(blk_0_info.b.miner_tx); blk_0_info.block_size = get_object_blobsize(blk_0_info.b.miner_tx); - blk_0_info.cumul_difficulty = DIFFICULTY_STARTER; + blk_0_info.cumul_difficulty = DIFFICULTY_POW_STARTER; blk_0_info.ks_hash = currency::null_hash; blk_0_info.m_transactions.clear(); events.push_back(blk_0_info.b);