From 83f8a931fd7d2f5b843e34936b8878fb0e05d65e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Sat, 12 Jul 2025 21:51:54 +0200 Subject: [PATCH] Allow manually configured zero work multipliers for testing --- nano/core_test/difficulty.cpp | 14 +++----------- nano/core_test/unchecked_map.cpp | 5 ----- nano/lib/constants.cpp | 1 - nano/lib/numbers.cpp | 10 ++++++++-- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/nano/core_test/difficulty.cpp b/nano/core_test/difficulty.cpp index 77fbc418d..2e46bd940 100644 --- a/nano/core_test/difficulty.cpp +++ b/nano/core_test/difficulty.cpp @@ -10,11 +10,8 @@ #include -TEST (difficultyDeathTest, multipliers) +TEST (difficulty, multipliers) { - // For ASSERT_DEATH_IF_SUPPORTED - testing::FLAGS_gtest_death_test_style = "threadsafe"; - { uint64_t base = 0xff00000000000000; uint64_t difficulty = 0xfff27e7a57c285cd; @@ -51,19 +48,14 @@ TEST (difficultyDeathTest, multipliers) ASSERT_EQ (difficulty, nano::difficulty::from_multiplier (expected_multiplier, base)); } - // The death checks don't fail on a release config, so guard against them -#ifndef NDEBUG - // Causes valgrind to be noisy - if (!nano::running_within_valgrind ()) { uint64_t base = 0xffffffc000000000; uint64_t difficulty_nil = 0; double multiplier_nil = 0.; - ASSERT_DEATH_IF_SUPPORTED (nano::difficulty::to_multiplier (difficulty_nil, base), ""); - ASSERT_DEATH_IF_SUPPORTED (nano::difficulty::from_multiplier (multiplier_nil, base), ""); + ASSERT_EQ (0., nano::difficulty::to_multiplier (difficulty_nil, base)); + ASSERT_EQ (0, nano::difficulty::from_multiplier (multiplier_nil, base)); } -#endif } TEST (difficulty, overflow) diff --git a/nano/core_test/unchecked_map.cpp b/nano/core_test/unchecked_map.cpp index ea19b8583..51af28c8f 100644 --- a/nano/core_test/unchecked_map.cpp +++ b/nano/core_test/unchecked_map.cpp @@ -129,11 +129,6 @@ TEST (unchecked, simple) TEST (unchecked, multiple) { nano::test::system system{}; - if (nano::rocksdb_config::using_rocksdb_in_tests ()) - { - // Don't test this in rocksdb mode - GTEST_SKIP (); - } nano::unchecked_map unchecked{ max_unchecked_blocks, system.stats, false }; nano::block_builder builder; auto block = builder diff --git a/nano/lib/constants.cpp b/nano/lib/constants.cpp index f32bbafd7..4e5f0cce2 100644 --- a/nano/lib/constants.cpp +++ b/nano/lib/constants.cpp @@ -168,7 +168,6 @@ double nano::work_thresholds::denormalized_multiplier (double const multiplier_a if (threshold_a == epoch_1 || threshold_a == epoch_2_receive) { auto ratio (nano::difficulty::to_multiplier (epoch_2, threshold_a)); - debug_assert (ratio >= 1); multiplier = multiplier * ratio + 1.0 - ratio; debug_assert (multiplier >= 1); } diff --git a/nano/lib/numbers.cpp b/nano/lib/numbers.cpp index 00ad310a1..e8172cb54 100644 --- a/nano/lib/numbers.cpp +++ b/nano/lib/numbers.cpp @@ -805,7 +805,10 @@ std::ostream & nano::operator<< (std::ostream & os, const nano::account & val) uint64_t nano::difficulty::from_multiplier (double const multiplier_a, uint64_t const base_difficulty_a) { - debug_assert (multiplier_a > 0.); + if (multiplier_a <= 0.) + { + return 0; + } nano::uint128_t reverse_difficulty ((-base_difficulty_a) / multiplier_a); if (reverse_difficulty > std::numeric_limits::max ()) { @@ -823,7 +826,10 @@ uint64_t nano::difficulty::from_multiplier (double const multiplier_a, uint64_t double nano::difficulty::to_multiplier (uint64_t const difficulty_a, uint64_t const base_difficulty_a) { - debug_assert (difficulty_a > 0); + if (difficulty_a == 0) + { + return 0; + } return static_cast (-base_difficulty_a) / (-difficulty_a); }