From 2297f50746a3e0516c3462f75774618d066b1799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Wed, 20 Mar 2024 17:39:08 +0100 Subject: [PATCH] WIP --- nano/node/active_transactions.cpp | 27 +++++++++------------------ nano/node/active_transactions.hpp | 5 ----- nano/node/vote_processor.cpp | 14 ++++++++++++-- nano/node/vote_processor.hpp | 1 + 4 files changed, 22 insertions(+), 25 deletions(-) diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index d9d8891848..de210bdd7a 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -405,9 +405,11 @@ void nano::active_transactions::trim () nano::election_insertion_result nano::active_transactions::insert (std::shared_ptr const & block_a, nano::election_behavior election_behavior_a) { - nano::unique_lock lock{ mutex }; debug_assert (block_a); debug_assert (block_a->has_sideband ()); + + nano::unique_lock lock{ mutex }; + nano::election_insertion_result result; if (stopped) @@ -450,15 +452,16 @@ nano::election_insertion_result nano::active_transactions::insert (std::shared_p result.election = existing->election; } - lock.unlock (); // end of critical section + lock.unlock (); if (result.inserted) { release_assert (result.election); - if (auto const cache = node.vote_cache.find (hash); cache) + auto cached = node.vote_cache.find (hash); + for (auto const & cached_vote : cached) { - cache->fill (result.election); + vote (cached_vote); } node.observers.active_started.notify (hash); @@ -470,7 +473,9 @@ nano::election_insertion_result nano::active_transactions::insert (std::shared_p { result.election->broadcast_vote (); } + trim (); + return result; } @@ -504,12 +509,6 @@ nano::vote_code nano::active_transactions::vote (std::shared_ptr con } } - // Process inactive votes outside of the critical section - for (auto & hash : inactive) - { - add_vote_cache (hash, vote_a); - } - if (!process.empty ()) { bool replay = false; @@ -680,14 +679,6 @@ boost::optional nano::active_transactions::confirm_b return status_type; } -void nano::active_transactions::add_vote_cache (nano::block_hash const & hash, std::shared_ptr const vote) -{ - if (node.ledger.weight (vote->account) > node.minimum_principal_weight ()) - { - node.vote_cache.vote (hash, vote); - } -} - std::size_t nano::active_transactions::election_winner_details_size () { nano::lock_guard guard{ election_winner_details_mutex }; diff --git a/nano/node/active_transactions.hpp b/nano/node/active_transactions.hpp index 9f56d5cad6..d79d2b1bea 100644 --- a/nano/node/active_transactions.hpp +++ b/nano/node/active_transactions.hpp @@ -190,11 +190,6 @@ class active_transactions final nano::stat::type completion_type (nano::election const & election) const; // Returns a list of elections sorted by difficulty, mutex must be locked std::vector> list_active_impl (std::size_t) const; - /** - * Checks if vote passes minimum representative weight threshold and adds it to inactive vote cache - * TODO: Should be moved to `vote_cache` class - */ - void add_vote_cache (nano::block_hash const & hash, std::shared_ptr vote); boost::optional election_status (std::shared_ptr const & block); void process_inactive_confirmation (nano::store::read_transaction const & transaction, std::shared_ptr const & block); void process_active_confirmation (nano::store::read_transaction const & transaction, std::shared_ptr const & block, nano::election_status_type status); diff --git a/nano/node/vote_processor.cpp b/nano/node/vote_processor.cpp index 337b0bddfb..60d55ed1e7 100644 --- a/nano/node/vote_processor.cpp +++ b/nano/node/vote_processor.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -10,8 +11,6 @@ #include #include -#include - #include using namespace std::chrono_literals; @@ -167,8 +166,19 @@ nano::vote_code nano::vote_processor::vote_blocking (std::shared_ptr if (validated || !vote_a->validate ()) { result = active.vote (vote_a); + + if (result != nano::vote_code::replay) + { + + } + if (ledger.weight (vote_a->account) > node.minimum_principal_weight ()) + { + node.vote_cache.vote (vote_a); + } + observers.vote.notify (vote_a, channel_a, result); } + std::string status; switch (result) { diff --git a/nano/node/vote_processor.hpp b/nano/node/vote_processor.hpp index b7498180fc..7bed071678 100644 --- a/nano/node/vote_processor.hpp +++ b/nano/node/vote_processor.hpp @@ -56,6 +56,7 @@ class vote_processor final std::atomic total_processed{ 0 }; private: // Dependencies + nano::node & node; nano::active_transactions & active; nano::node_observers & observers; nano::stats & stats;