Skip to content

Commit

Permalink
Adding active_transactions::insert_fn
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Sep 3, 2023
1 parent 2b8245c commit 8d0415e
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 9 deletions.
2 changes: 2 additions & 0 deletions nano/core_test/scheduler_buckets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ std::shared_ptr<nano::state_block> & block3 ()
return result;
}

namespace {
auto test_insert = [] (std::shared_ptr<nano::block> const & block, nano::election_behavior behavior) { return nano::election_insertion_result{}; };
}

TEST (buckets, construction)
{
Expand Down
2 changes: 2 additions & 0 deletions nano/core_test/scheduler_limiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

#include <gtest/gtest.h>

namespace {
auto test_insert = [] (std::shared_ptr<nano::block> const & block, nano::election_behavior behavior) { return nano::election_insertion_result{}; };
}

TEST (scheduler_limiter, construction)
{
Expand Down
7 changes: 7 additions & 0 deletions nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,13 @@ nano::election_insertion_result nano::active_transactions::insert (const std::sh
return result;
}

std::function<nano::election_insertion_result (std::shared_ptr<nano::block> const & block, nano::election_behavior behavior)> nano::active_transactions::insert_fn ()
{
return [this] (std::shared_ptr<nano::block> const & block, nano::election_behavior behavior) {
return insert (block, behavior);
};
}

void nano::active_transactions::trim ()
{
/*
Expand Down
2 changes: 2 additions & 0 deletions nano/node/active_transactions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ class active_transactions final
* Starts new election with a specified behavior type
*/
nano::election_insertion_result insert (std::shared_ptr<nano::block> const & block, nano::election_behavior behavior = nano::election_behavior::normal);
// Function wrapper around call to ::insert
std::function<nano::election_insertion_result (std::shared_ptr<nano::block> const & block, nano::election_behavior behavior)> insert_fn ();
// Distinguishes replay votes, cannot be determined if the block is not in any election
nano::vote_code vote (std::shared_ptr<nano::vote> const &);
// Is the root of this block in the roots container
Expand Down
4 changes: 1 addition & 3 deletions nano/node/scheduler/hinted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ nano::scheduler::hinted::hinted (config const & config_a, nano::node & node_a, n
config_m{ config_a },
node{ node_a },
inactive_vote_cache{ inactive_vote_cache_a },
limiter{ std::make_shared<nano::scheduler::limiter> ([this] (auto const & block, auto const & behavior) {
return node.active.insert (block, behavior);
}, node.config.active_elections_hinted_limit_percentage * node.config.active_elections_size / 100, nano::election_behavior::hinted) },
limiter{ std::make_shared<nano::scheduler::limiter> (node.active.insert_fn (), node.config.active_elections_hinted_limit_percentage * node.config.active_elections_size / 100, nano::election_behavior::hinted) },
online_reps{ online_reps_a }, stats{ stats_a }
{
}
Expand Down
4 changes: 1 addition & 3 deletions nano/node/scheduler/optimistic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ nano::scheduler::optimistic::optimistic (optimistic_config const & config_a, nan
config{ config_a },
node{ node_a },
ledger{ ledger_a },
limiter{ std::make_shared <nano::scheduler::limiter> ([this] (auto const & block, auto const & behavior) {
return node.active.insert(block, behavior);
}, node.config.active_elections_optimistic_limit_percentage * node.config.active_elections_size / 100, nano::election_behavior::optimistic) },
limiter{ std::make_shared <nano::scheduler::limiter> (node.active.insert_fn (), node.config.active_elections_optimistic_limit_percentage * node.config.active_elections_size / 100, nano::election_behavior::optimistic) },
network_constants{ network_constants_a },
stats{ stats_a }
{
Expand Down
4 changes: 1 addition & 3 deletions nano/node/scheduler/priority.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
nano::scheduler::priority::priority (nano::node & node_a, nano::stats & stats_a) :
node{ node_a },
stats{ stats_a },
buckets{ [this] (auto const & block, auto const & behavior) {
return node.active.insert (block, behavior);
} }
buckets{ node.active.insert_fn () }
{
}

Expand Down

0 comments on commit 8d0415e

Please sign in to comment.