Browse Source

EstimateSmart functions consider mempool min fee

0.13
Alex Morcos 9 years ago
parent
commit
6303051470
  1. 2
      src/main.h
  2. 16
      src/policy/fees.cpp
  3. 5
      src/policy/fees.h
  4. 2
      src/policy/policy.h
  5. 1
      src/rpcblockchain.cpp
  6. 4
      src/txmempool.cpp

2
src/main.h

@ -55,8 +55,6 @@ static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT = 101;
static const unsigned int DEFAULT_DESCENDANT_LIMIT = 25; static const unsigned int DEFAULT_DESCENDANT_LIMIT = 25;
/** Default for -limitdescendantsize, maximum kilobytes of in-mempool descendants */ /** Default for -limitdescendantsize, maximum kilobytes of in-mempool descendants */
static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT = 101; static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT = 101;
/** Default for -maxmempool, maximum megabytes of mempool memory usage */
static const unsigned int DEFAULT_MAX_MEMPOOL_SIZE = 300;
/** Default for -mempoolexpiry, expiration time for mempool transactions in hours */ /** Default for -mempoolexpiry, expiration time for mempool transactions in hours */
static const unsigned int DEFAULT_MEMPOOL_EXPIRY = 72; static const unsigned int DEFAULT_MEMPOOL_EXPIRY = 72;
/** The maximum size of a blk?????.dat file (since 0.8) */ /** The maximum size of a blk?????.dat file (since 0.8) */

16
src/policy/fees.cpp

