Retrieve copy of wallets in scan_receivable (#2934)

Locking the wallets items mutex
This commit is contained in:
Guilherme Lawless 2020-09-14 17:21:41 +01:00 committed by GitHub
commit e8c3f89fc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 2 deletions

View file

@ -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))
{

View file

@ -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::wallet_id, std::shared_ptr<nano::wallet>> nano::wallets::get_wallets ()
{
nano::lock_guard<std::mutex> guard (mutex);
return items;
}
nano::uint128_t const nano::wallets::generate_priority = std::numeric_limits<nano::uint128_t>::max ();
nano::uint128_t const nano::wallets::high_priority = std::numeric_limits<nano::uint128_t>::max () - 1;

View file

@ -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<nano::wallet_id, std::shared_ptr<nano::wallet>> get_wallets ();
nano::network_params network_params;
std::function<void(bool)> observer;
std::unordered_map<nano::wallet_id, std::shared_ptr<nano::wallet>> items;