@@ -55,7 +55,7 @@ class TxConfirmStats
5555
5656 // Sum the total feerate of all tx's in each bucket
5757 // Track the historical moving average of this total over blocks
58- std::vector<double > avg ;
58+ std::vector<double > m_feerate_avg ;
5959
6060 // Combine the conf counts with tx counts to calculate the confirmation % for each Y,X
6161 // Combine the total value with the tx counts to calculate the avg feerate per bucket
@@ -137,11 +137,9 @@ class TxConfirmStats
137137TxConfirmStats::TxConfirmStats (const std::vector<double >& defaultBuckets,
138138 const std::map<double , unsigned int >& defaultBucketMap,
139139 unsigned int maxPeriods, double _decay, unsigned int _scale)
140- : buckets(defaultBuckets), bucketMap(defaultBucketMap)
140+ : buckets(defaultBuckets), bucketMap(defaultBucketMap), decay(_decay), scale(_scale)
141141{
142- decay = _decay;
143142 assert (_scale != 0 && " _scale must be non-zero" );
144- scale = _scale;
145143 confAvg.resize (maxPeriods);
146144 for (unsigned int i = 0 ; i < maxPeriods; i++) {
147145 confAvg[i].resize (buckets.size ());
@@ -152,7 +150,7 @@ TxConfirmStats::TxConfirmStats(const std::vector<double>& defaultBuckets,
152150 }
153151
154152 txCtAvg.resize (buckets.size ());
155- avg .resize (buckets.size ());
153+ m_feerate_avg .resize (buckets.size ());
156154
157155 resizeInMemoryCounters (buckets.size ());
158156}
@@ -170,24 +168,24 @@ void TxConfirmStats::resizeInMemoryCounters(size_t newbuckets) {
170168void TxConfirmStats::ClearCurrent (unsigned int nBlockHeight)
171169{
172170 for (unsigned int j = 0 ; j < buckets.size (); j++) {
173- oldUnconfTxs[j] += unconfTxs[nBlockHeight% unconfTxs.size ()][j];
171+ oldUnconfTxs[j] += unconfTxs[nBlockHeight % unconfTxs.size ()][j];
174172 unconfTxs[nBlockHeight%unconfTxs.size ()][j] = 0 ;
175173 }
176174}
177175
178176
179- void TxConfirmStats::Record (int blocksToConfirm, double val )
177+ void TxConfirmStats::Record (int blocksToConfirm, double feerate )
180178{
181179 // blocksToConfirm is 1-based
182180 if (blocksToConfirm < 1 )
183181 return ;
184- int periodsToConfirm = (blocksToConfirm + scale - 1 )/ scale;
185- unsigned int bucketindex = bucketMap.lower_bound (val )->second ;
182+ int periodsToConfirm = (blocksToConfirm + scale - 1 ) / scale;
183+ unsigned int bucketindex = bucketMap.lower_bound (feerate )->second ;
186184 for (size_t i = periodsToConfirm; i <= confAvg.size (); i++) {
187185 confAvg[i - 1 ][bucketindex]++;
188186 }
189187 txCtAvg[bucketindex]++;
190- avg [bucketindex] += val ;
188+ m_feerate_avg [bucketindex] += feerate ;
191189}
192190
193191void TxConfirmStats::UpdateMovingAverages ()
@@ -197,8 +195,8 @@ void TxConfirmStats::UpdateMovingAverages()
197195 confAvg[i][j] = confAvg[i][j] * decay;
198196 for (unsigned int i = 0 ; i < failAvg.size (); i++)
199197 failAvg[i][j] = failAvg[i][j] * decay;
200- avg [j] = avg[j] * decay;
201- txCtAvg[j] = txCtAvg[j] * decay;
198+ m_feerate_avg [j] *= decay;
199+ txCtAvg[j] *= decay;
202200 }
203201}
204202
@@ -212,8 +210,8 @@ double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal,
212210 double totalNum = 0 ; // Total number of tx's that were ever confirmed
213211 int extraNum = 0 ; // Number of tx's still in mempool for confTarget or longer
214212 double failNum = 0 ; // Number of tx's that were never confirmed but removed from the mempool after confTarget
215- int periodTarget = (confTarget + scale - 1 )/ scale;
216- int maxbucketindex = buckets.size () - 1 ;
213+ const int periodTarget = (confTarget + scale - 1 ) / scale;
214+ const int maxbucketindex = buckets.size () - 1 ;
217215
218216 // We'll combine buckets until we have enough samples.
219217 // The near and far variables will define the range we've combined
@@ -243,7 +241,7 @@ double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal,
243241 totalNum += txCtAvg[bucket];
244242 failNum += failAvg[periodTarget - 1 ][bucket];
245243 for (unsigned int confct = confTarget; confct < GetMaxConfirms (); confct++)
246- extraNum += unconfTxs[(nBlockHeight - confct)% bins][bucket];
244+ extraNum += unconfTxs[(nBlockHeight - confct) % bins][bucket];
247245 extraNum += oldUnconfTxs[bucket];
248246 // If we have enough transaction data points in this range of buckets,
249247 // we can test for success
@@ -307,7 +305,7 @@ double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal,
307305 if (txCtAvg[j] < txSum)
308306 txSum -= txCtAvg[j];
309307 else { // we're in the right bucket
310- median = avg [j] / txCtAvg[j];
308+ median = m_feerate_avg [j] / txCtAvg[j];
311309 break ;
312310 }
313311 }
@@ -351,7 +349,7 @@ void TxConfirmStats::Write(CAutoFile& fileout) const
351349{
352350 fileout << decay;
353351 fileout << scale;
354- fileout << avg ;
352+ fileout << m_feerate_avg ;
355353 fileout << txCtAvg;
356354 fileout << confAvg;
357355 fileout << failAvg;
@@ -374,8 +372,8 @@ void TxConfirmStats::Read(CAutoFile& filein, int nFileVersion, size_t numBuckets
374372 throw std::runtime_error (" Corrupt estimates file. Scale must be non-zero" );
375373 }
376374
377- filein >> avg ;
378- if (avg .size () != numBuckets) {
375+ filein >> m_feerate_avg ;
376+ if (m_feerate_avg .size () != numBuckets) {
379377 throw std::runtime_error (" Corrupt estimates file. Mismatch in feerate average bucket count" );
380378 }
381379 filein >> txCtAvg;
0 commit comments