@ -4,6 +4,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "policy/fees.h" #include "policy/fees.h"
#include "policy/policy.h"
#include "amount.h" #include "amount.h"
#include "primitives/transaction.h" #include "primitives/transaction.h"
@ -504,7 +505,7 @@ CFeeRate CBlockPolicyEstimator::estimateFee(int confTarget)
return CFeeRate(median); return CFeeRate(median);
} }
CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, int *answerFoundAtTarget) CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, int *answerFoundAtTarget, const CTxMemPool *pool)
{ {
if (answerFoundAtTarget) if (answerFoundAtTarget)
*answerFoundAtTarget = confTarget; *answerFoundAtTarget = confTarget;
@ -520,6 +521,11 @@ CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, int *answerFoun
if (answerFoundAtTarget) if (answerFoundAtTarget)
*answerFoundAtTarget = confTarget - 1; *answerFoundAtTarget = confTarget - 1;
// If mempool is limiting txs , return at least the min fee from the mempool
CAmount minPoolFee = pool->GetMinFee(GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK();
if (minPoolFee > 0 && minPoolFee > median)
return CFeeRate(minPoolFee);
if (median < 0) if (median < 0)
return CFeeRate(0); return CFeeRate(0);
@ -535,7 +541,7 @@ double CBlockPolicyEstimator::estimatePriority(int confTarget)
return priStats.EstimateMedianVal(confTarget, SUFFICIENT_PRITXS, MIN_SUCCESS_PCT, true, nBestSeenHeight); return priStats.EstimateMedianVal(confTarget, SUFFICIENT_PRITXS, MIN_SUCCESS_PCT, true, nBestSeenHeight);
} }
double CBlockPolicyEstimator::estimateSmartPriority(int confTarget, int *answerFoundAtTarget) double CBlockPolicyEstimator::estimateSmartPriority(int confTarget, int *answerFoundAtTarget, const CTxMemPool *pool)
{ {
if (answerFoundAtTarget) if (answerFoundAtTarget)
*answerFoundAtTarget = confTarget; *answerFoundAtTarget = confTarget;
@ -543,6 +549,11 @@ double CBlockPolicyEstimator::estimateSmartPriority(int confTarget, int *answerF
if (confTarget <= 0 || (unsigned int)confTarget > priStats.GetMaxConfirms()) if (confTarget <= 0 || (unsigned int)confTarget > priStats.GetMaxConfirms())
return -1; return -1;
// If mempool is limiting txs, no priority txs are allowed
CAmount minPoolFee = pool->GetMinFee(GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK();
if (minPoolFee > 0)
return INF_PRIORITY;
double median = -1; double median = -1;
while (median < 0 && (unsigned int)confTarget <= priStats.GetMaxConfirms()) { while (median < 0 && (unsigned int)confTarget <= priStats.GetMaxConfirms()) {
median = priStats.EstimateMedianVal(confTarget++, SUFFICIENT_PRITXS, MIN_SUCCESS_PCT, true, nBestSeenHeight); median = priStats.EstimateMedianVal(confTarget++, SUFFICIENT_PRITXS, MIN_SUCCESS_PCT, true, nBestSeenHeight);
@ -551,6 +562,7 @@ double CBlockPolicyEstimator::estimateSmartPriority(int confTarget, int *answerF
if (answerFoundAtTarget) if (answerFoundAtTarget)
*answerFoundAtTarget = confTarget - 1; *answerFoundAtTarget = confTarget - 1;
return median; return median;
} }

5
src/policy/fees.h

@ -15,6 +15,7 @@
class CAutoFile; class CAutoFile;
class CFeeRate; class CFeeRate;
class CTxMemPoolEntry; class CTxMemPoolEntry;
class CTxMemPool;
/** \class CBlockPolicyEstimator /** \class CBlockPolicyEstimator
* The BlockPolicyEstimator is used for estimating the fee or priority needed * The BlockPolicyEstimator is used for estimating the fee or priority needed
@ -246,7 +247,7 @@ public:
* confTarget blocks. If no answer can be given at confTarget, return an * confTarget blocks. If no answer can be given at confTarget, return an
* estimate at the lowest target where one can be given. * estimate at the lowest target where one can be given.
*/ */
CFeeRate estimateSmartFee(int confTarget, int *answerFoundAtTarget); CFeeRate estimateSmartFee(int confTarget, int *answerFoundAtTarget, const CTxMemPool *pool);
/** Return a priority estimate */ /** Return a priority estimate */
double estimatePriority(int confTarget); double estimatePriority(int confTarget);
@ -255,7 +256,7 @@ public:
* confTarget blocks. If no answer can be given at confTarget, return an * confTarget blocks. If no answer can be given at confTarget, return an
* estimate at the lowest target where one can be given. * estimate at the lowest target where one can be given.
*/ */
double estimateSmartPriority(int confTarget, int *answerFoundAtTarget); double estimateSmartPriority(int confTarget, int *answerFoundAtTarget, const CTxMemPool *pool);
/** Write estimation data to a file */ /** Write estimation data to a file */
void Write(CAutoFile& fileout); void Write(CAutoFile& fileout);

2
src/policy/policy.h

@ -25,6 +25,8 @@ static const unsigned int MAX_STANDARD_TX_SIZE = 100000;
static const unsigned int MAX_P2SH_SIGOPS = 15; static const unsigned int MAX_P2SH_SIGOPS = 15;
/** The maximum number of sigops we're willing to relay/mine in a single tx */ /** The maximum number of sigops we're willing to relay/mine in a single tx */
static const unsigned int MAX_STANDARD_TX_SIGOPS = MAX_BLOCK_SIGOPS/5; static const unsigned int MAX_STANDARD_TX_SIGOPS = MAX_BLOCK_SIGOPS/5;
/** Default for -maxmempool, maximum megabytes of mempool memory usage */
static const unsigned int DEFAULT_MAX_MEMPOOL_SIZE = 300;
/** /**
* Standard script verification flags that standard transactions will comply * Standard script verification flags that standard transactions will comply
* with. However scripts violating these flags may still be present in valid * with. However scripts violating these flags may still be present in valid

1
src/rpcblockchain.cpp

@ -10,6 +10,7 @@
#include "coins.h" #include "coins.h"
#include "consensus/validation.h" #include "consensus/validation.h"
#include "main.h" #include "main.h"
#include "policy/policy.h"
#include "primitives/transaction.h" #include "primitives/transaction.h"
#include "rpcserver.h" #include "rpcserver.h"
#include "streams.h" #include "streams.h"

4
src/txmempool.cpp

@ -704,7 +704,7 @@ CFeeRate CTxMemPool::estimateFee(int nBlocks) const
CFeeRate CTxMemPool::estimateSmartFee(int nBlocks, int *answerFoundAtBlocks) const CFeeRate CTxMemPool::estimateSmartFee(int nBlocks, int *answerFoundAtBlocks) const
{ {
LOCK(cs); LOCK(cs);
return minerPolicyEstimator->estimateSmartFee(nBlocks, answerFoundAtBlocks); return minerPolicyEstimator->estimateSmartFee(nBlocks, answerFoundAtBlocks, this);
} }
double CTxMemPool::estimatePriority(int nBlocks) const double CTxMemPool::estimatePriority(int nBlocks) const
{ {
@ -714,7 +714,7 @@ double CTxMemPool::estimatePriority(int nBlocks) const
double CTxMemPool::estimateSmartPriority(int nBlocks, int *answerFoundAtBlocks) const double CTxMemPool::estimateSmartPriority(int nBlocks, int *answerFoundAtBlocks) const
{ {
LOCK(cs); LOCK(cs);
return minerPolicyEstimator->estimateSmartPriority(nBlocks, answerFoundAtBlocks); return minerPolicyEstimator->estimateSmartPriority(nBlocks, answerFoundAtBlocks, this);
} }
bool bool

Loading…
Cancel
Save