Skip to content

Commit

Permalink
Move event to observers class
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Dec 21, 2024
1 parent c902da1 commit 546ddaf
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 25 deletions.
8 changes: 5 additions & 3 deletions nano/node/bootstrap/bootstrap_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <nano/node/bootstrap/bootstrap_service.hpp>
#include <nano/node/bootstrap/crawlers.hpp>
#include <nano/node/network.hpp>
#include <nano/node/node_observers.hpp>
#include <nano/node/nodeconfig.hpp>
#include <nano/node/transport/transport.hpp>
#include <nano/secure/common.hpp>
Expand All @@ -18,9 +19,10 @@

using namespace std::chrono_literals;

nano::bootstrap_service::bootstrap_service (nano::node_config const & node_config_a, nano::block_processor & block_processor_a, nano::ledger & ledger_a, nano::network & network_a, nano::stats & stat_a, nano::logger & logger_a) :
nano::bootstrap_service::bootstrap_service (nano::node_config const & node_config_a, nano::node_observers & observers_a, nano::block_processor & block_processor_a, nano::ledger & ledger_a, nano::network & network_a, nano::stats & stat_a, nano::logger & logger_a) :
config{ node_config_a.bootstrap },
network_constants{ node_config_a.network_params.network },
observers{ observers_a },
block_processor{ block_processor_a },
ledger{ ledger_a },
network{ network_a },
Expand Down Expand Up @@ -299,7 +301,7 @@ void nano::bootstrap_service::inspect (secure::transaction const & tx, nano::blo
bool blocked = accounts.block (account, source_hash);
if (blocked)
{
account_done.notify (account);
observers.account_bootstrapped.notify (account);
}
}
}
Expand Down Expand Up @@ -865,7 +867,7 @@ bool nano::bootstrap_service::process (const nano::asc_pull_ack::blocks_payload
bool erased = accounts.priority_down (tag.account);
if (erased)
{
account_done.notify (tag.account);
observers.account_bootstrapped.notify (tag.account);
}

accounts.timestamp_reset (tag.account);
Expand Down
10 changes: 3 additions & 7 deletions nano/node/bootstrap/bootstrap_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ namespace nano
class bootstrap_service
{
public:
bootstrap_service (nano::node_config const &, nano::block_processor &, nano::ledger &, nano::network &, nano::stats &, nano::logger &);
bootstrap_service (nano::node_config const &, nano::node_observers &, nano::block_processor &, nano::ledger &, nano::network &, nano::stats &, nano::logger &);
~bootstrap_service ();

void start ();
void stop ();

/**
* Process `asc_pull_ack` message coming from network
*/
/** Process messages coming from network */
void process (nano::asc_pull_ack const & message, std::shared_ptr<nano::transport::channel> const &);

std::size_t blocked_size () const;
Expand All @@ -52,12 +50,10 @@ class bootstrap_service

nano::bootstrap::account_sets::info_t info () const;

public: // Events
nano::observer_set<nano::account> account_done;

private: // Dependencies
bootstrap_config const & config;
nano::network_constants const & network_constants;
nano::node_observers & observers;
nano::block_processor & block_processor;
nano::ledger & ledger;
nano::network & network;
Expand Down
1 change: 1 addition & 0 deletions nano/node/fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class bootstrap_server;
class bootstrap_service;
class confirming_set;
class election;
class election_status;
class local_block_broadcaster;
class local_vote_history;
class logger;
Expand Down
2 changes: 1 addition & 1 deletion nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy
backlog{ *backlog_impl },
bootstrap_server_impl{ std::make_unique<nano::bootstrap_server> (config.bootstrap_server, store, ledger, network_params.network, stats) },
bootstrap_server{ *bootstrap_server_impl },
bootstrap_impl{ std::make_unique<nano::bootstrap_service> (config, block_processor, ledger, network, stats, logger) },
bootstrap_impl{ std::make_unique<nano::bootstrap_service> (config, observers, block_processor, ledger, network, stats, logger) },
bootstrap{ *bootstrap_impl },
websocket{ config.websocket_config, observers, wallets, ledger, io_ctx, logger },
epoch_upgrader{ *this, ledger, store, network_params, logger },
Expand Down
21 changes: 7 additions & 14 deletions nano/node/node_observers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,17 @@

#include <nano/lib/numbers.hpp>
#include <nano/lib/utility.hpp>
#include <nano/node/fwd.hpp>
#include <nano/node/transport/transport.hpp>
#include <nano/node/vote_with_weight_info.hpp>

namespace nano
{
enum class vote_source;
class election_status;
class telemetry;
enum class vote_code;
}
namespace nano::transport
{
class channel;
}

namespace nano
{
class node_observers final
{
public:
using blocks_t = nano::observer_set<nano::election_status const &, std::vector<nano::vote_with_weight_info> const &, nano::account const &, nano::uint128_t const &, bool, bool>;
blocks_t blocks; // Notification upon election completion or cancellation
using blocks_event = nano::observer_set<nano::election_status const &, std::vector<nano::vote_with_weight_info> const &, nano::account const &, nano::uint128_t const &, bool, bool>;
blocks_event blocks; // Notification upon election completion or cancellation
nano::observer_set<bool> wallet;
nano::observer_set<std::shared_ptr<nano::vote>, std::shared_ptr<nano::transport::channel>, nano::vote_source, nano::vote_code> vote;
nano::observer_set<nano::block_hash const &> active_started;
Expand All @@ -35,6 +24,10 @@ class node_observers final
nano::observer_set<nano::telemetry_data const &, std::shared_ptr<nano::transport::channel> const &> telemetry;
nano::observer_set<nano::transport::tcp_socket &> socket_connected;

// Called when an account that was being bootstrapped is now likely up-to-date
nano::observer_set<nano::account> account_bootstrapped;

public:
nano::container_info container_info () const;
};
}

0 comments on commit 546ddaf

Please sign in to comment.