diff --git a/nano/core_test/active_elections.cpp b/nano/core_test/active_elections.cpp index 05c243aa..9bd1d6c2 100644 --- a/nano/core_test/active_elections.cpp +++ b/nano/core_test/active_elections.cpp @@ -1398,6 +1398,8 @@ TEST (active_elections, bound_election_winners) nano::node_config config = system.default_config (); // Set election winner limit to a low value config.active_elections.max_election_winners = 5; + // Large batch size would complicate this testcase + config.confirming_set.batch_size = 1; auto & node = *system.add_node (config); // Start elections for a couple of blocks, number of elections is larger than the election winner set limit @@ -1411,22 +1413,12 @@ TEST (active_elections, bound_election_winners) auto guard = node.ledger.tx_begin_write (nano::store::writer::testing); // Ensure that when the number of election winners reaches the limit, AEC vacancy reflects that + // Confirming more elections should make the vacancy negative ASSERT_TRUE (node.active.vacancy (nano::election_behavior::priority) > 0); - int index = 0; - for (; index < config.active_elections.max_election_winners; ++index) + for (auto const & block : blocks) { - auto election = node.vote_router.election (blocks[index]->hash ()); - ASSERT_TRUE (election); - election->force_confirm (); - } - - ASSERT_TIMELY_EQ (5s, node.active.vacancy (nano::election_behavior::priority), 0); - - // Confirming more elections should make the vacancy negative - for (; index < blocks.size (); ++index) - { - auto election = node.vote_router.election (blocks[index]->hash ()); + auto election = node.vote_router.election (block->hash ()); ASSERT_TRUE (election); election->force_confirm (); } diff --git a/nano/node/active_elections.cpp b/nano/node/active_elections.cpp index feafab86..0cc4953f 100644 --- a/nano/node/active_elections.cpp +++ b/nano/node/active_elections.cpp @@ -40,13 +40,9 @@ nano::active_elections::active_elections (nano::node & node_a, nano::confirming_ // Notify elections about alternative (forked) blocks block_processor.block_processed.add ([this] (auto const & result, auto const & context) { - switch (result) + if (result == nano::block_status::fork) { - case nano::block_status::fork: - publish (context.block); - break; - default: - break; + publish (context.block); } }); } diff --git a/nano/node/confirming_set.cpp b/nano/node/confirming_set.cpp index de92e853..d669153b 100644 --- a/nano/node/confirming_set.cpp +++ b/nano/node/confirming_set.cpp @@ -48,6 +48,11 @@ void nano::confirming_set::start () { debug_assert (!thread.joinable ()); + if (!config.enable) + { + return; + } + thread = std::thread{ [this] () { nano::thread_role::set (nano::thread_role::name::confirmation_height); run (); @@ -123,7 +128,7 @@ void nano::confirming_set::run_batch (std::unique_lock & lock) std::deque cemented; std::deque already; - auto batch = next_batch (batch_size); + auto batch = next_batch (config.batch_size); lock.unlock (); diff --git a/nano/node/confirming_set.hpp b/nano/node/confirming_set.hpp index 00329fea..7085b5ba 100644 --- a/nano/node/confirming_set.hpp +++ b/nano/node/confirming_set.hpp @@ -28,6 +28,9 @@ public: // TODO: Serialization & deserialization public: + bool enable{ true }; + size_t batch_size{ 256 }; + /** Maximum number of dependent blocks to be stored in memory during processing */ size_t max_blocks{ 128 * 1024 }; size_t max_queued_notifications{ 8 }; @@ -106,7 +109,5 @@ private: mutable std::mutex mutex; std::condition_variable condition; std::thread thread; - - static size_t constexpr batch_size = 256; }; }