Skip to content

Commit 864798f

Browse files
committed
PR review adjustments and additional minor changes
1 parent c68975e commit 864798f

File tree

4 files changed

+74
-63
lines changed

4 files changed

+74
-63
lines changed

src/qt/bitcoingui.cpp

+5-9
Original file line numberDiff line numberDiff line change
@@ -722,10 +722,10 @@ void BitcoinGUI::aboutClicked()
722722
dlg.exec();
723723
}
724724

725-
void BitcoinGUI::setNumConnections(int count)
725+
void BitcoinGUI::setNumConnections(int n)
726726
{
727727
QString icon;
728-
switch(count)
728+
switch (n)
729729
{
730730
case 0: icon = ":/icons/connect_0"; break;
731731
case 1: case 2: case 3: icon = ":/icons/connect_1"; break;
@@ -735,19 +735,15 @@ void BitcoinGUI::setNumConnections(int count)
735735
}
736736
labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
737737

738-
if (count == 0)
738+
if (n == 0)
739739
{
740740
labelConnectionsIcon->setToolTip(tr("No active connections to the Gridcoin network. "
741741
"If this persists more than a few minutes, please check your configuration "
742-
"and your network connectivity.").arg(count));
743-
}
744-
else if (count == 1)
745-
{
746-
labelConnectionsIcon->setToolTip(tr("%1 active connection to the Gridcoin network").arg(count));
742+
"and your network connectivity."));
747743
}
748744
else
749745
{
750-
labelConnectionsIcon->setToolTip(tr("%1 active connections to the Gridcoin network").arg(count));
746+
labelConnectionsIcon->setToolTip(tr("%n active connection(s) to the Gridcoin network", "", n));
751747
}
752748
}
753749

src/qt/diagnosticsdialog.cpp

+62-47
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#include <numeric>
1616
#include <fstream>
1717

18-
extern std::unique_ptr<Upgrade> g_UpdateChecker;
19-
2018
namespace NN { std::string GetPrimaryCpid(); }
2119

2220
DiagnosticsDialog::DiagnosticsDialog(QWidget *parent) :
@@ -82,7 +80,7 @@ void DiagnosticsDialog::UpdateOverallDiagnosticResult(DiagnosticResult diagnosti
8280
diagnostic_result_status = pending;
8381
}
8482

85-
diagnostic_result = (DiagnosticResult) std::max((int) diagnostic_result_in, (int) diagnostic_result);
83+
diagnostic_result = (DiagnosticResult) std::max<int>(diagnostic_result_in, diagnostic_result);
8684

8785
// If diagnostic_result_status is still set to completed, then at least all tests
8886
// are registered. Walk through the map of tests one by one and check the status.
@@ -134,7 +132,7 @@ void DiagnosticsDialog::DisplayOverallDiagnosticResult()
134132

135133
case passed:
136134
ui->overallResultResultLabel->setText(tr("Passed"));
137-
ui->overallResultResultLabel->setStyleSheet("color:black;background-color:green");
135+
ui->overallResultResultLabel->setStyleSheet("color:white;background-color:green");
138136
break;
139137

140138
case warning:
@@ -144,7 +142,7 @@ void DiagnosticsDialog::DisplayOverallDiagnosticResult()
144142

145143
case failed:
146144
ui->overallResultResultLabel->setText(tr("Failed"));
147-
ui->overallResultResultLabel->setStyleSheet("color:black;background-color:red");
145+
ui->overallResultResultLabel->setStyleSheet("color:white;background-color:red");
148146
}
149147
}
150148

@@ -300,7 +298,7 @@ void DiagnosticsDialog::on_testButton_clicked()
300298

