From eab8e1b1725f7458e3db6f0ea0bc04ec603d8e9b Mon Sep 17 00:00:00 2001 From: Alex Morcos Date: Mon, 5 Dec 2016 21:46:08 -0500 Subject: [PATCH 1/2] fix a bug if the min fee is 0 for FeeFilterRounder --- src/policy/fees.cpp | 3 ++- src/policy/fees.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp index 9eb831bc1..9f01c24d2 100644 --- a/src/policy/fees.cpp +++ b/src/policy/fees.cpp @@ -299,6 +299,7 @@ void CBlockPolicyEstimator::removeTx(uint256 hash) CBlockPolicyEstimator::CBlockPolicyEstimator(const CFeeRate& _minRelayFee) : nBestSeenHeight(0) { + static_assert(MIN_FEERATE > 0, "Min feerate must be nonzero"); minTrackedFee = _minRelayFee < CFeeRate(MIN_FEERATE) ? CFeeRate(MIN_FEERATE) : _minRelayFee; std::vector vfeelist; for (double bucketBoundary = minTrackedFee.GetFeePerK(); bucketBoundary <= MAX_FEERATE; bucketBoundary *= FEE_SPACING) { @@ -485,7 +486,7 @@ void CBlockPolicyEstimator::Read(CAutoFile& filein, int nFileVersion) FeeFilterRounder::FeeFilterRounder(const CFeeRate& minIncrementalFee) { - CAmount minFeeLimit = minIncrementalFee.GetFeePerK() / 2; + CAmount minFeeLimit = std::max(CAmount(1), minIncrementalFee.GetFeePerK() / 2); feeset.insert(0); for (double bucketBoundary = minFeeLimit; bucketBoundary <= MAX_FEERATE; bucketBoundary *= FEE_SPACING) { feeset.insert(bucketBoundary); diff --git a/src/policy/fees.h b/src/policy/fees.h index ea4c70e61..003f7a7f2 100644 --- a/src/policy/fees.h +++ b/src/policy/fees.h @@ -179,7 +179,7 @@ static const double MIN_SUCCESS_PCT = .95; static const double SUFFICIENT_FEETXS = 1; // Minimum and Maximum values for tracking feerates -static const double MIN_FEERATE = 10; +static constexpr double MIN_FEERATE = 10; static const double MAX_FEERATE = 1e7; static const double INF_FEERATE = MAX_MONEY; static const double INF_PRIORITY = 1e9 * MAX_MONEY; From f8d43b8081eef080ebb4514d1493c0c8d81d27ab Mon Sep 17 00:00:00 2001 From: Alex Morcos Date: Thu, 8 Dec 2016 09:15:01 -0500 Subject: [PATCH 2/2] Avoid rollingMinimumFeeRate never being able to decay below half --- src/txmempool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index c035a84db..981f31f48 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -1082,7 +1082,7 @@ CFeeRate CTxMemPool::GetMinFee(size_t sizelimit) const { rollingMinimumFeeRate = rollingMinimumFeeRate / pow(2.0, (time - lastRollingFeeUpdate) / halflife); lastRollingFeeUpdate = time; - if (rollingMinimumFeeRate < minReasonableRelayFee.GetFeePerK() / 2) { + if (rollingMinimumFeeRate < (double)minReasonableRelayFee.GetFeePerK() / 2) { rollingMinimumFeeRate = 0; return CFeeRate(0); }