Skip to content

Commit

Permalink
Fee estimation: don't extend bucket ranges
Browse files Browse the repository at this point in the history
When calculating a median fee for a confirmation target at a particular
threshold, we analyse buckets in ranges rather than individually in
case some buckets have very little data. This patch ensures the breaks
between ranges are independent of the the confirmation target.
  • Loading branch information
ajtowns committed Feb 13, 2021
1 parent bf3189e commit f7d5e9c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/policy/fees.cpp
Expand Up @@ -223,6 +223,11 @@ double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal,
unsigned int curFarBucket = maxbucketindex;
unsigned int bestFarBucket = maxbucketindex;

// We'll always group buckets into sets tha meets sufficientTxVal --
// this ensures that we're using consistent groups between different
// confirmation targets.
double partialNum = 0;

bool foundAnswer = false;
unsigned int bins = unconfTxs.size();
bool newBucketRange = true;
Expand All @@ -238,6 +243,7 @@ double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal,
}
curFarBucket = bucket;
nConf += confAvg[periodTarget - 1][bucket];
partialNum += txCtAvg[bucket];
totalNum += txCtAvg[bucket];
failNum += failAvg[periodTarget - 1][bucket];
for (unsigned int confct = confTarget; confct < GetMaxConfirms(); confct++)
Expand All @@ -247,7 +253,14 @@ double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal,
// we can test for success
// (Only count the confirmed data points, so that each confirmation count
// will be looking at the same amount of data and same bucket breaks)
if (totalNum >= sufficientTxVal / (1 - decay)) {

if (partialNum < sufficientTxVal / (1 - decay)) {
// the buckets we've added in this round aren't sufficient
// so keep adding
continue;
} else {
partialNum = 0; // reset for the next range we'll add

double curPct = nConf / (totalNum + failNum + extraNum);

// Check to see if we are no longer getting confirmed at the success rate
Expand Down

0 comments on commit f7d5e9c

Please sign in to comment.