Skip to content

Commit 6303051

Browse files
committed
EstimateSmart functions consider mempool min fee
1 parent f22ac4a commit 6303051

File tree

6 files changed

+22
-8
lines changed

6 files changed

+22
-8
lines changed

src/main.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT = 101;
5555
static const unsigned int DEFAULT_DESCENDANT_LIMIT = 25;
5656
/** Default for -limitdescendantsize, maximum kilobytes of in-mempool descendants */
5757
static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT = 101;
58-
/** Default for -maxmempool, maximum megabytes of mempool memory usage */
59-
static const unsigned int DEFAULT_MAX_MEMPOOL_SIZE = 300;
6058
/** Default for -mempoolexpiry, expiration time for mempool transactions in hours */
6159
static const unsigned int DEFAULT_MEMPOOL_EXPIRY = 72;
6260
/** The maximum size of a blk?????.dat file (since 0.8) */

src/policy/fees.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

66
#include "policy/fees.h"
7+
#include "policy/policy.h"
78

89
#include "amount.h"
910
#include "primitives/transaction.h"
@@ -504,7 +505,7 @@ CFeeRate CBlockPolicyEstimator::estimateFee(int confTarget)
504505
return CFeeRate(median);
505506
}
506507

507-
CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, int *answerFoundAtTarget)
508+
CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, int *answerFoundAtTarget, const CTxMemPool *pool)
508509
{
509510
if (answerFoundAtTarget)
510511
*answerFoundAtTarget = confTarget;
@@ -520,6 +521,11 @@ CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, int *answerFoun
520521
if (answerFoundAtTarget)
521522
*answerFoundAtTarget = confTarget - 1;
522523

524+
// If mempool is limiting txs , return at least the min fee from the mempool
525+
CAmount minPoolFee = pool->GetMinFee(GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK();
526+
if (minPoolFee > 0 && minPoolFee > median)
527+
return CFeeRate(minPoolFee);
528+
523529
if (median < 0)
524530
return CFeeRate(0);
525531

@@ -535,14 +541,19 @@ double CBlockPolicyEstimator::estimatePriority(int confTarget)
535541
return priStats.EstimateMedianVal(confTarget, SUFFICIENT_PRITXS, MIN_SUCCESS_PCT, true, nBestSeenHeight);
536542
}
537543

538-
double CBlockPolicyEstimator::estimateSmartPriority(int confTarget, int *answerFoundAtTarget)
544+
double CBlockPolicyEstimator::estimateSmartPriority(int confTarget, int *answerFoundAtTarget, const CTxMemPool *pool)
539545
{
540546
if (answerFoundAtTarget)
541547
*answerFoundAtTarget = confTarget;
542548
// Return failure if trying to analyze a target we're not tracking
543549
if (confTarget <= 0 || (unsigned int)confTarget > priStats.GetMaxConfirms())
544550
return -1;
545551

552+
// If mempool is limiting txs, no priority txs are allowed
553+
CAmount minPoolFee = pool->GetMinFee(GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK();
554+
if (minPoolFee > 0)
555+
return INF_PRIORITY;
556+
546557
double median = -1;
547558
while (median < 0 && (unsigned int)confTarget <= priStats.GetMaxConfirms()) {
548559
median = priStats.EstimateMedianVal(confTarget++, SUFFICIENT_PRITXS, MIN_SUCCESS_PCT, true, nBestSeenHeight);
@@ -551,6 +562,7 @@ double CBlockPolicyEstimator::estimateSmartPriority(int confTarget, int *answerF
551562
if (answerFoundAtTarget)
552563
*answerFoundAtTarget = confTarget - 1;
553564

565+
554566
return median;
555567
}
556568

src/policy/fees.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
class CAutoFile;
1616
class CFeeRate;
1717
class CTxMemPoolEntry;
18+
class CTxMemPool;
1819

1920
/** \class CBlockPolicyEstimator
2021
* The BlockPolicyEstimator is used for estimating the fee or priority needed
@@ -246,7 +247,7 @@ class CBlockPolicyEstimator
246247
* confTarget blocks. If no answer can be given at confTarget, return an
247248
* estimate at the lowest target where one can be given.
248249
*/
249-
CFeeRate estimateSmartFee(int confTarget, int *answerFoundAtTarget);
250+
CFeeRate estimateSmartFee(int confTarget, int *answerFoundAtTarget, const CTxMemPool *pool);
250251

251252
/** Return a priority estimate */
252253
double estimatePriority(int confTarget);
@@ -255,7 +256,7 @@ class CBlockPolicyEstimator
255256
* confTarget blocks. If no answer can be given at confTarget, return an
256257
* estimate at the lowest target where one can be given.
257258
*/
258-
double estimateSmartPriority(int confTarget, int *answerFoundAtTarget);
259+
double estimateSmartPriority(int confTarget, int *answerFoundAtTarget, const CTxMemPool *pool);
259260

260261
/** Write estimation data to a file */
261262
void Write(CAutoFile& fileout);

src/policy/policy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ static const unsigned int MAX_STANDARD_TX_SIZE = 100000;
2525
static const unsigned int MAX_P2SH_SIGOPS = 15;
2626
/** The maximum number of sigops we're willing to relay/mine in a single tx */
2727
static const unsigned int MAX_STANDARD_TX_SIGOPS = MAX_BLOCK_SIGOPS/5;
28+
/** Default for -maxmempool, maximum megabytes of mempool memory usage */
29+
static const unsigned int DEFAULT_MAX_MEMPOOL_SIZE = 300;
2830
/**
2931
* Standard script verification flags that standard transactions will comply
3032
* with. However scripts violating these flags may still be present in valid

src/rpcblockchain.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "coins.h"
1111
#include "consensus/validation.h"
1212
#include "main.h"
13+
#include "policy/policy.h"
1314
#include "primitives/transaction.h"
1415
#include "rpcserver.h"
1516
#include "streams.h"

src/txmempool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ CFeeRate CTxMemPool::estimateFee(int nBlocks) const
704704
CFeeRate CTxMemPool::estimateSmartFee(int nBlocks, int *answerFoundAtBlocks) const
705705
{
706706
LOCK(cs);
707-
return minerPolicyEstimator->estimateSmartFee(nBlocks, answerFoundAtBlocks);
707+
return minerPolicyEstimator->estimateSmartFee(nBlocks, answerFoundAtBlocks, this);
708708
}
709709
double CTxMemPool::estimatePriority(int nBlocks) const
710710
{
@@ -714,7 +714,7 @@ double CTxMemPool::estimatePriority(int nBlocks) const
714714
double CTxMemPool::estimateSmartPriority(int nBlocks, int *answerFoundAtBlocks) const
715715
{
716716
LOCK(cs);
717-
return minerPolicyEstimator->estimateSmartPriority(nBlocks, answerFoundAtBlocks);
717+
return minerPolicyEstimator->estimateSmartPriority(nBlocks, answerFoundAtBlocks, this);
718718
}
719719

720720
bool

0 commit comments

Comments
 (0)