diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 31eaf231e8..e19ba0688a 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -468,8 +468,9 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy confirming_set.cemented_observers.add ([this] (auto const & block) { if (block->is_send ()) { - auto transaction = store.tx_begin_read (); - receive_confirmed (transaction, block->hash (), block->destination ()); + workers.push_task ([this, hash = block->hash (), destination = block->destination ()] () { + wallets.receive_confirmed (hash, destination); + }); } }); } @@ -1217,40 +1218,6 @@ void nano::node::ongoing_online_weight_calculation () ongoing_online_weight_calculation_queue (); } -void nano::node::receive_confirmed (store::transaction const & block_transaction_a, nano::block_hash const & hash_a, nano::account const & destination_a) -{ - nano::unique_lock lk{ wallets.mutex }; - auto wallets_l = wallets.get_wallets (); - auto wallet_transaction = wallets.tx_begin_read (); - lk.unlock (); - for ([[maybe_unused]] auto const & [id, wallet] : wallets_l) - { - if (wallet->store.exists (wallet_transaction, destination_a)) - { - nano::account representative; - representative = wallet->store.representative (wallet_transaction); - auto pending = ledger.pending_info (block_transaction_a, nano::pending_key (destination_a, hash_a)); - if (pending) - { - auto amount (pending->amount.number ()); - wallet->receive_async (hash_a, representative, amount, destination_a, [] (std::shared_ptr const &) {}); - } - else - { - if (!ledger.block_or_pruned_exists (block_transaction_a, hash_a)) - { - logger.warn (nano::log::type::node, "Confirmed block is missing: {}", hash_a.to_string ()); - debug_assert (false, "Confirmed block is missing"); - } - else - { - logger.warn (nano::log::type::node, "Block has already been received: {}", hash_a.to_string ()); - } - } - } - } -} - void nano::node::process_confirmed (nano::election_status const & status_a, uint64_t iteration_a) { auto hash (status_a.winner->hash ()); @@ -1376,4 +1343,4 @@ std::string nano::node::make_logger_identifier (const nano::keypair & node_id) { // Node identifier consists of first 10 characters of node id return node_id.pub.to_node_id ().substr (0, 10); -} \ No newline at end of file +} diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 3a4bfdcc7b..101d3391cc 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -87,7 +87,6 @@ class node final : public std::enable_shared_from_this void stop (); std::shared_ptr shared (); int store_version (); - void receive_confirmed (store::transaction const & block_transaction_a, nano::block_hash const & hash_a, nano::account const & destination_a); void process_confirmed (nano::election_status const &, uint64_t = 0); void process_active (std::shared_ptr const &); std::optional process_local (std::shared_ptr const &); @@ -236,4 +235,4 @@ std::unique_ptr collect_container_info (node & node, s nano::node_flags const & inactive_node_flag_defaults (); -} \ No newline at end of file +} diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index 922edd4abc..3ebad41b6b 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -1707,6 +1707,40 @@ void nano::wallets::ongoing_compute_reps () }); } +void nano::wallets::receive_confirmed (nano::block_hash const & hash_a, nano::account const & destination_a) +{ + nano::unique_lock lk{ mutex }; + auto wallets_l = get_wallets (); + auto wallet_transaction = tx_begin_read (); + lk.unlock (); + for ([[maybe_unused]] auto const & [id, wallet] : wallets_l) + { + if (wallet->store.exists (wallet_transaction, destination_a)) + { + nano::account representative; + representative = wallet->store.representative (wallet_transaction); + auto pending = node.ledger.pending_info (node.ledger.store.tx_begin_read (), nano::pending_key (destination_a, hash_a)); + if (pending) + { + auto amount (pending->amount.number ()); + wallet->receive_async (hash_a, representative, amount, destination_a, [] (std::shared_ptr const &) {}); + } + else + { + if (!node.ledger.block_or_pruned_exists (node.ledger.store.tx_begin_read (), hash_a)) + { + node.logger.warn (nano::log::type::wallet, "Confirmed block is missing: {}", hash_a.to_string ()); + debug_assert (false, "Confirmed block is missing"); + } + else + { + node.logger.warn (nano::log::type::wallet, "Block has already been received: {}", hash_a.to_string ()); + } + } + } + } +} + std::unordered_map> nano::wallets::get_wallets () { debug_assert (!mutex.try_lock ()); diff --git a/nano/node/wallet.hpp b/nano/node/wallet.hpp index 40409f5e35..7366ec4702 100644 --- a/nano/node/wallet.hpp +++ b/nano/node/wallet.hpp @@ -220,6 +220,7 @@ class wallets final bool check_rep (nano::account const &, nano::uint128_t const &, bool const = true); void compute_reps (); void ongoing_compute_reps (); + void receive_confirmed (nano::block_hash const & hash_a, nano::account const & destination_a); std::unordered_map> get_wallets (); nano::network_params & network_params; std::function observer;