Moving ::value function on to nano::work_thresholds where it belongs.
This commit is contained in:
parent
0e8b7cdd73
commit
442fb1eaba
5 changed files with 26 additions and 29 deletions
|
@ -70,6 +70,24 @@ uint64_t nano::work_thresholds::threshold_entry (nano::work_version const versio
|
|||
return result;
|
||||
}
|
||||
|
||||
#ifndef NANO_FUZZER_TEST
|
||||
uint64_t nano::work_thresholds::value (nano::root const & root_a, uint64_t work_a)
|
||||
{
|
||||
uint64_t result;
|
||||
blake2b_state hash;
|
||||
blake2b_init (&hash, sizeof (result));
|
||||
blake2b_update (&hash, reinterpret_cast<uint8_t *> (&work_a), sizeof (work_a));
|
||||
blake2b_update (&hash, root_a.bytes.data (), root_a.bytes.size ());
|
||||
blake2b_final (&hash, reinterpret_cast<uint8_t *> (&result), sizeof (result));
|
||||
return result;
|
||||
}
|
||||
#else
|
||||
uint64_t nano::work_thresholds::value (nano::root const & root_a, uint64_t work_a)
|
||||
{
|
||||
return base + 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace nano
|
||||
{
|
||||
const char * network_constants::active_network_err_msg = "Invalid network. Valid values are live, test, beta and dev.";
|
||||
|
|
|
@ -82,6 +82,7 @@ enum class work_version
|
|||
work_1
|
||||
};
|
||||
enum class block_type : uint8_t;
|
||||
class root;
|
||||
|
||||
class work_thresholds
|
||||
{
|
||||
|
@ -109,6 +110,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);
|
||||
|
||||
/** Network work thresholds. Define these inline as constexpr when moving to cpp17. */
|
||||
static const nano::work_thresholds publish_full;
|
||||
|
|
|
@ -36,11 +36,12 @@ bool nano::work_validate_entry (nano::work_version const version_a, nano::root c
|
|||
|
||||
uint64_t nano::work_difficulty (nano::work_version const version_a, nano::root const & root_a, uint64_t const work_a)
|
||||
{
|
||||
static nano::network_constants network_constants;
|
||||
uint64_t result{ 0 };
|
||||
switch (version_a)
|
||||
{
|
||||
case nano::work_version::work_1:
|
||||
result = nano::work_v1::value (root_a, work_a);
|
||||
result = network_constants.publish_thresholds.value (root_a, work_a);
|
||||
break;
|
||||
default:
|
||||
debug_assert (false && "Invalid version specified to work_difficulty");
|
||||
|
@ -98,30 +99,6 @@ uint64_t nano::work_v1::threshold (nano::block_details const details_a)
|
|||
return result;
|
||||
}
|
||||
|
||||
#ifndef NANO_FUZZER_TEST
|
||||
uint64_t nano::work_v1::value (nano::root const & root_a, uint64_t work_a)
|
||||
{
|
||||
uint64_t result;
|
||||
blake2b_state hash;
|
||||
blake2b_init (&hash, sizeof (result));
|
||||
blake2b_update (&hash, reinterpret_cast<uint8_t *> (&work_a), sizeof (work_a));
|
||||
blake2b_update (&hash, root_a.bytes.data (), root_a.bytes.size ());
|
||||
blake2b_final (&hash, reinterpret_cast<uint8_t *> (&result), sizeof (result));
|
||||
return result;
|
||||
}
|
||||
#else
|
||||
uint64_t nano::work_v1::value (nano::root const & root_a, uint64_t work_a)
|
||||
{
|
||||
static nano::network_constants network_constants;
|
||||
if (!network_constants.is_dev_network ())
|
||||
{
|
||||
debug_assert (false);
|
||||
std::exit (1);
|
||||
}
|
||||
return network_constants.publish_thresholds.base + 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
double nano::normalized_multiplier (double const multiplier_a, uint64_t const threshold_a)
|
||||
{
|
||||
static nano::network_constants network_constants;
|
||||
|
@ -235,7 +212,7 @@ void nano::work_pool::loop (uint64_t thread)
|
|||
if (opt_work.is_initialized ())
|
||||
{
|
||||
work = *opt_work;
|
||||
output = nano::work_v1::value (current_l.item, work);
|
||||
output = network_constants.publish_thresholds.value (current_l.item, work);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -268,7 +245,7 @@ void nano::work_pool::loop (uint64_t thread)
|
|||
{
|
||||
// If the ticket matches what we started with, we're the ones that found the solution
|
||||
debug_assert (output >= current_l.difficulty);
|
||||
debug_assert (current_l.difficulty == 0 || nano::work_v1::value (current_l.item, work) == output);
|
||||
debug_assert (current_l.difficulty == 0 || network_constants.publish_thresholds.value (current_l.item, work) == output);
|
||||
// Signal other threads to stop their work next time they check ticket
|
||||
++ticket;
|
||||
pending.pop_front ();
|
||||
|
|
|
@ -29,7 +29,6 @@ uint64_t work_threshold (nano::work_version const, nano::block_details const);
|
|||
|
||||
namespace work_v1
|
||||
{
|
||||
uint64_t value (nano::root const & root_a, uint64_t work_a);
|
||||
uint64_t threshold (nano::block_details const);
|
||||
}
|
||||
|
||||
|
|
|
@ -508,6 +508,7 @@ int main (int argc, char * const * argv)
|
|||
}
|
||||
else if (vm.count ("debug_profile_validate"))
|
||||
{
|
||||
nano::network_constants network_constants;
|
||||
uint64_t difficulty{ nano::work_thresholds::publish_full.base };
|
||||
std::cerr << "Starting validation profile" << std::endl;
|
||||
auto start (std::chrono::steady_clock::now ());
|
||||
|
@ -516,7 +517,7 @@ int main (int argc, char * const * argv)
|
|||
uint64_t count{ 10000000U }; // 10M
|
||||
for (uint64_t i (0); i < count; ++i)
|
||||
{
|
||||
valid = nano::work_v1::value (hash, i) > difficulty;
|
||||
valid = network_constants.publish_thresholds.value (hash, i) > difficulty;
|
||||
}
|
||||
std::ostringstream oss (valid ? "true" : "false"); // IO forces compiler to not dismiss the variable
|
||||
auto total_time (std::chrono::duration_cast<std::chrono::nanoseconds> (std::chrono::steady_clock::now () - start).count ());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue