From 0dc9d4fa53e944f1fb46c3630cdc4d083ccbb131 Mon Sep 17 00:00:00 2001 From: Roy Keene Date: Fri, 23 Aug 2019 11:32:58 -0500 Subject: [PATCH] No write transactions on I/O threads (#1264) * Remove write transactions from io threads * TSAN error, make sure thread is initialized last --- nano/core_test/CMakeLists.txt | 1 + nano/core_test/utility.cpp | 34 + nano/core_test/wallet.cpp | 14 +- nano/lib/utility.cpp | 73 +++ nano/lib/utility.hpp | 24 +- nano/node/json_handler.cpp | 1099 +++++++++++++++++---------------- nano/node/node.cpp | 22 +- nano/node/node.hpp | 1 + nano/rpc_test/rpc.cpp | 260 +++++++- nano/secure/blockstore.cpp | 4 + 10 files changed, 975 insertions(+), 557 deletions(-) create mode 100644 nano/core_test/utility.cpp diff --git a/nano/core_test/CMakeLists.txt b/nano/core_test/CMakeLists.txt index ac774e5c..d692f3eb 100644 --- a/nano/core_test/CMakeLists.txt +++ b/nano/core_test/CMakeLists.txt @@ -28,6 +28,7 @@ add_executable (core_test socket.cpp timer.cpp uint256_union.cpp + utility.cpp versioning.cpp wallet.cpp wallets.cpp diff --git a/nano/core_test/utility.cpp b/nano/core_test/utility.cpp new file mode 100644 index 00000000..386bb90b --- /dev/null +++ b/nano/core_test/utility.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +#include + +namespace +{ +std::atomic passed_sleep{ false }; + +void func () +{ + std::this_thread::sleep_for (std::chrono::seconds (1)); + passed_sleep = true; +} +} + +TEST (thread, worker) +{ + nano::worker worker; + worker.push_task (func); + ASSERT_FALSE (passed_sleep); + + nano::timer timer_l; + timer_l.start (); + while (!passed_sleep) + { + if (timer_l.since_start () > std::chrono::seconds (10)) + { + break; + } + } + ASSERT_TRUE (passed_sleep); +} diff --git a/nano/core_test/wallet.cpp b/nano/core_test/wallet.cpp index 3a4f581a..8d020ad3 100644 --- a/nano/core_test/wallet.cpp +++ b/nano/core_test/wallet.cpp @@ -956,7 +956,7 @@ TEST (wallet, password_race) nano::system system (24000, 1); nano::thread_runner runner (system.io_ctx, system.nodes[0]->config.io_threads); auto wallet = system.wallet (0); - system.nodes[0]->background ([&wallet]() { + std::thread thread ([&wallet]() { for (int i = 0; i < 100; i++) { auto transaction (wallet->wallets.tx_begin_write ()); @@ -974,6 +974,7 @@ TEST (wallet, password_race) break; } } + thread.join (); system.stop (); runner.join (); } @@ -990,23 +991,24 @@ TEST (wallet, password_race_corrupt_seed) wallet->store.seed (seed, transaction); ASSERT_FALSE (wallet->store.attempt_password (transaction, "4567")); } + std::vector threads; for (int i = 0; i < 100; i++) { - system.nodes[0]->background ([&wallet]() { + threads.emplace_back ([&wallet]() { for (int i = 0; i < 10; i++) { auto transaction (wallet->wallets.tx_begin_write ()); wallet->store.rekey (transaction, "0000"); } }); - system.nodes[0]->background ([&wallet]() { + threads.emplace_back ([&wallet]() { for (int i = 0; i < 10; i++) { auto transaction (wallet->wallets.tx_begin_write ()); wallet->store.rekey (transaction, "1234"); } }); - system.nodes[0]->background ([&wallet]() { + threads.emplace_back ([&wallet]() { for (int i = 0; i < 10; i++) { auto transaction (wallet->wallets.tx_begin_read ()); @@ -1014,6 +1016,10 @@ TEST (wallet, password_race_corrupt_seed) } }); } + for (auto & thread : threads) + { + thread.join (); + } system.stop (); runner.join (); { diff --git a/nano/lib/utility.cpp b/nano/lib/utility.cpp index 33d97f20..a983c970 100644 --- a/nano/lib/utility.cpp +++ b/nano/lib/utility.cpp @@ -134,6 +134,9 @@ namespace thread_role case nano::thread_role::name::confirmation_height_processing: thread_role_name_string = "Conf height"; break; + case nano::thread_role::name::worker: + thread_role_name_string = "Worker"; + break; } /* @@ -225,6 +228,76 @@ void nano::thread_runner::stop_event_processing () io_guard.get_executor ().context ().stop (); } +nano::worker::worker () : +thread ([this]() { + nano::thread_role::set (nano::thread_role::name::worker); + this->run (); +}) +{ +} + +void nano::worker::run () +{ + while (!stopped) + { + std::unique_lock lk (mutex); + if (!queue.empty ()) + { + auto func = queue.front (); + queue.pop_front (); + lk.unlock (); + func (); + // So that we reduce locking for anything being pushed as that will + // most likely be on an io-thread + std::this_thread::yield (); + lk.lock (); + } + else + { + cv.wait (lk); + } + } +} + +nano::worker::~worker () +{ + stop (); +} + +void nano::worker::push_task (std::function func_a) +{ + { + std::lock_guard guard (mutex); + queue.emplace_back (func_a); + } + + cv.notify_one (); +} + +void nano::worker::stop () +{ + stopped = true; + cv.notify_one (); + if (thread.joinable ()) + { + thread.join (); + } +} + +std::unique_ptr nano::collect_seq_con_info (nano::worker & worker, const std::string & name) +{ + auto composite = std::make_unique (name); + + size_t count = 0; + { + std::lock_guard guard (worker.mutex); + count = worker.queue.size (); + } + auto sizeof_element = sizeof (decltype (worker.queue)::value_type); + composite->add_component (std::make_unique (nano::seq_con_info{ "queue", count, sizeof_element })); + return composite; +} + /* * Backing code for "release_assert", which is itself a macro */ diff --git a/nano/lib/utility.hpp b/nano/lib/utility.hpp index 1614feee..597ac0ff 100644 --- a/nano/lib/utility.hpp +++ b/nano/lib/utility.hpp @@ -110,7 +110,8 @@ namespace thread_role rpc_request_processor, rpc_process_container, work_watcher, - confirmation_height_processing + confirmation_height_processing, + worker }; /* * Get/Set the identifier for the current thread @@ -152,6 +153,27 @@ public: boost::asio::executor_work_guard io_guard; }; +class worker final +{ +public: + worker (); + ~worker (); + void run (); + void push_task (std::function func); + void stop (); + +private: + std::condition_variable cv; + std::deque> queue; + std::mutex mutex; + std::atomic stopped{ false }; + std::thread thread; + + friend std::unique_ptr collect_seq_con_info (worker &, const std::string &); +}; + +std::unique_ptr collect_seq_con_info (worker & worker, const std::string & name); + /** * Returns seconds passed since unix epoch (posix time) */ diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index ab6fba02..a834a009 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -456,42 +456,45 @@ void nano::json_handler::account_block_count () void nano::json_handler::account_create () { - auto wallet (wallet_impl ()); - if (!ec) - { - const bool generate_work = request.get ("work", true); - nano::account new_key; - auto index_text (request.get_optional ("index")); - if (index_text.is_initialized ()) + auto rpc_l (shared_from_this ()); + node.worker.push_task ([rpc_l]() { + auto wallet (rpc_l->wallet_impl ()); + if (!rpc_l->ec) { - uint64_t index; - if (decode_unsigned (index_text.get (), index) || index > static_cast (std::numeric_limits::max ())) + const bool generate_work = rpc_l->request.get ("work", true); + nano::account new_key; + auto index_text (rpc_l->request.get_optional ("index")); + if (index_text.is_initialized ()) { - ec = nano::error_common::invalid_index; + uint64_t index; + if (decode_unsigned (index_text.get (), index) || index > static_cast (std::numeric_limits::max ())) + { + rpc_l->ec = nano::error_common::invalid_index; + } + else + { + new_key = wallet->deterministic_insert (static_cast (index), generate_work); + } } else { - new_key = wallet->deterministic_insert (static_cast (index), generate_work); + new_key = wallet->deterministic_insert (generate_work); } - } - else - { - new_key = wallet->deterministic_insert (generate_work); - } - if (!ec) - { - if (!new_key.is_zero ()) + if (!rpc_l->ec) { - response_l.put ("account", new_key.to_account ()); - } - else - { - ec = nano::error_common::wallet_locked; + if (!new_key.is_zero ()) + { + rpc_l->response_l.put ("account", new_key.to_account ()); + } + else + { + rpc_l->ec = nano::error_common::wallet_locked; + } } } - } - response_errors (); + rpc_l->response_errors (); + }); } void nano::json_handler::account_get () @@ -588,57 +591,63 @@ void nano::json_handler::account_list () void nano::json_handler::account_move () { - auto wallet (wallet_impl ()); - if (!ec) - { - std::string source_text (request.get ("source")); - auto accounts_text (request.get_child ("accounts")); - nano::uint256_union source; - if (!source.decode_hex (source_text)) + auto rpc_l (shared_from_this ()); + node.worker.push_task ([rpc_l]() { + auto wallet (rpc_l->wallet_impl ()); + if (!rpc_l->ec) { - auto existing (node.wallets.items.find (source)); - if (existing != node.wallets.items.end ()) + std::string source_text (rpc_l->request.get ("source")); + auto accounts_text (rpc_l->request.get_child ("accounts")); + nano::uint256_union source; + if (!source.decode_hex (source_text)) { - auto source (existing->second); - std::vector accounts; - for (auto i (accounts_text.begin ()), n (accounts_text.end ()); i != n; ++i) + auto existing (rpc_l->node.wallets.items.find (source)); + if (existing != rpc_l->node.wallets.items.end ()) { - auto account (account_impl (i->second.get (""))); - accounts.push_back (account); + auto source (existing->second); + std::vector accounts; + for (auto i (accounts_text.begin ()), n (accounts_text.end ()); i != n; ++i) + { + auto account (rpc_l->account_impl (i->second.get (""))); + accounts.push_back (account); + } + auto transaction (rpc_l->node.wallets.tx_begin_write ()); + auto error (wallet->store.move (transaction, source->store, accounts)); + rpc_l->response_l.put ("moved", error ? "0" : "1"); + } + else + { + rpc_l->ec = nano::error_rpc::source_not_found; } - auto transaction (node.wallets.tx_begin_write ()); - auto error (wallet->store.move (transaction, source->store, accounts)); - response_l.put ("moved", error ? "0" : "1"); } else { - ec = nano::error_rpc::source_not_found; + rpc_l->ec = nano::error_rpc::bad_source; } } - else - { - ec = nano::error_rpc::bad_source; - } - } - response_errors (); + rpc_l->response_errors (); + }); } void nano::json_handler::account_remove () { - auto wallet (wallet_impl ()); - auto account (account_impl ()); - if (!ec) - { - auto transaction (node.wallets.tx_begin_write ()); - wallet_locked_impl (transaction, wallet); - wallet_account_impl (transaction, wallet, account); - if (!ec) + auto rpc_l (shared_from_this ()); + node.worker.push_task ([rpc_l]() { + auto wallet (rpc_l->wallet_impl ()); + auto account (rpc_l->account_impl ()); + if (!rpc_l->ec) { - wallet->store.erase (transaction, account); - response_l.put ("removed", "1"); + auto transaction (rpc_l->node.wallets.tx_begin_write ()); + rpc_l->wallet_locked_impl (transaction, wallet); + rpc_l->wallet_account_impl (transaction, wallet, account); + if (!rpc_l->ec) + { + wallet->store.erase (transaction, account); + rpc_l->response_l.put ("removed", "1"); + } } - } - response_errors (); + rpc_l->response_errors (); + }); } void nano::json_handler::account_representative () @@ -664,63 +673,66 @@ void nano::json_handler::account_representative () void nano::json_handler::account_representative_set () { - auto wallet (wallet_impl ()); - auto account (account_impl ()); - std::string representative_text (request.get ("representative")); - auto representative (account_impl (representative_text, nano::error_rpc::bad_representative_number)); - if (!ec) - { - auto work (work_optional_impl ()); - if (!ec && work) + auto rpc_l (shared_from_this ()); + node.worker.push_task ([rpc_l]() { + auto wallet (rpc_l->wallet_impl ()); + auto account (rpc_l->account_impl ()); + std::string representative_text (rpc_l->request.get ("representative")); + auto representative (rpc_l->account_impl (representative_text, nano::error_rpc::bad_representative_number)); + if (!rpc_l->ec) { - auto transaction (node.wallets.tx_begin_write ()); - wallet_locked_impl (transaction, wallet); - wallet_account_impl (transaction, wallet, account); - if (!ec) + auto work (rpc_l->work_optional_impl ()); + if (!rpc_l->ec && work) { - nano::account_info info; - auto block_transaction (node.store.tx_begin_read ()); - if (!node.store.account_get (block_transaction, account, info)) + auto transaction (rpc_l->node.wallets.tx_begin_write ()); + rpc_l->wallet_locked_impl (transaction, wallet); + rpc_l->wallet_account_impl (transaction, wallet, account); + if (!rpc_l->ec) { - if (nano::work_validate (info.head, work)) + nano::account_info info; + auto block_transaction (rpc_l->node.store.tx_begin_read ()); + if (!rpc_l->node.store.account_get (block_transaction, account, info)) { - ec = nano::error_common::invalid_work; + if (nano::work_validate (info.head, work)) + { + rpc_l->ec = nano::error_common::invalid_work; + } + } + else + { + rpc_l->ec = nano::error_common::account_not_found; } } - else - { - ec = nano::error_common::account_not_found; - } + } + if (!rpc_l->ec) + { + bool generate_work (work == 0); // Disable work generation if "work" option is provided + auto response_a (rpc_l->response); + auto response_data (std::make_shared (rpc_l->response_l)); + // clang-format off + wallet->change_async(account, representative, [response_a, response_data](std::shared_ptr block) { + if (block != nullptr) + { + response_data->put("block", block->hash().to_string()); + std::stringstream ostream; + boost::property_tree::write_json(ostream, *response_data); + response_a(ostream.str()); + } + else + { + json_error_response(response_a, "Error generating block"); + } + }, + work, generate_work); + // clang-format on } } - if (!ec) + // Because of change_async + if (rpc_l->ec) { - bool generate_work (work == 0); // Disable work generation if "work" option is provided - auto response_a (response); - auto response_data (std::make_shared (response_l)); - // clang-format off - wallet->change_async (account, representative, [response_a, response_data](std::shared_ptr block) { - if (block != nullptr) - { - response_data->put ("block", block->hash ().to_string ()); - std::stringstream ostream; - boost::property_tree::write_json (ostream, *response_data); - response_a (ostream.str ()); - } - else - { - json_error_response (response_a, "Error generating block"); - } - }, - work, generate_work); - // clang-format on + rpc_l->response_errors (); } - } - // Because of change_async - if (ec) - { - response_errors (); - } + }); } void nano::json_handler::account_weight () @@ -755,25 +767,28 @@ void nano::json_handler::accounts_balances () void nano::json_handler::accounts_create () { - auto wallet (wallet_impl ()); - auto count (count_impl ()); - if (!ec) - { - const bool generate_work = request.get ("work", false); - boost::property_tree::ptree accounts; - for (auto i (0); accounts.size () < count; ++i) + auto rpc_l (shared_from_this ()); + node.worker.push_task ([rpc_l]() { + auto wallet (rpc_l->wallet_impl ()); + auto count (rpc_l->count_impl ()); + if (!rpc_l->ec) { - nano::account new_key (wallet->deterministic_insert (generate_work)); - if (!new_key.is_zero ()) + const bool generate_work = rpc_l->request.get ("work", false); + boost::property_tree::ptree accounts; + for (auto i (0); accounts.size () < count; ++i) { - boost::property_tree::ptree entry; - entry.put ("", new_key.to_account ()); - accounts.push_back (std::make_pair ("", entry)); + nano::account new_key (wallet->deterministic_insert (generate_work)); + if (!new_key.is_zero ()) + { + boost::property_tree::ptree entry; + entry.put ("", new_key.to_account ()); + accounts.push_back (std::make_pair ("", entry)); + } } + rpc_l->response_l.add_child ("accounts", accounts); } - response_l.add_child ("accounts", accounts); - } - response_errors (); + rpc_l->response_errors (); + }); } void nano::json_handler::accounts_frontiers () @@ -2499,36 +2514,42 @@ void nano::json_handler::node_id_delete () void nano::json_handler::password_change () { - auto wallet (wallet_impl ()); - if (!ec) - { - auto transaction (node.wallets.tx_begin_write ()); - wallet_locked_impl (transaction, wallet); - if (!ec) + auto rpc_l (shared_from_this ()); + node.worker.push_task ([rpc_l]() { + auto wallet (rpc_l->wallet_impl ()); + if (!rpc_l->ec) { - std::string password_text (request.get ("password")); - bool error (wallet->store.rekey (transaction, password_text)); - response_l.put ("changed", error ? "0" : "1"); - if (!error) + auto transaction (rpc_l->node.wallets.tx_begin_write ()); + rpc_l->wallet_locked_impl (transaction, wallet); + if (!rpc_l->ec) { - node.logger.try_log ("Wallet password changed"); + std::string password_text (rpc_l->request.get ("password")); + bool error (wallet->store.rekey (transaction, password_text)); + rpc_l->response_l.put ("changed", error ? "0" : "1"); + if (!error) + { + rpc_l->node.logger.try_log ("Wallet password changed"); + } } } - } - response_errors (); + rpc_l->response_errors (); + }); } void nano::json_handler::password_enter () { - auto wallet (wallet_impl ()); - if (!ec) - { - std::string password_text (request.get ("password")); - auto transaction (wallet->wallets.tx_begin_write ()); - auto error (wallet->enter_password (transaction, password_text)); - response_l.put ("valid", error ? "0" : "1"); - } - response_errors (); + auto rpc_l (shared_from_this ()); + node.worker.push_task ([rpc_l]() { + auto wallet (rpc_l->wallet_impl ()); + if (!rpc_l->ec) + { + std::string password_text (rpc_l->request.get ("password")); + auto transaction (wallet->wallets.tx_begin_write ()); + auto error (wallet->enter_password (transaction, password_text)); + rpc_l->response_l.put ("valid", error ? "0" : "1"); + } + rpc_l->response_errors (); + }); } void nano::json_handler::password_valid (bool wallet_locked) @@ -2691,91 +2712,97 @@ void nano::json_handler::pending_exists () void nano::json_handler::payment_begin () { - std::string id_text (request.get ("wallet")); - nano::uint256_union id; - if (!id.decode_hex (id_text)) - { - auto existing (node.wallets.items.find (id)); - if (existing != node.wallets.items.end ()) + auto rpc_l (shared_from_this ()); + node.worker.push_task ([rpc_l]() { + std::string id_text (rpc_l->request.get ("wallet")); + nano::uint256_union id; + if (!id.decode_hex (id_text)) { - auto transaction (node.wallets.tx_begin_write ()); - std::shared_ptr wallet (existing->second); - if (wallet->store.valid_password (transaction)) + auto existing (rpc_l->node.wallets.items.find (id)); + if (existing != rpc_l->node.wallets.items.end ()) { - nano::account account (0); - do + auto transaction (rpc_l->node.wallets.tx_begin_write ()); + std::shared_ptr wallet (existing->second); + if (wallet->store.valid_password (transaction)) { - auto existing (wallet->free_accounts.begin ()); - if (existing != wallet->free_accounts.end ()) + nano::account account (0); + do { - account = *existing; - wallet->free_accounts.erase (existing); - if (wallet->store.find (transaction, account) == wallet->store.end ()) + auto existing (wallet->free_accounts.begin ()); + if (existing != wallet->free_accounts.end ()) { - node.logger.always_log (boost::str (boost::format ("Transaction wallet %1% externally modified listing account %2% as free but no longer exists") % id.to_string () % account.to_account ())); - account.clear (); + account = *existing; + wallet->free_accounts.erase (existing); + if (wallet->store.find (transaction, account) == wallet->store.end ()) + { + rpc_l->node.logger.always_log (boost::str (boost::format ("Transaction wallet %1% externally modified listing account %2% as free but no longer exists") % id.to_string () % account.to_account ())); + account.clear (); + } + else + { + auto block_transaction (rpc_l->node.store.tx_begin_read ()); + if (!rpc_l->node.ledger.account_balance (block_transaction, account).is_zero ()) + { + rpc_l->node.logger.always_log (boost::str (boost::format ("Skipping account %1% for use as a transaction account: non-zero balance") % account.to_account ())); + account.clear (); + } + } } else { - auto block_transaction (node.store.tx_begin_read ()); - if (!node.ledger.account_balance (block_transaction, account).is_zero ()) - { - node.logger.always_log (boost::str (boost::format ("Skipping account %1% for use as a transaction account: non-zero balance") % account.to_account ())); - account.clear (); - } + account = wallet->deterministic_insert (transaction); + break; } + } while (account.is_zero ()); + if (!account.is_zero ()) + { + rpc_l->response_l.put ("deprecated", "1"); + rpc_l->response_l.put ("account", account.to_account ()); } else { - account = wallet->deterministic_insert (transaction); - break; + rpc_l->ec = nano::error_rpc::payment_unable_create_account; } - } while (account.is_zero ()); - if (!account.is_zero ()) - { - response_l.put ("deprecated", "1"); - response_l.put ("account", account.to_account ()); } else { - ec = nano::error_rpc::payment_unable_create_account; + rpc_l->ec = nano::error_common::wallet_locked; } } else { - ec = nano::error_common::wallet_locked; + rpc_l->ec = nano::error_common::wallet_not_found; } } else { - ec = nano::error_common::wallet_not_found; + rpc_l->ec = nano::error_common::bad_wallet_number; } - } - else - { - ec = nano::error_common::bad_wallet_number; - } - response_errors (); + rpc_l->response_errors (); + }); } void nano::json_handler::payment_init () { - auto wallet (wallet_impl ()); - if (!ec) - { - auto transaction (node.wallets.tx_begin_write ()); - if (wallet->store.valid_password (transaction)) + auto rpc_l (shared_from_this ()); + node.worker.push_task ([rpc_l]() { + auto wallet (rpc_l->wallet_impl ()); + if (!rpc_l->ec) { - wallet->init_free_accounts (transaction); - response_l.put ("deprecated", "1"); - response_l.put ("status", "Ready"); + auto transaction (rpc_l->node.wallets.tx_begin_write ()); + if (wallet->store.valid_password (transaction)) + { + wallet->init_free_accounts (transaction); + rpc_l->response_l.put ("deprecated", "1"); + rpc_l->response_l.put ("status", "Ready"); + } + else + { + rpc_l->ec = nano::error_common::wallet_locked; + } } - else - { - ec = nano::error_common::wallet_locked; - } - } - response_errors (); + rpc_l->response_errors (); + }); } void nano::json_handler::payment_end () @@ -2834,166 +2861,169 @@ void nano::json_handler::payment_wait () void nano::json_handler::process () { - const bool json_block_l = request.get ("json_block", false); - const bool watch_work_l = request.get ("watch_work", true); - std::shared_ptr block; - if (json_block_l) - { - block = block_json_impl (true); - } - else - { - block = block_impl (true); - } - - // State blocks subtype check - if (!ec && block->type () == nano::block_type::state) - { - std::string subtype_text (request.get ("subtype", "")); - if (!subtype_text.empty ()) + auto rpc_l (shared_from_this ()); + node.worker.push_task ([rpc_l]() { + const bool json_block_l = rpc_l->request.get ("json_block", false); + const bool watch_work_l = rpc_l->request.get ("watch_work", true); + std::shared_ptr block; + if (json_block_l) { - std::shared_ptr block_state (std::static_pointer_cast (block)); - auto transaction (node.store.tx_begin_read ()); - if (!block_state->hashables.previous.is_zero () && !node.store.block_exists (transaction, block_state->hashables.previous)) - { - ec = nano::error_process::gap_previous; - } - else - { - auto balance (node.ledger.account_balance (transaction, block_state->hashables.account)); - if (subtype_text == "send") - { - if (balance <= block_state->hashables.balance.number ()) - { - ec = nano::error_rpc::invalid_subtype_balance; - } - // Send with previous == 0 fails balance check. No previous != 0 check required - } - else if (subtype_text == "receive") - { - if (balance > block_state->hashables.balance.number ()) - { - ec = nano::error_rpc::invalid_subtype_balance; - } - // Receive can be point to open block. No previous != 0 check required - } - else if (subtype_text == "open") - { - if (!block_state->hashables.previous.is_zero ()) - { - ec = nano::error_rpc::invalid_subtype_previous; - } - } - else if (subtype_text == "change") - { - if (balance != block_state->hashables.balance.number ()) - { - ec = nano::error_rpc::invalid_subtype_balance; - } - else if (block_state->hashables.previous.is_zero ()) - { - ec = nano::error_rpc::invalid_subtype_previous; - } - } - else if (subtype_text == "epoch") - { - if (balance != block_state->hashables.balance.number ()) - { - ec = nano::error_rpc::invalid_subtype_balance; - } - else if (!node.ledger.is_epoch_link (block_state->hashables.link)) - { - ec = ec = nano::error_rpc::invalid_subtype_epoch_link; - } - } - else - { - ec = nano::error_rpc::invalid_subtype; - } - } - } - } - if (!ec) - { - if (!nano::work_validate (*block)) - { - auto result (node.process_local (block, watch_work_l)); - switch (result.code) - { - case nano::process_result::progress: - { - response_l.put ("hash", block->hash ().to_string ()); - break; - } - case nano::process_result::gap_previous: - { - ec = nano::error_process::gap_previous; - break; - } - case nano::process_result::gap_source: - { - ec = nano::error_process::gap_source; - break; - } - case nano::process_result::old: - { - ec = nano::error_process::old; - break; - } - case nano::process_result::bad_signature: - { - ec = nano::error_process::bad_signature; - break; - } - case nano::process_result::negative_spend: - { - // TODO once we get RPC versioning, this should be changed to "negative spend" - ec = nano::error_process::negative_spend; - break; - } - case nano::process_result::balance_mismatch: - { - ec = nano::error_process::balance_mismatch; - break; - } - case nano::process_result::unreceivable: - { - ec = nano::error_process::unreceivable; - break; - } - case nano::process_result::block_position: - { - ec = nano::error_process::block_position; - break; - } - case nano::process_result::fork: - { - const bool force = request.get ("force", false); - if (force) - { - node.active.erase (*block); - node.block_processor.force (block); - response_l.put ("hash", block->hash ().to_string ()); - } - else - { - ec = nano::error_process::fork; - } - break; - } - default: - { - ec = nano::error_process::other; - break; - } - } + block = rpc_l->block_json_impl (true); } else { - ec = nano::error_blocks::work_low; + block = rpc_l->block_impl (true); } - } - response_errors (); + + // State blocks subtype check + if (!rpc_l->ec && block->type () == nano::block_type::state) + { + std::string subtype_text (rpc_l->request.get ("subtype", "")); + if (!subtype_text.empty ()) + { + std::shared_ptr block_state (std::static_pointer_cast (block)); + auto transaction (rpc_l->node.store.tx_begin_read ()); + if (!block_state->hashables.previous.is_zero () && !rpc_l->node.store.block_exists (transaction, block_state->hashables.previous)) + { + rpc_l->ec = nano::error_process::gap_previous; + } + else + { + auto balance (rpc_l->node.ledger.account_balance (transaction, block_state->hashables.account)); + if (subtype_text == "send") + { + if (balance <= block_state->hashables.balance.number ()) + { + rpc_l->ec = nano::error_rpc::invalid_subtype_balance; + } + // Send with previous == 0 fails balance check. No previous != 0 check required + } + else if (subtype_text == "receive") + { + if (balance > block_state->hashables.balance.number ()) + { + rpc_l->ec = nano::error_rpc::invalid_subtype_balance; + } + // Receive can be point to open block. No previous != 0 check required + } + else if (subtype_text == "open") + { + if (!block_state->hashables.previous.is_zero ()) + { + rpc_l->ec = nano::error_rpc::invalid_subtype_previous; + } + } + else if (subtype_text == "change") + { + if (balance != block_state->hashables.balance.number ()) + { + rpc_l->ec = nano::error_rpc::invalid_subtype_balance; + } + else if (block_state->hashables.previous.is_zero ()) + { + rpc_l->ec = nano::error_rpc::invalid_subtype_previous; + } + } + else if (subtype_text == "epoch") + { + if (balance != block_state->hashables.balance.number ()) + { + rpc_l->ec = nano::error_rpc::invalid_subtype_balance; + } + else if (!rpc_l->node.ledger.is_epoch_link (block_state->hashables.link)) + { + rpc_l->ec = nano::error_rpc::invalid_subtype_epoch_link; + } + } + else + { + rpc_l->ec = nano::error_rpc::invalid_subtype; + } + } + } + } + if (!rpc_l->ec) + { + if (!nano::work_validate (*block)) + { + auto result (rpc_l->node.process_local (block, watch_work_l)); + switch (result.code) + { + case nano::process_result::progress: + { + rpc_l->response_l.put ("hash", block->hash ().to_string ()); + break; + } + case nano::process_result::gap_previous: + { + rpc_l->ec = nano::error_process::gap_previous; + break; + } + case nano::process_result::gap_source: + { + rpc_l->ec = nano::error_process::gap_source; + break; + } + case nano::process_result::old: + { + rpc_l->ec = nano::error_process::old; + break; + } + case nano::process_result::bad_signature: + { + rpc_l->ec = nano::error_process::bad_signature; + break; + } + case nano::process_result::negative_spend: + { + // TODO once we get RPC versioning, this should be changed to "negative spend" + rpc_l->ec = nano::error_process::negative_spend; + break; + } + case nano::process_result::balance_mismatch: + { + rpc_l->ec = nano::error_process::balance_mismatch; + break; + } + case nano::process_result::unreceivable: + { + rpc_l->ec = nano::error_process::unreceivable; + break; + } + case nano::process_result::block_position: + { + rpc_l->ec = nano::error_process::block_position; + break; + } + case nano::process_result::fork: + { + const bool force = rpc_l->request.get ("force", false); + if (force) + { + rpc_l->node.active.erase (*block); + rpc_l->node.block_processor.force (block); + rpc_l->response_l.put ("hash", block->hash ().to_string ()); + } + else + { + rpc_l->ec = nano::error_process::fork; + } + break; + } + default: + { + rpc_l->ec = nano::error_process::other; + break; + } + } + } + else + { + rpc_l->ec = nano::error_blocks::work_low; + } + } + rpc_l->response_errors (); + }); } void nano::json_handler::receive () @@ -3037,21 +3067,21 @@ void nano::json_handler::receive () bool generate_work (work == 0); // Disable work generation if "work" option is provided auto response_a (response); // clang-format off - wallet->receive_async (std::move (block), account, node.network_params.ledger.genesis_amount, [response_a](std::shared_ptr block_a) { + wallet->receive_async(std::move(block), account, node.network_params.ledger.genesis_amount, [response_a](std::shared_ptr block_a) { if (block_a != nullptr) { boost::property_tree::ptree response_l; - response_l.put ("block", block_a->hash ().to_string ()); + response_l.put("block", block_a->hash().to_string()); std::stringstream ostream; - boost::property_tree::write_json (ostream, response_l); - response_a (ostream.str ()); + boost::property_tree::write_json(ostream, response_l); + response_a(ostream.str()); } else { - json_error_response (response_a, "Error generating block"); + json_error_response(response_a, "Error generating block"); } }, - work, generate_work); + work, generate_work); // clang-format on } } @@ -3377,32 +3407,31 @@ void nano::json_handler::send () { bool generate_work (work == 0); // Disable work generation if "work" option is provided boost::optional send_id (request.get_optional ("id")); - auto rpc_l (shared_from_this ()); auto response_a (response); auto response_data (std::make_shared (response_l)); // clang-format off - wallet->send_async (source, destination, amount.number (), [balance, amount, response_a, response_data](std::shared_ptr block_a) { + wallet->send_async(source, destination, amount.number(), [balance, amount, response_a, response_data](std::shared_ptr block_a) { if (block_a != nullptr) { - response_data->put ("block", block_a->hash ().to_string ()); + response_data->put("block", block_a->hash().to_string()); std::stringstream ostream; - boost::property_tree::write_json (ostream, *response_data); - response_a (ostream.str ()); + boost::property_tree::write_json(ostream, *response_data); + response_a(ostream.str()); } else { - if (balance >= amount.number ()) + if (balance >= amount.number()) { - json_error_response (response_a, "Error generating block"); + json_error_response(response_a, "Error generating block"); } else { - std::error_code ec (nano::error_common::insufficient_balance); - json_error_response (response_a, ec.message ()); + std::error_code ec(nano::error_common::insufficient_balance); + json_error_response(response_a, ec.message()); } } }, - work, generate_work, send_id); + work, generate_work, send_id); // clang-format on } } @@ -3596,10 +3625,13 @@ void nano::json_handler::unchecked () void nano::json_handler::unchecked_clear () { - auto transaction (node.store.tx_begin_write ()); - node.store.unchecked_clear (transaction); - response_l.put ("success", ""); - response_errors (); + auto rpc_l (shared_from_this ()); + node.worker.push_task ([rpc_l]() { + auto transaction (rpc_l->node.store.tx_begin_write ()); + rpc_l->node.store.unchecked_clear (transaction); + rpc_l->response_l.put ("success", ""); + rpc_l->response_errors (); + }); } void nano::json_handler::unchecked_get () @@ -3771,56 +3803,62 @@ void nano::json_handler::validate_account_number () void nano::json_handler::wallet_add () { - auto wallet (wallet_impl ()); - if (!ec) - { - std::string key_text (request.get ("key")); - nano::raw_key key; - if (!key.data.decode_hex (key_text)) + auto rpc_l (shared_from_this ()); + node.worker.push_task ([rpc_l]() { + auto wallet (rpc_l->wallet_impl ()); + if (!rpc_l->ec) { - const bool generate_work = request.get ("work", true); - auto pub (wallet->insert_adhoc (key, generate_work)); - if (!pub.is_zero ()) + std::string key_text (rpc_l->request.get ("key")); + nano::raw_key key; + if (!key.data.decode_hex (key_text)) { - response_l.put ("account", pub.to_account ()); + const bool generate_work = rpc_l->request.get ("work", true); + auto pub (wallet->insert_adhoc (key, generate_work)); + if (!pub.is_zero ()) + { + rpc_l->response_l.put ("account", pub.to_account ()); + } + else + { + rpc_l->ec = nano::error_common::wallet_locked; + } } else { - ec = nano::error_common::wallet_locked; + rpc_l->ec = nano::error_common::bad_private_key; } } - else - { - ec = nano::error_common::bad_private_key; - } - } - response_errors (); + rpc_l->response_errors (); + }); } void nano::json_handler::wallet_add_watch () { - auto wallet (wallet_impl ()); - if (!ec) - { - auto transaction (node.wallets.tx_begin_write ()); - if (wallet->store.valid_password (transaction)) + auto rpc_l (shared_from_this ()); + node.worker.push_task ([rpc_l]() { + auto wallet (rpc_l->wallet_impl ()); + if (!rpc_l->ec) { - for (auto & accounts : request.get_child ("accounts")) + auto transaction (rpc_l->node.wallets.tx_begin_write ()); + if (wallet->store.valid_password (transaction)) { - auto account (account_impl (accounts.second.data ())); - if (!ec) + for (auto & accounts : rpc_l->request.get_child ("accounts")) { - wallet->insert_watch (transaction, account); + auto account (rpc_l->account_impl (accounts.second.data ())); + if (!rpc_l->ec) + { + wallet->insert_watch (transaction, account); + } } + rpc_l->response_l.put ("success", ""); + } + else + { + rpc_l->ec = nano::error_common::wallet_locked; } - response_l.put ("success", ""); } - else - { - ec = nano::error_common::wallet_locked; - } - } - response_errors (); + rpc_l->response_errors (); + }); } void nano::json_handler::wallet_info () @@ -3891,35 +3929,38 @@ void nano::json_handler::wallet_balances () void nano::json_handler::wallet_change_seed () { - auto wallet (wallet_impl ()); - if (!ec) - { - std::string seed_text (request.get ("seed")); - nano::raw_key seed; - if (!seed.data.decode_hex (seed_text)) + auto rpc_l (shared_from_this ()); + node.worker.push_task ([rpc_l]() { + auto wallet (rpc_l->wallet_impl ()); + if (!rpc_l->ec) { - auto count (static_cast (count_optional_impl (0))); - auto transaction (node.wallets.tx_begin_write ()); - if (wallet->store.valid_password (transaction)) + std::string seed_text (rpc_l->request.get ("seed")); + nano::raw_key seed; + if (!seed.data.decode_hex (seed_text)) { - nano::public_key account (wallet->change_seed (transaction, seed, count)); - response_l.put ("success", ""); - response_l.put ("last_restored_account", account.to_account ()); - auto index (wallet->store.deterministic_index_get (transaction)); - assert (index > 0); - response_l.put ("restored_count", std::to_string (index)); + auto count (static_cast (rpc_l->count_optional_impl (0))); + auto transaction (rpc_l->node.wallets.tx_begin_write ()); + if (wallet->store.valid_password (transaction)) + { + nano::public_key account (wallet->change_seed (transaction, seed, count)); + rpc_l->response_l.put ("success", ""); + rpc_l->response_l.put ("last_restored_account", account.to_account ()); + auto index (wallet->store.deterministic_index_get (transaction)); + assert (index > 0); + rpc_l->response_l.put ("restored_count", std::to_string (index)); + } + else + { + rpc_l->ec = nano::error_common::wallet_locked; + } } else { - ec = nano::error_common::wallet_locked; + rpc_l->ec = nano::error_common::bad_seed; } } - else - { - ec = nano::error_common::bad_seed; - } - } - response_errors (); + rpc_l->response_errors (); + }); } void nano::json_handler::wallet_contains () @@ -3937,61 +3978,67 @@ void nano::json_handler::wallet_contains () void nano::json_handler::wallet_create () { - nano::raw_key seed; - auto seed_text (request.get_optional ("seed")); - if (seed_text.is_initialized () && seed.data.decode_hex (seed_text.get ())) - { - ec = nano::error_common::bad_seed; - } - if (!ec) - { - nano::keypair wallet_id; - auto wallet (node.wallets.create (wallet_id.pub)); - auto existing (node.wallets.items.find (wallet_id.pub)); - if (existing != node.wallets.items.end ()) + auto rpc_l (shared_from_this ()); + node.worker.push_task ([rpc_l]() { + nano::raw_key seed; + auto seed_text (rpc_l->request.get_optional ("seed")); + if (seed_text.is_initialized () && seed.data.decode_hex (seed_text.get ())) { - response_l.put ("wallet", wallet_id.pub.to_string ()); + rpc_l->ec = nano::error_common::bad_seed; } - else + if (!rpc_l->ec) { - ec = nano::error_common::wallet_lmdb_max_dbs; + nano::keypair wallet_id; + auto wallet (rpc_l->node.wallets.create (wallet_id.pub)); + auto existing (rpc_l->node.wallets.items.find (wallet_id.pub)); + if (existing != rpc_l->node.wallets.items.end ()) + { + rpc_l->response_l.put ("wallet", wallet_id.pub.to_string ()); + } + else + { + rpc_l->ec = nano::error_common::wallet_lmdb_max_dbs; + } + if (!rpc_l->ec && seed_text.is_initialized ()) + { + auto transaction (rpc_l->node.wallets.tx_begin_write ()); + nano::public_key account (wallet->change_seed (transaction, seed)); + rpc_l->response_l.put ("last_restored_account", account.to_account ()); + auto index (wallet->store.deterministic_index_get (transaction)); + assert (index > 0); + rpc_l->response_l.put ("restored_count", std::to_string (index)); + } } - if (!ec && seed_text.is_initialized ()) - { - auto transaction (node.wallets.tx_begin_write ()); - nano::public_key account (wallet->change_seed (transaction, seed)); - response_l.put ("last_restored_account", account.to_account ()); - auto index (wallet->store.deterministic_index_get (transaction)); - assert (index > 0); - response_l.put ("restored_count", std::to_string (index)); - } - } - response_errors (); + rpc_l->response_errors (); + }); } void nano::json_handler::wallet_destroy () { - std::string wallet_text (request.get ("wallet")); - nano::uint256_union wallet; - if (!wallet.decode_hex (wallet_text)) - { - auto existing (node.wallets.items.find (wallet)); - if (existing != node.wallets.items.end ()) + auto rpc_l (shared_from_this ()); + node.worker.push_task ([rpc_l]() { + std::string wallet_text (rpc_l->request.get ("wallet")); + nano::uint256_union wallet; + if (!wallet.decode_hex (wallet_text)) { - node.wallets.destroy (wallet); - bool destroyed (node.wallets.items.find (wallet) == node.wallets.items.end ()); - response_l.put ("destroyed", destroyed ? "1" : "0"); + auto existing (rpc_l->node.wallets.items.find (wallet)); + if (existing != rpc_l->node.wallets.items.end ()) + { + rpc_l->node.wallets.destroy (wallet); + bool destroyed (rpc_l->node.wallets.items.find (wallet) == rpc_l->node.wallets.items.end ()); + rpc_l->response_l.put ("destroyed", destroyed ? "1" : "0"); + } + else + { + rpc_l->ec = nano::error_common::wallet_not_found; + } } else { - ec = nano::error_common::wallet_not_found; + rpc_l->ec = nano::error_common::bad_wallet_number; } - } - else - { - ec = nano::error_common::bad_wallet_number; - } - response_errors (); + rpc_l->response_errors (); + }); } void nano::json_handler::wallet_export () @@ -4255,55 +4302,58 @@ void nano::json_handler::wallet_representative () void nano::json_handler::wallet_representative_set () { - auto wallet (wallet_impl ()); - std::string representative_text (request.get ("representative")); - auto representative (account_impl (representative_text, nano::error_rpc::bad_representative_number)); - if (!ec) - { - bool update_existing_accounts (request.get ("update_existing_accounts", false)); + auto rpc_l (shared_from_this ()); + node.worker.push_task ([rpc_l]() { + auto wallet (rpc_l->wallet_impl ()); + std::string representative_text (rpc_l->request.get ("representative")); + auto representative (rpc_l->account_impl (representative_text, nano::error_rpc::bad_representative_number)); + if (!rpc_l->ec) { - auto transaction (node.wallets.tx_begin_write ()); - if (wallet->store.valid_password (transaction) || !update_existing_accounts) + bool update_existing_accounts (rpc_l->request.get ("update_existing_accounts", false)); { - wallet->store.representative_set (transaction, representative); - response_l.put ("set", "1"); - } - else - { - ec = nano::error_common::wallet_locked; - } - } - // Change representative for all wallet accounts - if (!ec && update_existing_accounts) - { - std::vector accounts; - { - auto transaction (node.wallets.tx_begin_read ()); - auto block_transaction (node.store.tx_begin_read ()); - for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) + auto transaction (rpc_l->node.wallets.tx_begin_write ()); + if (wallet->store.valid_password (transaction) || !update_existing_accounts) { - nano::account const & account (i->first); - nano::account_info info; - if (!node.store.account_get (block_transaction, account, info)) + wallet->store.representative_set (transaction, representative); + rpc_l->response_l.put ("set", "1"); + } + else + { + rpc_l->ec = nano::error_common::wallet_locked; + } + } + // Change representative for all wallet accounts + if (!rpc_l->ec && update_existing_accounts) + { + std::vector accounts; + { + auto transaction (rpc_l->node.wallets.tx_begin_read ()); + auto block_transaction (rpc_l->node.store.tx_begin_read ()); + for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) { - auto block (node.store.block_get (block_transaction, info.rep_block)); - assert (block != nullptr); - if (block->representative () != representative) + nano::account const & account (i->first); + nano::account_info info; + if (!rpc_l->node.store.account_get (block_transaction, account, info)) { - accounts.push_back (account); + auto block (rpc_l->node.store.block_get (block_transaction, info.rep_block)); + assert (block != nullptr); + if (block->representative () != representative) + { + accounts.push_back (account); + } } } } - } - for (auto & account : accounts) - { - // clang-format off - wallet->change_async (account, representative, [](std::shared_ptr) {}, 0, false); - // clang-format on + for (auto & account : accounts) + { + // clang-format off + wallet->change_async(account, representative, [](std::shared_ptr) {}, 0, false); + // clang-format on + } } } - } - response_errors (); + rpc_l->response_errors (); + }); } void nano::json_handler::wallet_republish () @@ -4465,20 +4515,23 @@ void nano::json_handler::work_get () void nano::json_handler::work_set () { - auto wallet (wallet_impl ()); - auto account (account_impl ()); - auto work (work_optional_impl ()); - if (!ec) - { - auto transaction (node.wallets.tx_begin_write ()); - wallet_account_impl (transaction, wallet, account); - if (!ec) + auto rpc_l (shared_from_this ()); + node.worker.push_task ([rpc_l]() { + auto wallet (rpc_l->wallet_impl ()); + auto account (rpc_l->account_impl ()); + auto work (rpc_l->work_optional_impl ()); + if (!rpc_l->ec) { - wallet->store.work_put (transaction, account, work); - response_l.put ("success", ""); + auto transaction (rpc_l->node.wallets.tx_begin_write ()); + rpc_l->wallet_account_impl (transaction, wallet, account); + if (!rpc_l->ec) + { + wallet->store.work_put (transaction, account, work); + rpc_l->response_l.put ("success", ""); + } } - } - response_errors (); + rpc_l->response_errors (); + }); } void nano::json_handler::work_validate () diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 5a7680b1..c9636bee 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -584,6 +584,7 @@ std::unique_ptr collect_seq_con_info (node & node, const composite->add_component (collect_seq_con_info (node.vote_uniquer, "vote_uniquer")); composite->add_component (collect_seq_con_info (node.confirmation_height_processor, "confirmation_height_processor")); composite->add_component (collect_seq_con_info (node.pending_confirmation_height, "pending_confirmation_height")); + composite->add_component (collect_seq_con_info (node.worker, "worker")); return composite; } } @@ -679,6 +680,7 @@ void nano::node::stop () wallets.stop (); stats.stop (); write_database_queue.stop (); + worker.stop (); } } @@ -790,7 +792,9 @@ void nano::node::ongoing_store_flush () alarm.add (std::chrono::steady_clock::now () + std::chrono::seconds (5), [node_w]() { if (auto node_l = node_w.lock ()) { - node_l->ongoing_store_flush (); + node_l->worker.push_task ([node_l]() { + node_l->ongoing_store_flush (); + }); } }); } @@ -803,7 +807,9 @@ void nano::node::ongoing_peer_store () alarm.add (std::chrono::steady_clock::now () + network_params.node.peer_interval, [node_w]() { if (auto node_l = node_w.lock ()) { - node_l->ongoing_peer_store (); + node_l->worker.push_task ([node_l]() { + node_l->ongoing_peer_store (); + }); } }); } @@ -834,7 +840,9 @@ void nano::node::search_pending () wallets.search_pending_all (); auto this_l (shared ()); alarm.add (std::chrono::steady_clock::now () + network_params.node.search_pending_interval, [this_l]() { - this_l->search_pending (); + this_l->worker.push_task ([this_l]() { + this_l->search_pending (); + }); }); } @@ -898,7 +906,9 @@ void nano::node::ongoing_unchecked_cleanup () } auto this_l (shared ()); alarm.add (std::chrono::steady_clock::now () + network_params.node.unchecked_cleaning_interval, [this_l]() { - this_l->ongoing_unchecked_cleanup (); + this_l->worker.push_task ([this_l]() { + this_l->ongoing_unchecked_cleanup (); + }); }); } @@ -1292,7 +1302,9 @@ void nano::node::ongoing_online_weight_calculation_queue () alarm.add (std::chrono::steady_clock::now () + (std::chrono::seconds (network_params.node.weight_period)), [node_w]() { if (auto node_l = node_w.lock ()) { - node_l->ongoing_online_weight_calculation (); + node_l->worker.push_task ([node_l]() { + node_l->ongoing_online_weight_calculation (); + }); } }); } diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 0d1ad77b..5c4143f1 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -141,6 +141,7 @@ public: void ongoing_online_weight_calculation (); void ongoing_online_weight_calculation_queue (); bool online () const; + nano::worker worker; nano::write_database_queue write_database_queue; boost::asio::io_context & io_ctx; boost::latch node_initialized_latch; diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 9c93c3e1..7bf2624e 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -123,11 +123,36 @@ void check_block_response_count (nano::system & system, nano::rpc & rpc, boost:: ASSERT_EQ (200, response.status); ASSERT_EQ (size_count, response.json.get_child ("blocks").front ().second.size ()); } + +class scoped_io_thread_name_change +{ +public: + scoped_io_thread_name_change () + { + renew (); + } + + ~scoped_io_thread_name_change () + { + reset (); + } + + void reset () + { + nano::thread_role::set (nano::thread_role::name::unknown); + } + + void renew () + { + nano::thread_role::set (nano::thread_role::name::io); + } +}; } TEST (rpc, account_balance) { nano::system system (24000, 1); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -155,6 +180,7 @@ TEST (rpc, account_balance) TEST (rpc, account_block_count) { nano::system system (24000, 1); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -180,6 +206,7 @@ TEST (rpc, account_block_count) TEST (rpc, account_create) { nano::system system (24000, 1); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -234,6 +261,7 @@ TEST (rpc, account_weight) auto & node1 (*system.nodes[0]); nano::change_block block (latest, key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, node1.work_generate_blocking (latest)); ASSERT_EQ (nano::process_result::progress, node1.process (block).code); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -258,6 +286,8 @@ TEST (rpc, account_weight) TEST (rpc, wallet_contains) { nano::system system (24000, 1); + system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -266,7 +296,6 @@ TEST (rpc, wallet_contains) nano::ipc_rpc_processor ipc_rpc_processor (system.io_ctx, rpc_config); nano::rpc rpc (system.io_ctx, rpc_config, ipc_rpc_processor); rpc.start (); - system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); boost::property_tree::ptree request; std::string wallet; node->wallets.items.begin ()->first.encode_hex (wallet); @@ -287,6 +316,7 @@ TEST (rpc, wallet_contains) TEST (rpc, wallet_doesnt_contain) { nano::system system (24000, 1); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -315,6 +345,8 @@ TEST (rpc, wallet_doesnt_contain) TEST (rpc, validate_account_number) { nano::system system (24000, 1); + system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -323,7 +355,6 @@ TEST (rpc, validate_account_number) nano::ipc_rpc_processor ipc_rpc_processor (system.io_ctx, rpc_config); nano::rpc rpc (system.io_ctx, rpc_config, ipc_rpc_processor); rpc.start (); - system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); boost::property_tree::ptree request; request.put ("action", "validate_account_number"); request.put ("account", nano::test_genesis_key.pub.to_account ()); @@ -340,6 +371,8 @@ TEST (rpc, validate_account_number) TEST (rpc, validate_account_invalid) { nano::system system (24000, 1); + system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -351,7 +384,6 @@ TEST (rpc, validate_account_invalid) std::string account; nano::test_genesis_key.pub.encode_account (account); account[0] ^= 0x1; - system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); boost::property_tree::ptree request; request.put ("action", "validate_account_number"); request.put ("account", account); @@ -369,6 +401,8 @@ TEST (rpc, validate_account_invalid) TEST (rpc, send) { nano::system system (24000, 1); + system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -377,7 +411,6 @@ TEST (rpc, send) nano::ipc_rpc_processor ipc_rpc_processor (system.io_ctx, rpc_config); nano::rpc rpc (system.io_ctx, rpc_config, ipc_rpc_processor); rpc.start (); - system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); boost::property_tree::ptree request; std::string wallet; system.nodes[0]->wallets.items.begin ()->first.encode_hex (wallet); @@ -410,6 +443,7 @@ TEST (rpc, send) TEST (rpc, send_fail) { nano::system system (24000, 1); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -447,6 +481,8 @@ TEST (rpc, send_fail) TEST (rpc, send_work) { nano::system system (24000, 1); + system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -455,7 +491,6 @@ TEST (rpc, send_work) nano::ipc_rpc_processor ipc_rpc_processor (system.io_ctx, rpc_config); nano::rpc rpc (system.io_ctx, rpc_config, ipc_rpc_processor); rpc.start (); - system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); boost::property_tree::ptree request; std::string wallet; system.nodes[0]->wallets.items.begin ()->first.encode_hex (wallet); @@ -491,6 +526,8 @@ TEST (rpc, send_work) TEST (rpc, send_idempotent) { nano::system system (24000, 1); + system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -499,7 +536,6 @@ TEST (rpc, send_idempotent) nano::ipc_rpc_processor ipc_rpc_processor (system.io_ctx, rpc_config); nano::rpc rpc (system.io_ctx, rpc_config, ipc_rpc_processor); rpc.start (); - system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); boost::property_tree::ptree request; std::string wallet; system.nodes[0]->wallets.items.begin ()->first.encode_hex (wallet); @@ -546,6 +582,7 @@ TEST (rpc, send_idempotent) TEST (rpc, stop) { nano::system system (24000, 1); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -567,6 +604,7 @@ TEST (rpc, stop) TEST (rpc, wallet_add) { nano::system system (24000, 1); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -599,6 +637,7 @@ TEST (rpc, wallet_add) TEST (rpc, wallet_password_valid) { nano::system system (24000, 1); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -626,6 +665,7 @@ TEST (rpc, wallet_password_valid) TEST (rpc, wallet_password_change) { nano::system system (24000, 1); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -649,6 +689,7 @@ TEST (rpc, wallet_password_change) ASSERT_EQ (200, response.status); std::string account_text1 (response.json.get ("changed")); ASSERT_EQ (account_text1, "1"); + scoped_thread_name_io.reset (); auto transaction (system.wallet (0)->wallets.tx_begin_write ()); ASSERT_TRUE (system.wallet (0)->store.valid_password (transaction)); ASSERT_TRUE (system.wallet (0)->enter_password (transaction, "")); @@ -660,6 +701,7 @@ TEST (rpc, wallet_password_change) TEST (rpc, wallet_password_enter) { nano::system system (24000, 1); + scoped_io_thread_name_change scoped_thread_name_io; nano::raw_key password_l; password_l.data.clear (); system.deadline_set (10s); @@ -696,6 +738,7 @@ TEST (rpc, wallet_password_enter) TEST (rpc, wallet_representative) { nano::system system (24000, 1); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -723,6 +766,7 @@ TEST (rpc, wallet_representative) TEST (rpc, wallet_representative_set) { nano::system system (24000, 1); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -752,6 +796,8 @@ TEST (rpc, wallet_representative_set) TEST (rpc, wallet_representative_set_force) { nano::system system (24000, 1); + system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -759,7 +805,6 @@ TEST (rpc, wallet_representative_set_force) nano::rpc_config rpc_config (true); nano::ipc_rpc_processor ipc_rpc_processor (system.io_ctx, rpc_config); nano::rpc rpc (system.io_ctx, rpc_config, ipc_rpc_processor); - system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); rpc.start (); boost::property_tree::ptree request; std::string wallet; @@ -798,6 +843,10 @@ TEST (rpc, wallet_representative_set_force) TEST (rpc, account_list) { nano::system system (24000, 1); + nano::keypair key2; + system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); + system.wallet (0)->insert_adhoc (key2.prv); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -806,9 +855,6 @@ TEST (rpc, account_list) nano::ipc_rpc_processor ipc_rpc_processor (system.io_ctx, rpc_config); nano::rpc rpc (system.io_ctx, rpc_config, ipc_rpc_processor); rpc.start (); - nano::keypair key2; - system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); - system.wallet (0)->insert_adhoc (key2.prv); boost::property_tree::ptree request; std::string wallet; system.nodes[0]->wallets.items.begin ()->first.encode_hex (wallet); @@ -840,6 +886,8 @@ TEST (rpc, account_list) TEST (rpc, wallet_key_valid) { nano::system system (24000, 1); + system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -848,7 +896,6 @@ TEST (rpc, wallet_key_valid) nano::ipc_rpc_processor ipc_rpc_processor (system.io_ctx, rpc_config); nano::rpc rpc (system.io_ctx, rpc_config, ipc_rpc_processor); rpc.start (); - system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); boost::property_tree::ptree request; std::string wallet; system.nodes[0]->wallets.items.begin ()->first.encode_hex (wallet); @@ -868,6 +915,7 @@ TEST (rpc, wallet_key_valid) TEST (rpc, wallet_create) { nano::system system (24000, 1); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -894,6 +942,7 @@ TEST (rpc, wallet_create) TEST (rpc, wallet_create_seed) { nano::system system (24000, 1); + scoped_io_thread_name_change scoped_thread_name_io; nano::keypair seed; nano::raw_key prv; nano::deterministic_key (seed.pub, 0, prv.data); @@ -937,6 +986,8 @@ TEST (rpc, wallet_create_seed) TEST (rpc, wallet_export) { nano::system system (24000, 1); + system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -945,7 +996,6 @@ TEST (rpc, wallet_export) nano::ipc_rpc_processor ipc_rpc_processor (system.io_ctx, rpc_config); nano::rpc rpc (system.io_ctx, rpc_config, ipc_rpc_processor); rpc.start (); - system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); boost::property_tree::ptree request; request.put ("action", "wallet_export"); request.put ("wallet", system.nodes[0]->wallets.items.begin ()->first.to_string ()); @@ -958,6 +1008,7 @@ TEST (rpc, wallet_export) ASSERT_EQ (200, response.status); std::string wallet_json (response.json.get ("json")); bool error (false); + scoped_thread_name_io.reset (); auto transaction (system.nodes[0]->wallets.tx_begin_write ()); nano::kdf kdf; nano::wallet_store store (error, kdf, transaction, nano::genesis_account, 1, "0", wallet_json); @@ -968,6 +1019,8 @@ TEST (rpc, wallet_export) TEST (rpc, wallet_destroy) { nano::system system (24000, 1); + system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); + scoped_io_thread_name_change scoped_thread_name_io; auto wallet_id (system.nodes[0]->wallets.items.begin ()->first); auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); @@ -977,7 +1030,6 @@ TEST (rpc, wallet_destroy) nano::ipc_rpc_processor ipc_rpc_processor (system.io_ctx, rpc_config); nano::rpc rpc (system.io_ctx, rpc_config, ipc_rpc_processor); rpc.start (); - system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); boost::property_tree::ptree request; request.put ("action", "wallet_destroy"); request.put ("wallet", wallet_id.to_string ()); @@ -995,6 +1047,13 @@ TEST (rpc, account_move) { nano::system system (24000, 1); auto wallet_id (system.nodes[0]->wallets.items.begin ()->first); + auto destination (system.wallet (0)); + destination->insert_adhoc (nano::test_genesis_key.prv); + nano::keypair key; + nano::keypair source_id; + auto source (system.nodes[0]->wallets.create (source_id.pub)); + source->insert_adhoc (key.prv); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -1003,12 +1062,6 @@ TEST (rpc, account_move) nano::ipc_rpc_processor ipc_rpc_processor (system.io_ctx, rpc_config); nano::rpc rpc (system.io_ctx, rpc_config, ipc_rpc_processor); rpc.start (); - auto destination (system.wallet (0)); - nano::keypair key; - destination->insert_adhoc (nano::test_genesis_key.prv); - nano::keypair source_id; - auto source (system.nodes[0]->wallets.create (source_id.pub)); - source->insert_adhoc (key.prv); boost::property_tree::ptree request; request.put ("action", "account_move"); request.put ("wallet", wallet_id.to_string ()); @@ -1035,6 +1088,7 @@ TEST (rpc, account_move) TEST (rpc, block) { nano::system system (24000, 1); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -1061,6 +1115,7 @@ TEST (rpc, block) TEST (rpc, block_account) { nano::system system (24000, 1); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -1095,6 +1150,7 @@ TEST (rpc, chain) auto block (system.wallet (0)->send_action (nano::test_genesis_key.pub, key.pub, 1)); ASSERT_NE (nullptr, block); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -1134,6 +1190,7 @@ TEST (rpc, chain_limit) auto block (system.wallet (0)->send_action (nano::test_genesis_key.pub, key.pub, 1)); ASSERT_NE (nullptr, block); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -1172,6 +1229,7 @@ TEST (rpc, chain_offset) auto block (system.wallet (0)->send_action (nano::test_genesis_key.pub, key.pub, 1)); ASSERT_NE (nullptr, block); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -1215,6 +1273,7 @@ TEST (rpc, frontier) system.nodes[0]->store.account_put (transaction, key.pub, nano::account_info (key.prv.data, 0, 0, 0, 0, 0, nano::epoch::epoch_0)); } } + scoped_io_thread_name_change scoped_thread_name_io; nano::keypair key; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); @@ -1263,6 +1322,8 @@ TEST (rpc, frontier_limited) system.nodes[0]->store.account_put (transaction, key.pub, nano::account_info (key.prv.data, 0, 0, 0, 0, 0, nano::epoch::epoch_0)); } } + + scoped_io_thread_name_change scoped_thread_name_io; nano::keypair key; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); @@ -1301,6 +1362,7 @@ TEST (rpc, frontier_startpoint) system.nodes[0]->store.account_put (transaction, key.pub, nano::account_info (key.prv.data, 0, 0, 0, 0, 0, nano::epoch::epoch_0)); } } + scoped_io_thread_name_change scoped_thread_name_io; nano::keypair key; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); @@ -1347,6 +1409,7 @@ TEST (rpc, history) ASSERT_EQ (nano::process_result::progress, node0->ledger.process (transaction, ureceive).code); ASSERT_EQ (nano::process_result::progress, node0->ledger.process (transaction, uchange).code); } + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node0->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node0, node_rpc_config); @@ -1416,6 +1479,7 @@ TEST (rpc, account_history) ASSERT_EQ (nano::process_result::progress, node0->ledger.process (transaction, ureceive).code); ASSERT_EQ (nano::process_result::progress, node0->ledger.process (transaction, uchange).code); } + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node0->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node0, node_rpc_config); @@ -1488,10 +1552,12 @@ TEST (rpc, account_history) } // Test filtering + scoped_thread_name_io.reset (); auto account2 (system.wallet (0)->deterministic_insert ()); auto send2 (system.wallet (0)->send_action (nano::test_genesis_key.pub, account2, system.nodes[0]->config.receive_minimum.number ())); ASSERT_NE (nullptr, send2); auto receive2 (system.wallet (0)->receive_action (*send2, account2, system.nodes[0]->config.receive_minimum.number ())); + scoped_thread_name_io.renew (); ASSERT_NE (nullptr, receive2); { boost::property_tree::ptree request; @@ -1523,6 +1589,7 @@ TEST (rpc, history_count) ASSERT_NE (nullptr, send); auto receive (system.wallet (0)->receive_action (*send, nano::test_genesis_key.pub, system.nodes[0]->config.receive_minimum.number ())); ASSERT_NE (nullptr, receive); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -1549,6 +1616,7 @@ TEST (rpc, history_count) TEST (rpc, process_block) { nano::system system (24000, 1); + scoped_io_thread_name_change scoped_thread_name_io; nano::keypair key; auto latest (system.nodes[0]->latest (nano::test_genesis_key.pub)); auto & node1 (*system.nodes[0]); @@ -1644,6 +1712,7 @@ TEST (rpc, process_block_with_work_watcher) TEST (rpc, process_block_no_work) { nano::system system (24000, 1); + scoped_io_thread_name_change scoped_thread_name_io; nano::keypair key; auto latest (system.nodes[0]->latest (nano::test_genesis_key.pub)); auto & node1 (*system.nodes[0]); @@ -1674,6 +1743,7 @@ TEST (rpc, process_block_no_work) TEST (rpc, process_republish) { nano::system system (24000, 2); + scoped_io_thread_name_change scoped_thread_name_io; nano::keypair key; auto latest (system.nodes[0]->latest (nano::test_genesis_key.pub)); auto & node1 (*system.nodes[0]); @@ -1707,6 +1777,7 @@ TEST (rpc, process_republish) TEST (rpc, process_subtype_send) { nano::system system (24000, 2); + scoped_io_thread_name_change scoped_thread_name_io; nano::keypair key; auto latest (system.nodes[0]->latest (nano::test_genesis_key.pub)); auto & node1 (*system.nodes[0]); @@ -1767,6 +1838,7 @@ TEST (rpc, process_subtype_open) auto transaction (node1.store.tx_begin_write ()); ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, send).code); } + scoped_io_thread_name_change scoped_thread_name_io; node1.active.start (std::make_shared (send)); nano::state_block open (key.pub, 0, key.pub, nano::Gxrb_ratio, send.hash (), key.prv, key.pub, node1.work_generate_blocking (key.pub)); enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); @@ -1824,6 +1896,7 @@ TEST (rpc, process_subtype_receive) auto transaction (node1.store.tx_begin_write ()); ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, send).code); } + scoped_io_thread_name_change scoped_thread_name_io; node1.active.start (std::make_shared (send)); nano::state_block receive (nano::test_genesis_key.pub, send.hash (), nano::test_genesis_key.pub, nano::genesis_amount, send.hash (), nano::test_genesis_key.prv, nano::test_genesis_key.pub, node1.work_generate_blocking (send.hash ())); enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); @@ -1880,6 +1953,7 @@ TEST (rpc, keepalive) node1->start (); system.nodes.push_back (node1); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -1918,6 +1992,7 @@ TEST (rpc, payment_init) nano::keypair wallet_id; auto wallet (node1->wallets.create (wallet_id.pub)); ASSERT_TRUE (node1->wallets.items.find (wallet_id.pub) != node1->wallets.items.end ()); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node1, node_rpc_config); @@ -1945,6 +2020,7 @@ TEST (rpc, payment_begin_end) nano::keypair wallet_id; auto wallet (node1->wallets.create (wallet_id.pub)); ASSERT_TRUE (node1->wallets.items.find (wallet_id.pub) != node1->wallets.items.end ()); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node1, node_rpc_config); @@ -2011,6 +2087,7 @@ TEST (rpc, payment_end_nonempty) auto transaction (node1->wallets.tx_begin_read ()); system.wallet (0)->init_free_accounts (transaction); auto wallet_id (node1->wallets.items.begin ()->first); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node1, node_rpc_config); @@ -2040,6 +2117,7 @@ TEST (rpc, payment_zero_balance) auto transaction (node1->wallets.tx_begin_read ()); system.wallet (0)->init_free_accounts (transaction); auto wallet_id (node1->wallets.items.begin ()->first); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node1, node_rpc_config); @@ -2070,6 +2148,7 @@ TEST (rpc, payment_begin_reuse) nano::keypair wallet_id; auto wallet (node1->wallets.create (wallet_id.pub)); ASSERT_TRUE (node1->wallets.items.find (wallet_id.pub) != node1->wallets.items.end ()); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node1, node_rpc_config); @@ -2129,6 +2208,7 @@ TEST (rpc, payment_begin_locked) wallet->store.rekey (transaction, "1"); ASSERT_TRUE (wallet->store.attempt_password (transaction, "")); } + scoped_io_thread_name_change scoped_thread_name_io; ASSERT_TRUE (node1->wallets.items.find (wallet_id.pub) != node1->wallets.items.end ()); enable_ipc_transport_tcp (node1->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -2157,6 +2237,7 @@ TEST (rpc, payment_wait) nano::keypair key; system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node1, node_rpc_config); @@ -2178,10 +2259,14 @@ TEST (rpc, payment_wait) ASSERT_EQ (200, response1.status); ASSERT_EQ ("nothing", response1.json.get ("status")); request1.put ("timeout", "100000"); + scoped_thread_name_io.reset (); system.wallet (0)->send_action (nano::test_genesis_key.pub, key.pub, nano::Mxrb_ratio); system.alarm.add (std::chrono::steady_clock::now () + std::chrono::milliseconds (500), [&]() { - system.wallet (0)->send_action (nano::test_genesis_key.pub, key.pub, nano::Mxrb_ratio); + system.nodes.front ()->worker.push_task ([&]() { + system.wallet (0)->send_action (nano::test_genesis_key.pub, key.pub, nano::Mxrb_ratio); + }); }); + scoped_thread_name_io.renew (); test_response response2 (request1, rpc.config.port, system.io_ctx); while (response2.status == 0) { @@ -2203,6 +2288,7 @@ TEST (rpc, payment_wait) TEST (rpc, peers) { nano::system system (24000, 2); + scoped_io_thread_name_change scoped_thread_name_io; nano::endpoint endpoint (boost::asio::ip::address_v6::from_string ("fc00::1"), 4000); auto node = system.nodes.front (); node->network.udp_channels.insert (endpoint, nano::protocol_version); @@ -2234,6 +2320,7 @@ TEST (rpc, peers) TEST (rpc, peers_node_id) { nano::system system (24000, 2); + scoped_io_thread_name_change scoped_thread_name_io; nano::endpoint endpoint (boost::asio::ip::address_v6::from_string ("fc00::1"), 4000); auto node = system.nodes.front (); node->network.udp_channels.insert (endpoint, nano::protocol_version); @@ -2272,6 +2359,7 @@ TEST (rpc, pending) nano::keypair key1; system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); auto block1 (system.wallet (0)->send_action (nano::test_genesis_key.pub, key1.pub, 100)); + scoped_io_thread_name_change scoped_thread_name_io; system.deadline_set (5s); while (system.nodes[0]->active.active (*block1)) { @@ -2400,7 +2488,9 @@ TEST (rpc, pending) request.put ("include_only_confirmed", "true"); check_block_response_count (1); + scoped_thread_name_io.reset (); reset_confirmation_height (system.nodes.front ()->store, block1->account ()); + scoped_thread_name_io.renew (); check_block_response_count (0); } @@ -2415,6 +2505,7 @@ TEST (rpc, search_pending) auto transaction (system.nodes[0]->store.tx_begin_write ()); ASSERT_EQ (nano::process_result::progress, system.nodes[0]->ledger.process (transaction, block).code); } + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -2447,6 +2538,7 @@ TEST (rpc, version) nano::keypair key; system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node1, node_rpc_config); @@ -2498,6 +2590,7 @@ TEST (rpc, work_generate) nano::keypair key; system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -2532,6 +2625,7 @@ TEST (rpc, work_generate_difficulty) { nano::system system (24000, 1); auto node (system.nodes[0]); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -2603,6 +2697,7 @@ TEST (rpc, work_generate_multiplier) { nano::system system (24000, 1); auto node (system.nodes[0]); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -2673,6 +2768,7 @@ TEST (rpc, work_cancel) nano::keypair key; system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -2710,6 +2806,7 @@ TEST (rpc, work_peer_bad) nano::keypair key; system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -2738,6 +2835,7 @@ TEST (rpc, work_peer_one) nano::keypair key; system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -2771,6 +2869,7 @@ TEST (rpc, work_peer_many) nano::keypair key; nano::rpc_config config2 (true); config2.port += 0; + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node2.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server2 (node2, node_rpc_config); @@ -2817,6 +2916,7 @@ TEST (rpc, block_count) { nano::system system (24000, 1); auto & node1 (*system.nodes[0]); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -2885,6 +2985,7 @@ TEST (rpc, frontier_count) { nano::system system (24000, 1); auto & node1 (*system.nodes[0]); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -2908,6 +3009,7 @@ TEST (rpc, account_count) { nano::system system (24000, 1); auto & node1 (*system.nodes[0]); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -2931,6 +3033,7 @@ TEST (rpc, available_supply) { nano::system system (24000, 1); auto & node1 (*system.nodes[0]); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -2948,9 +3051,11 @@ TEST (rpc, available_supply) } ASSERT_EQ (200, response1.status); ASSERT_EQ ("0", response1.json.get ("available")); + scoped_thread_name_io.reset (); system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); nano::keypair key; auto block (system.wallet (0)->send_action (nano::test_genesis_key.pub, key.pub, 1)); + scoped_thread_name_io.renew (); test_response response2 (request1, rpc.config.port, system.io_ctx); system.deadline_set (5s); while (response2.status == 0) @@ -2959,7 +3064,9 @@ TEST (rpc, available_supply) } ASSERT_EQ (200, response2.status); ASSERT_EQ ("1", response2.json.get ("available")); + scoped_thread_name_io.reset (); auto block2 (system.wallet (0)->send_action (nano::test_genesis_key.pub, 0, 100)); // Sending to burning 0 account + scoped_thread_name_io.renew (); test_response response3 (request1, rpc.config.port, system.io_ctx); system.deadline_set (5s); while (response3.status == 0) @@ -2974,6 +3081,7 @@ TEST (rpc, mrai_to_raw) { nano::system system (24000, 1); auto & node1 (*system.nodes[0]); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -2998,6 +3106,7 @@ TEST (rpc, mrai_from_raw) { nano::system system (24000, 1); auto & node1 (*system.nodes[0]); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -3022,6 +3131,7 @@ TEST (rpc, krai_to_raw) { nano::system system (24000, 1); auto & node1 (*system.nodes[0]); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -3046,6 +3156,7 @@ TEST (rpc, krai_from_raw) { nano::system system (24000, 1); auto & node1 (*system.nodes[0]); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -3070,6 +3181,7 @@ TEST (rpc, nano_to_raw) { nano::system system (24000, 1); auto & node1 (*system.nodes[0]); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -3094,6 +3206,7 @@ TEST (rpc, nano_from_raw) { nano::system system (24000, 1); auto & node1 (*system.nodes[0]); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -3118,6 +3231,7 @@ TEST (rpc, account_representative) { nano::system system (24000, 1); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -3143,6 +3257,7 @@ TEST (rpc, account_representative_set) { nano::system system (24000, 1); system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -3183,6 +3298,7 @@ TEST (rpc, bootstrap) auto transaction (system1.nodes[0]->store.tx_begin_write ()); ASSERT_EQ (nano::process_result::progress, system1.nodes[0]->ledger.process (transaction, send).code); } + scoped_io_thread_name_change scoped_thread_name_io; auto & node = system0.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -3212,6 +3328,7 @@ TEST (rpc, account_remove) { nano::system system0 (24000, 1); auto key1 (system0.wallet (0)->deterministic_insert ()); + scoped_io_thread_name_change scoped_thread_name_io; ASSERT_TRUE (system0.wallet (0)->exists (key1)); auto & node = system0.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); @@ -3237,6 +3354,7 @@ TEST (rpc, representatives) { nano::system system0 (24000, 1); auto & node = system0.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -3273,6 +3391,7 @@ TEST (rpc, wallet_seed) auto transaction (system.nodes[0]->wallets.tx_begin_read ()); system.wallet (0)->store.seed (seed, transaction); } + scoped_io_thread_name_change scoped_thread_name_io; auto & node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -3307,6 +3426,7 @@ TEST (rpc, wallet_change_seed) system0.wallet (0)->store.seed (seed0, transaction); ASSERT_NE (seed.pub, seed0.data); } + scoped_io_thread_name_change scoped_thread_name_io; nano::raw_key prv; nano::deterministic_key (seed.pub, 0, prv.data); auto pub (nano::pub_key (prv.data)); @@ -3347,6 +3467,7 @@ TEST (rpc, wallet_frontiers) { nano::system system0 (24000, 1); system0.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); + scoped_io_thread_name_change scoped_thread_name_io; auto & node = system0.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -3382,6 +3503,7 @@ TEST (rpc, work_validate) nano::keypair key; system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -3485,6 +3607,7 @@ TEST (rpc, successors) ASSERT_FALSE (genesis.is_zero ()); auto block (system.wallet (0)->send_action (nano::test_genesis_key.pub, key.pub, 1)); ASSERT_NE (nullptr, block); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -3535,6 +3658,7 @@ TEST (rpc, bootstrap_any) auto transaction (system1.nodes[0]->store.tx_begin_write ()); ASSERT_EQ (nano::process_result::progress, system1.nodes[0]->ledger.process (transaction, send).code); } + scoped_io_thread_name_change scoped_thread_name_io; auto & node = system0.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -3565,6 +3689,7 @@ TEST (rpc, republish) node1.process (send); nano::open_block open (send.hash (), key.pub, key.pub, key.prv, key.pub, node1.work_generate_blocking (key.pub)); ASSERT_EQ (nano::process_result::progress, node1.process (open).code); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -3647,6 +3772,7 @@ TEST (rpc, deterministic_key) nano::account account1 (system0.wallet (0)->deterministic_insert ()); nano::account account2 (system0.wallet (0)->deterministic_insert ()); auto & node = system0.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -3682,6 +3808,7 @@ TEST (rpc, accounts_balances) { nano::system system (24000, 1); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -3719,6 +3846,7 @@ TEST (rpc, accounts_frontiers) nano::system system (24000, 1); system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -3755,6 +3883,7 @@ TEST (rpc, accounts_pending) nano::keypair key1; system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); auto block1 (system.wallet (0)->send_action (nano::test_genesis_key.pub, key1.pub, 100)); + scoped_io_thread_name_change scoped_thread_name_io; system.deadline_set (5s); while (system.nodes[0]->active.active (*block1)) { @@ -3867,7 +3996,9 @@ TEST (rpc, accounts_pending) request.put ("include_only_confirmed", "true"); check_block_response_count (system, rpc, request, 1); + scoped_thread_name_io.reset (); reset_confirmation_height (system.nodes.front ()->store, block1->account ()); + scoped_thread_name_io.renew (); check_block_response_count (system, rpc, request, 0); } @@ -3875,6 +4006,7 @@ TEST (rpc, blocks) { nano::system system (24000, 1); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -3919,6 +4051,7 @@ TEST (rpc, wallet_info) } account = system.wallet (0)->deterministic_insert (); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -3955,6 +4088,7 @@ TEST (rpc, wallet_balances) nano::system system0 (24000, 1); system0.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); auto & node = system0.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -3981,8 +4115,10 @@ TEST (rpc, wallet_balances) ASSERT_EQ ("0", pending_text); } nano::keypair key; + scoped_thread_name_io.reset (); system0.wallet (0)->insert_adhoc (key.prv); auto send (system0.wallet (0)->send_action (nano::test_genesis_key.pub, key.pub, 1)); + scoped_thread_name_io.renew (); request.put ("threshold", "2"); test_response response1 (request, rpc.config.port, system0.io_ctx); while (response1.status == 0) @@ -4008,6 +4144,7 @@ TEST (rpc, pending_exists) system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); auto hash0 (system.nodes[0]->latest (nano::genesis_account)); auto block1 (system.wallet (0)->send_action (nano::test_genesis_key.pub, key1.pub, 100)); + scoped_io_thread_name_change scoped_thread_name_io; system.deadline_set (5s); while (system.nodes[0]->active.active (*block1)) { @@ -4044,7 +4181,9 @@ TEST (rpc, pending_exists) request.put ("include_only_confirmed", "true"); pending_exists ("1"); + scoped_thread_name_io.reset (); reset_confirmation_height (system.nodes.front ()->store, block1->account ()); + scoped_thread_name_io.renew (); pending_exists ("0"); } @@ -4056,6 +4195,7 @@ TEST (rpc, wallet_pending) system0.wallet (0)->insert_adhoc (key1.prv); auto block1 (system0.wallet (0)->send_action (nano::test_genesis_key.pub, key1.pub, 100)); auto iterations (0); + scoped_io_thread_name_change scoped_thread_name_io; while (system0.nodes[0]->active.active (*block1)) { system0.poll (); @@ -4154,8 +4294,9 @@ TEST (rpc, wallet_pending) request.put ("include_only_confirmed", "true"); check_block_response_count (system0, rpc, request, 1); + scoped_thread_name_io.reset (); reset_confirmation_height (system0.nodes.front ()->store, block1->account ()); - + scoped_thread_name_io.renew (); { test_response response (request, rpc.config.port, system0.io_ctx); system0.deadline_set (5s); @@ -4172,6 +4313,7 @@ TEST (rpc, receive_minimum) { nano::system system (24000, 1); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -4196,6 +4338,7 @@ TEST (rpc, receive_minimum_set) { nano::system system (24000, 1); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -4225,6 +4368,7 @@ TEST (rpc, work_get) system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); system.wallet (0)->work_cache_blocking (nano::test_genesis_key.pub, system.nodes[0]->latest (nano::test_genesis_key.pub)); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -4256,6 +4400,7 @@ TEST (rpc, wallet_work_get) system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); system.wallet (0)->work_cache_blocking (nano::test_genesis_key.pub, system.nodes[0]->latest (nano::test_genesis_key.pub)); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -4291,6 +4436,7 @@ TEST (rpc, work_set) system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); uint64_t work0 (100); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -4328,6 +4474,7 @@ TEST (rpc, search_pending_all) auto transaction (system.nodes[0]->store.tx_begin_write ()); ASSERT_EQ (nano::process_result::progress, system.nodes[0]->ledger.process (transaction, block).code); } + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -4371,6 +4518,7 @@ TEST (rpc, wallet_republish) system.nodes[0]->process (send); nano::open_block open (send.hash (), key.pub, key.pub, key.prv, key.pub, node1.work_generate_blocking (key.pub)); ASSERT_EQ (nano::process_result::progress, system.nodes[0]->process (open).code); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -4413,6 +4561,7 @@ TEST (rpc, delegators) nano::open_block open (send.hash (), nano::test_genesis_key.pub, key.pub, key.prv, key.pub, node1.work_generate_blocking (key.pub)); ASSERT_EQ (nano::process_result::progress, system.nodes[0]->process (open).code); enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); + scoped_io_thread_name_change scoped_thread_name_io; nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); nano::rpc_config rpc_config (true); @@ -4452,6 +4601,7 @@ TEST (rpc, delegators_count) node1.process (send); nano::open_block open (send.hash (), nano::test_genesis_key.pub, key.pub, key.prv, key.pub, node1.work_generate_blocking (key.pub)); ASSERT_EQ (nano::process_result::progress, system.nodes[0]->process (open).code); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -4480,6 +4630,7 @@ TEST (rpc, account_info) nano::genesis genesis; auto & node1 (*system.nodes[0]); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -4506,6 +4657,7 @@ TEST (rpc, account_info) ASSERT_EQ (error.get (), std::error_code (nano::error_common::account_not_found).message ()); } + scoped_thread_name_io.reset (); system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); auto latest (system.nodes[0]->latest (nano::test_genesis_key.pub)); @@ -4516,6 +4668,7 @@ TEST (rpc, account_info) auto transaction = node1.store.tx_begin_write (); node1.store.confirmation_height_put (transaction, nano::test_genesis_key.pub, 1); } + scoped_thread_name_io.renew (); request.put ("account", nano::test_genesis_key.pub.to_account ()); { @@ -4575,8 +4728,10 @@ TEST (rpc, json_block_input) { nano::system system (24000, 1); nano::keypair key; + system.wallet (0)->insert_adhoc (key.prv); auto & node1 (*system.nodes[0]); nano::state_block send (nano::genesis_account, node1.latest (nano::test_genesis_key.pub), nano::genesis_account, nano::genesis_amount - nano::Gxrb_ratio, key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -4587,7 +4742,6 @@ TEST (rpc, json_block_input) boost::property_tree::ptree request; request.put ("action", "sign"); request.put ("json_block", "true"); - system.wallet (0)->insert_adhoc (key.prv); std::string wallet; system.nodes[0]->wallets.items.begin ()->first.encode_hex (wallet); request.put ("wallet", wallet); @@ -4622,6 +4776,7 @@ TEST (rpc, json_block_output) auto latest (system.nodes[0]->latest (nano::test_genesis_key.pub)); nano::send_block send (latest, key.pub, 100, nano::test_genesis_key.prv, nano::test_genesis_key.pub, node1.work_generate_blocking (latest)); system.nodes[0]->process (send); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -4651,6 +4806,7 @@ TEST (rpc, blocks_info) { nano::system system (24000, 1); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -4757,6 +4913,7 @@ TEST (rpc, blocks_info_subtype) ASSERT_NE (nullptr, receive); auto change (system.wallet (0)->change_action (nano::test_genesis_key.pub, key.pub)); ASSERT_NE (nullptr, change); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -4796,6 +4953,7 @@ TEST (rpc, work_peers_all) nano::system system (24000, 1); auto & node1 (*system.nodes[0]); system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -4864,6 +5022,7 @@ TEST (rpc, block_count_type) auto receive (system.wallet (0)->receive_action (*send, nano::test_genesis_key.pub, system.nodes[0]->config.receive_minimum.number ())); ASSERT_NE (nullptr, receive); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -4909,6 +5068,7 @@ TEST (rpc, ledger) nano::open_block open (send.hash (), nano::test_genesis_key.pub, key.pub, key.prv, key.pub, node1.work_generate_blocking (key.pub)); ASSERT_EQ (nano::process_result::progress, node1.process (open).code); auto time (nano::seconds_since_epoch ()); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -4995,7 +5155,9 @@ TEST (rpc, ledger) auto send2_amount (50); genesis_balance -= send2_amount; nano::send_block send2 (send.hash (), key.pub, genesis_balance, nano::test_genesis_key.prv, nano::test_genesis_key.pub, node1.work_generate_blocking (send.hash ())); + scoped_thread_name_io.reset (); node1.process (send2); + scoped_thread_name_io.renew (); // When asking for pending, pending amount is taken into account for threshold so the account must show up request.put ("count", 2); request.put ("threshold", (send_amount + send2_amount).convert_to ()); @@ -5022,6 +5184,7 @@ TEST (rpc, accounts_create) { nano::system system (24000, 1); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -5064,6 +5227,7 @@ TEST (rpc, block_create) nano::send_block send (latest, key.pub, 100, nano::test_genesis_key.prv, nano::test_genesis_key.pub, send_work); auto open_work = node1.work_generate_blocking (key.pub); nano::open_block open (send.hash (), nano::test_genesis_key.pub, key.pub, key.prv, key.pub, open_work); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -5095,7 +5259,9 @@ TEST (rpc, block_create) boost::property_tree::read_json (block_stream, block_l); auto send_block (nano::deserialize_block_json (block_l)); ASSERT_EQ (send.hash (), send_block->hash ()); + scoped_thread_name_io.reset (); system.nodes[0]->process (send); + scoped_thread_name_io.renew (); boost::property_tree::ptree request1; request1.put ("action", "block_create"); request1.put ("type", "open"); @@ -5119,7 +5285,9 @@ TEST (rpc, block_create) boost::property_tree::read_json (block_stream1, block_l); auto open_block (nano::deserialize_block_json (block_l)); ASSERT_EQ (open.hash (), open_block->hash ()); + scoped_thread_name_io.reset (); ASSERT_EQ (nano::process_result::progress, system.nodes[0]->process (open).code); + scoped_thread_name_io.renew (); request1.put ("representative", key.pub.to_account ()); test_response response2 (request1, rpc.config.port, system.io_ctx); system.deadline_set (5s); @@ -5148,9 +5316,11 @@ TEST (rpc, block_create) boost::property_tree::read_json (block_stream4, block_l); auto change_block (nano::deserialize_block_json (block_l)); ASSERT_EQ (change.hash (), change_block->hash ()); + scoped_thread_name_io.reset (); ASSERT_EQ (nano::process_result::progress, node1.process (change).code); nano::send_block send2 (send.hash (), key.pub, 0, nano::test_genesis_key.prv, nano::test_genesis_key.pub, node1.work_generate_blocking (send.hash ())); ASSERT_EQ (nano::process_result::progress, system.nodes[0]->process (send2).code); + scoped_thread_name_io.renew (); boost::property_tree::ptree request2; request2.put ("action", "block_create"); request2.put ("type", "receive"); @@ -5194,6 +5364,7 @@ TEST (rpc, block_create_state) request.put ("link", key.pub.to_account ()); request.put ("work", nano::to_string_hex (system.nodes[0]->work_generate_blocking (genesis.hash ()))); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -5217,6 +5388,7 @@ TEST (rpc, block_create_state) ASSERT_NE (nullptr, state_block); ASSERT_EQ (nano::block_type::state, state_block->type ()); ASSERT_EQ (state_hash, state_block->hash ().to_string ()); + scoped_thread_name_io.reset (); auto process_result (system.nodes[0]->process (*state_block)); ASSERT_EQ (nano::process_result::progress, process_result.code); } @@ -5240,6 +5412,7 @@ TEST (rpc, block_create_state_open) request.put ("link", send_block->hash ().to_string ()); request.put ("work", nano::to_string_hex (system.nodes[0]->work_generate_blocking (key.pub))); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -5264,6 +5437,7 @@ TEST (rpc, block_create_state_open) ASSERT_EQ (nano::block_type::state, state_block->type ()); ASSERT_EQ (state_hash, state_block->hash ().to_string ()); ASSERT_TRUE (system.nodes[0]->latest (key.pub).is_zero ()); + scoped_thread_name_io.reset (); auto process_result (system.nodes[0]->process (*state_block)); ASSERT_EQ (nano::process_result::progress, process_result.code); ASSERT_FALSE (system.nodes[0]->latest (key.pub).is_zero ()); @@ -5283,6 +5457,7 @@ TEST (rpc, block_create_state_request_work) nano::keypair key; nano::genesis genesis; system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); + scoped_io_thread_name_change scoped_thread_name_io; boost::property_tree::ptree request; request.put ("action", "block_create"); request.put ("type", "state"); @@ -5323,6 +5498,7 @@ TEST (rpc, block_hash) auto latest (system.nodes[0]->latest (nano::test_genesis_key.pub)); auto & node1 (*system.nodes[0]); nano::send_block send (latest, key.pub, 100, nano::test_genesis_key.prv, nano::test_genesis_key.pub, node1.work_generate_blocking (latest)); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -5351,6 +5527,7 @@ TEST (rpc, wallet_lock) nano::system system (24000, 1); auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); + scoped_io_thread_name_change scoped_thread_name_io; nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); nano::rpc_config rpc_config (true); @@ -5383,6 +5560,7 @@ TEST (rpc, wallet_locked) { nano::system system (24000, 1); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -5423,6 +5601,7 @@ TEST (rpc, wallet_create_fail) node->wallets.create (key.pub); } rpc.start (); + scoped_io_thread_name_change scoped_thread_name_io; boost::property_tree::ptree request; request.put ("action", "wallet_create"); test_response response (request, rpc.config.port, system.io_ctx); @@ -5447,6 +5626,7 @@ TEST (rpc, wallet_ledger) nano::open_block open (send.hash (), nano::test_genesis_key.pub, key.pub, key.prv, key.pub, node1.work_generate_blocking (key.pub)); ASSERT_EQ (nano::process_result::progress, node1.process (open).code); auto time (nano::seconds_since_epoch ()); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -5515,6 +5695,7 @@ TEST (rpc, wallet_add_watch) { nano::system system (24000, 1); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -5552,6 +5733,7 @@ TEST (rpc, online_reps) ASSERT_TRUE (system.nodes[1]->online_reps.online_stake () == system.nodes[1]->config.online_weight_minimum.number ()); auto send_block (system.wallet (0)->send_action (nano::test_genesis_key.pub, key.pub, nano::Gxrb_ratio)); ASSERT_NE (nullptr, send_block); + scoped_io_thread_name_change scoped_thread_name_io; system.deadline_set (10s); while (system.nodes[1]->online_reps.list ().empty ()) { @@ -5599,22 +5781,28 @@ TEST (rpc, online_reps) auto weight2 (item2->second.get ("weight")); ASSERT_EQ (system.nodes[1]->weight (nano::test_genesis_key.pub).convert_to (), weight2); //Test accounts filter + scoped_thread_name_io.reset (); auto new_rep (system.wallet (1)->deterministic_insert ()); auto send (system.wallet (0)->send_action (nano::test_genesis_key.pub, new_rep, system.nodes[0]->config.receive_minimum.number ())); + scoped_thread_name_io.renew (); ASSERT_NE (nullptr, send); system.deadline_set (5s); while (system.nodes[1]->block (send->hash ()) == nullptr) { ASSERT_NO_ERROR (system.poll ()); } + scoped_thread_name_io.reset (); auto receive (system.wallet (1)->receive_action (*send, new_rep, system.nodes[0]->config.receive_minimum.number ())); + scoped_thread_name_io.renew (); ASSERT_NE (nullptr, receive); system.deadline_set (5s); while (system.nodes[1]->block (receive->hash ()) == nullptr) { ASSERT_NO_ERROR (system.poll ()); } + scoped_thread_name_io.reset (); auto change (system.wallet (0)->change_action (nano::test_genesis_key.pub, new_rep)); + scoped_thread_name_io.renew (); ASSERT_NE (nullptr, change); system.deadline_set (5s); while (system.nodes[1]->block (change->hash ()) == nullptr) @@ -5673,6 +5861,8 @@ TEST (rpc, confirmation_height_currently_processing) previous_genesis_chain_hash = send.hash (); } + scoped_io_thread_name_change scoped_thread_name_io; + std::shared_ptr frontier; { auto transaction = node->store.tx_begin_read (); @@ -5746,6 +5936,7 @@ TEST (rpc, confirmation_history) system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); ASSERT_TRUE (system.nodes[0]->active.list_confirmed ().empty ()); auto block (system.wallet (0)->send_action (nano::test_genesis_key.pub, key.pub, nano::Gxrb_ratio)); + scoped_io_thread_name_change scoped_thread_name_io; system.deadline_set (10s); while (system.nodes[0]->active.list_confirmed ().empty ()) { @@ -5791,6 +5982,7 @@ TEST (rpc, confirmation_history_hash) auto send1 (system.wallet (0)->send_action (nano::test_genesis_key.pub, key.pub, nano::Gxrb_ratio)); auto send2 (system.wallet (0)->send_action (nano::test_genesis_key.pub, key.pub, nano::Gxrb_ratio)); auto send3 (system.wallet (0)->send_action (nano::test_genesis_key.pub, key.pub, nano::Gxrb_ratio)); + scoped_io_thread_name_change scoped_thread_name_io; system.deadline_set (10s); while (system.nodes[0]->active.list_confirmed ().size () != 3) { @@ -5839,6 +6031,7 @@ TEST (rpc, block_confirm) auto transaction (system.nodes[0]->store.tx_begin_write ()); ASSERT_EQ (nano::process_result::progress, system.nodes[0]->ledger.process (transaction, *send1).code); } + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; @@ -5865,6 +6058,7 @@ TEST (rpc, block_confirm_absent) nano::system system (24000, 1); system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -5905,7 +6099,7 @@ TEST (rpc, block_confirm_confirmed) ASSERT_TRUE (node->ledger.block_confirmed (transaction, genesis.hash ())); } ASSERT_EQ (0, node->stats.count (nano::stat::type::error, nano::stat::detail::http_callback, nano::stat::dir::out)); - + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -5943,6 +6137,7 @@ TEST (rpc, node_id) { nano::system system (24000, 1); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -5969,6 +6164,7 @@ TEST (rpc, stats_clear) nano::system system (24000, 1); nano::keypair key; auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -6004,6 +6200,7 @@ TEST (rpc, unopened) auto send2 (system.wallet (0)->send_action (nano::test_genesis_key.pub, account2, 10)); ASSERT_NE (nullptr, send2); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -6100,6 +6297,7 @@ TEST (rpc, unopened_burn) auto send (system.wallet (0)->send_action (nano::test_genesis_key.pub, nano::burn_account, 1)); ASSERT_NE (nullptr, send); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -6124,6 +6322,7 @@ TEST (rpc, unopened_no_accounts) { nano::system system (24000, 1); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -6148,6 +6347,7 @@ TEST (rpc, uptime) { nano::system system (24000, 1); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -6188,6 +6388,7 @@ TEST (rpc, wallet_history) ASSERT_NE (nullptr, send2); system.deadline_set (10s); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -6244,6 +6445,7 @@ TEST (rpc, sign_hash) nano::keypair key; auto & node1 (*system.nodes[0]); nano::state_block send (nano::genesis_account, node1.latest (nano::test_genesis_key.pub), nano::genesis_account, nano::genesis_amount - nano::Gxrb_ratio, key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -6280,8 +6482,10 @@ TEST (rpc, sign_block) { nano::system system (24000, 1); nano::keypair key; + system.wallet (0)->insert_adhoc (key.prv); auto & node1 (*system.nodes[0]); nano::state_block send (nano::genesis_account, node1.latest (nano::test_genesis_key.pub), nano::genesis_account, nano::genesis_amount - nano::Gxrb_ratio, key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node1.config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (node1, node_rpc_config); @@ -6291,7 +6495,6 @@ TEST (rpc, sign_block) rpc.start (); boost::property_tree::ptree request; request.put ("action", "sign"); - system.wallet (0)->insert_adhoc (key.prv); std::string wallet; system.nodes[0]->wallets.items.begin ()->first.encode_hex (wallet); request.put ("wallet", wallet); @@ -6319,6 +6522,7 @@ TEST (rpc, memory_stats) { nano::system system (24000, 1); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -6352,6 +6556,7 @@ TEST (rpc, block_confirmed) { nano::system system (24000, 1); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -6381,6 +6586,7 @@ TEST (rpc, block_confirmed) ASSERT_EQ (200, response1.status); ASSERT_EQ (std::error_code (nano::error_blocks::not_found).message (), response1.json.get ("error")); + scoped_thread_name_io.reset (); system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); nano::keypair key; system.wallet (0)->insert_adhoc (key.prv); @@ -6395,6 +6601,7 @@ TEST (rpc, block_confirmed) nano::open_block open1 (send1.hash (), nano::genesis_account, key.pub, key.prv, key.pub, system.work.generate (key.pub)); ASSERT_EQ (nano::process_result::progress, node->ledger.process (transaction, open1).code); } + scoped_thread_name_io.renew (); // This should not be confirmed nano::block_hash latest (node->latest (nano::test_genesis_key.pub)); @@ -6454,6 +6661,7 @@ TEST (rpc, database_txn_tracker) { nano::system system (24000, 1); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -6482,6 +6690,7 @@ TEST (rpc, database_txn_tracker) nano::node_config node_config (24000, system.logging); node_config.diagnostics_config.txn_tracking.enable = true; auto node = system.add_node (node_config); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -6578,6 +6787,7 @@ TEST (rpc, active_difficulty) { nano::system system (24000, 1); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -6650,6 +6860,7 @@ TEST (rpc, simultaneous_calls) { // This tests simulatenous calls to the same node in different threads nano::system system (24000, 1); + scoped_io_thread_name_change scoped_thread_name_io; auto node = system.nodes.front (); nano::thread_runner runner (system.io_ctx, node->config.io_threads); enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); @@ -6713,6 +6924,7 @@ TEST (rpc, in_process) { nano::system system (24000, 1); auto node = system.nodes.front (); + scoped_io_thread_name_change scoped_thread_name_io; enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp); nano::rpc_config rpc_config (true); nano::node_rpc_config node_rpc_config; diff --git a/nano/secure/blockstore.cpp b/nano/secure/blockstore.cpp index 54ac9f75..15cb88ae 100644 --- a/nano/secure/blockstore.cpp +++ b/nano/secure/blockstore.cpp @@ -394,6 +394,10 @@ void nano::read_transaction::refresh () const nano::write_transaction::write_transaction (std::unique_ptr write_transaction_impl) : impl (std::move (write_transaction_impl)) { + /* + * For IO threads, we do not want them to block on creating write transactions. + */ + assert (nano::thread_role::get () != nano::thread_role::name::io); } void * nano::write_transaction::get_handle () const