Skip to content

Commit

Permalink
FIX TESTS
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Mar 21, 2024
1 parent e61fb01 commit 69e12f5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion nano/core_test/vote_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ());

Expand Down
12 changes: 9 additions & 3 deletions nano/core_test/vote_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nano::vote> (*vote);
Expand Down Expand Up @@ -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));
}

Expand Down
11 changes: 7 additions & 4 deletions nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,26 +540,29 @@ std::shared_ptr<nano::block> 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<nano::mutex> lock{ mutex };
auto root_it (roots.get<tag_root> ().find (root_a));
if (root_it != roots.get<tag_root> ().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<nano::mutex> lock{ mutex };
[[maybe_unused]] auto erased (blocks.erase (hash_a));
debug_assert (erased == 1);
return erased == 1;
}

void nano::active_transactions::erase_oldest ()
Expand Down
6 changes: 3 additions & 3 deletions nano/node/active_transactions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ class active_transactions final
std::shared_ptr<nano::block> winner (nano::block_hash const &) const;
// Returns a list of elections sorted by difficulty
std::vector<std::shared_ptr<nano::election>> list_active (std::size_t = std::numeric_limits<std::size_t>::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;
Expand Down Expand Up @@ -197,7 +198,6 @@ class active_transactions final
void trim ();
void request_loop ();
void request_confirm (nano::unique_lock<nano::mutex> &);
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<nano::mutex> & lock_a, std::shared_ptr<nano::election>);
nano::stat::type completion_type (nano::election const & election) const;
Expand Down

0 comments on commit 69e12f5

Please sign in to comment.