aboutsummaryrefslogtreecommitdiff
path: root/src/daemon
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-02-22 20:17:45 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-03-09 20:51:53 +0000
commit59478c80dd01d00e16994a77e36a94cdbe3c9412 (patch)
tree7feed5e760c8affa62a9277a414942d13a05d2a9 /src/daemon
parentMerge pull request #4988 (diff)
downloadmonero-59478c80dd01d00e16994a77e36a94cdbe3c9412.tar.xz
daemon: new mining_status command
Diffstat (limited to 'src/daemon')
-rw-r--r--src/daemon/command_parser_executor.cpp5
-rw-r--r--src/daemon/command_parser_executor.h2
-rw-r--r--src/daemon/command_server.cpp5
-rw-r--r--src/daemon/rpc_command_executor.cpp77
-rw-r--r--src/daemon/rpc_command_executor.h2
5 files changed, 90 insertions, 1 deletions
diff --git a/src/daemon/command_parser_executor.cpp b/src/daemon/command_parser_executor.cpp
index 73f33a674..5d11dabb1 100644
--- a/src/daemon/command_parser_executor.cpp
+++ b/src/daemon/command_parser_executor.cpp
@@ -404,6 +404,11 @@ bool t_command_parser_executor::stop_mining(const std::vector<std::string>& args
return m_executor.stop_mining();
}
+bool t_command_parser_executor::mining_status(const std::vector<std::string>& args)
+{
+ return m_executor.mining_status();
+}
+
bool t_command_parser_executor::stop_daemon(const std::vector<std::string>& args)
{
if (!args.empty()) return false;
diff --git a/src/daemon/command_parser_executor.h b/src/daemon/command_parser_executor.h
index 5b8927908..de94039c3 100644
--- a/src/daemon/command_parser_executor.h
+++ b/src/daemon/command_parser_executor.h
@@ -97,6 +97,8 @@ public:
bool stop_mining(const std::vector<std::string>& args);
+ bool mining_status(const std::vector<std::string>& args);
+
bool stop_daemon(const std::vector<std::string>& args);
bool print_status(const std::vector<std::string>& args);
diff --git a/src/daemon/command_server.cpp b/src/daemon/command_server.cpp
index 96dea76b6..45a1e9d98 100644
--- a/src/daemon/command_server.cpp
+++ b/src/daemon/command_server.cpp
@@ -113,6 +113,11 @@ t_command_server::t_command_server(
, "Stop mining."
);
m_command_lookup.set_handler(
+ "mining_status"
+ , std::bind(&t_command_parser_executor::mining_status, &m_parser, p::_1)
+ , "Show current mining status."
+ );
+ m_command_lookup.set_handler(
"print_pool"
, std::bind(&t_command_parser_executor::print_transaction_pool_long, &m_parser, p::_1)
, "Print the transaction pool using a long format."
diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp
index 839350522..af7beef46 100644
--- a/src/daemon/rpc_command_executor.cpp
+++ b/src/daemon/rpc_command_executor.cpp
@@ -461,7 +461,7 @@ bool t_rpc_command_executor::show_status() {
% get_sync_percentage(ires)
% (ires.testnet ? "testnet" : ires.stagenet ? "stagenet" : "mainnet")
% bootstrap_msg
- % (!has_mining_info ? "mining info unavailable" : mining_busy ? "syncing" : mres.active ? ( ( mres.is_background_mining_enabled ? "smart " : "" ) + std::string("mining at ") + get_mining_speed(mres.speed) + std::string(" to ") + mres.address ) : "not mining")
+ % (!has_mining_info ? "mining info unavailable" : mining_busy ? "syncing" : mres.active ? ( ( mres.is_background_mining_enabled ? "smart " : "" ) + std::string("mining at ") + get_mining_speed(mres.speed)) : "not mining")
% get_mining_speed(ires.difficulty / ires.target)
% (unsigned)hfres.version
% get_fork_extra_info(hfres.earliest_height, net_height, ires.target)
@@ -486,6 +486,81 @@ bool t_rpc_command_executor::show_status() {
return true;
}
+bool t_rpc_command_executor::mining_status() {
+ cryptonote::COMMAND_RPC_MINING_STATUS::request mreq;
+ cryptonote::COMMAND_RPC_MINING_STATUS::response mres;
+ epee::json_rpc::error error_resp;
+ bool has_mining_info = true;
+
+ std::string fail_message = "Problem fetching info";
+
+ bool mining_busy = false;
+ if (m_is_rpc)
+ {
+ // mining info is only available non unrestricted RPC mode
+ has_mining_info = m_rpc_client->rpc_request(mreq, mres, "/mining_status", fail_message.c_str());
+ }
+ else
+ {
+ if (!m_rpc_server->on_mining_status(mreq, mres))
+ {
+ tools::fail_msg_writer() << fail_message.c_str();
+ return true;
+ }
+
+ if (mres.status == CORE_RPC_STATUS_BUSY)
+ {
+ mining_busy = true;
+ }
+ else if (mres.status != CORE_RPC_STATUS_OK)
+ {
+ tools::fail_msg_writer() << make_error(fail_message, mres.status);
+ return true;
+ }
+ }
+
+ if (!has_mining_info)
+ {
+ tools::fail_msg_writer() << "Mining info unavailable";
+ return true;
+ }
+
+ if (mining_busy || !mres.active)
+ {
+ tools::msg_writer() << "Not currently mining";
+ }
+ else
+ {
+ tools::msg_writer() << "Mining at " << get_mining_speed(mres.speed) << " with " << mres.threads_count << " threads";
+ }
+
+ if (mres.active || mres.is_background_mining_enabled)
+ {
+ tools::msg_writer() << "PoW algorithm: " << mres.pow_algorithm;
+ tools::msg_writer() << "Mining address: " << mres.address;
+ }
+
+ if (mres.is_background_mining_enabled)
+ {
+ tools::msg_writer() << "Smart mining enabled:";
+ tools::msg_writer() << " Target: " << (unsigned)mres.bg_target << "% CPU";
+ tools::msg_writer() << " Idle threshold: " << (unsigned)mres.bg_idle_threshold << "% CPU";
+ tools::msg_writer() << " Min idle time: " << (unsigned)mres.bg_min_idle_seconds << " seconds";
+ tools::msg_writer() << " Ignore battery: " << (mres.bg_ignore_battery ? "yes" : "no");
+ }
+
+ if (!mining_busy && mres.active)
+ {
+ uint64_t daily = 86400ull / mres.block_target * mres.block_reward;
+ uint64_t monthly = 86400ull / mres.block_target * 30.5 * mres.block_reward;
+ uint64_t yearly = 86400ull / mres.block_target * 356 * mres.block_reward;
+ tools::msg_writer() << "Expected: " << cryptonote::print_money(daily) << " monero daily, "
+ << cryptonote::print_money(monthly) << " monero monthly, " << cryptonote::print_money(yearly) << " yearly";
+ }
+
+ return true;
+}
+
bool t_rpc_command_executor::print_connections() {
cryptonote::COMMAND_RPC_GET_CONNECTIONS::request req;
cryptonote::COMMAND_RPC_GET_CONNECTIONS::response res;
diff --git a/src/daemon/rpc_command_executor.h b/src/daemon/rpc_command_executor.h
index b1e9828a0..5221a8cf1 100644
--- a/src/daemon/rpc_command_executor.h
+++ b/src/daemon/rpc_command_executor.h
@@ -109,6 +109,8 @@ public:
bool stop_mining();
+ bool mining_status();
+
bool stop_daemon();
bool print_status();