14
14
#include " txmempool.h"
15
15
#include " util.h"
16
16
17
+ static constexpr double INF_FEERATE = 1e99 ;
18
+
17
19
/* *
18
20
* We will instantiate an instance of this class to track transactions that were
19
21
* included in a block. We will lump transactions into a bucket according to their
@@ -400,6 +402,8 @@ bool CBlockPolicyEstimator::removeTx(uint256 hash)
400
402
std::map<uint256, TxStatsInfo>::iterator pos = mapMemPoolTxs.find (hash);
401
403
if (pos != mapMemPoolTxs.end ()) {
402
404
feeStats->removeTx (pos->second .blockHeight , nBestSeenHeight, pos->second .bucketIndex );
405
+ shortStats->removeTx (pos->second .blockHeight , nBestSeenHeight, pos->second .bucketIndex );
406
+ longStats->removeTx (pos->second .blockHeight , nBestSeenHeight, pos->second .bucketIndex );
403
407
mapMemPoolTxs.erase (hash);
404
408
return true ;
405
409
} else {
@@ -421,9 +425,9 @@ CBlockPolicyEstimator::CBlockPolicyEstimator()
421
425
bucketMap[INF_FEERATE] = bucketIndex;
422
426
assert (bucketMap.size () == buckets.size ());
423
427
424
- feeStats = new TxConfirmStats (buckets, bucketMap, MAX_BLOCK_CONFIRMS, DEFAULT_DECAY );
425
- shortStats = new TxConfirmStats (buckets, bucketMap, MAX_BLOCK_CONFIRMS, DEFAULT_DECAY );
426
- longStats = new TxConfirmStats (buckets, bucketMap, MAX_BLOCK_CONFIRMS, DEFAULT_DECAY );
428
+ feeStats = new TxConfirmStats (buckets, bucketMap, MED_BLOCK_CONFIRMS, MED_DECAY );
429
+ shortStats = new TxConfirmStats (buckets, bucketMap, SHORT_BLOCK_CONFIRMS, SHORT_DECAY );
430
+ longStats = new TxConfirmStats (buckets, bucketMap, LONG_BLOCK_CONFIRMS, LONG_DECAY );
427
431
}
428
432
429
433
CBlockPolicyEstimator::~CBlockPolicyEstimator ()
@@ -464,7 +468,12 @@ void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, boo
464
468
CFeeRate feeRate (entry.GetFee (), entry.GetTxSize ());
465
469
466
470
mapMemPoolTxs[hash].blockHeight = txHeight;
467
- mapMemPoolTxs[hash].bucketIndex = feeStats->NewTx (txHeight, (double )feeRate.GetFeePerK ());
471
+ unsigned int bucketIndex = feeStats->NewTx (txHeight, (double )feeRate.GetFeePerK ());
472
+ mapMemPoolTxs[hash].bucketIndex = bucketIndex;
473
+ unsigned int bucketIndex2 = shortStats->NewTx (txHeight, (double )feeRate.GetFeePerK ());
474
+ assert (bucketIndex == bucketIndex2);
475
+ unsigned int bucketIndex3 = longStats->NewTx (txHeight, (double )feeRate.GetFeePerK ());
476
+ assert (bucketIndex == bucketIndex3);
468
477
}
469
478
470
479
bool CBlockPolicyEstimator::processBlockTx (unsigned int nBlockHeight, const CTxMemPoolEntry* entry)
@@ -489,6 +498,8 @@ bool CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxM
489
498
CFeeRate feeRate (entry->GetFee (), entry->GetTxSize ());
490
499
491
500
feeStats->Record (blocksToConfirm, (double )feeRate.GetFeePerK ());
501
+ shortStats->Record (blocksToConfirm, (double )feeRate.GetFeePerK ());
502
+ longStats->Record (blocksToConfirm, (double )feeRate.GetFeePerK ());
492
503
return true ;
493
504
}
494
505
@@ -512,6 +523,8 @@ void CBlockPolicyEstimator::processBlock(unsigned int nBlockHeight,
512
523
513
524
// Clear the current block state and update unconfirmed circular buffer
514
525
feeStats->ClearCurrent (nBlockHeight);
526
+ shortStats->ClearCurrent (nBlockHeight);
527
+ longStats->ClearCurrent (nBlockHeight);
515
528
516
529
unsigned int countedTxs = 0 ;
517
530
// Repopulate the current block states
@@ -522,6 +535,8 @@ void CBlockPolicyEstimator::processBlock(unsigned int nBlockHeight,
522
535
523
536
// Update all exponential averages with the current block state
524
537
feeStats->UpdateMovingAverages ();
538
+ shortStats->UpdateMovingAverages ();
539
+ longStats->UpdateMovingAverages ();
525
540
526
541
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 " ,
527
542
countedTxs, entries.size (), trackedTxs, trackedTxs + untrackedTxs, mapMemPoolTxs.size ());
@@ -538,7 +553,7 @@ CFeeRate CBlockPolicyEstimator::estimateFee(int confTarget) const
538
553
if (confTarget <= 1 || (unsigned int )confTarget > feeStats->GetMaxConfirms ())
539
554
return CFeeRate (0 );
540
555
541
- double median = feeStats->EstimateMedianVal (confTarget, SUFFICIENT_FEETXS, MIN_SUCCESS_PCT , true , nBestSeenHeight);
556
+ double median = feeStats->EstimateMedianVal (confTarget, SUFFICIENT_FEETXS, DOUBLE_SUCCESS_PCT , true , nBestSeenHeight);
542
557
543
558
if (median < 0 )
544
559
return CFeeRate (0 );
@@ -565,7 +580,7 @@ CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, int *answerFoun
565
580
confTarget = 2 ;
566
581
567
582
while (median < 0 && (unsigned int )confTarget <= feeStats->GetMaxConfirms ()) {
568
- median = feeStats->EstimateMedianVal (confTarget++, SUFFICIENT_FEETXS, MIN_SUCCESS_PCT , true , nBestSeenHeight);
583
+ median = feeStats->EstimateMedianVal (confTarget++, SUFFICIENT_FEETXS, DOUBLE_SUCCESS_PCT , true , nBestSeenHeight);
569
584
}
570
585
} // Must unlock cs_feeEstimator before taking mempool locks
571
586
@@ -634,7 +649,7 @@ bool CBlockPolicyEstimator::Read(CAutoFile& filein)
634
649
635
650
std::map<double , unsigned int > tempMap;
636
651
637
- std::unique_ptr<TxConfirmStats> tempFeeStats (new TxConfirmStats (tempBuckets, tempMap, MAX_BLOCK_CONFIRMS , tempDecay));
652
+ std::unique_ptr<TxConfirmStats> tempFeeStats (new TxConfirmStats (tempBuckets, tempMap, MED_BLOCK_CONFIRMS , tempDecay));
638
653
tempFeeStats->Read (filein, nVersionThatWrote, tempNum);
639
654
// if nVersionThatWrote < 139900 then another TxConfirmStats (for priority) follows but can be ignored.
640
655
@@ -653,9 +668,9 @@ bool CBlockPolicyEstimator::Read(CAutoFile& filein)
653
668
if (numBuckets <= 1 || numBuckets > 1000 )
654
669
throw std::runtime_error (" Corrupt estimates file. Must have between 2 and 1000 feerate buckets" );
655
670
656
- std::unique_ptr<TxConfirmStats> fileFeeStats (new TxConfirmStats (buckets, bucketMap, MAX_BLOCK_CONFIRMS, DEFAULT_DECAY ));
657
- std::unique_ptr<TxConfirmStats> fileShortStats (new TxConfirmStats (buckets, bucketMap, MAX_BLOCK_CONFIRMS, DEFAULT_DECAY ));
658
- std::unique_ptr<TxConfirmStats> fileLongStats (new TxConfirmStats (buckets, bucketMap, MAX_BLOCK_CONFIRMS, DEFAULT_DECAY ));
671
+ std::unique_ptr<TxConfirmStats> fileFeeStats (new TxConfirmStats (buckets, bucketMap, MED_BLOCK_CONFIRMS, MED_DECAY ));
672
+ std::unique_ptr<TxConfirmStats> fileShortStats (new TxConfirmStats (buckets, bucketMap, SHORT_BLOCK_CONFIRMS, SHORT_DECAY ));
673
+ std::unique_ptr<TxConfirmStats> fileLongStats (new TxConfirmStats (buckets, bucketMap, LONG_BLOCK_CONFIRMS, LONG_DECAY ));
659
674
fileFeeStats->Read (filein, nVersionThatWrote, numBuckets);
660
675
fileShortStats->Read (filein, nVersionThatWrote, numBuckets);
661
676
fileLongStats->Read (filein, nVersionThatWrote, numBuckets);
@@ -690,7 +705,7 @@ FeeFilterRounder::FeeFilterRounder(const CFeeRate& minIncrementalFee)
690
705
{
691
706
CAmount minFeeLimit = std::max (CAmount (1 ), minIncrementalFee.GetFeePerK () / 2 );
692
707
feeset.insert (0 );
693
- for (double bucketBoundary = minFeeLimit; bucketBoundary <= MAX_BUCKET_FEERATE ; bucketBoundary *= FEE_SPACING ) {
708
+ for (double bucketBoundary = minFeeLimit; bucketBoundary <= MAX_FILTER_FEERATE ; bucketBoundary *= FEE_FILTER_SPACING ) {
694
709
feeset.insert (bucketBoundary);
695
710
}
696
711
}
0 commit comments