diff --git a/src/bench/coin_selection.cpp b/src/bench/coin_selection.cpp --- a/src/bench/coin_selection.cpp +++ b/src/bench/coin_selection.cpp @@ -7,7 +7,7 @@ #include -static void addCoin(const CAmount &nValue, const CWallet &wallet, +static void addCoin(const Amount nValue, const CWallet &wallet, std::vector &vCoins) { int nInput = 0; diff --git a/src/policy/fees.h b/src/policy/fees.h --- a/src/policy/fees.h +++ b/src/policy/fees.h @@ -199,15 +199,15 @@ // Minimum and Maximum values for tracking feerates static constexpr double MIN_FEERATE = 10; -static const double MAX_FEERATE = 1e7; -static const double INF_FEERATE = MAX_MONEY.GetSatoshis(); -static const double INF_PRIORITY = 1e9 * MAX_MONEY.GetSatoshis(); +static const Amount MAX_FEERATE(int64_t(1e7)); +static const Amount INF_FEERATE(MAX_MONEY); +static const Amount INF_PRIORITY(int64_t(1e9) * MAX_MONEY); // We have to lump transactions into buckets based on feerate, but we want to be // able to give accurate estimates over a large range of potential feerates. // Therefore it makes sense to exponentially space the buckets /** Spacing of FeeRate buckets */ -static const double FEE_SPACING = 1.1; +static const int64_t FEE_SPACING_FRACTION = 10; /** * We want to be able to estimate feerates that are needed on tx's to be @@ -297,10 +297,10 @@ FeeFilterRounder(const CFeeRate &minIncrementalFee); /** Quantize a minimum fee for privacy purpose before broadcast **/ - CAmount round(CAmount currentMinFee); + Amount round(const Amount currentMinFee); private: - std::set feeset; + std::set feeset; FastRandomContext insecure_rand; }; #endif /*BITCOIN_POLICYESTIMATOR_H */ diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp --- a/src/policy/fees.cpp +++ b/src/policy/fees.cpp @@ -343,11 +343,12 @@ ? CFeeRate(Amount(int64_t(MIN_FEERATE))) : _minRelayFee; std::vector vfeelist; - for (double bucketBoundary = minTrackedFee.GetFeePerK().GetSatoshis(); - bucketBoundary <= MAX_FEERATE; bucketBoundary *= FEE_SPACING) { - vfeelist.push_back(bucketBoundary); + for (Amount bucketBoundary = minTrackedFee.GetFeePerK(); + bucketBoundary <= MAX_FEERATE; + bucketBoundary += bucketBoundary / FEE_SPACING_FRACTION) { + vfeelist.push_back(double(bucketBoundary.GetSatoshis())); } - vfeelist.push_back(INF_FEERATE); + vfeelist.push_back(double(INF_FEERATE.GetSatoshis())); feeStats.Initialize(vfeelist, MAX_BLOCK_CONFIRMS, DEFAULT_DECAY); } @@ -535,7 +536,7 @@ 1000000) .GetFeePerK(); if (minPoolFee > 0) { - return INF_PRIORITY; + return double(INF_PRIORITY.GetSatoshis()); } return -1; @@ -560,15 +561,15 @@ FeeFilterRounder::FeeFilterRounder(const CFeeRate &minIncrementalFee) { Amount minFeeLimit = std::max(Amount(1), minIncrementalFee.GetFeePerK() / 2); - feeset.insert(0); - for (double bucketBoundary = minFeeLimit.GetSatoshis(); - bucketBoundary <= MAX_FEERATE; bucketBoundary *= FEE_SPACING) { + feeset.insert(Amount(0)); + for (Amount bucketBoundary = minFeeLimit; bucketBoundary <= MAX_FEERATE; + bucketBoundary += bucketBoundary / FEE_SPACING_FRACTION) { feeset.insert(bucketBoundary); } } -CAmount FeeFilterRounder::round(CAmount currentMinFee) { - std::set::iterator it = feeset.lower_bound(currentMinFee); +Amount FeeFilterRounder::round(const Amount currentMinFee) { + std::set::iterator it = feeset.lower_bound(currentMinFee); if ((it != feeset.begin() && insecure_rand.rand32() % 3 != 0) || it == feeset.end()) { it--; diff --git a/src/test/policyestimator_tests.cpp b/src/test/policyestimator_tests.cpp --- a/src/test/policyestimator_tests.cpp +++ b/src/test/policyestimator_tests.cpp @@ -17,13 +17,13 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates) { CTxMemPool mpool(CFeeRate(1000)); TestMemPoolEntryHelper entry; - CAmount basefee(2000); - CAmount deltaFee(100); - std::vector feeV; + Amount basefee(2000); + Amount deltaFee(100); + std::vector feeV; // Populate vectors of increasing fees for (int j = 0; j < 10; j++) { - feeV.push_back(basefee * (j + 1)); + feeV.push_back((j + 1) * basefee); } // Store the hashes of transactions that have been added to the mempool by @@ -234,7 +234,8 @@ mpool.estimateFee(i).GetFeePerK()); BOOST_CHECK(mpool.estimateSmartFee(i).GetFeePerK() >= mpool.GetMinFee(1).GetFeePerK()); - BOOST_CHECK(mpool.estimateSmartPriority(i) == INF_PRIORITY); + BOOST_CHECK(mpool.estimateSmartPriority(i) == + double(INF_PRIORITY.GetSatoshis())); } } diff --git a/src/test/test_bitcoin.h b/src/test/test_bitcoin.h --- a/src/test/test_bitcoin.h +++ b/src/test/test_bitcoin.h @@ -67,7 +67,7 @@ struct TestMemPoolEntryHelper { // Default values - CAmount nFee; + Amount nFee; int64_t nTime; double dPriority; unsigned int nHeight; @@ -84,7 +84,7 @@ CTxMemPoolEntry FromTx(const CTransaction &tx, CTxMemPool *pool = nullptr); // Change the default value - TestMemPoolEntryHelper &Fee(CAmount _fee) { + TestMemPoolEntryHelper &Fee(Amount _fee) { nFee = _fee; return *this; }