Skip to content

Commit

Permalink
DEBUG
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Oct 9, 2023
1 parent fb3007f commit 5cbeb96
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ TEST (active_transactions, inactive_votes_cache_fork)
.work (*system.work.generate (latest))
.build_shared ();

std::cout << "send1: " << send1->hash ().to_string () << std::endl;
std::cout << "send2: " << send2->hash ().to_string () << std::endl;

auto const vote = std::make_shared<nano::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_max, nano::vote::duration_max, std::vector<nano::block_hash> (1, send1->hash ()));
node.vote_processor.vote (vote, std::make_shared<nano::transport::inproc::channel> (node, node));
ASSERT_TIMELY (5s, node.vote_cache.size () == 1);
Expand All @@ -312,6 +315,7 @@ TEST (active_transactions, inactive_votes_cache_fork)
ASSERT_TIMELY (5s, election->blocks ().size () == 2);
ASSERT_TIMELY (5s, node.block_confirmed (send1->hash ()));
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::vote_cached));
ASSERT_ALWAYS (1s, 1 == node.stats.count (nano::stat::type::election, nano::stat::detail::vote_cached));
}

TEST (active_transactions, inactive_votes_cache_existing_vote)
Expand Down
35 changes: 35 additions & 0 deletions nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,18 @@ void nano::active_transactions::cleanup_election (nano::unique_lock<nano::mutex>
debug_assert (!mutex.try_lock ());
debug_assert (lock_a.owns_lock ());

if (election->confirmed())
{
debug_assert (recently_confirmed.exists (election->qualified_root));
}

std::cout << "stopped active: " << election->qualified_root.to_string ()
<< " confirmed: " << election->confirmed ()
<< " failed: " << election->failed ()
<< " blocks: " << election->blocks ().size ()
<< " votes: " << election->votes ().size ()
<< std::endl;

node.stats.inc (completion_type (*election), nano::to_stat_detail (election->behavior ()));
// Keep track of election count by election type
debug_assert (count_by_behavior[election->behavior ()] > 0);
Expand Down Expand Up @@ -419,12 +431,33 @@ void nano::active_transactions::request_loop ()
}
}

namespace
{
std::string to_str (nano::election_behavior behavior)
{
switch (behavior)
{
case nano::election_behavior::normal:
return "normal";
case nano::election_behavior::hinted:
return "hinted";
case nano::election_behavior::optimistic:
return "optimistic";
}

debug_assert (false);
return "<unknown>";
}
}

nano::election_insertion_result nano::active_transactions::insert (const std::shared_ptr<nano::block> & block, nano::election_behavior behavior)
{
debug_assert (block != nullptr);

nano::unique_lock<nano::mutex> lock{ mutex };

// std::cout << "activating: " << block->hash ().to_string () << " behavior: " << to_str (behavior) << std::endl;

auto result = insert_impl (lock, block, behavior);
return result;
}
Expand Down Expand Up @@ -457,6 +490,8 @@ nano::election_insertion_result nano::active_transactions::insert_impl (nano::un
{
if (!recently_confirmed.exists (root))
{
std::cout << "activating: " << block_a->hash ().to_string () << " behavior: " << to_str (election_behavior_a) << std::endl;

result.inserted = true;
auto hash (block_a->hash ());
result.election = nano::make_shared<nano::election> (
Expand Down
5 changes: 5 additions & 0 deletions nano/node/election.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,11 @@ nano::election_vote_result nano::election::vote (nano::account const & rep, uint
live_vote_action (rep);
}

if (vote_source_a == vote_source::cache)
{
debug_assert (node.stats.count (nano::stat::type::election, nano::stat::detail::vote_cached) == 0);
}

node.stats.inc (nano::stat::type::election, vote_source_a == vote_source::live ? nano::stat::detail::vote_new : nano::stat::detail::vote_cached);

if (!confirmed ())
Expand Down

0 comments on commit 5cbeb96

Please sign in to comment.