From 0b0c0adbd828fd93493e24aa4e818a8d4f53be51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Tue, 25 Jun 2024 14:03:20 +0200 Subject: [PATCH] More cleanup --- nano/core_test/election.cpp | 8 +++----- nano/lib/config.cpp | 5 +++++ nano/lib/config.hpp | 7 +++++-- nano/lib/constants.hpp | 5 +++++ nano/node/online_reps.cpp | 8 ++++++++ nano/node/online_reps.hpp | 3 ++- 6 files changed, 28 insertions(+), 8 deletions(-) diff --git a/nano/core_test/election.cpp b/nano/core_test/election.cpp index 365746eae..d32985221 100644 --- a/nano/core_test/election.cpp +++ b/nano/core_test/election.cpp @@ -260,11 +260,9 @@ TEST (election, quorum_minimum_update_weight_before_quorum_checks) node1.rep_crawler.force_process (vote2, channel); ASSERT_FALSE (election->confirmed ()); - { - nano::lock_guard guard (node1.online_reps.mutex); - // Modify online_m for online_reps to more than is available, this checks that voting below updates it to current online reps. - node1.online_reps.online_m = node_config.online_weight_minimum.number () + 20; - } + + // Modify online_m for online_reps to more than is available, this checks that voting below updates it to current online reps. + node1.online_reps.force_online_weight (node_config.online_weight_minimum.number () + 20); ASSERT_EQ (nano::vote_code::vote, node1.vote_router.vote (vote2).at (send1->hash ())); ASSERT_TIMELY (5s, election->confirmed ()); ASSERT_NE (nullptr, node1.block (send1->hash ())); diff --git a/nano/lib/config.cpp b/nano/lib/config.cpp index 13366a5d5..e8d0f928d 100644 --- a/nano/lib/config.cpp +++ b/nano/lib/config.cpp @@ -36,6 +36,11 @@ void force_nano_dev_network () nano::network_constants::set_active_network (nano::networks::nano_dev_network); } +bool is_dev_run () +{ + return nano::network_constants::get_active_network () == nano::networks::nano_dev_network; +} + bool running_within_valgrind () { return (RUNNING_ON_VALGRIND > 0); diff --git a/nano/lib/config.hpp b/nano/lib/config.hpp index 11edc9ab3..a0eb430af 100644 --- a/nano/lib/config.hpp +++ b/nano/lib/config.hpp @@ -41,7 +41,7 @@ consteval bool is_asan_build () #else return false; #endif -// GCC builds + // GCC builds #elif defined(__SANITIZE_ADDRESS__) return true; #else @@ -57,7 +57,7 @@ consteval bool is_tsan_build () #else return false; #endif -// GCC builds + // GCC builds #elif defined(__SANITIZE_THREAD__) return true; #else @@ -105,6 +105,9 @@ bool slow_instrumentation (); /** Set the active network to the dev network */ void force_nano_dev_network (); + +/** Checks that we are running in test mode */ +bool is_dev_run (); } namespace nano diff --git a/nano/lib/constants.hpp b/nano/lib/constants.hpp index f58438bd1..de6e82222 100644 --- a/nano/lib/constants.hpp +++ b/nano/lib/constants.hpp @@ -205,6 +205,11 @@ public: active_network = network_a; } + static nano::networks get_active_network () + { + return active_network; + } + /** * Optionally called on startup to override the global active network. * If not called, the compile-time option will be used. diff --git a/nano/node/online_reps.cpp b/nano/node/online_reps.cpp index 621bbe342..a8d5d58f9 100644 --- a/nano/node/online_reps.cpp +++ b/nano/node/online_reps.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -117,6 +118,13 @@ void nano::online_reps::clear () online_m = 0; } +void nano::online_reps::force_online_weight (nano::uint128_t const & online_weight) +{ + release_assert (nano::is_dev_run ()); + nano::lock_guard lock{ mutex }; + online_m = online_weight; +} + nano::container_info nano::online_reps::container_info () const { nano::lock_guard guard{ mutex }; diff --git a/nano/node/online_reps.hpp b/nano/node/online_reps.hpp index e1f66c8e5..19cc58692 100644 --- a/nano/node/online_reps.hpp +++ b/nano/node/online_reps.hpp @@ -77,6 +77,7 @@ private: mutable nano::mutex mutex; - friend class election_quorum_minimum_update_weight_before_quorum_checks_Test; +public: // Only for tests + void force_online_weight (nano::uint128_t const & online_weight); }; }