Skip to content

Commit

Permalink
Fix some bugs due to new implementation and change in BOINC dir handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescowens committed Oct 30, 2022
1 parent e0168e8 commit 8b21110
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 58 deletions.
51 changes: 35 additions & 16 deletions src/wallet/diagnose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ boost::asio::io_service Diagnose::s_ioService;
*/
void VerifyClock::clkReportResults(const int64_t& time_offset, const bool& timeout_during_check)
{
m_results_string_arg.clear();
m_results_tip_arg.clear();

if (!timeout_during_check) {
if (abs64(time_offset) < 3 * 60) {
m_results = PASS;
Expand Down Expand Up @@ -119,36 +122,52 @@ void VerifyClock::connectToNTPHost()
{
m_startedTesting = true;
boost::asio::ip::udp::resolver resolver(s_ioService);
boost::asio::ip::udp::resolver::results_type receiver_endpoint;
try {
#if BOOST_VERSION > 106501
// results_type is only in boost 1.66 and above.
boost::asio::ip::udp::resolver::results_type receiver_endpoint;

receiver_endpoint = resolver.resolve(boost::asio::ip::udp::v4(),
"pool.ntp.org", "ntp");

if (receiver_endpoint == boost::asio::ip::udp::resolver::iterator()) {
// If can not connect to server, then finish the test with a warning.
clkReportResults(0, true);
} else {
if (m_udpSocket.is_open())
m_udpSocket.close();
m_udpSocket.open(boost::asio::ip::udp::v4());

m_udpSocket.async_send_to(boost::asio::buffer(m_sendBuf), *receiver_endpoint,
boost::bind(&VerifyClock::sockSendToHandle, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
}

#else
boost::asio::ip::udp::resolver::query query(
boost::asio::ip::udp::v4(),
"pool.ntp.org",
"ntp");
receiver_endpoint = resolver.resolve(query);

boost::asio::ip::udp::resolver::iterator endpoint_iterator = resolver.resolve(query);
boost::asio::ip::udp::resolver::iterator end;

if (endpoint_iterator == end) {
// If can not connect to server, then finish the test with a warning.
clkReportResults(0, true);
} else {
if (m_udpSocket.is_open())
m_udpSocket.close();
m_udpSocket.open(boost::asio::ip::udp::v4());

// There is only going to be one valid entry in the iterator.
m_udpSocket.async_send_to(boost::asio::buffer(m_sendBuf), *endpoint_iterator,
boost::bind(&VerifyClock::sockSendToHandle, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
};
#endif
} catch (...) {
clkReportResults(0, true);
return;
}


if (receiver_endpoint == boost::asio::ip::udp::resolver::iterator()) {
// If can not connect to server, then finish the test with a warning.
clkReportResults(0, true);
} else {
if (m_udpSocket.is_open())
m_udpSocket.close();
m_udpSocket.open(boost::asio::ip::udp::v4());


m_udpSocket.async_send_to(boost::asio::buffer(m_sendBuf), *receiver_endpoint,
boost::bind(&VerifyClock::sockSendToHandle, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
}
}

void VerifyTCPPort::handle_connect(const boost::system::error_code& err,
Expand Down
125 changes: 83 additions & 42 deletions src/wallet/diagnose.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace DiagnoseLib {
/**
* This is the base class for all diagnostics than can be run
* m_results: an enum to indicate warning, failed, or passed test
* Note: Each derived class must declare its unique name using he member m_test_name,
* Note: Each derived class must declare its unique name using the member m_test_name,
* the m_test_name will be used to check the test status
**/
class Diagnose
Expand All @@ -56,10 +56,10 @@ class Diagnose
FAIL,
NONE };
enum TestNames {
CheckConnectionCount, // This must remain first, because other tests depend on it.
CheckOutboundConnectionCount,
VerifyWalletIsSynced,
CheckClientVersion,
CheckConnectionCount,
CheckOutboundConnectionCount,
VerifyBoincPath,
VerifyCPIDHasRAC,
VerifyCPIDIsActive,
Expand Down Expand Up @@ -192,6 +192,9 @@ class VerifyWalletIsSynced : public Diagnose
}
void runCheck()
{
m_results_string_arg.clear();
m_results_tip_arg.clear();

if (g_nTimeBestReceived == 0 && OutOfSyncByAge()) {
m_results = Diagnose::WARNING;
m_results_tip = "Your wallet is still in initial sync. If this is a sync from the beginning (genesis), the "
Expand Down Expand Up @@ -228,14 +231,20 @@ class CheckOutboundConnectionCount : public Diagnose
{
m_test_name = Diagnose::CheckOutboundConnectionCount;
}

void runCheck()
{
LOCK(cs_vNodes);
m_results_string_arg.clear();
m_results_tip_arg.clear();

int outbound_connections = 0;

for (const auto& vnodes : vNodes) {
if (!vnodes->fInbound) ++outbound_connections;
{
LOCK(cs_vNodes);

for (const auto& vnodes : vNodes) {
if (!vnodes->fInbound) ++outbound_connections;
}
}

if (outbound_connections < 1) {
Expand Down Expand Up @@ -270,24 +279,26 @@ class CheckOutboundConnectionCount : public Diagnose
*/
class CheckConnectionCount : public Diagnose
{
protected:
size_t m_connections;

public:
CheckConnectionCount()
CheckConnectionCount() : m_connections(0)
{
m_connections = 0;
{
LOCK(cs_vNodes);
m_connections = vNodes.size();
}

m_test_name = Diagnose::CheckConnectionCount;
}

size_t getConnectionsNum() { return m_connections; }

void runCheck()
{
m_results_string_arg.clear();
m_results_tip_arg.clear();

{
LOCK(cs_vNodes);
m_connections = vNodes.size();
}

size_t minimum_connections_to_stake = fTestNet ? 1 : 3;
std::string s_connections = ToString(m_connections);

if (m_connections <= 7 && m_connections >= minimum_connections_to_stake) {
m_results_tip = "Please check your network and also check the config file and ensure your addnode entries "
Expand All @@ -296,13 +307,11 @@ 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 = ToString(m_connections);
m_results_string_arg.push_back(ss);
m_results_string_arg.push_back(s_connections);
} else if (m_connections >= 8) {
m_results_tip = "";
m_results_string = "Warning: Count = %1";
std::string ss = ToString(m_connections);
m_results_string_arg.push_back(ss);
m_results_string_arg.push_back(s_connections);
m_results = Diagnose::PASS;

} else {
Expand All @@ -313,16 +322,19 @@ class CheckConnectionCount : public Diagnose
"https://addnodes.cycy.me/.";
m_results = Diagnose::FAIL;
m_results_string = "Warning: Count = %1";
std::string ss = ToString(minimum_connections_to_stake);
m_results_string_arg.push_back(ss);
m_results_string_arg.push_back(s_connections);
m_results_tip_arg.push_back(ToString(minimum_connections_to_stake));
}
}

private:
size_t m_connections;
};

/**
* Diagnose class to check number of connection counts
*/
class VerifyClock : public CheckConnectionCount
class VerifyClock : public Diagnose
{
private:
boost::asio::ip::udp::socket m_udpSocket;
Expand All @@ -345,7 +357,10 @@ class VerifyClock : public CheckConnectionCount
~VerifyClock() {}
void runCheck()
{
if (m_connections >= 5) {
class CheckConnectionCount* CheckConnectionCount_Test =
static_cast<class CheckConnectionCount*>(getTest(Diagnose::CheckConnectionCount));

if (CheckConnectionCount_Test && CheckConnectionCount_Test->getConnectionsNum() >= 5) {
int64_t time_offset = 0;

{
Expand Down Expand Up @@ -376,6 +391,9 @@ class CheckClientVersion : public Diagnose
}
void runCheck()
{
m_results_string_arg.clear();
m_results_tip_arg.clear();

std::string client_message;

if (g_UpdateChecker->CheckForLatestUpdate(client_message, false) && client_message.find("mandatory") != std::string::npos) {
Expand All @@ -402,6 +420,9 @@ class VerifyBoincPath : public Diagnose
}
void runCheck()
{
m_results_string_arg.clear();
m_results_tip_arg.clear();

// This test is only applicable if the wallet is in researcher mode.
if (!m_researcher_mode) {
m_results_tip = "";
Expand All @@ -411,25 +432,29 @@ class VerifyBoincPath : public Diagnose
return;
}

// This is now similar to ReadClientStateXml in researcher.
fs::path boincPath = GRC::GetBoincDataDir();
std::string contents;

fs::path boincPath = (fs::path)GRC::GetBoincDataDir();

if (boincPath.empty()) {
boincPath = (fs::path)gArgs.GetArg("-boincdatadir", "");
bool access_error = false;

boincPath = boincPath / "client_state.xml";
try {
contents = GetFileContents(boincPath / "client_state.xml");
} catch (boost::filesystem::filesystem_error& e) {
error("%s: %s", __func__, e.what());
access_error = true;
}

if (fs::exists(boincPath)) {
m_results_tip = "";
m_results_string = "";
m_results = Diagnose::PASS;
} else {
m_results_tip = "Check that BOINC is installed and that you have the correct path in the config file "
"if you installed it to a nonstandard location.";
if (!access_error) {
m_results_tip = "";
m_results_string = "";
m_results = Diagnose::PASS;
} else {
m_results_tip = "Check that BOINC is installed and that you have the correct path in the config file "
"if you installed it to a nonstandard location.";

m_results_string = "";
m_results = Diagnose::FAIL;
}
m_results_string = "";
m_results = Diagnose::FAIL;
}
}
};
Expand All @@ -446,6 +471,9 @@ class VerifyCPIDValid : public Diagnose
}
void runCheck()
{
m_results_string_arg.clear();
m_results_tip_arg.clear();

// This test is only applicable if the wallet is in researcher mode.
if (!m_researcher_mode) {
m_results_tip = "";
Expand Down Expand Up @@ -499,7 +527,7 @@ class VerifyCPIDHasRAC : public Diagnose
if (!beacon->Expired(GetAdjustedTime())) {
return true;
}
for (auto beacon_ptr : beacons.FindPending(*cpid)) {
for (const auto& beacon_ptr : beacons.FindPending(*cpid)) {
if (!beacon_ptr->Expired(GetAdjustedTime())) {
return true;
}
Expand All @@ -509,6 +537,9 @@ class VerifyCPIDHasRAC : public Diagnose
}
void runCheck()
{
m_results_string_arg.clear();
m_results_tip_arg.clear();

// This test is only applicable if the wallet is in researcher mode.
if (!m_researcher_mode) {
m_results_tip = "";
Expand All @@ -517,7 +548,6 @@ class VerifyCPIDHasRAC : public Diagnose
return;
}


if (hasActiveBeacon()) {
m_results = Diagnose::PASS;
m_results_tip = "";
Expand Down Expand Up @@ -553,6 +583,9 @@ class VerifyCPIDIsActive : public Diagnose
}
void runCheck()
{
m_results_string_arg.clear();
m_results_tip_arg.clear();

// This test is only applicable if the wallet is in researcher mode.
if (!m_researcher_mode) {
m_results_tip = "";
Expand All @@ -561,7 +594,6 @@ class VerifyCPIDIsActive : public Diagnose
return;
}


if (GRC::Researcher::Get()->HasRAC()) {
m_results = Diagnose::PASS;
m_results_tip = "";
Expand Down Expand Up @@ -605,6 +637,9 @@ class VerifyTCPPort : public Diagnose
~VerifyTCPPort() {}
void runCheck()
{
m_results_string_arg.clear();
m_results_tip_arg.clear();

auto CheckConnectionCount_Test = getTest(Diagnose::CheckConnectionCount);
if (CheckConnectionCount_Test && CheckConnectionCount_Test->getResults() != Diagnose::NONE && CheckConnectionCount_Test->getResults() != Diagnose::FAIL) {
m_results = Diagnose::PASS;
Expand Down Expand Up @@ -656,6 +691,9 @@ class CheckDifficulty : public Diagnose
}
void runCheck()
{
m_results_string_arg.clear();
m_results_tip_arg.clear();

double diff = 0;
double scale_factor = 1.0;

Expand Down Expand Up @@ -725,6 +763,9 @@ class CheckETTS : public Diagnose
}
void runCheck()
{
m_results_string_arg.clear();
m_results_tip_arg.clear();

// This test is only applicable if the wallet is in researcher mode.
if (!m_researcher_mode) {
m_results = Diagnose::NONE;
Expand Down

0 comments on commit 8b21110

Please sign in to comment.