diff --git a/nano/core_test/active_transactions.cpp b/nano/core_test/active_transactions.cpp index 10de180ec6..14db5c7997 100644 --- a/nano/core_test/active_transactions.cpp +++ b/nano/core_test/active_transactions.cpp @@ -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::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_max, nano::vote::duration_max, std::vector (1, send1->hash ())); node.vote_processor.vote (vote, std::make_shared (node, node)); ASSERT_TIMELY (5s, node.vote_cache.size () == 1); @@ -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) diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index 5079cb2cd8..fc98e5ecb8 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -327,6 +327,18 @@ void nano::active_transactions::cleanup_election (nano::unique_lock 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); @@ -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 ""; +} +} + nano::election_insertion_result nano::active_transactions::insert (const std::shared_ptr & block, nano::election_behavior behavior) { debug_assert (block != nullptr); nano::unique_lock lock{ mutex }; + // std::cout << "activating: " << block->hash ().to_string () << " behavior: " << to_str (behavior) << std::endl; + auto result = insert_impl (lock, block, behavior); return result; } @@ -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 ( diff --git a/nano/node/election.cpp b/nano/node/election.cpp index 03e7e68cc9..e11044bf2f 100644 --- a/nano/node/election.cpp +++ b/nano/node/election.cpp @@ -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 ())