Merge pull request #4814 from pwojcikdev/use-unique-ptrs

Use unique ptrs for all node components
This commit is contained in:
Piotr Wójcik 2024-12-30 22:04:37 +01:00 committed by GitHub
commit d5b3379def
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 112 additions and 105 deletions

View file

@ -17,6 +17,7 @@ class network_constants;
class object_stream; class object_stream;
class root; class root;
class thread_pool; class thread_pool;
class thread_runner;
class tomlconfig; class tomlconfig;
template <typename Key, typename Value> template <typename Key, typename Value>
class uniquer; class uniquer;

View file

@ -53,6 +53,7 @@ enum class vote_code;
namespace nano::scheduler namespace nano::scheduler
{ {
class component;
class hinted; class hinted;
class manual; class manual;
class optimistic; class optimistic;

View file

@ -78,17 +78,22 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, uint16_t pe
} }
nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesystem::path const & application_path_a, nano::node_config const & config_a, nano::work_pool & work_a, nano::node_flags flags_a, unsigned seq) : nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesystem::path const & application_path_a, nano::node_config const & config_a, nano::work_pool & work_a, nano::node_flags flags_a, unsigned seq) :
application_path{ application_path_a },
node_id{ load_or_create_node_id (application_path_a) }, node_id{ load_or_create_node_id (application_path_a) },
node_initialized_latch{ 1 },
config{ config_a }, config{ config_a },
flags{ flags_a }, flags{ flags_a },
network_params{ config.network_params },
io_ctx_shared{ std::make_shared<boost::asio::io_context> () }, io_ctx_shared{ std::make_shared<boost::asio::io_context> () },
io_ctx{ *io_ctx_shared }, io_ctx{ *io_ctx_shared },
logger{ make_logger_identifier (node_id) }, logger_impl{ std::make_unique<nano::logger> (make_logger_identifier (node_id)) },
logger{ *logger_impl },
stats_impl{ std::make_unique<nano::stats> (logger, config.stats_config) },
stats{ *stats_impl },
runner_impl{ std::make_unique<nano::thread_runner> (io_ctx_shared, logger, config.io_threads) }, runner_impl{ std::make_unique<nano::thread_runner> (io_ctx_shared, logger, config.io_threads) },
runner{ *runner_impl }, runner{ *runner_impl },
node_initialized_latch (1), observers_impl{ std::make_unique<nano::node_observers> () },
network_params{ config.network_params }, observers{ *observers_impl },
stats{ logger, config.stats_config },
workers_impl{ std::make_unique<nano::thread_pool> (config.background_threads, nano::thread_role::name::worker, /* start immediately */ true) }, workers_impl{ std::make_unique<nano::thread_pool> (config.background_threads, nano::thread_role::name::worker, /* start immediately */ true) },
workers{ *workers_impl }, workers{ *workers_impl },
bootstrap_workers_impl{ std::make_unique<nano::thread_pool> (config.bootstrap_serving_threads, nano::thread_role::name::bootstrap_worker, /* start immediately */ true) }, bootstrap_workers_impl{ std::make_unique<nano::thread_pool> (config.bootstrap_serving_threads, nano::thread_role::name::bootstrap_worker, /* start immediately */ true) },
@ -97,13 +102,17 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy
wallet_workers{ *wallet_workers_impl }, wallet_workers{ *wallet_workers_impl },
election_workers_impl{ std::make_unique<nano::thread_pool> (1, nano::thread_role::name::election_worker, /* start immediately */ true) }, election_workers_impl{ std::make_unique<nano::thread_pool> (1, nano::thread_role::name::election_worker, /* start immediately */ true) },
election_workers{ *election_workers_impl }, election_workers{ *election_workers_impl },
work (work_a), work{ work_a },
distributed_work (*this), distributed_work_impl{ std::make_unique<nano::distributed_work_factory> (*this) },
store_impl (nano::make_store (logger, application_path_a, network_params.ledger, flags.read_only, true, config_a.rocksdb_config, config_a.diagnostics_config.txn_tracking, config_a.block_processor_batch_max_time, config_a.lmdb_config, config_a.backup_before_upgrade)), distributed_work{ *distributed_work_impl },
store (*store_impl), store_impl{ nano::make_store (logger, application_path_a, network_params.ledger, flags.read_only, true, config_a.rocksdb_config, config_a.diagnostics_config.txn_tracking, config_a.block_processor_batch_max_time, config_a.lmdb_config, config_a.backup_before_upgrade) },
unchecked{ config.max_unchecked_blocks, stats, flags.disable_block_processor_unchecked_deletion }, store{ *store_impl },
wallets_store_impl (std::make_unique<nano::mdb_wallets_store> (application_path_a / "wallets.ldb", config_a.lmdb_config)), unchecked_impl{ std::make_unique<nano::unchecked_map> (config.max_unchecked_blocks, stats, flags.disable_block_processor_unchecked_deletion) },
wallets_store (*wallets_store_impl), unchecked{ *unchecked_impl },
wallets_store_impl{ std::make_unique<nano::mdb_wallets_store> (application_path_a / "wallets.ldb", config_a.lmdb_config) },
wallets_store{ *wallets_store_impl },
wallets_impl{ std::make_unique<nano::wallets> (wallets_store.init_error (), *this) },
wallets{ *wallets_impl },
ledger_impl{ std::make_unique<nano::ledger> (store, stats, network_params.ledger, flags_a.generate_cache, config_a.representative_vote_weight_minimum.number ()) }, ledger_impl{ std::make_unique<nano::ledger> (store, stats, network_params.ledger, flags_a.generate_cache, config_a.representative_vote_weight_minimum.number ()) },
ledger{ *ledger_impl }, ledger{ *ledger_impl },
outbound_limiter_impl{ std::make_unique<nano::bandwidth_limiter> (config) }, outbound_limiter_impl{ std::make_unique<nano::bandwidth_limiter> (config) },
@ -113,7 +122,8 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy
// empty `config.peering_port` means the user made no port choice at all; // empty `config.peering_port` means the user made no port choice at all;
// otherwise, any value is considered, with `0` having the special meaning of 'let the OS pick a port instead' // otherwise, any value is considered, with `0` having the special meaning of 'let the OS pick a port instead'
// //
network (*this, config.peering_port.has_value () ? *config.peering_port : 0), network_impl{ std::make_unique<nano::network> (*this, config.peering_port.has_value () ? *config.peering_port : 0) },
network{ *network_impl },
telemetry_impl{ std::make_unique<nano::telemetry> (flags, *this, network, observers, network_params, stats) }, telemetry_impl{ std::make_unique<nano::telemetry> (flags, *this, network, observers, network_params, stats) },
telemetry{ *telemetry_impl }, telemetry{ *telemetry_impl },
// BEWARE: `bootstrap` takes `network.port` instead of `config.peering_port` because when the user doesn't specify // BEWARE: `bootstrap` takes `network.port` instead of `config.peering_port` because when the user doesn't specify
@ -125,7 +135,6 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy
// //
tcp_listener_impl{ std::make_unique<nano::transport::tcp_listener> (network.port, config.tcp, *this) }, tcp_listener_impl{ std::make_unique<nano::transport::tcp_listener> (network.port, config.tcp, *this) },
tcp_listener{ *tcp_listener_impl }, tcp_listener{ *tcp_listener_impl },
application_path (application_path_a),
port_mapping_impl{ std::make_unique<nano::port_mapping> (*this) }, port_mapping_impl{ std::make_unique<nano::port_mapping> (*this) },
port_mapping{ *port_mapping_impl }, port_mapping{ *port_mapping_impl },
block_processor_impl{ std::make_unique<nano::block_processor> (config, ledger, unchecked, stats, logger) }, block_processor_impl{ std::make_unique<nano::block_processor> (config, ledger, unchecked, stats, logger) },
@ -136,15 +145,20 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy
bucketing{ *bucketing_impl }, bucketing{ *bucketing_impl },
active_impl{ std::make_unique<nano::active_elections> (*this, confirming_set, block_processor) }, active_impl{ std::make_unique<nano::active_elections> (*this, confirming_set, block_processor) },
active{ *active_impl }, active{ *active_impl },
rep_crawler (config.rep_crawler, *this),
rep_tiers{ ledger, network_params, online_reps, stats, logger },
warmed_up (0),
online_reps_impl{ std::make_unique<nano::online_reps> (config, ledger, stats, logger) }, online_reps_impl{ std::make_unique<nano::online_reps> (config, ledger, stats, logger) },
online_reps{ *online_reps_impl }, online_reps{ *online_reps_impl },
rep_crawler_impl{ std::make_unique<nano::rep_crawler> (config.rep_crawler, *this) },
rep_crawler{ *rep_crawler_impl },
rep_tiers_impl{ std::make_unique<nano::rep_tiers> (ledger, network_params, online_reps, stats, logger) },
rep_tiers{ *rep_tiers_impl },
history_impl{ std::make_unique<nano::local_vote_history> (config.network_params.voting) }, history_impl{ std::make_unique<nano::local_vote_history> (config.network_params.voting) },
history{ *history_impl }, history{ *history_impl },
vote_uniquer{}, block_uniquer_impl{ std::make_unique<nano::block_uniquer> () },
vote_cache{ config.vote_cache, stats }, block_uniquer{ *block_uniquer_impl },
vote_uniquer_impl{ std::make_unique<nano::vote_uniquer> () },
vote_uniquer{ *vote_uniquer_impl },
vote_cache_impl{ std::make_unique<nano::vote_cache> (config.vote_cache, stats) },
vote_cache{ *vote_cache_impl },
vote_router_impl{ std::make_unique<nano::vote_router> (vote_cache, active.recently_confirmed) }, vote_router_impl{ std::make_unique<nano::vote_router> (vote_cache, active.recently_confirmed) },
vote_router{ *vote_router_impl }, vote_router{ *vote_router_impl },
vote_processor_impl{ std::make_unique<nano::vote_processor> (config.vote_processor, vote_router, observers, stats, flags, logger, online_reps, rep_crawler, ledger, network_params, rep_tiers) }, vote_processor_impl{ std::make_unique<nano::vote_processor> (config.vote_processor, vote_router, observers, stats, flags, logger, online_reps, rep_crawler, ledger, network_params, rep_tiers) },
@ -159,7 +173,6 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy
scheduler{ *scheduler_impl }, scheduler{ *scheduler_impl },
aggregator_impl{ std::make_unique<nano::request_aggregator> (config.request_aggregator, *this, stats, generator, final_generator, history, ledger, wallets, vote_router) }, aggregator_impl{ std::make_unique<nano::request_aggregator> (config.request_aggregator, *this, stats, generator, final_generator, history, ledger, wallets, vote_router) },
aggregator{ *aggregator_impl }, aggregator{ *aggregator_impl },
wallets (wallets_store.init_error (), *this),
backlog_scan_impl{ std::make_unique<nano::backlog_scan> (config.backlog_scan, ledger, stats) }, backlog_scan_impl{ std::make_unique<nano::backlog_scan> (config.backlog_scan, ledger, stats) },
backlog_scan{ *backlog_scan_impl }, backlog_scan{ *backlog_scan_impl },
backlog_impl{ std::make_unique<nano::bounded_backlog> (config, *this, ledger, bucketing, backlog_scan, block_processor, confirming_set, stats, logger) }, backlog_impl{ std::make_unique<nano::bounded_backlog> (config, *this, ledger, bucketing, backlog_scan, block_processor, confirming_set, stats, logger) },
@ -168,17 +181,20 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy
bootstrap_server{ *bootstrap_server_impl }, 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, block_processor, ledger, network, stats, logger) },
bootstrap{ *bootstrap_impl }, bootstrap{ *bootstrap_impl },
websocket{ config.websocket_config, observers, wallets, ledger, io_ctx, logger }, websocket_impl{ std::make_unique<nano::websocket_server> (config.websocket_config, observers, wallets, ledger, io_ctx, logger) },
epoch_upgrader{ *this, ledger, store, network_params, logger }, websocket{ *websocket_impl },
epoch_upgrader_impl{ std::make_unique<nano::epoch_upgrader> (*this, ledger, store, network_params, logger) },
epoch_upgrader{ *epoch_upgrader_impl },
local_block_broadcaster_impl{ std::make_unique<nano::local_block_broadcaster> (config.local_block_broadcaster, *this, block_processor, network, confirming_set, stats, logger, !flags.disable_block_processor_republishing) }, local_block_broadcaster_impl{ std::make_unique<nano::local_block_broadcaster> (config.local_block_broadcaster, *this, block_processor, network, confirming_set, stats, logger, !flags.disable_block_processor_republishing) },
local_block_broadcaster{ *local_block_broadcaster_impl }, local_block_broadcaster{ *local_block_broadcaster_impl },
process_live_dispatcher{ ledger, scheduler.priority, vote_cache, websocket }, process_live_dispatcher_impl{ std::make_unique<nano::process_live_dispatcher> (ledger, scheduler.priority, vote_cache, websocket) },
process_live_dispatcher{ *process_live_dispatcher_impl },
peer_history_impl{ std::make_unique<nano::peer_history> (config.peer_history, store, network, logger, stats) }, peer_history_impl{ std::make_unique<nano::peer_history> (config.peer_history, store, network, logger, stats) },
peer_history{ *peer_history_impl }, peer_history{ *peer_history_impl },
monitor_impl{ std::make_unique<nano::monitor> (config.monitor, *this) }, monitor_impl{ std::make_unique<nano::monitor> (config.monitor, *this) },
monitor{ *monitor_impl }, monitor{ *monitor_impl },
startup_time (std::chrono::steady_clock::now ()), startup_time{ std::chrono::steady_clock::now () },
node_seq (seq) node_seq{ seq }
{ {
logger.debug (nano::log::type::node, "Constructing node..."); logger.debug (nano::log::type::node, "Constructing node...");

View file

@ -31,37 +31,6 @@
#include <optional> #include <optional>
#include <vector> #include <vector>
namespace nano
{
class active_elections;
class bandwidth_limiter;
class confirming_set;
class message_processor;
class monitor;
class node;
class telemetry;
class online_reps;
class vote_processor;
class vote_cache_processor;
class vote_router;
class work_pool;
class peer_history;
class port_mapping;
class thread_runner;
namespace scheduler
{
class component;
}
namespace transport
{
class tcp_listener;
}
namespace rocksdb
{
} // Declare a namespace rocksdb inside nano so all references to the rocksdb library need to be globally scoped e.g. ::rocksdb::Slice
}
namespace nano namespace nano
{ {
class node final : public std::enable_shared_from_this<node> class node final : public std::enable_shared_from_this<node>
@ -127,18 +96,22 @@ public:
nano::container_info container_info () const; nano::container_info container_info () const;
public: public:
const std::filesystem::path application_path;
const nano::keypair node_id; const nano::keypair node_id;
boost::latch node_initialized_latch;
nano::node_config config; nano::node_config config;
nano::node_flags flags; nano::node_flags flags;
nano::network_params & network_params;
std::shared_ptr<boost::asio::io_context> io_ctx_shared; std::shared_ptr<boost::asio::io_context> io_ctx_shared;
boost::asio::io_context & io_ctx; boost::asio::io_context & io_ctx;
nano::logger logger; std::unique_ptr<nano::logger> logger_impl;
nano::logger & logger;
std::unique_ptr<nano::stats> stats_impl;
nano::stats & stats;
std::unique_ptr<nano::thread_runner> runner_impl; std::unique_ptr<nano::thread_runner> runner_impl;
nano::thread_runner & runner; nano::thread_runner & runner;
boost::latch node_initialized_latch; std::unique_ptr<nano::node_observers> observers_impl;
nano::network_params & network_params; nano::node_observers & observers;
nano::stats stats;
nano::node_observers observers;
std::unique_ptr<nano::thread_pool> workers_impl; std::unique_ptr<nano::thread_pool> workers_impl;
nano::thread_pool & workers; nano::thread_pool & workers;
std::unique_ptr<nano::thread_pool> bootstrap_workers_impl; std::unique_ptr<nano::thread_pool> bootstrap_workers_impl;
@ -148,24 +121,28 @@ public:
std::unique_ptr<nano::thread_pool> election_workers_impl; std::unique_ptr<nano::thread_pool> election_workers_impl;
nano::thread_pool & election_workers; nano::thread_pool & election_workers;
nano::work_pool & work; nano::work_pool & work;
nano::distributed_work_factory distributed_work; std::unique_ptr<nano::distributed_work_factory> distributed_work_impl;
nano::distributed_work_factory & distributed_work;
std::unique_ptr<nano::store::component> store_impl; std::unique_ptr<nano::store::component> store_impl;
nano::store::component & store; nano::store::component & store;
nano::unchecked_map unchecked; std::unique_ptr<nano::unchecked_map> unchecked_impl;
nano::unchecked_map & unchecked;
std::unique_ptr<nano::wallets_store> wallets_store_impl; std::unique_ptr<nano::wallets_store> wallets_store_impl;
nano::wallets_store & wallets_store; nano::wallets_store & wallets_store;
std::unique_ptr<nano::wallets> wallets_impl;
nano::wallets & wallets;
std::unique_ptr<nano::ledger> ledger_impl; std::unique_ptr<nano::ledger> ledger_impl;
nano::ledger & ledger; nano::ledger & ledger;
std::unique_ptr<nano::bandwidth_limiter> outbound_limiter_impl; std::unique_ptr<nano::bandwidth_limiter> outbound_limiter_impl;
nano::bandwidth_limiter & outbound_limiter; nano::bandwidth_limiter & outbound_limiter;
std::unique_ptr<nano::message_processor> message_processor_impl; std::unique_ptr<nano::message_processor> message_processor_impl;
nano::message_processor & message_processor; nano::message_processor & message_processor;
nano::network network; std::unique_ptr<nano::network> network_impl;
nano::network & network;
std::unique_ptr<nano::telemetry> telemetry_impl; std::unique_ptr<nano::telemetry> telemetry_impl;
nano::telemetry & telemetry; nano::telemetry & telemetry;
std::unique_ptr<nano::transport::tcp_listener> tcp_listener_impl; std::unique_ptr<nano::transport::tcp_listener> tcp_listener_impl;
nano::transport::tcp_listener & tcp_listener; nano::transport::tcp_listener & tcp_listener;
std::filesystem::path application_path;
std::unique_ptr<nano::port_mapping> port_mapping_impl; std::unique_ptr<nano::port_mapping> port_mapping_impl;
nano::port_mapping & port_mapping; nano::port_mapping & port_mapping;
std::unique_ptr<nano::block_processor> block_processor_impl; std::unique_ptr<nano::block_processor> block_processor_impl;
@ -178,14 +155,18 @@ public:
nano::active_elections & active; nano::active_elections & active;
std::unique_ptr<nano::online_reps> online_reps_impl; std::unique_ptr<nano::online_reps> online_reps_impl;
nano::online_reps & online_reps; nano::online_reps & online_reps;
nano::rep_crawler rep_crawler; std::unique_ptr<nano::rep_crawler> rep_crawler_impl;
nano::rep_tiers rep_tiers; nano::rep_crawler & rep_crawler;
unsigned warmed_up; std::unique_ptr<nano::rep_tiers> rep_tiers_impl;
nano::rep_tiers & rep_tiers;
std::unique_ptr<nano::local_vote_history> history_impl; std::unique_ptr<nano::local_vote_history> history_impl;
nano::local_vote_history & history; nano::local_vote_history & history;
nano::block_uniquer block_uniquer; std::unique_ptr<nano::block_uniquer> block_uniquer_impl;
nano::vote_uniquer vote_uniquer; nano::block_uniquer & block_uniquer;
nano::vote_cache vote_cache; std::unique_ptr<nano::vote_uniquer> vote_uniquer_impl;
nano::vote_uniquer & vote_uniquer;
std::unique_ptr<nano::vote_cache> vote_cache_impl;
nano::vote_cache & vote_cache;
std::unique_ptr<nano::vote_router> vote_router_impl; std::unique_ptr<nano::vote_router> vote_router_impl;
nano::vote_router & vote_router; nano::vote_router & vote_router;
std::unique_ptr<nano::vote_processor> vote_processor_impl; std::unique_ptr<nano::vote_processor> vote_processor_impl;
@ -200,7 +181,6 @@ public:
nano::scheduler::component & scheduler; nano::scheduler::component & scheduler;
std::unique_ptr<nano::request_aggregator> aggregator_impl; std::unique_ptr<nano::request_aggregator> aggregator_impl;
nano::request_aggregator & aggregator; nano::request_aggregator & aggregator;
nano::wallets wallets;
std::unique_ptr<nano::backlog_scan> backlog_scan_impl; std::unique_ptr<nano::backlog_scan> backlog_scan_impl;
nano::backlog_scan & backlog_scan; nano::backlog_scan & backlog_scan;
std::unique_ptr<nano::bounded_backlog> backlog_impl; std::unique_ptr<nano::bounded_backlog> backlog_impl;
@ -209,11 +189,14 @@ public:
nano::bootstrap_server & bootstrap_server; nano::bootstrap_server & bootstrap_server;
std::unique_ptr<nano::bootstrap_service> bootstrap_impl; std::unique_ptr<nano::bootstrap_service> bootstrap_impl;
nano::bootstrap_service & bootstrap; nano::bootstrap_service & bootstrap;
nano::websocket_server websocket; std::unique_ptr<nano::websocket_server> websocket_impl;
nano::epoch_upgrader epoch_upgrader; nano::websocket_server & websocket;
std::unique_ptr<nano::epoch_upgrader> epoch_upgrader_impl;
nano::epoch_upgrader & epoch_upgrader;
std::unique_ptr<nano::local_block_broadcaster> local_block_broadcaster_impl; std::unique_ptr<nano::local_block_broadcaster> local_block_broadcaster_impl;
nano::local_block_broadcaster & local_block_broadcaster; nano::local_block_broadcaster & local_block_broadcaster;
nano::process_live_dispatcher process_live_dispatcher; std::unique_ptr<nano::process_live_dispatcher> process_live_dispatcher_impl;
nano::process_live_dispatcher & process_live_dispatcher;
std::unique_ptr<nano::peer_history> peer_history_impl; std::unique_ptr<nano::peer_history> peer_history_impl;
nano::peer_history & peer_history; nano::peer_history & peer_history;
std::unique_ptr<nano::monitor> monitor_impl; std::unique_ptr<nano::monitor> monitor_impl;
@ -228,7 +211,7 @@ public:
static double constexpr free_cutoff = 1024.0; static double constexpr free_cutoff = 1024.0;
public: // For tests only public: // For tests only
unsigned node_seq; const unsigned node_seq;
std::optional<uint64_t> work_generate_blocking (nano::block &); std::optional<uint64_t> work_generate_blocking (nano::block &);
std::optional<uint64_t> work_generate_blocking (nano::root const &, uint64_t); std::optional<uint64_t> work_generate_blocking (nano::root const &, uint64_t);
std::optional<uint64_t> work_generate_blocking (nano::root const &); std::optional<uint64_t> work_generate_blocking (nano::root const &);

View file

@ -1349,6 +1349,10 @@ void nano::wallets::do_wallet_actions ()
} }
} }
/*
* wallets
*/
nano::wallets::wallets (bool error_a, nano::node & node_a) : nano::wallets::wallets (bool error_a, nano::node & node_a) :
network_params{ node_a.config.network_params }, network_params{ node_a.config.network_params },
observer ([] (bool) {}), observer ([] (bool) {}),
@ -1413,11 +1417,6 @@ nano::wallets::wallets (bool error_a, nano::node & node_a) :
{ {
item.second->enter_initial_password (); item.second->enter_initial_password ();
} }
if (node_a.config.enable_voting)
{
lock.unlock ();
ongoing_compute_reps ();
}
} }
nano::wallets::~wallets () nano::wallets::~wallets ()
@ -1425,6 +1424,33 @@ nano::wallets::~wallets ()
stop (); stop ();
} }
void nano::wallets::start ()
{
thread = std::thread{ [this] () {
nano::thread_role::set (nano::thread_role::name::wallet_actions);
do_wallet_actions ();
} };
if (node.config.enable_voting)
{
ongoing_compute_reps ();
}
}
void nano::wallets::stop ()
{
{
nano::lock_guard<nano::mutex> action_lock{ action_mutex };
stopped = true;
actions.clear ();
}
condition.notify_all ();
if (thread.joinable ())
{
thread.join ();
}
}
std::shared_ptr<nano::wallet> nano::wallets::open (nano::wallet_id const & id_a) std::shared_ptr<nano::wallet> nano::wallets::open (nano::wallet_id const & id_a)
{ {
nano::lock_guard<nano::mutex> lock{ mutex }; nano::lock_guard<nano::mutex> lock{ mutex };
@ -1610,28 +1636,6 @@ bool nano::wallets::exists (store::transaction const & transaction_a, nano::acco
return result; return result;
} }
void nano::wallets::stop ()
{
{
nano::lock_guard<nano::mutex> action_lock{ action_mutex };
stopped = true;
actions.clear ();
}
condition.notify_all ();
if (thread.joinable ())
{
thread.join ();
}
}
void nano::wallets::start ()
{
thread = std::thread{ [this] () {
nano::thread_role::set (nano::thread_role::name::wallet_actions);
do_wallet_actions ();
} };
}
nano::store::write_transaction nano::wallets::tx_begin_write () nano::store::write_transaction nano::wallets::tx_begin_write ()
{ {
return env.tx_begin_write (); return env.tx_begin_write ();

View file

@ -205,8 +205,12 @@ public:
class wallets final class wallets final
{ {
public: public:
wallets (bool, nano::node &); wallets (bool error, nano::node &);
~wallets (); ~wallets ();
void start ();
void stop ();
std::shared_ptr<nano::wallet> open (nano::wallet_id const &); std::shared_ptr<nano::wallet> open (nano::wallet_id const &);
std::shared_ptr<nano::wallet> create (nano::wallet_id const &); std::shared_ptr<nano::wallet> create (nano::wallet_id const &);
bool search_receivable (nano::wallet_id const &); bool search_receivable (nano::wallet_id const &);
@ -217,8 +221,6 @@ public:
void queue_wallet_action (nano::uint128_t const &, std::shared_ptr<nano::wallet> const &, std::function<void (nano::wallet &)>); void queue_wallet_action (nano::uint128_t const &, std::shared_ptr<nano::wallet> const &, std::function<void (nano::wallet &)>);
void foreach_representative (std::function<void (nano::public_key const &, nano::raw_key const &)> const &); void foreach_representative (std::function<void (nano::public_key const &, nano::raw_key const &)> const &);
bool exists (store::transaction const &, nano::account const &); bool exists (store::transaction const &, nano::account const &);
void start ();
void stop ();
void clear_send_ids (store::transaction const &); void clear_send_ids (store::transaction const &);
nano::wallet_representatives reps () const; nano::wallet_representatives reps () const;
bool check_rep (nano::account const &, nano::uint128_t const &, bool const = true); bool check_rep (nano::account const &, nano::uint128_t const &, bool const = true);