diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2017-07-02 22:41:15 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2017-08-07 09:33:04 +0100 |
commit | 5be43fcdbad5ed034b07831473e07f47b7b10947 (patch) | |
tree | 260422ebe0f60763ad1d61c610c77805ffa25a72 /src/rpc/core_rpc_server.cpp | |
parent | Merge pull request #2159 (diff) | |
download | monero-5be43fcdbad5ed034b07831473e07f47b7b10947.tar.xz |
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.
Diffstat (limited to 'src/rpc/core_rpc_server.cpp')
-rw-r--r-- | src/rpc/core_rpc_server.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 97fe18696..c2a91a1c8 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -1668,6 +1668,41 @@ namespace cryptonote return true; } //------------------------------------------------------------------------------------------------------------------------------ + bool core_rpc_server::on_sync_info(const COMMAND_RPC_SYNC_INFO::request& req, COMMAND_RPC_SYNC_INFO::response& res, epee::json_rpc::error& error_resp) + { + if(!check_core_busy()) + { + error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY; + error_resp.message = "Core is busy."; + return false; + } + + crypto::hash top_hash; + if (!m_core.get_blockchain_top(res.height, top_hash)) + { + res.status = "Failed"; + return false; + } + ++res.height; // turn top block height into blockchain height + res.target_height = m_core.get_target_blockchain_height(); + + for (const auto &c: m_p2p.get_payload_object().get_connections()) + res.peers.push_back({c}); + const cryptonote::block_queue &block_queue = m_p2p.get_payload_object().get_block_queue(); + block_queue.foreach([&](const cryptonote::block_queue::span &span) { + uint32_t speed = (uint32_t)(100.0f * block_queue.get_speed(span.connection_id) + 0.5f); + std::string address = ""; + for (const auto &c: m_p2p.get_payload_object().get_connections()) + if (c.connection_id == span.connection_id) + address = c.address; + res.spans.push_back({span.start_block_height, span.nblocks, span.connection_id, (uint32_t)(span.rate + 0.5f), speed, span.size, address}); + return true; + }); + + res.status = CORE_RPC_STATUS_OK; + return true; + } + //------------------------------------------------------------------------------------------------------------------------------ const command_line::arg_descriptor<std::string> core_rpc_server::arg_rpc_bind_port = { "rpc-bind-port" |