aboutsummaryrefslogtreecommitdiff
path: root/src/daemon
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon')
-rw-r--r--src/daemon/command_parser_executor.cpp10
-rw-r--r--src/daemon/command_parser_executor.h2
-rw-r--r--src/daemon/command_server.cpp5
-rw-r--r--src/daemon/daemon.cpp2
-rw-r--r--src/daemon/rpc_command_executor.cpp73
-rw-r--r--src/daemon/rpc_command_executor.h7
6 files changed, 92 insertions, 7 deletions
diff --git a/src/daemon/command_parser_executor.cpp b/src/daemon/command_parser_executor.cpp
index a7caeeffc..d949a57b1 100644
--- a/src/daemon/command_parser_executor.cpp
+++ b/src/daemon/command_parser_executor.cpp
@@ -256,7 +256,8 @@ bool t_command_parser_executor::start_mining(const std::vector<std::string>& arg
if(!cryptonote::get_account_integrated_address_from_str(adr, has_payment_id, payment_id, true, args.front()))
{
bool dnssec_valid;
- std::string address_str = tools::dns_utils::get_account_address_as_str_from_url(args.front(), dnssec_valid);
+ std::string address_str = tools::dns_utils::get_account_address_as_str_from_url(args.front(), dnssec_valid,
+ [](const std::string &url, const std::vector<std::string> &addresses, bool dnssec_valid){return addresses[0];});
if(!cryptonote::get_account_integrated_address_from_str(adr, has_payment_id, payment_id, false, address_str))
{
if(!cryptonote::get_account_integrated_address_from_str(adr, has_payment_id, payment_id, true, address_str))
@@ -578,4 +579,11 @@ bool t_command_parser_executor::relay_tx(const std::vector<std::string>& args)
return m_executor.relay_tx(txid);
}
+bool t_command_parser_executor::sync_info(const std::vector<std::string>& args)
+{
+ if (args.size() != 0) return false;
+
+ return m_executor.sync_info();
+}
+
} // namespace daemonize
diff --git a/src/daemon/command_parser_executor.h b/src/daemon/command_parser_executor.h
index a453553f1..f301ef14a 100644
--- a/src/daemon/command_parser_executor.h
+++ b/src/daemon/command_parser_executor.h
@@ -134,6 +134,8 @@ public:
bool update(const std::vector<std::string>& args);
bool relay_tx(const std::vector<std::string>& args);
+
+ bool sync_info(const std::vector<std::string>& args);
};
} // namespace daemonize
diff --git a/src/daemon/command_server.cpp b/src/daemon/command_server.cpp
index f47891fdd..12f7c5fa4 100644
--- a/src/daemon/command_server.cpp
+++ b/src/daemon/command_server.cpp
@@ -253,6 +253,11 @@ t_command_server::t_command_server(
, std::bind(&t_command_parser_executor::relay_tx, &m_parser, p::_1)
, "Relay a given transaction by its txid"
);
+ m_command_lookup.set_handler(
+ "sync_info"
+ , std::bind(&t_command_parser_executor::sync_info, &m_parser, p::_1)
+ , "Print information about blockchain sync state"
+ );
}
bool t_command_server::process_command_str(const std::string& cmd)
diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp
index 241cb3883..683eaf4ff 100644
--- a/src/daemon/daemon.cpp
+++ b/src/daemon/daemon.cpp
@@ -41,7 +41,7 @@
#include "daemon/rpc.h"
#include "daemon/command_server.h"
#include "version.h"
-#include "../../contrib/epee/include/syncobj.h"
+#include "syncobj.h"
using namespace epee;
diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp
index 5d8d95b03..995fee484 100644
--- a/src/daemon/rpc_command_executor.cpp
+++ b/src/daemon/rpc_command_executor.cpp
@@ -111,6 +111,13 @@ namespace {
return base;
return base + " -- " + status;
}
+
+ std::string pad(std::string s, size_t n)
+ {
+ if (s.size() < n)
+ s.append(n - s.size(), ' ');
+ return s;
+ }
}
t_rpc_command_executor::t_rpc_command_executor(
@@ -1583,6 +1590,7 @@ bool t_rpc_command_executor::print_blockchain_dynamic_stats(uint64_t nblocks)
double avgreward = 0;
std::vector<uint64_t> sizes;
sizes.reserve(nblocks);
+ uint64_t earliest = std::numeric_limits<uint64_t>::max(), latest = 0;
std::vector<unsigned> major_versions(256, 0), minor_versions(256, 0);
for (const auto &bhr: bhres.headers)
{
@@ -1594,12 +1602,14 @@ bool t_rpc_command_executor::print_blockchain_dynamic_stats(uint64_t nblocks)
static_assert(sizeof(bhr.minor_version) == 1, "major_version expected to be uint8_t");
major_versions[(unsigned)bhr.major_version]++;
minor_versions[(unsigned)bhr.minor_version]++;
+ earliest = std::min(earliest, bhr.timestamp);
+ latest = std::max(latest, bhr.timestamp);
}
avgdiff /= nblocks;
avgnumtxes /= nblocks;
avgreward /= nblocks;
uint64_t median_block_size = epee::misc_utils::median(sizes);
- tools::msg_writer() << "Last " << nblocks << ": avg. diff " << (uint64_t)avgdiff << ", avg num txes " << avgnumtxes
+ tools::msg_writer() << "Last " << nblocks << ": avg. diff " << (uint64_t)avgdiff << ", " << (latest - earliest) / nblocks << " avg sec/block, avg num txes " << avgnumtxes
<< ", avg. reward " << cryptonote::print_money(avgreward) << ", median block size " << median_block_size;
unsigned int max_major = 256, max_minor = 256;
@@ -1694,4 +1704,65 @@ bool t_rpc_command_executor::relay_tx(const std::string &txid)
return true;
}
+bool t_rpc_command_executor::sync_info()
+{
+ cryptonote::COMMAND_RPC_SYNC_INFO::request req;
+ cryptonote::COMMAND_RPC_SYNC_INFO::response res;
+ std::string fail_message = "Unsuccessful";
+ epee::json_rpc::error error_resp;
+
+ if (m_is_rpc)
+ {
+ if (!m_rpc_client->json_rpc_request(req, res, "sync_info", fail_message.c_str()))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if (!m_rpc_server->on_sync_info(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
+ {
+ tools::fail_msg_writer() << make_error(fail_message, res.status);
+ return true;
+ }
+ }
+
+ uint64_t target = res.target_height < res.height ? res.height : res.target_height;
+ tools::success_msg_writer() << "Height: " << res.height << ", target: " << target << " (" << (100.0 * res.height / target) << "%)";
+ uint64_t current_download = 0;
+ for (const auto &p: res.peers)
+ current_download += p.info.current_download;
+ tools::success_msg_writer() << "Downloading at " << current_download << " kB/s";
+
+ tools::success_msg_writer() << std::to_string(res.peers.size()) << " peers";
+ for (const auto &p: res.peers)
+ {
+ std::string address = pad(p.info.address, 24);
+ uint64_t nblocks = 0, size = 0;
+ for (const auto &s: res.spans)
+ if (s.rate > 0.0f && s.connection_id == p.info.connection_id)
+ nblocks += s.nblocks, size += s.size;
+ tools::success_msg_writer() << address << " " << p.info.peer_id << " " << p.info.height << " " << p.info.current_download << " kB/s, " << nblocks << " blocks / " << size/1e6 << " MB queued";
+ }
+
+ uint64_t total_size = 0;
+ for (const auto &s: res.spans)
+ total_size += s.size;
+ tools::success_msg_writer() << std::to_string(res.spans.size()) << " spans, " << total_size/1e6 << " MB";
+ for (const auto &s: res.spans)
+ {
+ std::string address = pad(s.remote_address, 24);
+ if (s.size == 0)
+ {
+ tools::success_msg_writer() << address << " " << s.nblocks << " (" << s.start_block_height << " - " << (s.start_block_height + s.nblocks - 1) << ") -";
+ }
+ else
+ {
+ tools::success_msg_writer() << address << " " << s.nblocks << " (" << s.start_block_height << " - " << (s.start_block_height + s.nblocks - 1) << ", " << (uint64_t)(s.size/1e3) << " kB) " << (unsigned)(s.rate/1e3) << " kB/s (" << s.speed/100.0f << ")";
+ }
+ }
+
+ return true;
+}
+
}// namespace daemonize
diff --git a/src/daemon/rpc_command_executor.h b/src/daemon/rpc_command_executor.h
index 3f551bd14..fc0b39654 100644
--- a/src/daemon/rpc_command_executor.h
+++ b/src/daemon/rpc_command_executor.h
@@ -42,10 +42,7 @@
#include "common/common_fwd.h"
#include "common/rpc_client.h"
-#include "misc_log_ex.h"
-#include "cryptonote_core/cryptonote_core.h"
-#include "cryptonote_protocol/cryptonote_protocol_handler.h"
-#include "p2p/net_node.h"
+#include "cryptonote_basic/cryptonote_basic.h"
#include "rpc/core_rpc_server.h"
#undef MONERO_DEFAULT_LOG_CATEGORY
@@ -155,6 +152,8 @@ public:
bool update(const std::string &command);
bool relay_tx(const std::string &txid);
+
+ bool sync_info();
};
} // namespace daemonize