daemon: add a status command
Displays current block height and target, net hash, hard fork basic info, and connections. Useful as a basic user friendly "what's going on here" command.
This commit is contained in:
parent
14dd279fe1
commit
9caf52bf5a
|
@ -75,6 +75,13 @@ bool t_command_parser_executor::show_difficulty(const std::vector<std::string>&
|
||||||
return m_executor.show_difficulty();
|
return m_executor.show_difficulty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool t_command_parser_executor::show_status(const std::vector<std::string>& args)
|
||||||
|
{
|
||||||
|
if (!args.empty()) return false;
|
||||||
|
|
||||||
|
return m_executor.show_status();
|
||||||
|
}
|
||||||
|
|
||||||
bool t_command_parser_executor::print_connections(const std::vector<std::string>& args)
|
bool t_command_parser_executor::print_connections(const std::vector<std::string>& args)
|
||||||
{
|
{
|
||||||
if (!args.empty()) return false;
|
if (!args.empty()) return false;
|
||||||
|
|
|
@ -63,6 +63,8 @@ public:
|
||||||
|
|
||||||
bool show_difficulty(const std::vector<std::string>& args);
|
bool show_difficulty(const std::vector<std::string>& args);
|
||||||
|
|
||||||
|
bool show_status(const std::vector<std::string>& args);
|
||||||
|
|
||||||
bool print_connections(const std::vector<std::string>& args);
|
bool print_connections(const std::vector<std::string>& args);
|
||||||
|
|
||||||
bool print_blockchain_info(const std::vector<std::string>& args);
|
bool print_blockchain_info(const std::vector<std::string>& args);
|
||||||
|
|
|
@ -134,6 +134,11 @@ t_command_server::t_command_server(
|
||||||
, std::bind(&t_command_parser_executor::show_difficulty, &m_parser, p::_1)
|
, std::bind(&t_command_parser_executor::show_difficulty, &m_parser, p::_1)
|
||||||
, "Show difficulty"
|
, "Show difficulty"
|
||||||
);
|
);
|
||||||
|
m_command_lookup.set_handler(
|
||||||
|
"status"
|
||||||
|
, std::bind(&t_command_parser_executor::show_status, &m_parser, p::_1)
|
||||||
|
, "Show status"
|
||||||
|
);
|
||||||
m_command_lookup.set_handler(
|
m_command_lookup.set_handler(
|
||||||
"stop_daemon"
|
"stop_daemon"
|
||||||
, std::bind(&t_command_parser_executor::stop_daemon, &m_parser, p::_1)
|
, std::bind(&t_command_parser_executor::stop_daemon, &m_parser, p::_1)
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include "daemon/rpc_command_executor.h"
|
#include "daemon/rpc_command_executor.h"
|
||||||
#include "rpc/core_rpc_server_commands_defs.h"
|
#include "rpc/core_rpc_server_commands_defs.h"
|
||||||
#include "cryptonote_core/cryptonote_core.h"
|
#include "cryptonote_core/cryptonote_core.h"
|
||||||
|
#include "cryptonote_core/hardfork.h"
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -246,6 +247,60 @@ bool t_rpc_command_executor::show_difficulty() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool t_rpc_command_executor::show_status() {
|
||||||
|
cryptonote::COMMAND_RPC_GET_INFO::request ireq;
|
||||||
|
cryptonote::COMMAND_RPC_GET_INFO::response ires;
|
||||||
|
cryptonote::COMMAND_RPC_HARD_FORK_INFO::request hfreq;
|
||||||
|
cryptonote::COMMAND_RPC_HARD_FORK_INFO::response hfres;
|
||||||
|
epee::json_rpc::error error_resp;
|
||||||
|
|
||||||
|
std::string fail_message = "Problem fetching info";
|
||||||
|
|
||||||
|
if (m_is_rpc)
|
||||||
|
{
|
||||||
|
if (!m_rpc_client->rpc_request(ireq, ires, "/getinfo", fail_message.c_str()))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!m_rpc_client->rpc_request(hfreq, hfres, "/hard_fork_info", fail_message.c_str()))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!m_rpc_server->on_get_info(ireq, ires))
|
||||||
|
{
|
||||||
|
tools::fail_msg_writer() << fail_message.c_str();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!m_rpc_server->on_hard_fork_info(hfreq, hfres, error_resp))
|
||||||
|
{
|
||||||
|
tools::fail_msg_writer() << fail_message.c_str();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tools::success_msg_writer() << boost::format("Height: %llu/%llu (%.1f%%) on %s, net hash %s, v%u, %s, %u+%u connections")
|
||||||
|
% (unsigned long long)ires.height
|
||||||
|
% (unsigned long long)(ires.target_height ? ires.target_height : ires.height)
|
||||||
|
% (100.0f * ires.height / (ires.target_height ? ires.target_height < ires.height ? ires.height : ires.target_height : ires.height))
|
||||||
|
% (m_rpc_server->is_testnet() ? "testnet" : "mainnet")
|
||||||
|
% [&ires]()->std::string {
|
||||||
|
float hr = ires.difficulty / 60.0f;
|
||||||
|
if (hr>1e9) return (boost::format("%.2f GH/s") % (hr/1e9)).str();
|
||||||
|
if (hr>1e6) return (boost::format("%.2f MH/s") % (hr/1e6)).str();
|
||||||
|
if (hr>1e3) return (boost::format("%.2f kH/s") % (hr/1e3)).str();
|
||||||
|
return (boost::format("%.0f H/s") % hr).str();
|
||||||
|
}()
|
||||||
|
% (unsigned)hfres.version
|
||||||
|
% (hfres.state == cryptonote::HardFork::Ready ? "up to date" : hfres.state == cryptonote::HardFork::UpdateNeeded ? "update needed" : "out of date, likely forked")
|
||||||
|
% (unsigned)ires.outgoing_connections_count % (unsigned)ires.incoming_connections_count
|
||||||
|
;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool t_rpc_command_executor::print_connections() {
|
bool t_rpc_command_executor::print_connections() {
|
||||||
cryptonote::COMMAND_RPC_GET_CONNECTIONS::request req;
|
cryptonote::COMMAND_RPC_GET_CONNECTIONS::request req;
|
||||||
cryptonote::COMMAND_RPC_GET_CONNECTIONS::response res;
|
cryptonote::COMMAND_RPC_GET_CONNECTIONS::response res;
|
||||||
|
|
|
@ -73,6 +73,8 @@ public:
|
||||||
|
|
||||||
bool show_difficulty();
|
bool show_difficulty();
|
||||||
|
|
||||||
|
bool show_status();
|
||||||
|
|
||||||
bool print_connections();
|
bool print_connections();
|
||||||
|
|
||||||
bool print_blockchain_info(uint64_t start_block_index, uint64_t end_block_index);
|
bool print_blockchain_info(uint64_t start_block_index, uint64_t end_block_index);
|
||||||
|
|
Loading…
Reference in New Issue