Skip to content

Commit 6f3a0bf

Browse files
committed
Add reasonable ETTS test to diagnostics
This commit also alters the ETTS function to allow ignoring the staking status and calculating ETTS anyway. This is useful for the diagnostics, and also will be used to modify the tooltip to report staking frequency even if all of the coins are on cooldown.
1 parent 73255ba commit 6f3a0bf

File tree

5 files changed

+153
-95
lines changed

5 files changed

+153
-95
lines changed

src/main.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ double GetAverageDifficulty(unsigned int nPoSInterval)
341341
return result;
342342
}
343343

344-
double GetEstimatedTimetoStake(double dDiff, double dConfidence)
344+
double GetEstimatedTimetoStake(bool ignore_staking_status, double dDiff, double dConfidence)
345345
{
346346
/*
347347
* The algorithm below is an attempt to come up with a more accurate way of estimating Time to Stake (ETTS) based on
@@ -378,8 +378,8 @@ double GetEstimatedTimetoStake(double dDiff, double dConfidence)
378378
}
379379

380380
bool staking = MinerStatus.nLastCoinStakeSearchInterval && MinerStatus.WeightSum;
381-
// Get out early if not staking and set return value of 0.
382-
if (!staking)
381+
// Get out early if not staking and ignore_staking_status is false and set return value of 0.
382+
if (!staking && !ignore_staking_status)
383383
{
384384
if (fDebug10) LogPrintf("GetEstimatedTimetoStake debug: Not staking: ETTS = %f", result);
385385
return result;

src/main.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,12 @@ double GetEstimatedNetworkWeight(unsigned int nPoSInterval = 40);
256256
double GetDifficulty(const CBlockIndex* blockindex = NULL);
257257
double GetBlockDifficulty(unsigned int nBits);
258258
double GetAverageDifficulty(unsigned int nPoSInterval = 40);
259+
259260
// Note that dDiff cannot be = 0 normally. This is set as default because you can't specify the output of
260261
// GetAverageDifficulty(nPosInterval) = to dDiff here.
261-
// The defeult confidence is 1-1/e which is the mean for the geometric distribution.
262-
263-
const double DEFAULT_ETTS_CONFIDENCE = 0.632120558829;
264-
double GetEstimatedTimetoStake(double dDiff = 0.0, double dConfidence = DEFAULT_ETTS_CONFIDENCE);
262+
// The defeult confidence is 1-1/e which is the mean for the geometric distribution for small probabilities.
263+
const double DEFAULT_ETTS_CONFIDENCE = 1.0 - 1.0 / exp(1.0);
264+
double GetEstimatedTimetoStake(bool ignore_staking_status = false, double dDiff = 0.0, double dConfidence = DEFAULT_ETTS_CONFIDENCE);
265265

266266
NN::ClaimOption GetClaimByIndex(const CBlockIndex* const pblockindex);
267267

src/qt/diagnosticsdialog.cpp

+44-1
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,19 @@ bool DiagnosticsDialog::VerifyCPIDHasRAC()
287287
return (racValue >= 1) ? true : false;
288288
}
289289

290+
double VerifyETTSReasonable()
291+
{
292+
// We are going to compute the ETTS with ignore_staking_status set to true
293+
// and also use a 960 block diff as the input, which smooths out short
294+
// term fluctuations. The standard 1-1/e confidence (mean) is used.
295+
296+
double diff = GetAverageDifficulty(960);
297+
298+
double result = GetEstimatedTimetoStake(true, diff);
299+
300+
return result;
301+
}
302+
290303
int DiagnosticsDialog::VerifyCountSeedNodes()
291304
{
292305
LOCK(cs_vNodes);
@@ -320,7 +333,7 @@ void DiagnosticsDialog::on_testButton_clicked()
320333
}
321334

322335
// This needs to be updated if there are more tests added.
323-
unsigned int number_of_tests = 10;
336+
unsigned int number_of_tests = 11;
324337

325338
ResetOverallDiagnosticResult(number_of_tests);
326339
DisplayOverallDiagnosticResult();
@@ -543,6 +556,36 @@ void DiagnosticsDialog::on_testButton_clicked()
543556
UpdateOverallDiagnosticResult(NA);
544557
}
545558

559+
// verify reasonable ETTS
560+
ui->checkETTSResultLabel->setStyleSheet("");
561+
ui->checkETTSResultLabel->setText(tr("Testing..."));
562+
UpdateTestStatus("checkETTS", pending);
563+
double ETTS = VerifyETTSReasonable() / (24.0 * 60.0 * 60.0);
564+
565+
if (ETTS > 90.0)
566+
{
567+
ui->checkETTSResultLabel->setText(tr("Failed: ETTS = %1 > 90 days"));
568+
ui->checkETTSResultLabel->setStyleSheet("color:white;background-color:red");
569+
UpdateTestStatus("checkETTS", completed);
570+
UpdateOverallDiagnosticResult(failed);
571+
}
572+
else if (ETTS > 45.0 && ETTS <= 90.0)
573+
{
574+
ui->checkETTSResultLabel->setText(tr("Warning: 45 days < ETTS = %1 <= 90 days"));
575+
ui->checkETTSResultLabel->setStyleSheet("color:black;background-color:yellow");
576+
UpdateTestStatus("checkETTS", completed);
577+
UpdateOverallDiagnosticResult(warning);
578+
}
579+
else
580+
{
581+
ui->checkETTSResultLabel->setText(tr("Passed: ETTS <= 45 days"));
582+
ui->checkETTSResultLabel->setStyleSheet("color:white;background-color:green");
583+
UpdateTestStatus("checkETTS", completed);
584+
UpdateOverallDiagnosticResult(passed);
585+
}
586+
587+
588+
546589
// client version
547590
ui->checkClientVersionResultLabel->setStyleSheet("");
548591
ui->checkClientVersionResultLabel->setText(tr("Testing..."));

src/qt/diagnosticsdialog.h

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class DiagnosticsDialog : public QDialog
4848
bool VerifyWalletIsSynced();
4949
bool VerifyIsCPIDValid();
5050
bool VerifyCPIDHasRAC();
51+
double VerifyETTSReasonable();
5152
int VerifyCountSeedNodes();
5253
int VerifyCountConnections();
5354
double GetTotalCPIDRAC(std::string cpid);

0 commit comments

Comments
 (0)