aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/core_rpc_server.cpp
diff options
context:
space:
mode:
authorluigi1111 <luigi1111w@gmail.com>2020-04-04 12:59:23 -0500
committerluigi1111 <luigi1111w@gmail.com>2020-04-04 12:59:23 -0500
commit0150a480fd108d3c04b4926a7c3e3b9a3dc59bec (patch)
treee917b158d9538c53c3d8842b52a2287833a2f82d /src/rpc/core_rpc_server.cpp
parentMerge pull request #6356 (diff)
parentdaemon: auto public nodes - cache and prioritize most stable nodes (diff)
downloadmonero-0150a480fd108d3c04b4926a7c3e3b9a3dc59bec.tar.xz
Merge pull request #6357
42a7a4d daemon: auto public nodes - cache and prioritize most stable nodes (xiphon)
Diffstat (limited to 'src/rpc/core_rpc_server.cpp')
-rw-r--r--src/rpc/core_rpc_server.cpp50
1 files changed, 27 insertions, 23 deletions
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index d33dbd16a..f097c93fa 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -178,7 +178,7 @@ namespace cryptonote
return set_bootstrap_daemon(address, credentials);
}
//------------------------------------------------------------------------------------------------------------------------------
- boost::optional<std::string> core_rpc_server::get_random_public_node()
+ std::map<std::string, bool> core_rpc_server::get_public_nodes(uint32_t credits_per_hash_threshold/* = 0*/)
{
COMMAND_RPC_GET_PUBLIC_NODES::request request;
COMMAND_RPC_GET_PUBLIC_NODES::response response;
@@ -187,47 +187,51 @@ namespace cryptonote
request.white = true;
if (!on_get_public_nodes(request, response) || response.status != CORE_RPC_STATUS_OK)
{
- return boost::none;
+ return {};
}
- const auto get_random_node_address = [](const std::vector<public_node>& public_nodes) -> std::string {
- const auto& random_node = public_nodes[crypto::rand_idx(public_nodes.size())];
- const auto address = random_node.host + ":" + std::to_string(random_node.rpc_port);
- return address;
- };
-
- if (!response.white.empty())
- {
- return get_random_node_address(response.white);
- }
+ std::map<std::string, bool> result;
- MDEBUG("No white public node found, checking gray peers");
-
- if (!response.gray.empty())
- {
- return get_random_node_address(response.gray);
- }
+ const auto append = [&result, &credits_per_hash_threshold](const std::vector<public_node> &nodes, bool white) {
+ for (const auto &node : nodes)
+ {
+ const bool rpc_payment_enabled = credits_per_hash_threshold > 0;
+ const bool node_rpc_payment_enabled = node.rpc_credits_per_hash > 0;
+ if (!node_rpc_payment_enabled ||
+ (rpc_payment_enabled && node.rpc_credits_per_hash >= credits_per_hash_threshold))
+ {
+ result.insert(std::make_pair(node.host + ":" + std::to_string(node.rpc_port), white));
+ }
+ }
+ };
- MERROR("Failed to find any suitable public node");
+ append(response.white, true);
+ append(response.gray, false);
- return boost::none;
+ return result;
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::set_bootstrap_daemon(const std::string &address, const boost::optional<epee::net_utils::http::login> &credentials)
{
boost::unique_lock<boost::shared_mutex> lock(m_bootstrap_daemon_mutex);
+ constexpr const uint32_t credits_per_hash_threshold = 0;
+ constexpr const bool rpc_payment_enabled = credits_per_hash_threshold != 0;
+
if (address.empty())
{
m_bootstrap_daemon.reset(nullptr);
}
else if (address == "auto")
{
- m_bootstrap_daemon.reset(new bootstrap_daemon([this]{ return get_random_public_node(); }));
+ auto get_nodes = [this, credits_per_hash_threshold]() {
+ return get_public_nodes(credits_per_hash_threshold);
+ };
+ m_bootstrap_daemon.reset(new bootstrap_daemon(std::move(get_nodes), rpc_payment_enabled));
}
else
{
- m_bootstrap_daemon.reset(new bootstrap_daemon(address, credentials));
+ m_bootstrap_daemon.reset(new bootstrap_daemon(address, credentials, rpc_payment_enabled));
}
m_should_use_bootstrap_daemon = m_bootstrap_daemon.get() != nullptr;
@@ -1941,7 +1945,7 @@ namespace cryptonote
if (*bootstrap_daemon_height < target_height)
{
MINFO("Bootstrap daemon is out of sync");
- return m_bootstrap_daemon->handle_result(false);
+ return m_bootstrap_daemon->handle_result(false, {});
}
uint64_t top_height = m_core.get_current_blockchain_height();