@@ -16,10 +16,10 @@ BOOST_FIXTURE_TEST_SUITE(policyestimator_tests, BasicTestingSetup)
16
16
17
17
BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
18
18
{
19
- CTxMemPool mpool (CFeeRate (1000 ));
19
+ CTxMemPool mpool (CFeeRate (100000 ));
20
20
TestMemPoolEntryHelper entry;
21
- CAmount basefee (2000 );
22
- CAmount deltaFee (100 );
21
+ CAmount basefee (200000 );
22
+ CAmount deltaFee (100 ); // error margin for feerate tests
23
23
std::vector<CAmount> feeV;
24
24
25
25
// Populate vectors of increasing fees
@@ -49,8 +49,8 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
49
49
int blocknum = 0 ;
50
50
51
51
// Loop through 200 blocks
52
- // At a decay .998 and 4 fee transactions per block
53
- // This makes the tx count about 1.33 per bucket, above the 1 threshold
52
+ // At a decay .98845 and 4 fee transactions per block
53
+ // This makes the tx count about 0.39 per bucket, above the 0. 1 threshold
54
54
while (blocknum < 200 ) {
55
55
for (int j = 0 ; j < 10 ; j++) { // For each fee
56
56
for (int k = 0 ; k < 4 ; k++) { // add 4 fee txs
@@ -74,20 +74,12 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
74
74
}
75
75
mpool.removeForBlock (block, ++blocknum);
76
76
block.clear ();
77
- if (blocknum == 30 ) {
78
- // At this point we should need to combine 5 buckets to get enough data points
79
- // So estimateFee(1,2,3) should fail and estimateFee(4) should return somewhere around
80
- // 8*baserate. estimateFee(4) %'s are 100,100,100,100,90 = average 98%
81
- BOOST_CHECK (mpool.estimateFee (1 ) == CFeeRate (0 ));
82
- BOOST_CHECK (mpool.estimateFee (2 ) == CFeeRate (0 ));
83
- BOOST_CHECK (mpool.estimateFee (3 ) == CFeeRate (0 ));
84
- BOOST_CHECK (mpool.estimateFee (4 ).GetFeePerK () < 8 *baseRate.GetFeePerK () + deltaFee);
85
- BOOST_CHECK (mpool.estimateFee (4 ).GetFeePerK () > 8 *baseRate.GetFeePerK () - deltaFee);
86
- int answerFound;
87
- BOOST_CHECK (mpool.estimateSmartFee (1 , &answerFound) == mpool.estimateFee (4 ) && answerFound == 4 );
88
- BOOST_CHECK (mpool.estimateSmartFee (3 , &answerFound) == mpool.estimateFee (4 ) && answerFound == 4 );
89
- BOOST_CHECK (mpool.estimateSmartFee (4 , &answerFound) == mpool.estimateFee (4 ) && answerFound == 4 );
90
- BOOST_CHECK (mpool.estimateSmartFee (8 , &answerFound) == mpool.estimateFee (8 ) && answerFound == 8 );
77
+ if (blocknum == 3 ) {
78
+ // At this point we should need to combine 2 buckets to get enough data points
79
+ // So estimateFee(2) should return somewhere around 9*baserate.
80
+ // estimateFee(2) %'s are 100,100,90 = average 97%
81
+ BOOST_CHECK (mpool.estimateFee (2 ).GetFeePerK () < 9 *baseRate.GetFeePerK () + deltaFee);
82
+ BOOST_CHECK (mpool.estimateFee (2 ).GetFeePerK () > 9 *baseRate.GetFeePerK () - deltaFee);
91
83
}
92
84
}
93
85
@@ -97,14 +89,14 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
97
89
// third highest feerate is 8*base rate, and gets in 8/10 blocks = 80%,
98
90
// so estimateFee(1) would return 10*baseRate but is hardcoded to return failure
99
91
// Second highest feerate has 100% chance of being included by 2 blocks,
100
- // so estimateFee(2) should return 9 *baseRate etc...
101
- for (int i = 1 ; i < 10 ;i++) {
92
+ // thus at 80% confidence, estimateFee(2) should return 8 *baseRate etc...
93
+ for (int i = 1 ; i < 8 ;i++) {
102
94
origFeeEst.push_back (mpool.estimateFee (i).GetFeePerK ());
103
95
if (i > 2 ) { // Fee estimates should be monotonically decreasing
104
96
BOOST_CHECK (origFeeEst[i-1 ] <= origFeeEst[i-2 ]);
105
97
}
106
- int mult = 11 -i;
107
- if (i > 1 ) {
98
+ int mult = 9 -i;
99
+ if (i > 1 && i < 8 ) {
108
100
BOOST_CHECK (origFeeEst[i-1 ] < mult*baseRate.GetFeePerK () + deltaFee);
109
101
BOOST_CHECK (origFeeEst[i-1 ] > mult*baseRate.GetFeePerK () - deltaFee);
110
102
}
@@ -119,7 +111,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
119
111
mpool.removeForBlock (block, ++blocknum);
120
112
121
113
BOOST_CHECK (mpool.estimateFee (1 ) == CFeeRate (0 ));
122
- for (int i = 2 ; i < 10 ;i++) {
114
+ for (int i = 2 ; i < 8 ;i++) {
123
115
BOOST_CHECK (mpool.estimateFee (i).GetFeePerK () < origFeeEst[i-1 ] + deltaFee);
124
116
BOOST_CHECK (mpool.estimateFee (i).GetFeePerK () > origFeeEst[i-1 ] - deltaFee);
125
117
}
@@ -140,7 +132,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
140
132
}
141
133
142
134
int answerFound;
143
- for (int i = 1 ; i < 10 ;i++) {
135
+ for (int i = 1 ; i < 8 ;i++) {
144
136
BOOST_CHECK (mpool.estimateFee (i) == CFeeRate (0 ) || mpool.estimateFee (i).GetFeePerK () > origFeeEst[i-1 ] - deltaFee);
145
137
BOOST_CHECK (mpool.estimateSmartFee (i, &answerFound).GetFeePerK () > origFeeEst[answerFound-1 ] - deltaFee);
146
138
}
@@ -158,7 +150,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
158
150
mpool.removeForBlock (block, 265 );
159
151
block.clear ();
160
152
BOOST_CHECK (mpool.estimateFee (1 ) == CFeeRate (0 ));
161
- for (int i = 2 ; i < 10 ;i++) {
153
+ for (int i = 2 ; i < 8 ;i++) {
162
154
BOOST_CHECK (mpool.estimateFee (i).GetFeePerK () > origFeeEst[i-1 ] - deltaFee);
163
155
}
164
156
@@ -180,7 +172,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
180
172
block.clear ();
181
173
}
182
174
BOOST_CHECK (mpool.estimateFee (1 ) == CFeeRate (0 ));
183
- for (int i = 2 ; i < 10 ; i++) {
175
+ for (int i = 2 ; i < 8 ; i++) {
184
176
BOOST_CHECK (mpool.estimateFee (i).GetFeePerK () < origFeeEst[i-1 ] - deltaFee);
185
177
}
186
178
0 commit comments