From 106ad6b4d3e1122e4ad60ecb257ddeb4b1d43e78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Sat, 11 Nov 2023 21:11:54 +0100 Subject: [PATCH] Move block observer logic into `active_transactions` --- nano/node/CMakeLists.txt | 2 -- nano/node/active_transactions.cpp | 17 +++++++++++++++-- nano/node/active_transactions.hpp | 6 ++++-- nano/node/block_publisher.cpp | 27 --------------------------- nano/node/block_publisher.hpp | 24 ------------------------ nano/node/node.cpp | 5 ++--- nano/node/node.hpp | 2 -- 7 files changed, 21 insertions(+), 62 deletions(-) delete mode 100644 nano/node/block_publisher.cpp delete mode 100644 nano/node/block_publisher.hpp diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index 7918388016..3de07bee3d 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -24,8 +24,6 @@ add_library( block_arrival.cpp block_broadcast.cpp block_broadcast.hpp - block_publisher.cpp - block_publisher.hpp gap_tracker.cpp gap_tracker.hpp blocking_observer.cpp diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index a66f69119d..20e3abba00 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -13,9 +13,10 @@ using namespace std::chrono; -nano::active_transactions::active_transactions (nano::node & node_a, nano::confirmation_height_processor & confirmation_height_processor_a) : - confirmation_height_processor{ confirmation_height_processor_a }, +nano::active_transactions::active_transactions (nano::node & node_a, nano::confirmation_height_processor & confirmation_height_processor_a, nano::block_processor & block_processor_a) : node{ node_a }, + confirmation_height_processor{ confirmation_height_processor_a }, + block_processor{ block_processor_a }, recently_confirmed{ 65536 }, recently_cemented{ node.config.confirmation_history_size }, election_time_to_live{ node_a.network_params.network.is_dev_network () ? 0s : 2s } @@ -31,6 +32,18 @@ nano::active_transactions::active_transactions (nano::node & node_a, nano::confi confirmation_height_processor.add_block_already_cemented_observer ([this] (nano::block_hash const & hash_a) { this->block_already_cemented_callback (hash_a); }); + + // Notify elections about alternative (forked) blocks + block_processor.processed.add ([this] (auto const & result, auto const & block) { + switch (result.code) + { + case nano::process_result::fork: + publish (block); + break; + default: + break; + } + }); } nano::active_transactions::~active_transactions () diff --git a/nano/node/active_transactions.hpp b/nano/node/active_transactions.hpp index ac83c4efa8..c2b945a9a9 100644 --- a/nano/node/active_transactions.hpp +++ b/nano/node/active_transactions.hpp @@ -25,6 +25,7 @@ class node; class active_transactions; class block; class block_sideband; +class block_processor; class election; class vote; class confirmation_height_processor; @@ -130,7 +131,7 @@ class active_transactions final std::unordered_map> blocks; public: - active_transactions (nano::node &, nano::confirmation_height_processor &); + active_transactions (nano::node &, nano::confirmation_height_processor &, nano::block_processor &); ~active_transactions (); void start (); @@ -204,8 +205,9 @@ class active_transactions final void notify_observers (nano::election_status const & status, std::vector const & votes, nano::account const & account, nano::uint128_t amount, bool is_state_send, bool is_state_epoch, nano::account const & pending_account); private: // Dependencies - nano::confirmation_height_processor & confirmation_height_processor; nano::node & node; + nano::confirmation_height_processor & confirmation_height_processor; + nano::block_processor & block_processor; public: recently_confirmed_cache recently_confirmed; diff --git a/nano/node/block_publisher.cpp b/nano/node/block_publisher.cpp deleted file mode 100644 index 1cc77e5edb..0000000000 --- a/nano/node/block_publisher.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include - -nano::block_publisher::block_publisher (nano::active_transactions & active) : - active{ active } -{ -} - -void nano::block_publisher::connect (nano::block_processor & block_processor) -{ - block_processor.processed.add ([this] (auto const & result, auto const & block) { - switch (result.code) - { - case nano::process_result::fork: - observe (block); - break; - default: - break; - } - }); -} - -void nano::block_publisher::observe (std::shared_ptr block) -{ - active.publish (block); -} diff --git a/nano/node/block_publisher.hpp b/nano/node/block_publisher.hpp deleted file mode 100644 index 29a2df906b..0000000000 --- a/nano/node/block_publisher.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include - -namespace nano -{ -class active_transactions; -class block_processor; -class block; - -// This class tracks processed blocks to be published. -class block_publisher -{ -public: - block_publisher (nano::active_transactions & active); - void connect (nano::block_processor & block_processor); - -private: - // Block_processor observer - void observe (std::shared_ptr block); - - nano::active_transactions & active; -}; -} diff --git a/nano/node/node.cpp b/nano/node/node.cpp index cb854c326f..acfb739d8b 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -187,7 +187,7 @@ nano::node::node (boost::asio::io_context & io_ctx_a, std::filesystem::path cons vote_cache{ config.vote_cache, stats }, generator{ config, ledger, wallets, vote_processor, history, network, stats, /* non-final */ false }, final_generator{ config, ledger, wallets, vote_processor, history, network, stats, /* final */ true }, - active (*this, confirmation_height_processor), + active{ *this, confirmation_height_processor, block_processor }, scheduler_impl{ std::make_unique (*this) }, scheduler{ *scheduler_impl }, aggregator (config, stats, generator, final_generator, history, ledger, wallets, active), @@ -199,16 +199,15 @@ nano::node::node (boost::asio::io_context & io_ctx_a, std::filesystem::path cons startup_time (std::chrono::steady_clock::now ()), node_seq (seq), block_broadcast{ network, block_arrival, !flags.disable_block_processor_republishing }, - block_publisher{ active }, gap_tracker{ gap_cache }, process_live_dispatcher{ ledger, scheduler.priority, vote_cache, websocket } { logger.debug (nano::log::type::node, "Constructing node..."); block_broadcast.connect (block_processor); - block_publisher.connect (block_processor); gap_tracker.connect (block_processor); process_live_dispatcher.connect (block_processor); + unchecked.satisfied.add ([this] (nano::unchecked_info const & info) { this->block_processor.add (info.block); }); diff --git a/nano/node/node.hpp b/nano/node/node.hpp index dcdffdcf8d..db274ff1ba 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -194,7 +193,6 @@ class node final : public std::enable_shared_from_this nano::websocket_server websocket; nano::epoch_upgrader epoch_upgrader; nano::block_broadcast block_broadcast; - nano::block_publisher block_publisher; nano::gap_tracker gap_tracker; nano::process_live_dispatcher process_live_dispatcher;