Skip to content

Commit

Permalink
Merge pull request #4758 from pwojcikdev/remove-process-confirmed
Browse files Browse the repository at this point in the history
Remove `node::process_confirmed (...)`
  • Loading branch information
pwojcikdev authored Nov 24, 2024
2 parents b06c9eb + 8221c05 commit b00064b
Show file tree
Hide file tree
Showing 15 changed files with 276 additions and 160 deletions.
55 changes: 41 additions & 14 deletions nano/core_test/confirming_set.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include <nano/lib/blocks.hpp>
#include <nano/lib/logging.hpp>
#include <nano/node/active_elections.hpp>
#include <nano/node/blockprocessor.hpp>
#include <nano/node/confirming_set.hpp>
#include <nano/node/election.hpp>
#include <nano/node/make_store.hpp>
#include <nano/node/unchecked_map.hpp>
#include <nano/secure/ledger.hpp>
#include <nano/secure/ledger_set_confirmed.hpp>
#include <nano/test_common/ledger_context.hpp>
Expand All @@ -16,45 +18,70 @@

using namespace std::chrono_literals;

namespace
{
struct confirming_set_context
{
nano::logger & logger;
nano::stats & stats;
nano::ledger & ledger;

nano::unchecked_map unchecked;
nano::block_processor block_processor;
nano::confirming_set confirming_set;

explicit confirming_set_context (nano::test::ledger_context & ledger_context, nano::node_config node_config = {}) :
logger{ ledger_context.logger () },
stats{ ledger_context.stats () },
ledger{ ledger_context.ledger () },
unchecked{ 0, stats, false },
block_processor{ node_config, ledger, unchecked, stats, logger },
confirming_set{ node_config.confirming_set, ledger, block_processor, stats, logger }
{
}
};
}

TEST (confirming_set, construction)
{
auto ctx = nano::test::ledger_empty ();
nano::confirming_set_config config{};
nano::confirming_set confirming_set{ config, ctx.ledger (), ctx.stats (), ctx.logger () };
auto ledger_ctx = nano::test::ledger_empty ();
confirming_set_context ctx{ ledger_ctx };
}

TEST (confirming_set, add_exists)
{
auto ctx = nano::test::ledger_send_receive ();
nano::confirming_set_config config{};
nano::confirming_set confirming_set{ config, ctx.ledger (), ctx.stats (), ctx.logger () };
auto send = ctx.blocks ()[0];
auto ledger_ctx = nano::test::ledger_send_receive ();
confirming_set_context ctx{ ledger_ctx };
nano::confirming_set & confirming_set = ctx.confirming_set;
auto send = ledger_ctx.blocks ()[0];
confirming_set.add (send->hash ());
ASSERT_TRUE (confirming_set.contains (send->hash ()));
}

TEST (confirming_set, process_one)
{
auto ctx = nano::test::ledger_send_receive ();
nano::confirming_set_config config{};
nano::confirming_set confirming_set{ config, ctx.ledger (), ctx.stats (), ctx.logger () };
auto ledger_ctx = nano::test::ledger_send_receive ();
confirming_set_context ctx{ ledger_ctx };
nano::confirming_set & confirming_set = ctx.confirming_set;
std::atomic<int> count = 0;
std::mutex mutex;
std::condition_variable condition;
confirming_set.cemented_observers.add ([&] (auto const &) { ++count; condition.notify_all (); });
confirming_set.add (ctx.blocks ()[0]->hash ());
confirming_set.add (ledger_ctx.blocks ()[0]->hash ());
nano::test::start_stop_guard guard{ confirming_set };
std::unique_lock lock{ mutex };
ASSERT_TRUE (condition.wait_for (lock, 5s, [&] () { return count == 1; }));
ASSERT_EQ (1, ctx.stats ().count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in));
ASSERT_EQ (2, ctx.ledger ().cemented_count ());
ASSERT_EQ (1, ctx.stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in));
ASSERT_EQ (2, ctx.ledger.cemented_count ());
}

TEST (confirming_set, process_multiple)
{
nano::test::system system;
auto & node = *system.add_node ();
auto ctx = nano::test::ledger_send_receive ();
nano::confirming_set_config config{};
nano::confirming_set confirming_set{ config, ctx.ledger (), ctx.stats (), ctx.logger () };
nano::confirming_set confirming_set{ config, ctx.ledger (), node.block_processor, ctx.stats (), ctx.logger () };
std::atomic<int> count = 0;
std::mutex mutex;
std::condition_variable condition;
Expand Down
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 @@ -3446,9 +3446,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 @@ -3497,9 +3497,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 @@ -3558,9 +3558,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
3 changes: 3 additions & 0 deletions nano/lib/stats_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ enum class detail
prioritized,
pending,
sync,
requeued,
evicted,

// processing queue
queue,
Expand Down Expand Up @@ -541,6 +543,7 @@ enum class detail
cementing,
cemented_hash,
cementing_failed,
deferred_failed,

// election_state
passive,
Expand Down
8 changes: 8 additions & 0 deletions nano/node/active_elections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ nano::active_elections::active_elections (nano::node & node_a, nano::confirming_
}
}
});

// Stop all rolled back active transactions except initial
block_processor.rolled_back.add ([this] (auto const & block, auto const & rollback_root) {
if (block->qualified_root () != rollback_root)
{
erase (block->qualified_root ());
}
});
}

nano::active_elections::~active_elections ()
Expand Down
Loading

0 comments on commit b00064b

Please sign in to comment.