301299
if (GetNumberOfTestsPending())
302300
{
303-
LogPrintf("INFO: on_testButton_clicked: Tests still in progress from a prior run: %u", GetNumberOfTestsPending());
301+
LogPrintf("INFO: DiagnosticsDialog::on_testButton_clicked: Tests still in progress from a prior run: %u", GetNumberOfTestsPending());
304302
this->repaint();
305303
return;
306304
}
@@ -342,14 +340,14 @@ void DiagnosticsDialog::on_testButton_clicked()
342340
if (VerifyBoincPath())
343341
{
344342
ui->boincPathResultLabel->setText(tr("Passed"));
345-
ui->boincPathResultLabel->setStyleSheet("color:black;background-color:green");
343+
ui->boincPathResultLabel->setStyleSheet("color:white;background-color:green");
346344
UpdateTestStatus("boincPath", completed);
347345
UpdateOverallDiagnosticResult(passed);
348346
}
349347
else
350348
{
351349
ui->boincPathResultLabel->setText(tr("Failed"));
352-
ui->boincPathResultLabel->setStyleSheet("color:black;background-color:red");
350+
ui->boincPathResultLabel->setStyleSheet("color:white;background-color:red");
353351
UpdateTestStatus("boincPath", completed);
354352
UpdateOverallDiagnosticResult(failed);
355353
}
@@ -363,14 +361,14 @@ void DiagnosticsDialog::on_testButton_clicked()
363361
if (VerifyIsCPIDValid())
364362
{
365363
ui->verifyCPIDValidResultLabel->setText(tr("Passed"));
366-
ui->verifyCPIDValidResultLabel->setStyleSheet("color:black;background-color:green");
364+
ui->verifyCPIDValidResultLabel->setStyleSheet("color:white;background-color:green");
367365
UpdateTestStatus("verifyCPIDValid", completed);
368366
UpdateOverallDiagnosticResult(passed);
369367
}
370368
else
371369
{
372370
ui->verifyCPIDValidResultLabel->setText(tr("Failed: BOINC CPID does not match CPID"));
373-
ui->verifyCPIDValidResultLabel->setStyleSheet("color:black;background-color:red");
371+
ui->verifyCPIDValidResultLabel->setStyleSheet("color:white;background-color:red");
374372
UpdateTestStatus("verifyCPIDValid", completed);
375373
UpdateOverallDiagnosticResult(failed);
376374
}
@@ -384,15 +382,15 @@ void DiagnosticsDialog::on_testButton_clicked()
384382
if (VerifyCPIDHasRAC())
385383
{
386384
ui->verifyCPIDHasRACResultLabel->setText(tr("Passed"));
387-
ui->verifyCPIDHasRACResultLabel->setStyleSheet("color:black;background-color:green");
385+
ui->verifyCPIDHasRACResultLabel->setStyleSheet("color:white;background-color:green");
388386
UpdateTestStatus("verifyCPIDHasRAC", completed);
389387
UpdateOverallDiagnosticResult(passed);
390388

391389
}
392390
else
393391
{
394392
ui->verifyCPIDHasRACResultLabel->setText(tr("Failed"));
395-
ui->verifyCPIDHasRACResultLabel->setStyleSheet("color:black;background-color:red");
393+
ui->verifyCPIDHasRACResultLabel->setStyleSheet("color:white;background-color:red");
396394
UpdateTestStatus("verifyCPIDHasRAC", completed);
397395
UpdateOverallDiagnosticResult(failed);
398396
}
@@ -406,14 +404,14 @@ void DiagnosticsDialog::on_testButton_clicked()
406404
if (VerifyCPIDIsInNeuralNetwork())
407405
{
408406
ui->verifyCPIDIsInNNResultLabel->setText(tr("Passed"));
409-
ui->verifyCPIDIsInNNResultLabel->setStyleSheet("color:black;background-color:green");
407+
ui->verifyCPIDIsInNNResultLabel->setStyleSheet("color:white;background-color:green");
410408
UpdateTestStatus("verifyCPIDIsInNN", completed);
411409
UpdateOverallDiagnosticResult(passed);
412410
}
413411
else
414412
{
415413
ui->verifyCPIDIsInNNResultLabel->setText(tr("Failed"));
416-
ui->verifyCPIDIsInNNResultLabel->setStyleSheet("color:black;background-color:red");
414+
ui->verifyCPIDIsInNNResultLabel->setStyleSheet("color:white;background-color:red");
417415
UpdateTestStatus("verifyCPIDIsInNN", completed);
418416
UpdateOverallDiagnosticResult(failed);
419417
}
@@ -429,15 +427,15 @@ void DiagnosticsDialog::on_testButton_clicked()
429427
if (VerifyWalletIsSynced())
430428
{
431429
ui->verifyWalletIsSyncedResultLabel->setText(tr("Passed"));
432-
ui->verifyWalletIsSyncedResultLabel->setStyleSheet("color:black;background-color:green");
430+
ui->verifyWalletIsSyncedResultLabel->setStyleSheet("color:white;background-color:green");
433431
UpdateTestStatus("verifyWalletIsSynced", completed);
434432
UpdateOverallDiagnosticResult(passed);
435433
}
436434

