diff --git a/nano/core_test/difficulty.cpp b/nano/core_test/difficulty.cpp index 3bb8a5cd..5034e16b 100644 --- a/nano/core_test/difficulty.cpp +++ b/nano/core_test/difficulty.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -106,10 +107,9 @@ TEST (difficulty, zero) TEST (difficulty, network_constants) { - nano::network_constants constants; - auto & full_thresholds = constants.publish_full; - auto & beta_thresholds = constants.publish_beta; - auto & dev_thresholds = constants.publish_dev; + auto & full_thresholds = nano::work_thresholds::publish_full; + auto & beta_thresholds = nano::work_thresholds::publish_beta; + auto & dev_thresholds = nano::work_thresholds::publish_dev; ASSERT_NEAR (8., nano::difficulty::to_multiplier (full_thresholds.epoch_2, full_thresholds.epoch_1), 1e-10); ASSERT_NEAR (1 / 8., nano::difficulty::to_multiplier (full_thresholds.epoch_2_receive, full_thresholds.epoch_1), 1e-10); @@ -128,23 +128,23 @@ TEST (difficulty, network_constants) ASSERT_NEAR (1., nano::difficulty::to_multiplier (dev_thresholds.epoch_2, dev_thresholds.base), 1e-10); nano::work_version version{ nano::work_version::work_1 }; - ASSERT_EQ (constants.publish_thresholds.base, constants.publish_thresholds.epoch_2); - ASSERT_EQ (constants.publish_thresholds.base, nano::work_threshold_base (version)); - ASSERT_EQ (constants.publish_thresholds.entry, nano::work_threshold_entry (version, nano::block_type::state)); - ASSERT_EQ (constants.publish_thresholds.epoch_1, nano::work_threshold_entry (version, nano::block_type::send)); - ASSERT_EQ (constants.publish_thresholds.epoch_1, nano::work_threshold_entry (version, nano::block_type::receive)); - ASSERT_EQ (constants.publish_thresholds.epoch_1, nano::work_threshold_entry (version, nano::block_type::open)); - ASSERT_EQ (constants.publish_thresholds.epoch_1, nano::work_threshold_entry (version, nano::block_type::change)); - ASSERT_EQ (constants.publish_thresholds.epoch_1, nano::work_threshold (version, nano::block_details (nano::epoch::epoch_0, false, false, false))); - ASSERT_EQ (constants.publish_thresholds.epoch_1, nano::work_threshold (version, nano::block_details (nano::epoch::epoch_1, false, false, false))); - ASSERT_EQ (constants.publish_thresholds.epoch_1, nano::work_threshold (version, nano::block_details (nano::epoch::epoch_1, false, false, false))); + ASSERT_EQ (nano::dev::network_params.network.publish_thresholds.base, nano::dev::network_params.network.publish_thresholds.epoch_2); + ASSERT_EQ (nano::dev::network_params.network.publish_thresholds.base, nano::work_threshold_base (version)); + ASSERT_EQ (nano::dev::network_params.network.publish_thresholds.entry, nano::work_threshold_entry (version, nano::block_type::state)); + ASSERT_EQ (nano::dev::network_params.network.publish_thresholds.epoch_1, nano::work_threshold_entry (version, nano::block_type::send)); + ASSERT_EQ (nano::dev::network_params.network.publish_thresholds.epoch_1, nano::work_threshold_entry (version, nano::block_type::receive)); + ASSERT_EQ (nano::dev::network_params.network.publish_thresholds.epoch_1, nano::work_threshold_entry (version, nano::block_type::open)); + ASSERT_EQ (nano::dev::network_params.network.publish_thresholds.epoch_1, nano::work_threshold_entry (version, nano::block_type::change)); + ASSERT_EQ (nano::dev::network_params.network.publish_thresholds.epoch_1, nano::work_threshold (version, nano::block_details (nano::epoch::epoch_0, false, false, false))); + ASSERT_EQ (nano::dev::network_params.network.publish_thresholds.epoch_1, nano::work_threshold (version, nano::block_details (nano::epoch::epoch_1, false, false, false))); + ASSERT_EQ (nano::dev::network_params.network.publish_thresholds.epoch_1, nano::work_threshold (version, nano::block_details (nano::epoch::epoch_1, false, false, false))); // Send [+ change] - ASSERT_EQ (constants.publish_thresholds.epoch_2, nano::work_threshold (version, nano::block_details (nano::epoch::epoch_2, true, false, false))); + ASSERT_EQ (nano::dev::network_params.network.publish_thresholds.epoch_2, nano::work_threshold (version, nano::block_details (nano::epoch::epoch_2, true, false, false))); // Change - ASSERT_EQ (constants.publish_thresholds.epoch_2, nano::work_threshold (version, nano::block_details (nano::epoch::epoch_2, false, false, false))); + ASSERT_EQ (nano::dev::network_params.network.publish_thresholds.epoch_2, nano::work_threshold (version, nano::block_details (nano::epoch::epoch_2, false, false, false))); // Receive [+ change] / Open - ASSERT_EQ (constants.publish_thresholds.epoch_2_receive, nano::work_threshold (version, nano::block_details (nano::epoch::epoch_2, false, true, false))); + ASSERT_EQ (nano::dev::network_params.network.publish_thresholds.epoch_2_receive, nano::work_threshold (version, nano::block_details (nano::epoch::epoch_2, false, true, false))); // Epoch - ASSERT_EQ (constants.publish_thresholds.epoch_2_receive, nano::work_threshold (version, nano::block_details (nano::epoch::epoch_2, false, false, true))); + ASSERT_EQ (nano::dev::network_params.network.publish_thresholds.epoch_2_receive, nano::work_threshold (version, nano::block_details (nano::epoch::epoch_2, false, false, true))); } diff --git a/nano/lib/config.cpp b/nano/lib/config.cpp index 955ddd59..72c0af2d 100644 --- a/nano/lib/config.cpp +++ b/nano/lib/config.cpp @@ -24,32 +24,32 @@ struct HexTo }; } // namespace -namespace nano -{ -work_thresholds const network_constants::publish_full ( +nano::work_thresholds const nano::work_thresholds::publish_full ( 0xffffffc000000000, 0xfffffff800000000, // 8x higher than epoch_1 0xfffffe0000000000 // 8x lower than epoch_1 ); -work_thresholds const network_constants::publish_beta ( +nano::work_thresholds const nano::work_thresholds::publish_beta ( 0xfffff00000000000, // 64x lower than publish_full.epoch_1 0xfffff00000000000, // same as epoch_1 0xffffe00000000000 // 2x lower than epoch_1 ); -work_thresholds const network_constants::publish_dev ( +nano::work_thresholds const nano::work_thresholds::publish_dev ( 0xfe00000000000000, // Very low for tests 0xffc0000000000000, // 8x higher than epoch_1 0xf000000000000000 // 8x lower than epoch_1 ); -work_thresholds const network_constants::publish_test ( //defaults to live network levels +nano::work_thresholds const nano::work_thresholds::publish_test ( //defaults to live network levels get_env_threshold_or_default ("NANO_TEST_EPOCH_1", 0xffffffc000000000), get_env_threshold_or_default ("NANO_TEST_EPOCH_2", 0xfffffff800000000), // 8x higher than epoch_1 get_env_threshold_or_default ("NANO_TEST_EPOCH_2_RECV", 0xfffffe0000000000) // 8x lower than epoch_1 ); +namespace nano +{ const char * network_constants::active_network_err_msg = "Invalid network. Valid values are live, test, beta and dev."; uint8_t get_major_node_version () diff --git a/nano/lib/config.hpp b/nano/lib/config.hpp index 720a35ef..6bcc9879 100644 --- a/nano/lib/config.hpp +++ b/nano/lib/config.hpp @@ -99,6 +99,12 @@ struct work_thresholds { return other_a; } + + /** Network work thresholds. Define these inline as constexpr when moving to cpp17. */ + static const nano::work_thresholds publish_full; + static const nano::work_thresholds publish_beta; + static const nano::work_thresholds publish_dev; + static const nano::work_thresholds publish_test; }; class network_constants @@ -111,7 +117,7 @@ public: network_constants (nano::networks network_a) : current_network (network_a), - publish_thresholds (is_live_network () ? publish_full : is_beta_network () ? publish_beta : is_test_network () ? publish_test : publish_dev) + publish_thresholds (is_live_network () ? nano::work_thresholds::publish_full : is_beta_network () ? nano::work_thresholds::publish_beta : is_test_network () ? nano::work_thresholds::publish_test : nano::work_thresholds::publish_dev) { // A representative is classified as principal based on its weight and this factor principal_weight_factor = 1000; // 0.1% @@ -130,12 +136,6 @@ public: peer_dump_interval = is_dev_network () ? std::chrono::seconds (1) : std::chrono::seconds (5 * 60); } - /** Network work thresholds. Define these inline as constexpr when moving to cpp17. */ - static const nano::work_thresholds publish_full; - static const nano::work_thresholds publish_beta; - static const nano::work_thresholds publish_dev; - static const nano::work_thresholds publish_test; - /** Error message when an invalid network is specified */ static const char * active_network_err_msg; diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index 472b90aa..ea9f20cd 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -456,7 +456,7 @@ int main (int argc, char * const * argv) else if (vm.count ("debug_profile_generate")) { nano::network_constants network_constants; - uint64_t difficulty{ network_constants.publish_full.base }; + uint64_t difficulty{ nano::work_thresholds::publish_full.base }; auto multiplier_it = vm.find ("multiplier"); if (multiplier_it != vm.end ()) { @@ -495,7 +495,7 @@ int main (int argc, char * const * argv) nano::change_block block (0, 0, nano::keypair ().prv, 0, 0); if (!result) { - std::cerr << boost::str (boost::format ("Starting generation profiling. Difficulty: %1$#x (%2%x from base difficulty %3$#x)\n") % difficulty % nano::to_string (nano::difficulty::to_multiplier (difficulty, network_constants.publish_full.base), 4) % network_constants.publish_full.base); + std::cerr << boost::str (boost::format ("Starting generation profiling. Difficulty: %1$#x (%2%x from base difficulty %3$#x)\n") % difficulty % nano::to_string (nano::difficulty::to_multiplier (difficulty, nano::work_thresholds::publish_full.base), 4) % nano::work_thresholds::publish_full.base); while (!result) { block.hashables.previous.qwords[0] += 1; @@ -508,7 +508,7 @@ int main (int argc, char * const * argv) } else if (vm.count ("debug_profile_validate")) { - uint64_t difficulty{ nano::network_constants ().publish_full.base }; + uint64_t difficulty{ nano::work_thresholds::publish_full.base }; std::cerr << "Starting validation profile" << std::endl; auto start (std::chrono::steady_clock::now ()); bool valid{ false }; @@ -572,7 +572,7 @@ int main (int argc, char * const * argv) return -1; } } - uint64_t difficulty (network_constants.publish_full.base); + uint64_t difficulty (nano::work_thresholds::publish_full.base); auto multiplier_it = vm.find ("multiplier"); if (multiplier_it != vm.end ()) { @@ -615,7 +615,7 @@ int main (int argc, char * const * argv) } : std::function (nano::work_version const, nano::root const &, uint64_t, std::atomic &)> (nullptr) }; nano::change_block block (0, 0, nano::keypair ().prv, 0, 0); - std::cerr << boost::str (boost::format ("Starting OpenCL generation profiling. Platform: %1%. Device: %2%. Threads: %3%. Difficulty: %4$#x (%5%x from base difficulty %6$#x)\n") % platform % device % threads % difficulty % nano::to_string (nano::difficulty::to_multiplier (difficulty, network_constants.publish_full.base), 4) % network_constants.publish_full.base); + std::cerr << boost::str (boost::format ("Starting OpenCL generation profiling. Platform: %1%. Device: %2%. Threads: %3%. Difficulty: %4$#x (%5%x from base difficulty %6$#x)\n") % platform % device % threads % difficulty % nano::to_string (nano::difficulty::to_multiplier (difficulty, nano::work_thresholds::publish_full.base), 4) % nano::work_thresholds::publish_full.base); for (uint64_t i (0); true; ++i) { block.hashables.previous.qwords[0] += 1;