14
14
#include " txmempool.h"
15
15
#include " util.h"
16
16
17
- void TxConfirmStats::Initialize ( std::vector<double >& defaultBuckets,
18
- unsigned int maxConfirms, double _decay)
17
+ TxConfirmStats::TxConfirmStats ( const std::vector<double >& defaultBuckets,
18
+ unsigned int maxConfirms, double _decay)
19
19
{
20
20
decay = _decay;
21
21
for (unsigned int i = 0 ; i < defaultBuckets.size (); i++) {
@@ -294,7 +294,7 @@ bool CBlockPolicyEstimator::removeTx(uint256 hash)
294
294
LOCK (cs_feeEstimator);
295
295
std::map<uint256, TxStatsInfo>::iterator pos = mapMemPoolTxs.find (hash);
296
296
if (pos != mapMemPoolTxs.end ()) {
297
- feeStats. removeTx (pos->second .blockHeight , nBestSeenHeight, pos->second .bucketIndex );
297
+ feeStats-> removeTx (pos->second .blockHeight , nBestSeenHeight, pos->second .bucketIndex );
298
298
mapMemPoolTxs.erase (hash);
299
299
return true ;
300
300
} else {
@@ -312,7 +312,12 @@ CBlockPolicyEstimator::CBlockPolicyEstimator()
312
312
vfeelist.push_back (bucketBoundary);
313
313
}
314
314
vfeelist.push_back (INF_FEERATE);
315
- feeStats.Initialize (vfeelist, MAX_BLOCK_CONFIRMS, DEFAULT_DECAY);
315
+ feeStats = new TxConfirmStats (vfeelist, MAX_BLOCK_CONFIRMS, DEFAULT_DECAY);
316
+ }
317
+
318
+ CBlockPolicyEstimator::~CBlockPolicyEstimator ()
319
+ {
320
+ delete feeStats;
316
321
}
317
322
318
323
void CBlockPolicyEstimator::processTransaction (const CTxMemPoolEntry& entry, bool validFeeEstimate)
@@ -346,7 +351,7 @@ void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, boo
346
351
CFeeRate feeRate (entry.GetFee (), entry.GetTxSize ());
347
352
348
353
mapMemPoolTxs[hash].blockHeight = txHeight;
349
- mapMemPoolTxs[hash].bucketIndex = feeStats. NewTx (txHeight, (double )feeRate.GetFeePerK ());
354
+ mapMemPoolTxs[hash].bucketIndex = feeStats-> NewTx (txHeight, (double )feeRate.GetFeePerK ());
350
355
}
351
356
352
357
bool CBlockPolicyEstimator::processBlockTx (unsigned int nBlockHeight, const CTxMemPoolEntry* entry)
@@ -370,7 +375,7 @@ bool CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxM
370
375
// Feerates are stored and reported as BTC-per-kb:
371
376
CFeeRate feeRate (entry->GetFee (), entry->GetTxSize ());
372
377
373
- feeStats. Record (blocksToConfirm, (double )feeRate.GetFeePerK ());
378
+ feeStats-> Record (blocksToConfirm, (double )feeRate.GetFeePerK ());
374
379
return true ;
375
380
}
376
381
@@ -393,7 +398,7 @@ void CBlockPolicyEstimator::processBlock(unsigned int nBlockHeight,
393
398
nBestSeenHeight = nBlockHeight;
394
399
395
400
// Clear the current block state and update unconfirmed circular buffer
396
- feeStats. ClearCurrent (nBlockHeight);
401
+ feeStats-> ClearCurrent (nBlockHeight);
397
402
398
403
unsigned int countedTxs = 0 ;
399
404
// Repopulate the current block states
@@ -403,7 +408,7 @@ void CBlockPolicyEstimator::processBlock(unsigned int nBlockHeight,
403
408
}
404
409
405
410
// Update all exponential averages with the current block state
406
- feeStats. UpdateMovingAverages ();
411
+ feeStats-> UpdateMovingAverages ();
407
412
408
413
LogPrint (BCLog::ESTIMATEFEE, " Blockpolicy after updating estimates for %u of %u txs in block, since last block %u of %u tracked, new mempool map size %u\n " ,
409
414
countedTxs, entries.size (), trackedTxs, trackedTxs + untrackedTxs, mapMemPoolTxs.size ());
@@ -417,10 +422,10 @@ CFeeRate CBlockPolicyEstimator::estimateFee(int confTarget) const
417
422
LOCK (cs_feeEstimator);
418
423
// Return failure if trying to analyze a target we're not tracking
419
424
// It's not possible to get reasonable estimates for confTarget of 1
420
- if (confTarget <= 1 || (unsigned int )confTarget > feeStats. GetMaxConfirms ())
425
+ if (confTarget <= 1 || (unsigned int )confTarget > feeStats-> GetMaxConfirms ())
421
426
return CFeeRate (0 );
422
427
423
- double median = feeStats. EstimateMedianVal (confTarget, SUFFICIENT_FEETXS, MIN_SUCCESS_PCT, true , nBestSeenHeight);
428
+ double median = feeStats-> EstimateMedianVal (confTarget, SUFFICIENT_FEETXS, MIN_SUCCESS_PCT, true , nBestSeenHeight);
424
429
425
430
if (median < 0 )
426
431
return CFeeRate (0 );
@@ -439,15 +444,15 @@ CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, int *answerFoun
439
444
LOCK (cs_feeEstimator);
440
445
441
446
// Return failure if trying to analyze a target we're not tracking
442
- if (confTarget <= 0 || (unsigned int )confTarget > feeStats. GetMaxConfirms ())
447
+ if (confTarget <= 0 || (unsigned int )confTarget > feeStats-> GetMaxConfirms ())
443
448
return CFeeRate (0 );
444
449
445
450
// It's not possible to get reasonable estimates for confTarget of 1
446
451
if (confTarget == 1 )
447
452
confTarget = 2 ;
448
453
449
- while (median < 0 && (unsigned int )confTarget <= feeStats. GetMaxConfirms ()) {
450
- median = feeStats. EstimateMedianVal (confTarget++, SUFFICIENT_FEETXS, MIN_SUCCESS_PCT, true , nBestSeenHeight);
454
+ while (median < 0 && (unsigned int )confTarget <= feeStats-> GetMaxConfirms ()) {
455
+ median = feeStats-> EstimateMedianVal (confTarget++, SUFFICIENT_FEETXS, MIN_SUCCESS_PCT, true , nBestSeenHeight);
451
456
}
452
457
} // Must unlock cs_feeEstimator before taking mempool locks
453
458
@@ -472,7 +477,7 @@ bool CBlockPolicyEstimator::Write(CAutoFile& fileout) const
472
477
fileout << 139900 ; // version required to read: 0.13.99 or later
473
478
fileout << CLIENT_VERSION; // version that wrote the file
474
479
fileout << nBestSeenHeight;
475
- feeStats. Write (fileout);
480
+ feeStats-> Write (fileout);
476
481
}
477
482
catch (const std::exception&) {
478
483
LogPrintf (" CBlockPolicyEstimator::Write(): unable to read policy estimator data (non-fatal)\n " );
@@ -490,7 +495,7 @@ bool CBlockPolicyEstimator::Read(CAutoFile& filein)
490
495
if (nVersionRequired > CLIENT_VERSION)
491
496
return error (" CBlockPolicyEstimator::Read(): up-version (%d) fee estimate file" , nVersionRequired);
492
497
filein >> nFileBestSeenHeight;
493
- feeStats. Read (filein);
498
+ feeStats-> Read (filein);
494
499
nBestSeenHeight = nFileBestSeenHeight;
495
500
// if nVersionThatWrote < 139900 then another TxConfirmStats (for priority) follows but can be ignored.
496
501
}
0 commit comments