437435
else
438436
{
439437
ui->verifyWalletIsSyncedResultLabel->setText(tr("Failed"));
440-
ui->verifyWalletIsSyncedResultLabel->setStyleSheet("color:black;background-color:red");
438+
ui->verifyWalletIsSyncedResultLabel->setStyleSheet("color:white;background-color:red");
441439
UpdateTestStatus("verifyWalletIsSynced", completed);
442440
UpdateOverallDiagnosticResult(failed);
443441
}
@@ -468,14 +466,14 @@ void DiagnosticsDialog::on_testButton_clicked()
468466
else if(seed_node_connections >= 3)
469467
{
470468
ui->verifySeedNodesResultLabel->setText(tr("Passed: Count = %1").arg(QString::number(seed_node_connections)));
471-
ui->verifySeedNodesResultLabel->setStyleSheet("color:black;background-color:green");
469+
ui->verifySeedNodesResultLabel->setStyleSheet("color:white;background-color:green");
472470
UpdateTestStatus("verifySeedNodes", completed);
473471
UpdateOverallDiagnosticResult(passed);
474472
}
475473
else
476474
{
477475
ui->verifySeedNodesResultLabel->setText(tr("Failed: Count = %1").arg(QString::number(seed_node_connections)));
478-
ui->verifySeedNodesResultLabel->setStyleSheet("color:black;background-color:red");
476+
ui->verifySeedNodesResultLabel->setStyleSheet("color:white;background-color:red");
479477
UpdateTestStatus("verifySeedNodes", completed);
480478
UpdateOverallDiagnosticResult(failed);
481479
}
@@ -498,25 +496,36 @@ void DiagnosticsDialog::on_testButton_clicked()
498496
else if (connections >= 8)
499497
{
500498
ui->verifyConnectionsResultLabel->setText(tr("Passed: Count = %1").arg(QString::number(connections)));
501-
ui->verifyConnectionsResultLabel->setStyleSheet("color:black;background-color:green");
499+
ui->verifyConnectionsResultLabel->setStyleSheet("color:white;background-color:green");
502500
UpdateTestStatus("verifyConnections", completed);
503501
UpdateOverallDiagnosticResult(passed);
504502
}
505503
else
506504
{
507505
ui->verifyConnectionsResultLabel->setText(tr("Failed: Count = %1").arg(QString::number(connections)));
508-
ui->verifyConnectionsResultLabel->setStyleSheet("color:black;background-color:red");
506+
ui->verifyConnectionsResultLabel->setStyleSheet("color:white;background-color:red");
509507
UpdateTestStatus("verifyConnections", completed);
510508
UpdateOverallDiagnosticResult(failed);
511509
}
512510

513511
// tcp port
514-
ui->verifyTCPPortResultLabel->setStyleSheet("");
515-
ui->verifyTCPPortResultLabel->setText(tr("Testing..."));
516-
UpdateTestStatus("verifyTCPPort", pending);
517-
this->repaint();
512+
// Only test this if intention is to run a full node (i.e. listen=1).
513+
if(GetArg("-listen", false))
514+
{
515+
ui->verifyTCPPortResultLabel->setStyleSheet("");
516+
ui->verifyTCPPortResultLabel->setText(tr("Testing..."));
517+
UpdateTestStatus("verifyTCPPort", pending);
518+
this->repaint();
518519

519-
VerifyTCPPort();
520+
VerifyTCPPort();
521+
}
522+
else
523+
{
524+
ui->verifyTCPPortResultLabel->setText(tr("NA"));
525+
ui->verifyTCPPortResultLabel->setStyleSheet("color:black;background-color:grey");
526+
UpdateTestStatus("verifyTCPPort", completed);
527+
UpdateOverallDiagnosticResult(NA);
528+
}
520529

521530
// client version
522531
ui->checkClientVersionResultLabel->setStyleSheet("");
@@ -535,7 +544,7 @@ void DiagnosticsDialog::on_testButton_clicked()
535544
else
536545
{
537546
ui->checkClientVersionResultLabel->setText(tr("Passed"));
538-
ui->checkClientVersionResultLabel->setStyleSheet("color:black;background-color:green");
547+
ui->checkClientVersionResultLabel->setStyleSheet("color:white;background-color:green");
539548
UpdateTestStatus("checkClientVersion", completed);
540549
UpdateOverallDiagnosticResult(passed);
541550
}
@@ -549,9 +558,8 @@ void DiagnosticsDialog::VerifyClock()
549558
udpSocket = new QUdpSocket(this);
550559

551560
connect(udpSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(clkStateChanged(QAbstractSocket::SocketState)));
552-
connect(udpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(clkSocketError(QAbstractSocket::SocketError)));
561+
connect(udpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(clkSocketError()));
553562

554-
udpSocket->bind(QHostAddress(NTPHost.addresses().first()), 123, QAbstractSocket::ShareAddress);
555563
udpSocket->connectToHost(QHostAddress(NTPHost.addresses().first()), 123, QIODevice::ReadWrite);
556564
}
557565

@@ -569,27 +577,21 @@ void DiagnosticsDialog::clkStateChanged(QAbstractSocket::SocketState state)
569577
return;
570578
}
571579

572-
void DiagnosticsDialog::clkSocketError(QAbstractSocket::SocketError error)
580+
void DiagnosticsDialog::clkSocketError()
573581
{
574582
udpSocket->close();
575583

576-
ui->verifyClockResultLabel->setText(tr("Warning: Cannot connect to NTP server"));
577-
ui->verifyClockResultLabel->setStyleSheet("color:black;background-color:yellow");
578-
UpdateTestStatus("verifyClockResult", completed);
579-
580-
// We need this here because there is no return call (callback) to the on_testButton_clicked function
581-
UpdateOverallDiagnosticResult(warning);
582-
583-
DisplayOverallDiagnosticResult();
584-
585584
return;
586585
}
587586

