diff --git a/nano/core_test/vote_cache.cpp b/nano/core_test/vote_cache.cpp index bc00d7f458..711f8a31b4 100644 --- a/nano/core_test/vote_cache.cpp +++ b/nano/core_test/vote_cache.cpp @@ -137,7 +137,7 @@ TEST (vote_cache, insert_many_hashes_many_votes) vote_cache.insert (vote3); // Ensure all of those are properly inserted ASSERT_EQ (3, vote_cache.size ()); - ASSERT_EQ (2, vote_cache.find (hash1).size ()); + ASSERT_EQ (1, vote_cache.find (hash1).size ()); ASSERT_EQ (1, vote_cache.find (hash2).size ()); ASSERT_EQ (1, vote_cache.find (hash3).size ()); diff --git a/nano/core_test/vote_processor.cpp b/nano/core_test/vote_processor.cpp index 8ed2dd221a..5b0b31e49f 100644 --- a/nano/core_test/vote_processor.cpp +++ b/nano/core_test/vote_processor.cpp @@ -15,8 +15,14 @@ using namespace std::chrono_literals; TEST (vote_processor, codes) { - nano::test::system system (1); - auto & node (*system.nodes[0]); + nano::test::system system; + auto node_config = system.default_config (); + // Disable all election schedulers + node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.hinted_scheduler.enabled = false; + node_config.optimistic_scheduler.enabled = false; + auto & node = *system.add_node (node_config); + auto blocks = nano::test::setup_chain (system, node, 1, nano::dev::genesis_key, false); auto vote = nano::test::make_vote (nano::dev::genesis_key, { blocks[0] }, nano::vote::timestamp_min * 1, 0); auto vote_invalid = std::make_shared (*vote); @@ -48,7 +54,7 @@ TEST (vote_processor, codes) ASSERT_EQ (nano::vote_code::invalid, node.vote_processor.vote_blocking (vote_invalid, channel)); // Once the election is removed (confirmed / dropped) the vote is again indeterminate - node.active.erase (*blocks[0]); + ASSERT_TRUE (node.active.erase (blocks[0]->qualified_root ())); ASSERT_EQ (nano::vote_code::indeterminate, node.vote_processor.vote_blocking (vote, channel)); } diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index a8286d01a6..c7411a4c63 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -540,26 +540,29 @@ std::shared_ptr nano::active_transactions::winner (nano::block_hash return result; } -void nano::active_transactions::erase (nano::block const & block_a) +bool nano::active_transactions::erase (nano::block const & block_a) { - erase (block_a.qualified_root ()); + return erase (block_a.qualified_root ()); } -void nano::active_transactions::erase (nano::qualified_root const & root_a) +bool nano::active_transactions::erase (nano::qualified_root const & root_a) { nano::unique_lock lock{ mutex }; auto root_it (roots.get ().find (root_a)); if (root_it != roots.get ().end ()) { cleanup_election (lock, root_it->election); + return true; } + return false; } -void nano::active_transactions::erase_hash (nano::block_hash const & hash_a) +bool nano::active_transactions::erase_hash (nano::block_hash const & hash_a) { nano::unique_lock lock{ mutex }; [[maybe_unused]] auto erased (blocks.erase (hash_a)); debug_assert (erased == 1); + return erased == 1; } void nano::active_transactions::erase_oldest () diff --git a/nano/node/active_transactions.hpp b/nano/node/active_transactions.hpp index c364d74462..5c2a07d928 100644 --- a/nano/node/active_transactions.hpp +++ b/nano/node/active_transactions.hpp @@ -164,8 +164,9 @@ class active_transactions final std::shared_ptr winner (nano::block_hash const &) const; // Returns a list of elections sorted by difficulty std::vector> list_active (std::size_t = std::numeric_limits::max ()); - void erase (nano::block const &); - void erase_hash (nano::block_hash const &); + bool erase (nano::block const &); + bool erase (nano::qualified_root const &); + bool erase_hash (nano::block_hash const &); void erase_oldest (); bool empty () const; std::size_t size () const; @@ -197,7 +198,6 @@ class active_transactions final void trim (); void request_loop (); void request_confirm (nano::unique_lock &); - void erase (nano::qualified_root const &); // Erase all blocks from active and, if not confirmed, clear digests from network filters void cleanup_election (nano::unique_lock & lock_a, std::shared_ptr); nano::stat::type completion_type (nano::election const & election) const;