diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2019-10-22 15:28:08 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2019-10-25 18:41:54 +0000 |
commit | a4dc575ccba8348886ed19594a16f5a7242f8fe6 (patch) | |
tree | e6afd9cd4b734b336e74af84931aa45a87f9e3eb /src/daemon | |
parent | Merge pull request #5357 (diff) | |
download | monero-a4dc575ccba8348886ed19594a16f5a7242f8fe6.tar.xz |
rpc: add a flush_cache RPC
This allows flushing internal caches (for now, the bad tx cache,
which will allow debugging a stuck monerod after it has failed to
verify a transaction in a block, since it would otherwise not try
again, making subsequent log changes pointless)
Diffstat (limited to 'src/daemon')
-rw-r--r-- | src/daemon/command_parser_executor.cpp | 12 | ||||
-rw-r--r-- | src/daemon/command_parser_executor.h | 2 | ||||
-rw-r--r-- | src/daemon/command_server.cpp | 6 | ||||
-rw-r--r-- | src/daemon/rpc_command_executor.cpp | 28 | ||||
-rw-r--r-- | src/daemon/rpc_command_executor.h | 2 |
5 files changed, 50 insertions, 0 deletions
diff --git a/src/daemon/command_parser_executor.cpp b/src/daemon/command_parser_executor.cpp index 8e78f3bd1..b827221f6 100644 --- a/src/daemon/command_parser_executor.cpp +++ b/src/daemon/command_parser_executor.cpp @@ -844,4 +844,16 @@ bool t_command_parser_executor::set_bootstrap_daemon(const std::vector<std::stri args_count > 2 ? args[2] : std::string()); } +bool t_command_parser_executor::flush_cache(const std::vector<std::string>& args) +{ + if (args.empty()) + goto show_list; + if (args[0] == "bad-txs") + return m_executor.flush_cache(true); + +show_list: + std::cout << "Cache type needed: bad-txs" << std::endl; + return true; +} + } // namespace daemonize diff --git a/src/daemon/command_parser_executor.h b/src/daemon/command_parser_executor.h index 5c94c540e..8b85dcf69 100644 --- a/src/daemon/command_parser_executor.h +++ b/src/daemon/command_parser_executor.h @@ -154,6 +154,8 @@ public: bool print_net_stats(const std::vector<std::string>& args); bool set_bootstrap_daemon(const std::vector<std::string>& args); + + bool flush_cache(const std::vector<std::string>& args); }; } // namespace daemonize diff --git a/src/daemon/command_server.cpp b/src/daemon/command_server.cpp index b00e253c7..8ec690631 100644 --- a/src/daemon/command_server.cpp +++ b/src/daemon/command_server.cpp @@ -322,6 +322,12 @@ t_command_server::t_command_server( , "URL of a 'bootstrap' remote daemon that the connected wallets can use while this daemon is still not fully synced.\n" "Use 'auto' to enable automatic public nodes discovering and bootstrap daemon switching" ); + m_command_lookup.set_handler( + "flush_cache" + , std::bind(&t_command_parser_executor::flush_cache, &m_parser, p::_1) + , "flush_cache bad-txs" + , "Flush the specified cache(s)." + ); } bool t_command_server::process_command_str(const std::string& cmd) diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index 552862d2f..ed614a89b 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -2373,6 +2373,34 @@ bool t_rpc_command_executor::set_bootstrap_daemon( return true; } +bool t_rpc_command_executor::flush_cache(bool bad_txs) +{ + cryptonote::COMMAND_RPC_FLUSH_CACHE::request req; + cryptonote::COMMAND_RPC_FLUSH_CACHE::response res; + std::string fail_message = "Unsuccessful"; + epee::json_rpc::error error_resp; + + req.bad_txs = bad_txs; + + if (m_is_rpc) + { + if (!m_rpc_client->json_rpc_request(req, res, "flush_cache", fail_message.c_str())) + { + return true; + } + } + else + { + if (!m_rpc_server->on_flush_cache(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK) + { + tools::fail_msg_writer() << make_error(fail_message, res.status); + return true; + } + } + + return true; +} + bool t_rpc_command_executor::rpc_payments() { cryptonote::COMMAND_RPC_ACCESS_DATA::request req; diff --git a/src/daemon/rpc_command_executor.h b/src/daemon/rpc_command_executor.h index 783b47373..e8b12cb9b 100644 --- a/src/daemon/rpc_command_executor.h +++ b/src/daemon/rpc_command_executor.h @@ -169,6 +169,8 @@ public: const std::string &password); bool rpc_payments(); + + bool flush_cache(bool bad_txs); }; } // namespace daemonize |