@@ -114,12 +114,10 @@ class TxConfirmStats
114
114
* @param confTarget target number of confirmations
115
115
* @param sufficientTxVal required average number of transactions per block in a bucket range
116
116
* @param minSuccess the success probability we require
117
- * @param requireGreater return the lowest feerate such that all higher values pass minSuccess OR
118
- * return the highest feerate such that all lower values fail minSuccess
119
117
* @param nBlockHeight the current block height
120
118
*/
121
119
double EstimateMedianVal (int confTarget, double sufficientTxVal,
122
- double minSuccess, bool requireGreater, unsigned int nBlockHeight,
120
+ double minSuccess, unsigned int nBlockHeight,
123
121
EstimationResult *result = nullptr ) const ;
124
122
125
123
/* * Return the max number of confirms we're tracking */
@@ -206,34 +204,26 @@ void TxConfirmStats::UpdateMovingAverages()
206
204
207
205
// returns -1 on error conditions
208
206
double TxConfirmStats::EstimateMedianVal (int confTarget, double sufficientTxVal,
209
- double successBreakPoint, bool requireGreater ,
210
- unsigned int nBlockHeight, EstimationResult *result) const
207
+ double successBreakPoint, unsigned int nBlockHeight ,
208
+ EstimationResult *result) const
211
209
{
212
210
// Counters for a bucket (or range of buckets)
213
211
double nConf = 0 ; // Number of tx's confirmed within the confTarget
214
212
double totalNum = 0 ; // Total number of tx's that were ever confirmed
215
213
int extraNum = 0 ; // Number of tx's still in mempool for confTarget or longer
216
214
double failNum = 0 ; // Number of tx's that were never confirmed but removed from the mempool after confTarget
217
215
int periodTarget = (confTarget + scale - 1 )/scale;
218
-
219
216
int maxbucketindex = buckets.size () - 1 ;
220
217
221
- // requireGreater means we are looking for the lowest feerate such that all higher
222
- // values pass, so we start at maxbucketindex (highest feerate) and look at successively
223
- // smaller buckets until we reach failure. Otherwise, we are looking for the highest
224
- // feerate such that all lower values fail, and we go in the opposite direction.
225
- unsigned int startbucket = requireGreater ? maxbucketindex : 0 ;
226
- int step = requireGreater ? -1 : 1 ;
227
-
228
218
// We'll combine buckets until we have enough samples.
229
219
// The near and far variables will define the range we've combined
230
220
// The best variables are the last range we saw which still had a high
231
221
// enough confirmation rate to count as success.
232
222
// The cur variables are the current range we're counting.
233
- unsigned int curNearBucket = startbucket ;
234
- unsigned int bestNearBucket = startbucket ;
235
- unsigned int curFarBucket = startbucket ;
236
- unsigned int bestFarBucket = startbucket ;
223
+ unsigned int curNearBucket = maxbucketindex ;
224
+ unsigned int bestNearBucket = maxbucketindex ;
225
+ unsigned int curFarBucket = maxbucketindex ;
226
+ unsigned int bestFarBucket = maxbucketindex ;
237
227
238
228
bool foundAnswer = false ;
239
229
unsigned int bins = unconfTxs.size ();
@@ -242,8 +232,8 @@ double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal,
242
232
EstimatorBucket passBucket;
243
233
EstimatorBucket failBucket;
244
234
245
- // Start counting from highest(default) or lowest feerate transactions
246
- for (int bucket = startbucket ; bucket >= 0 && bucket <= maxbucketindex; bucket += step ) {
235
+ // Start counting from highest feerate transactions
236
+ for (int bucket = maxbucketindex ; bucket >= 0 ; -- bucket) {
247
237
if (newBucketRange) {
248
238
curNearBucket = bucket;
249
239
newBucketRange = false ;
@@ -263,7 +253,7 @@ double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal,
263
253
double curPct = nConf / (totalNum + failNum + extraNum);
264
254
265
255
// Check to see if we are no longer getting confirmed at the success rate
266
- if ((requireGreater && curPct < successBreakPoint) || (!requireGreater && curPct > successBreakPoint) ) {
256
+ if (curPct < successBreakPoint) {
267
257
if (passing == true ) {
268
258
// First time we hit a failure record the failed bucket
269
259
unsigned int failMinBucket = std::min (curNearBucket, curFarBucket);
@@ -338,8 +328,8 @@ double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal,
338
328
failBucket.leftMempool = failNum;
339
329
}
340
330
341
- LogPrint (BCLog::ESTIMATEFEE, " FeeEst: %d %s %.0f%% decay %.5f: feerate: %g from (%g - %g) %.2f%% %.1f/(%.1f %d mem %.1f out) Fail: (%g - %g) %.2f%% %.1f/(%.1f %d mem %.1f out)\n " ,
342
- confTarget, requireGreater ? " > " : " < " , 100.0 * successBreakPoint, decay,
331
+ LogPrint (BCLog::ESTIMATEFEE, " FeeEst: %d > %.0f%% decay %.5f: feerate: %g from (%g - %g) %.2f%% %.1f/(%.1f %d mem %.1f out) Fail: (%g - %g) %.2f%% %.1f/(%.1f %d mem %.1f out)\n " ,
332
+ confTarget, 100.0 * successBreakPoint, decay,
343
333
median, passBucket.start , passBucket.end ,
344
334
100 * passBucket.withinTarget / (passBucket.totalConfirmed + passBucket.inMempool + passBucket.leftMempool ),
345
335
passBucket.withinTarget , passBucket.totalConfirmed , passBucket.inMempool , passBucket.leftMempool ,
@@ -664,7 +654,7 @@ CFeeRate CBlockPolicyEstimator::estimateRawFee(int confTarget, double successThr
664
654
if (successThreshold > 1 )
665
655
return CFeeRate (0 );
666
656
667
- double median = stats->EstimateMedianVal (confTarget, sufficientTxs, successThreshold, true , nBestSeenHeight, result);
657
+ double median = stats->EstimateMedianVal (confTarget, sufficientTxs, successThreshold, nBestSeenHeight, result);
668
658
669
659
if (median < 0 )
670
660
return CFeeRate (0 );
@@ -725,26 +715,26 @@ double CBlockPolicyEstimator::estimateCombinedFee(unsigned int confTarget, doubl
725
715
if (confTarget >= 1 && confTarget <= longStats->GetMaxConfirms ()) {
726
716
// Find estimate from shortest time horizon possible
727
717
if (confTarget <= shortStats->GetMaxConfirms ()) { // short horizon
728
- estimate = shortStats->EstimateMedianVal (confTarget, SUFFICIENT_TXS_SHORT, successThreshold, true , nBestSeenHeight, result);
718
+ estimate = shortStats->EstimateMedianVal (confTarget, SUFFICIENT_TXS_SHORT, successThreshold, nBestSeenHeight, result);
729
719
}
730
720
else if (confTarget <= feeStats->GetMaxConfirms ()) { // medium horizon
731
- estimate = feeStats->EstimateMedianVal (confTarget, SUFFICIENT_FEETXS, successThreshold, true , nBestSeenHeight, result);
721
+ estimate = feeStats->EstimateMedianVal (confTarget, SUFFICIENT_FEETXS, successThreshold, nBestSeenHeight, result);
732
722
}
733
723
else { // long horizon
734
- estimate = longStats->EstimateMedianVal (confTarget, SUFFICIENT_FEETXS, successThreshold, true , nBestSeenHeight, result);
724
+ estimate = longStats->EstimateMedianVal (confTarget, SUFFICIENT_FEETXS, successThreshold, nBestSeenHeight, result);
735
725
}
736
726
if (checkShorterHorizon) {
737
727
EstimationResult tempResult;
738
728
// If a lower confTarget from a more recent horizon returns a lower answer use it.
739
729
if (confTarget > feeStats->GetMaxConfirms ()) {
740
- double medMax = feeStats->EstimateMedianVal (feeStats->GetMaxConfirms (), SUFFICIENT_FEETXS, successThreshold, true , nBestSeenHeight, &tempResult);
730
+ double medMax = feeStats->EstimateMedianVal (feeStats->GetMaxConfirms (), SUFFICIENT_FEETXS, successThreshold, nBestSeenHeight, &tempResult);
741
731
if (medMax > 0 && (estimate == -1 || medMax < estimate)) {
742
732
estimate = medMax;
743
733
if (result) *result = tempResult;
744
734
}
745
735
}
746
736
if (confTarget > shortStats->GetMaxConfirms ()) {
747
- double shortMax = shortStats->EstimateMedianVal (shortStats->GetMaxConfirms (), SUFFICIENT_TXS_SHORT, successThreshold, true , nBestSeenHeight, &tempResult);
737
+ double shortMax = shortStats->EstimateMedianVal (shortStats->GetMaxConfirms (), SUFFICIENT_TXS_SHORT, successThreshold, nBestSeenHeight, &tempResult);
748
738
if (shortMax > 0 && (estimate == -1 || shortMax < estimate)) {
749
739
estimate = shortMax;
750
740
if (result) *result = tempResult;
@@ -763,10 +753,10 @@ double CBlockPolicyEstimator::estimateConservativeFee(unsigned int doubleTarget,
763
753
double estimate = -1 ;
764
754
EstimationResult tempResult;
765
755
if (doubleTarget <= shortStats->GetMaxConfirms ()) {
766
- estimate = feeStats->EstimateMedianVal (doubleTarget, SUFFICIENT_FEETXS, DOUBLE_SUCCESS_PCT, true , nBestSeenHeight, result);
756
+ estimate = feeStats->EstimateMedianVal (doubleTarget, SUFFICIENT_FEETXS, DOUBLE_SUCCESS_PCT, nBestSeenHeight, result);
767
757
}
768
758
if (doubleTarget <= feeStats->GetMaxConfirms ()) {
769
- double longEstimate = longStats->EstimateMedianVal (doubleTarget, SUFFICIENT_FEETXS, DOUBLE_SUCCESS_PCT, true , nBestSeenHeight, &tempResult);
759
+ double longEstimate = longStats->EstimateMedianVal (doubleTarget, SUFFICIENT_FEETXS, DOUBLE_SUCCESS_PCT, nBestSeenHeight, &tempResult);
770
760
if (longEstimate > estimate) {
771
761
estimate = longEstimate;
772
762
if (result) *result = tempResult;
0 commit comments