From bab0ad51bf31e34d08841abf79e39cd4b33a8926 Mon Sep 17 00:00:00 2001 From: Maxim Shishmarev Date: Fri, 6 Sep 2019 10:30:50 +1000 Subject: [PATCH] Don't forget to test decommissioned nodes --- httpserver/https_client.cpp | 2 +- httpserver/reachability_testing.cpp | 26 +++++++++++++------------- httpserver/reachability_testing.h | 4 ++-- httpserver/service_node.cpp | 6 +++--- httpserver/swarm.cpp | 4 ++++ 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/httpserver/https_client.cpp b/httpserver/https_client.cpp index f8d5b378..ff82ff26 100644 --- a/httpserver/https_client.cpp +++ b/httpserver/https_client.cpp @@ -23,7 +23,7 @@ void make_https_request(boost::asio::io_context& ioc, #else if (sn_address == "0.0.0.0") { - LOKI_LOG(warn, "Could not initiate request to snode (we don't know " + LOKI_LOG(debug, "Could not initiate request to snode (we don't know " "their IP yet)."); cb(sn_response_t{SNodeError::NO_REACH, nullptr}); diff --git a/httpserver/reachability_testing.cpp b/httpserver/reachability_testing.cpp index 74b8b748..5082789c 100644 --- a/httpserver/reachability_testing.cpp +++ b/httpserver/reachability_testing.cpp @@ -21,31 +21,31 @@ constexpr std::chrono::minutes UNREACH_GRACE_PERIOD = 120min; bool reachability_records_t::record_unreachable(const sn_pub_key_t& sn) { - auto it = offline_nodes_.find(sn); + const auto it = offline_nodes_.find(sn); if (it == offline_nodes_.end()) { - LOKI_LOG(info, "adding a new node to UNREACHABLE: {}", sn); + /// TODO: change this to debug + LOKI_LOG(debug, "Adding a new node to UNREACHABLE: {}", sn); offline_nodes_.insert({sn, {}}); } else { - LOKI_LOG(info, "node is ALREAY known to be UNREACHABLE: {}", sn); + LOKI_LOG(debug, "Node is ALREAY known to be UNREACHABLE: {}", sn); it->second.last_tested = steady_clock::now(); const auto elapsed = it->second.last_tested - it->second.first_failure; const auto elapsed_sec = std::chrono::duration_cast(elapsed).count(); - LOKI_LOG(info, " - first time failed {} seconds ago", elapsed_sec); + LOKI_LOG(debug, "First time failed {} seconds ago", elapsed_sec); /// TODO: Might still want to report as unreachable since this status /// gets reset to `true` on Lokid restart - if (elapsed > UNREACH_GRACE_PERIOD && !it->second.reported) { - LOKI_LOG(warn, " - will REPORT this node to Lokid!"); + if (it->second.reported) { + LOKI_LOG(debug, "Already reported node: {}", sn); + } else if (elapsed > UNREACH_GRACE_PERIOD) { + LOKI_LOG(debug, "Will REPORT this node to Lokid!"); return true; - } else { - if (it->second.reported) { - LOKI_LOG(warn, " - Already reported node: {}", sn); - } } + } return false; @@ -58,13 +58,13 @@ bool reachability_records_t::record_reachable(const sn_pub_key_t& sn) { bool reachability_records_t::expire(const sn_pub_key_t& sn) { if (offline_nodes_.erase(sn)) { - LOKI_LOG(warn, " - removed entry for {}", sn); + LOKI_LOG(debug, "Removed entry for {}", sn); } } void reachability_records_t::set_reported(const sn_pub_key_t& sn) { - auto it = offline_nodes_.find(sn); + const auto it = offline_nodes_.find(sn); if (it != offline_nodes_.end()) { it->second.reported = true; } @@ -82,7 +82,7 @@ boost::optional reachability_records_t::next_to_test() { return boost::none; } else { - LOKI_LOG(warn, "~~~ Selecting to be re-tested: {}", it->first); + LOKI_LOG(debug, "Selecting to be re-tested: {}", it->first); return it->first; } diff --git a/httpserver/reachability_testing.h b/httpserver/reachability_testing.h index a26d6922..2c15fe5d 100644 --- a/httpserver/reachability_testing.h +++ b/httpserver/reachability_testing.h @@ -11,12 +11,12 @@ namespace detail { /// TODO: make this class "private"? class reach_record_t { - // The time the node failed for the first time - // (and hasn't come back online) using time_point_t = std::chrono::time_point; public: + // The time the node failed for the first time + // (and hasn't come back online) time_point_t first_failure; time_point_t last_tested; // whether it's been reported to Lokid diff --git a/httpserver/service_node.cpp b/httpserver/service_node.cpp index 35e663ca..e88a3b42 100644 --- a/httpserver/service_node.cpp +++ b/httpserver/service_node.cpp @@ -1006,12 +1006,12 @@ void ServiceNode::report_node_reachability(const sn_pub_key_t& sn_pk, auto cb = [this, sn_pk, reachable](const sn_response_t&& res) { if (res.error_code != SNodeError::NO_ERROR) { - LOKI_LOG(error, "Could not report node status"); + LOKI_LOG(warn, "Could not report node status"); return; } if (!res.body) { - LOKI_LOG(error, "Empty body on Lokid report node status"); + LOKI_LOG(warn, "Empty body on Lokid report node status"); return; } @@ -1026,7 +1026,7 @@ void ServiceNode::report_node_reachability(const sn_pub_key_t& sn_pk, if (status == "OK") { success = true; } else { - LOKI_LOG(error, "Could not report node. Status: {}", status); + LOKI_LOG(warn, "Could not report node. Status: {}", status); } } catch (...) { LOKI_LOG(error, diff --git a/httpserver/swarm.cpp b/httpserver/swarm.cpp index ca2d2e1c..03f2e8bc 100644 --- a/httpserver/swarm.cpp +++ b/httpserver/swarm.cpp @@ -192,6 +192,10 @@ void Swarm::update_state(const all_swarms_t& swarms, all_funded_nodes_.push_back(sn); } } + + for (const auto& sn : decommissioned) { + all_funded_nodes_.push_back(sn); + } } boost::optional Swarm::choose_funded_node() const {