Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Mar 20, 2024
1 parent 8532f27 commit 2297f50
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
27 changes: 9 additions & 18 deletions nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,11 @@ void nano::active_transactions::trim ()

nano::election_insertion_result nano::active_transactions::insert (std::shared_ptr<nano::block> const & block_a, nano::election_behavior election_behavior_a)
{
nano::unique_lock<nano::mutex> lock{ mutex };
debug_assert (block_a);
debug_assert (block_a->has_sideband ());

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

nano::election_insertion_result result;

if (stopped)
Expand Down Expand Up @@ -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);
Expand All @@ -470,7 +473,9 @@ nano::election_insertion_result nano::active_transactions::insert (std::shared_p
{
result.election->broadcast_vote ();
}

trim ();

return result;
}

Expand Down Expand Up @@ -504,12 +509,6 @@ nano::vote_code nano::active_transactions::vote (std::shared_ptr<nano::vote> 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;
Expand Down Expand Up @@ -680,14 +679,6 @@ boost::optional<nano::election_status_type> nano::active_transactions::confirm_b
return status_type;
}

void nano::active_transactions::add_vote_cache (nano::block_hash const & hash, std::shared_ptr<nano::vote> 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<nano::mutex> guard{ election_winner_details_mutex };
Expand Down
5 changes: 0 additions & 5 deletions nano/node/active_transactions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::shared_ptr<nano::election>> 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<nano::vote> vote);
boost::optional<nano::election_status_type> election_status (std::shared_ptr<nano::block> const & block);
void process_inactive_confirmation (nano::store::read_transaction const & transaction, std::shared_ptr<nano::block> const & block);
void process_active_confirmation (nano::store::read_transaction const & transaction, std::shared_ptr<nano::block> const & block, nano::election_status_type status);
Expand Down
14 changes: 12 additions & 2 deletions nano/node/vote_processor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <nano/lib/stats.hpp>
#include <nano/lib/timer.hpp>
#include <nano/node/active_transactions.hpp>
#include <nano/node/node.hpp>
#include <nano/node/node_observers.hpp>
#include <nano/node/nodeconfig.hpp>
#include <nano/node/online_reps.hpp>
Expand All @@ -10,8 +11,6 @@
#include <nano/secure/common.hpp>
#include <nano/secure/ledger.hpp>

#include <boost/format.hpp>

#include <chrono>

using namespace std::chrono_literals;
Expand Down Expand Up @@ -167,8 +166,19 @@ nano::vote_code nano::vote_processor::vote_blocking (std::shared_ptr<nano::vote>
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)
{
Expand Down
1 change: 1 addition & 0 deletions nano/node/vote_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class vote_processor final
std::atomic<uint64_t> total_processed{ 0 };

private: // Dependencies
nano::node & node;
nano::active_transactions & active;
nano::node_observers & observers;
nano::stats & stats;
Expand Down

0 comments on commit 2297f50

Please sign in to comment.