Skip to content

Commit

Permalink
Fix start for wallets class
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Dec 30, 2024
1 parent 97ee5ca commit f4e940f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 34 deletions.
66 changes: 35 additions & 31 deletions nano/node/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,14 +670,14 @@ void nano::kdf::phs (nano::raw_key & result_a, std::string const & password_a, n
}

nano::wallet::wallet (bool & init_a, store::transaction & transaction_a, nano::wallets & wallets_a, std::string const & wallet_a) :
lock_observer ([] (bool, bool) {}),
lock_observer ([] (bool, bool) { }),
store (init_a, wallets_a.kdf, transaction_a, wallets_a.env, wallets_a.node.config.random_representative (), wallets_a.node.config.password_fanout, wallet_a),
wallets (wallets_a)
{
}

nano::wallet::wallet (bool & init_a, store::transaction & transaction_a, nano::wallets & wallets_a, std::string const & wallet_a, std::string const & json) :
lock_observer ([] (bool, bool) {}),
lock_observer ([] (bool, bool) { }),
store (init_a, wallets_a.kdf, transaction_a, wallets_a.env, wallets_a.node.config.random_representative (), wallets_a.node.config.password_fanout, wallet_a, json),
wallets (wallets_a)
{
Expand Down Expand Up @@ -1205,7 +1205,7 @@ bool nano::wallet::search_receivable (store::transaction const & wallet_transact
{
auto representative = store.representative (wallet_transaction_a);
// Receive confirmed block
receive_async (hash, representative, amount, account, [] (std::shared_ptr<nano::block> const &) {});
receive_async (hash, representative, amount, account, [] (std::shared_ptr<nano::block> const &) { });
}
else if (!wallets.node.confirming_set.contains (hash))
{
Expand Down Expand Up @@ -1349,9 +1349,13 @@ void nano::wallets::do_wallet_actions ()
}
}

/*
* wallets
*/

nano::wallets::wallets (bool error_a, nano::node & node_a) :
network_params{ node_a.config.network_params },
observer ([] (bool) {}),
observer ([] (bool) { }),
kdf{ node_a.config.network_params.kdf_work },
node (node_a),
env (boost::polymorphic_downcast<nano::mdb_wallets_store *> (node_a.wallets_store_impl.get ())->environment),
Expand Down Expand Up @@ -1413,16 +1417,38 @@ nano::wallets::wallets (bool error_a, nano::node & node_a) :
{
item.second->enter_initial_password ();
}
if (node_a.config.enable_voting)
}

nano::wallets::~wallets ()
{
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)
{
lock.unlock ();
ongoing_compute_reps ();
}
}

nano::wallets::~wallets ()
void nano::wallets::stop ()
{
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)
Expand Down Expand Up @@ -1610,28 +1636,6 @@ bool nano::wallets::exists (store::transaction const & transaction_a, nano::acco
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 ()
{
return env.tx_begin_write ();
Expand Down Expand Up @@ -1736,7 +1740,7 @@ void nano::wallets::receive_confirmed (nano::block_hash const & hash_a, nano::ac
if (pending)
{
auto amount (pending->amount.number ());
wallet->receive_async (hash_a, representative, amount, destination_a, [] (std::shared_ptr<nano::block> const &) {});
wallet->receive_async (hash_a, representative, amount, destination_a, [] (std::shared_ptr<nano::block> const &) { });
}
else
{
Expand Down
8 changes: 5 additions & 3 deletions nano/node/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,12 @@ class wallet_representatives
class wallets final
{
public:
wallets (bool, nano::node &);
wallets (bool error, nano::node &);
~wallets ();

void start ();
void stop ();

std::shared_ptr<nano::wallet> open (nano::wallet_id const &);
std::shared_ptr<nano::wallet> create (nano::wallet_id const &);
bool search_receivable (nano::wallet_id const &);
Expand All @@ -217,8 +221,6 @@ class wallets final
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 &);
bool exists (store::transaction const &, nano::account const &);
void start ();
void stop ();
void clear_send_ids (store::transaction const &);
nano::wallet_representatives reps () const;
bool check_rep (nano::account const &, nano::uint128_t const &, bool const = true);
Expand Down

0 comments on commit f4e940f

Please sign in to comment.