Skip to content

Commit

Permalink
Move block observer logic into active_transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Feb 5, 2024
1 parent 647c3c4 commit 106ad6b
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 62 deletions.
2 changes: 0 additions & 2 deletions nano/node/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 ()
Expand Down
6 changes: 4 additions & 2 deletions nano/node/active_transactions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -130,7 +131,7 @@ class active_transactions final
std::unordered_map<nano::block_hash, std::shared_ptr<nano::election>> 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 ();
Expand Down Expand Up @@ -204,8 +205,9 @@ class active_transactions final
void notify_observers (nano::election_status const & status, std::vector<nano::vote_with_weight_info> 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;
Expand Down
27 changes: 0 additions & 27 deletions nano/node/block_publisher.cpp

This file was deleted.

24 changes: 0 additions & 24 deletions nano/node/block_publisher.hpp

This file was deleted.

5 changes: 2 additions & 3 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nano::scheduler::component> (*this) },
scheduler{ *scheduler_impl },
aggregator (config, stats, generator, final_generator, history, ledger, wallets, active),
Expand All @@ -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);
});
Expand Down
2 changes: 0 additions & 2 deletions nano/node/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <nano/node/bandwidth_limiter.hpp>
#include <nano/node/block_arrival.hpp>
#include <nano/node/block_broadcast.hpp>
#include <nano/node/block_publisher.hpp>
#include <nano/node/blockprocessor.hpp>
#include <nano/node/bootstrap/bootstrap.hpp>
#include <nano/node/bootstrap/bootstrap_attempt.hpp>
Expand Down Expand Up @@ -194,7 +193,6 @@ class node final : public std::enable_shared_from_this<nano::node>
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;

Expand Down

0 comments on commit 106ad6b

Please # to comment.