Skip to content

Commit

Permalink
Merge pull request #2 from jamescowens/implement_core_diagnostics
Browse files Browse the repository at this point in the history
util: Implement core diagnostics
  • Loading branch information
MinaFarhan authored Oct 24, 2022
2 parents ce236ed + 8c15e83 commit caaf952
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 45 deletions.
12 changes: 2 additions & 10 deletions src/qt/diagnosticsdialog.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
// Copyright (c) 2014-2021 The Gridcoin developers
// Copyright (c) 2014-2022 The Gridcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or https://opensource.org/licenses/mit-license.php.

#include "fs.h"
#include "main.h"
#include "util.h"

#include <boost/algorithm/string.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

#include "diagnosticsdialog.h"
#include "ui_diagnosticsdialog.h"
#include "gridcoin/boinc.h"
#include "gridcoin/researcher.h"
#include "gridcoin/staking/difficulty.h"
#include "gridcoin/upgrade.h"
#include "qt/forms/ui_diagnosticsdialog.h"
#include "qt/decoration.h"
#include "qt/researcher/researchermodel.h"

Expand Down
5 changes: 4 additions & 1 deletion src/wallet/diagnose.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2014-2022 The Gridcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or https://opensource.org/licenses/mit-license.php.

#include "diagnose.h"
#include "net.h"
Expand Down Expand Up @@ -160,7 +163,7 @@ void VerifyTCPPort::handle_connect(const boost::system::error_code& err,
m_tcpSocket.close();
m_results = WARNING;
m_results_tip = "Outbound communication to TCP port %1 appears to be blocked. ";
std::string ss = argToString(GetListenPort());
std::string ss = ToString(GetListenPort());
m_results_string_arg.push_back(ss);

switch (err.value()) {
Expand Down
65 changes: 31 additions & 34 deletions src/wallet/diagnose.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// Copyright (c) 2014-2022 The Gridcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or https://opensource.org/licenses/mit-license.php.

#ifndef GRIDCOIN_WALLET_DIAGNOSE_H
#define GRIDCOIN_WALLET_DIAGNOSE_H

#include "fs.h"
#include "gridcoin/beacon.h"
#include "gridcoin/boinc.h"
#include "gridcoin/researcher.h"
Expand All @@ -20,13 +25,9 @@
#include <unordered_map>
#include <vector>


extern std::atomic<int64_t> g_nTimeBestReceived;
extern std::unique_ptr<GRC::Upgrade> g_UpdateChecker;

#ifndef GRIDCOIN_WALLET_DIAGNOSE_H
#define GRIDCOIN_WALLET_DIAGNOSE_H

class Researcher;
/*
* This class monitors the tests, upon construction, it will register the test
Expand Down Expand Up @@ -114,22 +115,16 @@ class Diagnose
* Register a running test to the map so we can check if it is running or not.
*/

/**
* change a into string with classic locale
*/
template <class T>
std::string argToString(T a)
{
std::stringstream ss;
ss.imbue(std::locale::classic());
ss << a;
return ss.str();
}

static void registerTest(Diagnose* test)
{
LOCK(cs_diagnostictests);
m_name_to_test_map[test->m_test_name] = test;

LogPrintf("INFO: %s: test->m_test_name %s registered, test map size = %u",
__func__,
test->m_test_name,
m_name_to_test_map.size());

assert(m_name_to_test_map.size() < Diagnose::TestSize);
};
/**
Expand Down Expand Up @@ -251,7 +246,7 @@ class CheckOutboundConnectionCount : public Diagnose
m_results_string = "Failed: Count = %1";
m_results = Diagnose::Diagnose::FAIL;

std::string ss = argToString(outbound_connections);
std::string ss = ToString(outbound_connections);
m_results_string_arg.push_back(ss);

} else if (outbound_connections < 3) {
Expand All @@ -263,7 +258,7 @@ class CheckOutboundConnectionCount : public Diagnose
} else {
m_results_tip = "";
m_results_string = "Passed: Count = %1";
std::string ss = argToString(outbound_connections);
std::string ss = ToString(outbound_connections);
m_results_string_arg.push_back(ss);
m_results = Diagnose::PASS;
}
Expand Down Expand Up @@ -301,12 +296,12 @@ class CheckConnectionCount : public Diagnose
"https://gridcoin.us/wiki/config-file.html and https://addnodes.cycy.me/.";
m_results = Diagnose::WARNING;
m_results_string = "Warning: Count = %1 (Pass = 8+)";
std::string ss = argToString(m_connections);
std::string ss = ToString(m_connections);
m_results_string_arg.push_back(ss);
} else if (m_connections >= 8) {
m_results_tip = "";
m_results_string = "Warning: Count = %1";
std::string ss = argToString(m_connections);
std::string ss = ToString(m_connections);
m_results_string_arg.push_back(ss);
m_results = Diagnose::PASS;

Expand All @@ -318,7 +313,7 @@ class CheckConnectionCount : public Diagnose
"https://addnodes.cycy.me/.";
m_results = Diagnose::FAIL;
m_results_string = "Warning: Count = %1";
std::string ss = argToString(minimum_connections_to_stake);
std::string ss = ToString(minimum_connections_to_stake);
m_results_string_arg.push_back(ss);
}
}
Expand Down Expand Up @@ -670,7 +665,7 @@ class CheckDifficulty : public Diagnose
// standard and just warn, with a different explanation.
if (g_nTimeBestReceived == 0 && OutOfSyncByAge() && diff < fail_diff) {
m_results_string = "Warning: 80 block difficulty is less than %1.";
std::string ss = argToString(fail_diff);
std::string ss = ToString(fail_diff);
m_results_string_arg.push_back(ss);

m_results_tip = "Your difficulty is low but your wallet is still in initial sync. Please recheck it later "
Expand All @@ -682,7 +677,7 @@ class CheckDifficulty : public Diagnose
else if (g_nTimeBestReceived > 0 && diff < fail_diff) {
m_results_string = "Failed: 80 block difficulty is less than %1. This wallet is almost certainly forked.";

std::string ss = argToString(fail_diff);
std::string ss = ToString(fail_diff);
m_results_string_arg.push_back(ss);

m_results_tip = "Your difficulty is extremely low and your wallet is almost certainly forked. Please ensure "
Expand All @@ -691,7 +686,7 @@ class CheckDifficulty : public Diagnose
m_results = Diagnose::FAIL;
} else if (g_nTimeBestReceived > 0 && diff < warn_diff) {
m_results_string = "Warning: 80 block difficulty is less than %1. This wallet is probably forked.";
std::string ss = argToString(warn_diff);
std::string ss = ToString(warn_diff);
m_results_string_arg.push_back(ss);

m_results_tip = "Your difficulty is very low and your wallet is probably forked. Please ensure you are "
Expand All @@ -700,7 +695,7 @@ class CheckDifficulty : public Diagnose
m_results = Diagnose::WARNING;
} else {
m_results_string = "Passed: 80 block difficulty is %1.";
std::string ss = argToString(diff);
std::string ss = ToString(diff);
m_results_string_arg.push_back(ss);
m_results = Diagnose::PASS;
}
Expand Down Expand Up @@ -754,20 +749,22 @@ class CheckETTS : public Diagnose
// ETTS of zero actually means no coins, i.e. infinite.
if (ETTS == 0.0) {
m_results_tip = "You have no balance and will be unable to retrieve your research rewards when solo "
"crunching. You should acquire GRC to stake so you can retrieve your research rewards. "
"crunching by staking. You can use MRC to retrieve your rewards, or you should "
"acquire GRC to stake so you can retrieve your research rewards. "
"Please see https://gridcoin.us/guides/boinc-install.htm.";
m_results_string = "Failed: ETTS is infinite. No coins to stake.";
m_results = Diagnose::FAIL;
m_results_string = "Warning: ETTS is infinite. No coins to stake - increase balance or use MRC";
m_results = Diagnose::WARNING;
} else if (ETTS > 90.0) {
m_results_tip = "Your balance is too low given the current network difficulty to stake in a reasonable "
"period of time to retrieve your research rewards when solo crunching. You should acquire "
"more GRC to stake more often.";
m_results_string = "Failed: ETTS is > 90 days. It will take a very long time to receive your research rewards";
m_results = Diagnose::FAIL;
"period of time to retrieve your research rewards when solo crunching. You can use MRC "
" to retrieve your rewards, or you should acquire more GRC to stake more often.";
m_results_string = "Warning: ETTS is > 90 days. It will take a very long time to receive your research "
"rewards by staking - increase balance or use MRC";
m_results = Diagnose::WARNING;
} else if (ETTS > 45.0 && ETTS <= 90.0) {
m_results_tip = "Your balance is low given the current network difficulty to stake in a reasonable "
"period of time to retrieve your research rewards when solo crunching. You should consider "
"acquiring more GRC to stake more often.";
"acquiring more GRC to stake more often, or else use MRC to retrieve your rewards.";
m_results_string = "Warning: 45 days < ETTS = %1 <= 90 days";
m_results = Diagnose::WARNING;
} else {
Expand Down
1 change: 1 addition & 0 deletions test/lint/lint-includes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ EXPECTED_BOOST_INCLUDES=(
boost/algorithm/string/replace.hpp
boost/algorithm/string/split.hpp
boost/asio.hpp
boost/asio/ip/udp.hpp
boost/asio/ip/v6_only.hpp
boost/asio/ssl.hpp
boost/assert.hpp
Expand Down

0 comments on commit caaf952

Please sign in to comment.