Skip to content

Commit

Permalink
Remove node::process_confirmed ()
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Oct 20, 2024
1 parent 435fcc8 commit af4ef05
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 55 deletions.
4 changes: 2 additions & 2 deletions nano/core_test/election_scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ TEST (election_scheduler, no_vacancy)
.work (*system.work.generate (nano::dev::genesis->hash ()))
.build ();
ASSERT_EQ (nano::block_status::progress, node.process (send));
node.process_confirmed (send->hash ());
node.confirming_set.add (send->hash ());

auto receive = builder.make_block ()
.account (key.pub)
Expand All @@ -207,7 +207,7 @@ TEST (election_scheduler, no_vacancy)
.work (*system.work.generate (key.pub))
.build ();
ASSERT_EQ (nano::block_status::progress, node.process (receive));
node.process_confirmed (receive->hash ());
node.confirming_set.add (receive->hash ());

ASSERT_TIMELY (5s, nano::test::confirmed (node, { send, receive }));

Expand Down
12 changes: 6 additions & 6 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3563,9 +3563,9 @@ TEST (node, pruning_automatic)
ASSERT_TIMELY (5s, node1.block (send2->hash ()) != nullptr);

// Force-confirm both blocks
node1.process_confirmed (send1->hash ());
node1.confirming_set.add (send1->hash ());
ASSERT_TIMELY (5s, node1.block_confirmed (send1->hash ()));
node1.process_confirmed (send2->hash ());
node1.confirming_set.add (send2->hash ());
ASSERT_TIMELY (5s, node1.block_confirmed (send2->hash ()));

// Check pruning result
Expand Down Expand Up @@ -3614,9 +3614,9 @@ TEST (node, DISABLED_pruning_age)
node1.process_active (send2);

// Force-confirm both blocks
node1.process_confirmed (send1->hash ());
node1.confirming_set.add (send1->hash ());
ASSERT_TIMELY (5s, node1.block_confirmed (send1->hash ()));
node1.process_confirmed (send2->hash ());
node1.confirming_set.add (send2->hash ());
ASSERT_TIMELY (5s, node1.block_confirmed (send2->hash ()));

// Three blocks in total, nothing pruned yet
Expand Down Expand Up @@ -3675,9 +3675,9 @@ TEST (node, DISABLED_pruning_depth)
node1.process_active (send2);

// Force-confirm both blocks
node1.process_confirmed (send1->hash ());
node1.confirming_set.add (send1->hash ());
ASSERT_TIMELY (5s, node1.block_confirmed (send1->hash ()));
node1.process_confirmed (send2->hash ());
node1.confirming_set.add (send2->hash ());
ASSERT_TIMELY (5s, node1.block_confirmed (send2->hash ()));

// Three blocks in total, nothing pruned yet
Expand Down
8 changes: 3 additions & 5 deletions nano/node/election.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ void nano::election::confirm_once (nano::unique_lock<nano::mutex> & lock)
nano::log::arg{ "qualified_root", qualified_root },
nano::log::arg{ "status", current_status_locked () });

lock.unlock ();
node.confirming_set.add (status_l.winner->hash (), shared_from_this ());

node.election_workers.push_task ([this_l = shared_from_this (), status_l, confirmation_action_l = confirmation_action] () {
// This is necessary if the winner of the election is one of the forks.
// In that case the winning block is not yet in the ledger and cementing needs to wait for rollbacks to complete.
this_l->node.process_confirmed (status_l.winner->hash (), this_l);
lock.unlock ();

node.election_workers.push_task ([status_l, confirmation_action_l = confirmation_action] () {
if (confirmation_action_l)
{
confirmation_action_l (status_l.winner);
Expand Down
38 changes: 5 additions & 33 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy
}
});

// Do some cleanup due to this block never being processed by confirmation height processor
confirming_set.cementing_failed.add ([this] (auto const & hash) {
active.recently_confirmed.erase (hash);
});

if (!init_error ())
{
// Notify election schedulers when AEC frees election slot
Expand Down Expand Up @@ -1151,39 +1156,6 @@ void nano::node::ongoing_online_weight_calculation ()
ongoing_online_weight_calculation_queue ();
}

// TODO: Replace this with a queue of some sort. Blocks submitted here could be in a limbo for a while: neither part of an active election nor cemented
void nano::node::process_confirmed (nano::block_hash hash, std::shared_ptr<nano::election> election, uint64_t iteration)
{
stats.inc (nano::stat::type::process_confirmed, nano::stat::detail::initiate);

// Limit the maximum number of iterations to avoid getting stuck
uint64_t const max_iterations = (config.block_processor_batch_max_time / network_params.node.process_confirmed_interval) * 4;

if (auto block = ledger.any.block_get (ledger.tx_begin_read (), hash))
{
stats.inc (nano::stat::type::process_confirmed, nano::stat::detail::done);
logger.trace (nano::log::type::node, nano::log::detail::process_confirmed, nano::log::arg{ "block", block });

confirming_set.add (block->hash (), election);
}
else if (iteration < max_iterations)
{
stats.inc (nano::stat::type::process_confirmed, nano::stat::detail::retry);

// Try again later
election_workers.add_timed_task (std::chrono::steady_clock::now () + network_params.node.process_confirmed_interval, [this, hash, election, iteration] () {
process_confirmed (hash, election, iteration + 1);
});
}
else
{
stats.inc (nano::stat::type::process_confirmed, nano::stat::detail::timeout);

// Do some cleanup due to this block never being processed by confirmation height processor
active.recently_confirmed.erase (hash);
}
}

std::shared_ptr<nano::node> nano::node::shared ()
{
return shared_from_this ();
Expand Down
11 changes: 2 additions & 9 deletions nano/node/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class node final : public std::enable_shared_from_this<node>
void keepalive (std::string const &, uint16_t);
int store_version ();
void inbound (nano::message const &, std::shared_ptr<nano::transport::channel> const &);
void process_confirmed (nano::block_hash, std::shared_ptr<nano::election> = nullptr, uint64_t iteration = 0);
void process_active (std::shared_ptr<nano::block> const &);
std::optional<nano::block_status> process_local (std::shared_ptr<nano::block> const &);
void process_local_async (std::shared_ptr<nano::block> const &);
Expand Down Expand Up @@ -235,20 +234,14 @@ class node final : public std::enable_shared_from_this<node>
std::atomic<bool> stopped{ false };
static double constexpr price_max = 16.0;
static double constexpr free_cutoff = 1024.0;
// For tests only

public: // For tests only
unsigned node_seq;
// For tests only
std::optional<uint64_t> work_generate_blocking (nano::block &);
// For tests only
std::optional<uint64_t> work_generate_blocking (nano::root const &, uint64_t);
// For tests only
std::optional<uint64_t> work_generate_blocking (nano::root const &);

public: // Testing convenience functions
/**
Creates a new write transaction and inserts `block' and returns result
Transaction is comitted before function return
*/
[[nodiscard]] nano::block_status process (std::shared_ptr<nano::block> block);
[[nodiscard]] nano::block_status process (secure::write_transaction const &, std::shared_ptr<nano::block> block);
nano::block_hash latest (nano::account const &);
Expand Down

0 comments on commit af4ef05

Please sign in to comment.