588587
void DiagnosticsDialog::clkFinished()
589588
{
590589
if (udpSocket->waitForReadyRead())
591590
{
592-
while (udpSocket->hasPendingDatagrams())
591+
int64_t start_time = GetAdjustedTime();
592+
593+
// Only allow this loop to run for 15 seconds maximum.
594+
while (udpSocket->hasPendingDatagrams() && GetAdjustedTime() - start_time <= 15)
593595
{
594596
QByteArray BufferSocket = udpSocket->readAll();
595597

@@ -609,7 +611,7 @@ void DiagnosticsDialog::clkFinished()
609611
if (timeDiff.minutes() < 3)
610612
{
611613
ui->verifyClockResultLabel->setText(tr("Passed"));
612-
ui->verifyClockResultLabel->setStyleSheet("color:black;background-color:green");
614+
ui->verifyClockResultLabel->setStyleSheet("color:white;background-color:green");
613615
UpdateTestStatus("verifyClockResult", completed);
614616

615617
// We need this here because there is no return call (callback) to the on_testButton_clicked function
@@ -618,20 +620,33 @@ void DiagnosticsDialog::clkFinished()
618620
else
619621
{
620622
ui->verifyClockResultLabel->setText(tr("Failed: Sync local time with network"));
621-
ui->verifyClockResultLabel->setStyleSheet("color:black;background-color:red");
623+
ui->verifyClockResultLabel->setStyleSheet("color:white;background-color:red");
622624
UpdateTestStatus("verifyClockResult", completed);
623625

624626
// We need this here because there is no return call (callback) to the on_testButton_clicked function
625627
UpdateOverallDiagnosticResult(failed);
626628
}
629+
630+
// We need this here because there is no return call (callback) to the on_testButton_clicked function
631+
DisplayOverallDiagnosticResult();
632+
633+
return;
627634
}
628635
}
629636
}
637+
else // The other state here is a socket or other indeterminate error (coming from clkSocketError).
638+
{
639+
ui->verifyClockResultLabel->setText(tr("Warning: Cannot connect to NTP server"));
640+
ui->verifyClockResultLabel->setStyleSheet("color:black;background-color:yellow");
641+
UpdateTestStatus("verifyClockResult", completed);
630642

631-
// We need this here because there is no return call (callback) to the on_testButton_clicked function
632-
DisplayOverallDiagnosticResult();
643+
// We need this here because there is no return call (callback) to the on_testButton_clicked function
644+
UpdateOverallDiagnosticResult(warning);
633645

634-
return;
646+
DisplayOverallDiagnosticResult();
647+
648+
return;
649+
}
635650
}
636651

637652
void DiagnosticsDialog::VerifyTCPPort()
@@ -648,7 +663,7 @@ void DiagnosticsDialog::TCPFinished()
648663
{
649664
tcpSocket->close();
650665
ui->verifyTCPPortResultLabel->setText(tr("Passed"));
651-
ui->verifyTCPPortResultLabel->setStyleSheet("color:black;background-color:green");
666+
ui->verifyTCPPortResultLabel->setStyleSheet("color:white;background-color:green");
652667

653668
// We need this here because there is no return call (callback) to the on_testButton_clicked function
654669
UpdateTestStatus("verifyTCPPort", completed);
@@ -661,8 +676,8 @@ void DiagnosticsDialog::TCPFinished()
661676

662677
void DiagnosticsDialog::TCPFailed(QAbstractSocket::SocketError socket)
663678
{
664-
ui->verifyTCPPortResultLabel->setText(tr("Failed: Port 32749 may be blocked by your firewall"));
665-
ui->verifyTCPPortResultLabel->setStyleSheet("color:black;background-color:red");
679+
ui->verifyTCPPortResultLabel->setText(tr("Warning: Port 32749 may be blocked by your firewall"));
680+
ui->verifyTCPPortResultLabel->setStyleSheet("color:black;background-color:yellow");
666681

667682
// We need this here because there is no return call (callback) to the on_testButton_clicked function
668683
UpdateTestStatus("verifyTCPPort", completed);

src/qt/diagnosticsdialog.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private slots:
8585
void on_testButton_clicked();
8686
void clkFinished();
8787
void clkStateChanged(QAbstractSocket::SocketState state);
88-
void clkSocketError(QAbstractSocket::SocketError error);
88+
void clkSocketError();
8989
void TCPFinished();
9090
void TCPFailed(QAbstractSocket::SocketError socketError);
9191
};

0 commit comments

Comments
 (0)