aboutsummaryrefslogtreecommitdiff
path: root/src/rpc
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-07-02 22:41:15 +0100
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-08-07 09:33:04 +0100
commit5be43fcdbad5ed034b07831473e07f47b7b10947 (patch)
tree260422ebe0f60763ad1d61c610c77805ffa25a72 /src/rpc
parentMerge pull request #2159 (diff)
downloadmonero-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')
-rw-r--r--src/rpc/core_rpc_server.cpp35
-rw-r--r--src/rpc/core_rpc_server.h2
-rw-r--r--src/rpc/core_rpc_server_commands_defs.h58
3 files changed, 94 insertions, 1 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"
diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h
index 44ac6f07a..ec0a2636a 100644
--- a/src/rpc/core_rpc_server.h
+++ b/src/rpc/core_rpc_server.h
@@ -123,6 +123,7 @@ namespace cryptonote
MAP_JON_RPC_WE("get_fee_estimate", on_get_per_kb_fee_estimate, COMMAND_RPC_GET_PER_KB_FEE_ESTIMATE)
MAP_JON_RPC_WE_IF("get_alternate_chains",on_get_alternate_chains, COMMAND_RPC_GET_ALTERNATE_CHAINS, !m_restricted)
MAP_JON_RPC_WE_IF("relay_tx", on_relay_tx, COMMAND_RPC_RELAY_TX, !m_restricted)
+ MAP_JON_RPC_WE_IF("sync_info", on_sync_info, COMMAND_RPC_SYNC_INFO, !m_restricted)
END_JSON_RPC_MAP()
END_URI_MAP2()
@@ -178,6 +179,7 @@ namespace cryptonote
bool on_get_per_kb_fee_estimate(const COMMAND_RPC_GET_PER_KB_FEE_ESTIMATE::request& req, COMMAND_RPC_GET_PER_KB_FEE_ESTIMATE::response& res, epee::json_rpc::error& error_resp);
bool on_get_alternate_chains(const COMMAND_RPC_GET_ALTERNATE_CHAINS::request& req, COMMAND_RPC_GET_ALTERNATE_CHAINS::response& res, epee::json_rpc::error& error_resp);
bool on_relay_tx(const COMMAND_RPC_RELAY_TX::request& req, COMMAND_RPC_RELAY_TX::response& res, epee::json_rpc::error& error_resp);
+ bool on_sync_info(const COMMAND_RPC_SYNC_INFO::request& req, COMMAND_RPC_SYNC_INFO::response& res, epee::json_rpc::error& error_resp);
//-----------------------
private:
diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h
index 7a1f5a963..4bac01fe3 100644
--- a/src/rpc/core_rpc_server_commands_defs.h
+++ b/src/rpc/core_rpc_server_commands_defs.h
@@ -49,7 +49,7 @@ namespace cryptonote
// advance which version they will stop working with
// Don't go over 32767 for any of these
#define CORE_RPC_VERSION_MAJOR 1
-#define CORE_RPC_VERSION_MINOR 12
+#define CORE_RPC_VERSION_MINOR 13
#define MAKE_CORE_RPC_VERSION(major,minor) (((major)<<16)|(minor))
#define CORE_RPC_VERSION MAKE_CORE_RPC_VERSION(CORE_RPC_VERSION_MAJOR, CORE_RPC_VERSION_MINOR)
@@ -1587,4 +1587,60 @@ namespace cryptonote
END_KV_SERIALIZE_MAP()
};
};
+
+ struct COMMAND_RPC_SYNC_INFO
+ {
+ struct request
+ {
+ BEGIN_KV_SERIALIZE_MAP()
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct peer
+ {
+ connection_info info;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(info)
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct span
+ {
+ uint64_t start_block_height;
+ uint64_t nblocks;
+ boost::uuids::uuid connection_id;
+ uint32_t rate;
+ uint32_t speed;
+ uint64_t size;
+ std::string remote_address;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(start_block_height)
+ KV_SERIALIZE(nblocks)
+ KV_SERIALIZE_VAL_POD_AS_BLOB(connection_id)
+ KV_SERIALIZE(rate)
+ KV_SERIALIZE(speed)
+ KV_SERIALIZE(size)
+ KV_SERIALIZE(remote_address)
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct response
+ {
+ std::string status;
+ uint64_t height;
+ uint64_t target_height;
+ std::list<peer> peers;
+ std::list<span> spans;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(status)
+ KV_SERIALIZE(height)
+ KV_SERIALIZE(target_height)
+ KV_SERIALIZE(peers)
+ KV_SERIALIZE(spans)
+ END_KV_SERIALIZE_MAP()
+ };
+ };
}