More cleanup

This commit is contained in:
Piotr Wójcik 2024-06-25 14:03:20 +02:00
commit 0b0c0adbd8
6 changed files with 28 additions and 8 deletions

View file

@ -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<nano::mutex> 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 ()));

View file

@ -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);

View file

@ -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

View file

@ -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.

View file

@ -1,3 +1,4 @@
#include <nano/lib/config.hpp>
#include <nano/node/nodeconfig.hpp>
#include <nano/node/online_reps.hpp>
#include <nano/secure/ledger.hpp>
@ -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<nano::mutex> lock{ mutex };
online_m = online_weight;
}
nano::container_info nano::online_reps::container_info () const
{
nano::lock_guard<nano::mutex> guard{ mutex };

View file

@ -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);
};
}