Skip to content

Commit a5e39d3

Browse files
committed
Fee estimation: extend bucket ranges consistently
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.
1 parent e191fac commit a5e39d3

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/policy/fees.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@ double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal,
259259
unsigned int curFarBucket = maxbucketindex;
260260
unsigned int bestFarBucket = maxbucketindex;
261261

262+
// We'll always group buckets into sets that meet sufficientTxVal --
263+
// this ensures that we're using consistent groups between different
264+
// confirmation targets.
265+
double partialNum = 0;
266+
262267
bool foundAnswer = false;
263268
unsigned int bins = unconfTxs.size();
264269
bool newBucketRange = true;
@@ -274,6 +279,7 @@ double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal,
274279
}
275280
curFarBucket = bucket;
276281
nConf += confAvg[periodTarget - 1][bucket];
282+
partialNum += txCtAvg[bucket];
277283
totalNum += txCtAvg[bucket];
278284
failNum += failAvg[periodTarget - 1][bucket];
279285
for (unsigned int confct = confTarget; confct < GetMaxConfirms(); confct++)
@@ -283,7 +289,14 @@ double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal,
283289
// we can test for success
284290
// (Only count the confirmed data points, so that each confirmation count
285291
// will be looking at the same amount of data and same bucket breaks)
286-
if (totalNum >= sufficientTxVal / (1 - decay)) {
292+
293+
if (partialNum < sufficientTxVal / (1 - decay)) {
294+
// the buckets we've added in this round aren't sufficient
295+
// so keep adding
296+
continue;
297+
} else {
298+
partialNum = 0; // reset for the next range we'll add
299+
287300
double curPct = nConf / (totalNum + failNum + extraNum);
288301

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

0 commit comments

Comments
 (0)