From e8c3f89fc6f82d816913c26bceadf2a64ffa7dd0 Mon Sep 17 00:00:00 2001 From: Guilherme Lawless Date: Mon, 14 Sep 2020 17:21:41 +0100 Subject: [PATCH] Retrieve copy of wallets in scan_receivable (#2934) Locking the wallets items mutex --- nano/node/node.cpp | 3 +-- nano/node/wallet.cpp | 6 ++++++ nano/node/wallet.hpp | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 7fd61f63..047d3464 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -1178,9 +1178,8 @@ public: virtual ~confirmed_visitor () = default; void scan_receivable (nano::account const & account_a) { - for (auto i (node.wallets.items.begin ()), n (node.wallets.items.end ()); i != n; ++i) + for (auto const & [id /*unused*/, wallet] : node.wallets.get_wallets ()) { - auto const & wallet (i->second); auto transaction_l (node.wallets.tx_begin_read ()); if (wallet->store.exists (transaction_l, account_a)) { diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index f048779f..95d8123c 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -1876,6 +1876,12 @@ void nano::wallets::move_table (std::string const & name_a, MDB_txn * tx_source, debug_assert (!error6); } +std::unordered_map> nano::wallets::get_wallets () +{ + nano::lock_guard guard (mutex); + return items; +} + nano::uint128_t const nano::wallets::generate_priority = std::numeric_limits::max (); nano::uint128_t const nano::wallets::high_priority = std::numeric_limits::max () - 1; diff --git a/nano/node/wallet.hpp b/nano/node/wallet.hpp index f646ec18..78a9a498 100644 --- a/nano/node/wallet.hpp +++ b/nano/node/wallet.hpp @@ -229,6 +229,7 @@ public: void ongoing_compute_reps (); void split_if_needed (nano::transaction &, nano::block_store &); void move_table (std::string const &, MDB_txn *, MDB_txn *); + std::unordered_map> get_wallets (); nano::network_params network_params; std::function observer; std::unordered_map> items;