From aef5020818342c5633620ab8573d223c3abfae1b Mon Sep 17 00:00:00 2001 From: clemahieu Date: Sun, 8 Aug 2021 20:29:56 +0100 Subject: [PATCH] Moving work_v1::value function on to work_thresholds where it belongs. --- nano/lib/config.cpp | 20 ++++++++++++++++++++ nano/lib/config.hpp | 2 ++ nano/lib/work.cpp | 24 ++---------------------- nano/lib/work.hpp | 5 ----- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/nano/lib/config.cpp b/nano/lib/config.cpp index 53e65fd6..cca4c6e4 100644 --- a/nano/lib/config.cpp +++ b/nano/lib/config.cpp @@ -88,6 +88,26 @@ uint64_t nano::work_thresholds::value (nano::root const & root_a, uint64_t work_ } #endif +uint64_t nano::work_thresholds::threshold (nano::block_details const & details_a) +{ + static_assert (nano::epoch::max == nano::epoch::epoch_2, "work_v1::threshold is ill-defined"); + + uint64_t result{ std::numeric_limits::max () }; + switch (details_a.epoch) + { + case nano::epoch::epoch_2: + result = (details_a.is_receive || details_a.is_epoch) ? epoch_2_receive : epoch_2; + break; + case nano::epoch::epoch_1: + case nano::epoch::epoch_0: + result = epoch_1; + break; + default: + debug_assert (false && "Invalid epoch specified to work_v1 ledger work_threshold"); + } + return result; +} + namespace nano { const char * network_constants::active_network_err_msg = "Invalid network. Valid values are live, test, beta and dev."; diff --git a/nano/lib/config.hpp b/nano/lib/config.hpp index e53aa5f6..aef7b452 100644 --- a/nano/lib/config.hpp +++ b/nano/lib/config.hpp @@ -83,6 +83,7 @@ enum class work_version }; enum class block_type : uint8_t; class root; +class block_details; class work_thresholds { @@ -111,6 +112,7 @@ public: uint64_t threshold_entry (nano::work_version const, nano::block_type const); uint64_t value (nano::root const & root_a, uint64_t work_a); + uint64_t threshold (nano::block_details const &); /** Network work thresholds. Define these inline as constexpr when moving to cpp17. */ static const nano::work_thresholds publish_full; diff --git a/nano/lib/work.cpp b/nano/lib/work.cpp index 17bc32e5..5c93dfd8 100644 --- a/nano/lib/work.cpp +++ b/nano/lib/work.cpp @@ -66,11 +66,12 @@ uint64_t nano::work_threshold_base (nano::work_version const version_a) uint64_t nano::work_threshold (nano::work_version const version_a, nano::block_details const details_a) { + static nano::network_constants network_constants; uint64_t result{ std::numeric_limits::max () }; switch (version_a) { case nano::work_version::work_1: - result = nano::work_v1::threshold (details_a); + result = network_constants.publish_thresholds.threshold (details_a); break; default: debug_assert (false && "Invalid version specified to ledger work_threshold"); @@ -78,27 +79,6 @@ uint64_t nano::work_threshold (nano::work_version const version_a, nano::block_d return result; } -uint64_t nano::work_v1::threshold (nano::block_details const details_a) -{ - static_assert (nano::epoch::max == nano::epoch::epoch_2, "work_v1::threshold is ill-defined"); - static nano::network_constants network_constants; - - uint64_t result{ std::numeric_limits::max () }; - switch (details_a.epoch) - { - case nano::epoch::epoch_2: - result = (details_a.is_receive || details_a.is_epoch) ? network_constants.publish_thresholds.epoch_2_receive : network_constants.publish_thresholds.epoch_2; - break; - case nano::epoch::epoch_1: - case nano::epoch::epoch_0: - result = network_constants.publish_thresholds.epoch_1; - break; - default: - debug_assert (false && "Invalid epoch specified to work_v1 ledger work_threshold"); - } - return result; -} - double nano::normalized_multiplier (double const multiplier_a, uint64_t const threshold_a) { static nano::network_constants network_constants; diff --git a/nano/lib/work.hpp b/nano/lib/work.hpp index 7cf9ae2e..fbfe3cc5 100644 --- a/nano/lib/work.hpp +++ b/nano/lib/work.hpp @@ -27,11 +27,6 @@ uint64_t work_threshold_base (nano::work_version const); // Ledger threshold uint64_t work_threshold (nano::work_version const, nano::block_details const); -namespace work_v1 -{ - uint64_t threshold (nano::block_details const); -} - double normalized_multiplier (double const, uint64_t const); double denormalized_multiplier (double const, uint64_t const); class opencl_work;