mirror of
https://github.com/monero-project/monero.git
synced 2025-12-13 07:10:57 -05:00
cryptonote_protocol_handler: sync speedup
A block queue is now placed between block download and block processing. Blocks are now requested only from one peer (unless starved). Includes a new sync_info coommand.
This commit is contained in:
parent
ab594cfee9
commit
5be43fcdba
22 changed files with 1463 additions and 134 deletions
|
|
@ -578,4 +578,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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
@ -1694,4 +1701,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.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
|
||||
|
|
|
|||
|
|
@ -155,6 +155,8 @@ public:
|
|||
bool update(const std::string &command);
|
||||
|
||||
bool relay_tx(const std::string &txid);
|
||||
|
||||
bool sync_info();
|
||||
};
|
||||
|
||||
} // namespace daemonize
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue