Skip to content

Commit f22ac4a

Browse files
committed
Increase success threshold for fee estimation to 95%
This provides more conservative estimates and reacts more quickly to a backlog. Unfortunately the unit test for fee estimation depends on the success threshold (and the decay) chosen; also modify the unit test for the new default success thresholds.
1 parent 4fe2823 commit f22ac4a

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

src/policy/fees.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ static const unsigned int MAX_BLOCK_CONFIRMS = 25;
182182
/** Decay of .998 is a half-life of 346 blocks or about 2.4 days */
183183
static const double DEFAULT_DECAY = .998;
184184

185-
/** Require greater than 85% of X fee transactions to be confirmed within Y blocks for X to be big enough */
186-
static const double MIN_SUCCESS_PCT = .85;
185+
/** Require greater than 95% of X fee transactions to be confirmed within Y blocks for X to be big enough */
186+
static const double MIN_SUCCESS_PCT = .95;
187187
static const double UNLIKELY_PCT = .5;
188188

189189
/** Require an avg of 1 tx in the combined fee bucket per block to have stat significance */

src/test/policyestimator_tests.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
8383
block.clear();
8484
if (blocknum == 30) {
8585
// At this point we should need to combine 5 buckets to get enough data points
86-
// So estimateFee(1) should fail and estimateFee(2) should return somewhere around
87-
// 8*baserate
86+
// So estimateFee(1,2,3) should fail and estimateFee(4) should return somewhere around
87+
// 8*baserate. estimateFee(4) %'s are 100,100,100,100,90 = average 98%
8888
BOOST_CHECK(mpool.estimateFee(1) == CFeeRate(0));
89-
BOOST_CHECK(mpool.estimateFee(2).GetFeePerK() < 8*baseRate.GetFeePerK() + deltaFee);
90-
BOOST_CHECK(mpool.estimateFee(2).GetFeePerK() > 8*baseRate.GetFeePerK() - deltaFee);
89+
BOOST_CHECK(mpool.estimateFee(2) == CFeeRate(0));
90+
BOOST_CHECK(mpool.estimateFee(3) == CFeeRate(0));
91+
BOOST_CHECK(mpool.estimateFee(4).GetFeePerK() < 8*baseRate.GetFeePerK() + deltaFee);
92+
BOOST_CHECK(mpool.estimateFee(4).GetFeePerK() > 8*baseRate.GetFeePerK() - deltaFee);
9193
}
9294
}
9395

@@ -96,20 +98,21 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
9698
// Highest feerate is 10*baseRate and gets in all blocks,
9799
// second highest feerate is 9*baseRate and gets in 9/10 blocks = 90%,
98100
// third highest feerate is 8*base rate, and gets in 8/10 blocks = 80%,
99-
// so estimateFee(1) should return 9*baseRate.
100-
// Third highest feerate has 90% chance of being included by 2 blocks,
101-
// so estimateFee(2) should return 8*baseRate etc...
101+
// so estimateFee(1) should return 10*baseRate.
102+
// Second highest feerate has 100% chance of being included by 2 blocks,
103+
// so estimateFee(2) should return 9*baseRate etc...
102104
for (int i = 1; i < 10;i++) {
103105
origFeeEst.push_back(mpool.estimateFee(i).GetFeePerK());
104106
origPriEst.push_back(mpool.estimatePriority(i));
105107
if (i > 1) { // Fee estimates should be monotonically decreasing
106108
BOOST_CHECK(origFeeEst[i-1] <= origFeeEst[i-2]);
107109
BOOST_CHECK(origPriEst[i-1] <= origPriEst[i-2]);
108110
}
109-
BOOST_CHECK(origFeeEst[i-1] < (10-i)*baseRate.GetFeePerK() + deltaFee);
110-
BOOST_CHECK(origFeeEst[i-1] > (10-i)*baseRate.GetFeePerK() - deltaFee);
111-
BOOST_CHECK(origPriEst[i-1] < pow(10,10-i) * basepri + deltaPri);
112-
BOOST_CHECK(origPriEst[i-1] > pow(10,10-i) * basepri - deltaPri);
111+
int mult = 11-i;
112+
BOOST_CHECK(origFeeEst[i-1] < mult*baseRate.GetFeePerK() + deltaFee);
113+
BOOST_CHECK(origFeeEst[i-1] > mult*baseRate.GetFeePerK() - deltaFee);
114+
BOOST_CHECK(origPriEst[i-1] < pow(10,mult) * basepri + deltaPri);
115+
BOOST_CHECK(origPriEst[i-1] > pow(10,mult) * basepri - deltaPri);
113116
}
114117

115118
// Mine 50 more blocks with no transactions happening, estimates shouldn't change
@@ -140,8 +143,8 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
140143
}
141144

142145
for (int i = 1; i < 10;i++) {
143-
BOOST_CHECK(mpool.estimateFee(i).GetFeePerK() > origFeeEst[i-1] - deltaFee);
144-
BOOST_CHECK(mpool.estimatePriority(i) > origPriEst[i-1] - deltaPri);
146+
BOOST_CHECK(mpool.estimateFee(i) == CFeeRate(0) || mpool.estimateFee(i).GetFeePerK() > origFeeEst[i-1] - deltaFee);
147+
BOOST_CHECK(mpool.estimatePriority(i) == -1 || mpool.estimatePriority(i) > origPriEst[i-1] - deltaPri);
145148
}
146149

147150
// Mine all those transactions
@@ -161,9 +164,9 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
161164
BOOST_CHECK(mpool.estimatePriority(i) > origPriEst[i-1] - deltaPri);
162165
}
163166

164-
// Mine 100 more blocks where everything is mined every block
165-
// Estimates should be below original estimates (not possible for last estimate)
166-
while (blocknum < 365) {
167+
// Mine 200 more blocks where everything is mined every block
168+
// Estimates should be below original estimates
169+
while (blocknum < 465) {
167170
for (int j = 0; j < 10; j++) { // For each fee/pri multiple
168171
for (int k = 0; k < 5; k++) { // add 4 fee txs for every priority tx
169172
tx.vin[0].prevout.n = 10000*blocknum+100*j+k;
@@ -177,7 +180,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
177180
mpool.removeForBlock(block, ++blocknum, dummyConflicted);
178181
block.clear();
179182
}
180-
for (int i = 1; i < 9; i++) {
183+
for (int i = 1; i < 10; i++) {
181184
BOOST_CHECK(mpool.estimateFee(i).GetFeePerK() < origFeeEst[i-1] - deltaFee);
182185
BOOST_CHECK(mpool.estimatePriority(i) < origPriEst[i-1] - deltaPri);
183186
}

0 commit comments

Comments
 (0)