@@ -377,9 +377,19 @@ double GetEstimatedTimetoStake(bool ignore_staking_status, double dDiff, double
377377 return result;
378378 }
379379
380- bool staking = MinerStatus.nLastCoinStakeSearchInterval && MinerStatus.WeightSum ;
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)
380+ bool staking;
381+ bool able_to_stake;
382+
383+ {
384+ LOCK (MinerStatus.lock );
385+
386+ staking = MinerStatus.nLastCoinStakeSearchInterval && MinerStatus.WeightSum ;
387+
388+ able_to_stake = MinerStatus.able_to_stake ;
389+ }
390+
391+ // Get out early if not staking, ignore_staking_status is false, and not able_to_stake and set return value of 0.
392+ if (!ignore_staking_status && !staking && !able_to_stake)
383393 {
384394 if (fDebug10 ) LogPrintf (" GetEstimatedTimetoStake debug: Not staking: ETTS = %f" , result);
385395 return result;
@@ -447,11 +457,9 @@ double GetEstimatedTimetoStake(bool ignore_staking_status, double dDiff, double
447457 {
448458 CTxIndex txindex;
449459 CBlock CoinBlock; // Block which contains CoinTx
450- if (!txdb.ReadTxIndex (out.tx ->GetHash (), txindex))
451- continue ; // error?
460+ if (!txdb.ReadTxIndex (out.tx ->GetHash (), txindex)) continue ; // Ignore transactions that can't be read.
452461
453- if (!CoinBlock.ReadFromDisk (txindex.pos .nFile , txindex.pos .nBlockPos , false ))
454- continue ;
462+ if (!CoinBlock.ReadFromDisk (txindex.pos .nFile , txindex.pos .nBlockPos , false )) continue ;
455463
456464 // We are going to store as an event the time that the UTXO matures (is available for staking again.)
457465 nTime = (CoinBlock.GetBlockTime () & ~ETTS_TIMESTAMP_MASK) + nStakeMinAge;
@@ -462,14 +470,14 @@ double GetEstimatedTimetoStake(bool ignore_staking_status, double dDiff, double
462470 // subtracting the reserve. Each UTXO also has to be greater than 1/80 GRC to result in a weight greater than zero in the CreateCoinStake loop,
463471 // so eliminate UTXO's with less than 0.0125 GRC balances right here. The test with Satoshi units for that is
464472 // nValue >= 1250000.
465- if (BalanceAvailForStaking >= nValue && nValue >= 1250000 )
473+ if (BalanceAvailForStaking >= nValue && nValue >= 1250000 )
466474 {
467475 vUTXO.push_back (std::pair<int64_t , int64_t >( nTime, nValue));
468476 if (fDebug10 ) LogPrintf (" GetEstimatedTimetoStake debug: pair (relative to current time: <%i, %i>" , nTime - nCurrentTime, nValue);
469477
470478 // Only record a time below if it is after nCurrentTime, because UTXO's that have matured already are already stakeable and can be grouped (will be found)
471479 // by the nCurrentTime record that was already injected above.
472- if (nTime > nCurrentTime) UniqueUTXOTimes.insert (nTime);
480+ if (nTime > nCurrentTime) UniqueUTXOTimes.insert (nTime);
473481 }
474482 }
475483
@@ -485,13 +493,13 @@ double GetEstimatedTimetoStake(bool ignore_staking_status, double dDiff, double
485493 // become significant. The CDF of a compound geometric distribution as you do tosses with different probabilities follows the
486494 // recursion relation... CDF.i = 1 - (1 - CDF.i-1)(1 - p.i). If all probabilities are the same, this reduces to the familiar
487495 // CDF.k = 1 - (1 - p)^k where ^ is exponentiation.
488- for (const auto & itertime : UniqueUTXOTimes)
496+ for (const auto & itertime : UniqueUTXOTimes)
489497 {
490498
491499 nTime = itertime;
492500 dProbAccumulator = 0 ;
493501
494- for ( auto & iterUTXO : vUTXO)
502+ for ( auto & iterUTXO : vUTXO)
495503 {
496504
497505 if (fDebug10 ) LogPrintf (" GetEstimatedTimetoStake debug: Unique UTXO Time: %u, vector pair <%u, %u>" , nTime, iterUTXO.first , iterUTXO.second );
@@ -515,8 +523,7 @@ double GetEstimatedTimetoStake(bool ignore_staking_status, double dDiff, double
515523 dCumulativeProbability = 1 - ((1 - dCumulativeProbability) * pow ((1 - dProbAccumulator), nThrows));
516524 if (fDebug10 ) LogPrintf (" GetEstimatedTimetoStake debug: dCumulativeProbability = %e" , dCumulativeProbability);
517525
518- if (dCumulativeProbability >= dConfidence)
519- break ;
526+ if (dCumulativeProbability >= dConfidence) break ;
520527
521528 nTimePrev = nTime;
522529 }
@@ -549,16 +556,6 @@ double GetEstimatedTimetoStake(bool ignore_staking_status, double dDiff, double
549556 result = nDeltaTime + nTime - nCurrentTime;
550557 if (fDebug10 ) LogPrintf (" GetEstimatedTimetoStake debug: ETTS at %d confidence = %i" , dConfidence, result);
551558
552- // The old calculation for comparative purposes, only done if fDebug10 set. Note that this is the "fixed" old
553- // calculation, because the old network weight calculation was wrong too...
554- if (fDebug10 )
555- {
556- double oldETTS = 0 ;
557-
558- oldETTS = GetTargetSpacing (nBestHeight) * GetEstimatedNetworkWeight (40 ) / MinerStatus.WeightSum ;
559- LogPrintf (" GetEstimatedTimetoStake debug: oldETTS = %f" , oldETTS);
560- }
561-
562559 return result;
563560}
564561
@@ -598,48 +595,57 @@ void GetGlobalStatus()
598595
599596 // It is necessary to assign a local variable for ETTS to avoid an occasional deadlock between the lock below,
600597 // the lock on cs_main in GetEstimateTimetoStake(), and the corresponding lock in the stakeminer.
601- double dETTS = GetEstimatedTimetoStake ()/86400.0 ;
598+ double dETTS = GetEstimatedTimetoStake () / 86400.0 ;
599+
602600 LOCK (GlobalStatusStruct.lock );
603- { LOCK (MinerStatus.lock );
604- GlobalStatusStruct.blocks = ToString (nBestHeight);
605- GlobalStatusStruct.difficulty = RoundToString (PORDiff,3 );
606- GlobalStatusStruct.netWeight = RoundToString (GetEstimatedNetworkWeight () / 80.0 ,2 );
607- // todo: use the real weight from miner status (requires scaling)
608- GlobalStatusStruct.coinWeight = sWeight ;
609- GlobalStatusStruct.magnitude = RoundToString (boincmagnitude,2 );
610- GlobalStatusStruct.ETTS = RoundToString (dETTS,3 );
611- GlobalStatusStruct.ERRperday = RoundToString (boincmagnitude * NN::Tally::GetMagnitudeUnit (GetAdjustedTime ()),2 );
612- GlobalStatusStruct.cpid = NN::GetPrimaryCpid ();
613- GlobalStatusStruct.poll = std::move (current_poll);
614-
615- GlobalStatusStruct.status = msMiningErrors;
616-
617- if (MinerStatus.WeightSum )
618- GlobalStatusStruct.coinWeight = RoundToString (MinerStatus.WeightSum / 80.0 ,2 );
619-
620- GlobalStatusStruct.errors .clear ();
621- std::string Alerts = GetWarnings (" statusbar" );
622- if (!Alerts.empty ())
623- GlobalStatusStruct.errors += _ (" Alert: " ) + Alerts + " ; " ;
624-
625- if (PORDiff < 0.1 )
626- GlobalStatusStruct.errors += _ (" Low difficulty!; " );
627-
628- if (!MinerStatus.ReasonNotStaking .empty ())
629- GlobalStatusStruct.errors += _ (" Miner: " ) + MinerStatus.ReasonNotStaking ;
630-
631- unsigned long stk_dropped = MinerStatus.KernelsFound - MinerStatus.AcceptedCnt ;
632- if (stk_dropped)
633- GlobalStatusStruct.errors += " Rejected " + ToString (stk_dropped) + " stakes;" ;
634-
635- if (!msMiningErrors6.empty ())
636- GlobalStatusStruct.errors +=msMiningErrors6 + " ; " ;
637- if (!msMiningErrors7.empty ())
638- GlobalStatusStruct.errors += msMiningErrors7 + " ; " ;
639- if (!msMiningErrors8.empty ())
640- GlobalStatusStruct.errors += msMiningErrors8 + " ; " ;
641601
602+ {
603+ GlobalStatusStruct.blocks = ToString (nBestHeight);
604+ GlobalStatusStruct.difficulty = RoundToString (PORDiff,3 );
605+ GlobalStatusStruct.netWeight = RoundToString (GetEstimatedNetworkWeight () / 80.0 ,2 );
606+ // todo: use the real weight from miner status (requires scaling)
607+ GlobalStatusStruct.coinWeight = sWeight ;
608+ GlobalStatusStruct.magnitude = RoundToString (boincmagnitude,2 );
609+ GlobalStatusStruct.ETTS = RoundToString (dETTS,3 );
610+ GlobalStatusStruct.ERRperday = RoundToString (boincmagnitude * NN::Tally::GetMagnitudeUnit (GetAdjustedTime ()),2 );
611+ GlobalStatusStruct.cpid = NN::GetPrimaryCpid ();
612+ GlobalStatusStruct.poll = std::move (current_poll);
613+
614+ GlobalStatusStruct.status = msMiningErrors;
615+
616+ unsigned long stk_dropped;
617+
618+ {
619+ LOCK (MinerStatus.lock );
620+
621+ if (MinerStatus.WeightSum )
622+ GlobalStatusStruct.coinWeight = RoundToString (MinerStatus.WeightSum / 80.0 ,2 );
623+
624+ GlobalStatusStruct.errors .clear ();
625+ std::string Alerts = GetWarnings (" statusbar" );
626+ if (!Alerts.empty ())
627+ GlobalStatusStruct.errors += _ (" Alert: " ) + Alerts + " ; " ;
628+
629+ if (PORDiff < 0.1 )
630+ GlobalStatusStruct.errors += _ (" Low difficulty!; " );
631+
632+ if (!MinerStatus.ReasonNotStaking .empty ())
633+ GlobalStatusStruct.errors += _ (" Miner: " ) + MinerStatus.ReasonNotStaking ;
634+
635+ stk_dropped = MinerStatus.KernelsFound - MinerStatus.AcceptedCnt ;
636+ }
637+
638+ if (stk_dropped)
639+ GlobalStatusStruct.errors += " Rejected " + ToString (stk_dropped) + " stakes;" ;
640+
641+ if (!msMiningErrors6.empty ())
642+ GlobalStatusStruct.errors +=msMiningErrors6 + " ; " ;
643+ if (!msMiningErrors7.empty ())
644+ GlobalStatusStruct.errors += msMiningErrors7 + " ; " ;
645+ if (!msMiningErrors8.empty ())
646+ GlobalStatusStruct.errors += msMiningErrors8 + " ; " ;
642647 }
648+
643649 return ;
644650 }
645651 catch (std::exception& e)
0 commit comments