fees: make FeeFilterRounder::feeset const

It is only set in the constructor, thus improve readability by marking
it as `const` and setting it from the initializer list using a helper
function to derive its value.

The idea was suggested by Anthony Towns <aj@erisian.com.au> in
https://github.com/bitcoin/bitcoin/pull/19268#discussion_r439929792
This commit is contained in:
Vasil Dimov 2022-02-21 17:11:59 +01:00
parent e7a5bf6be7
commit 8b4ad203d0
No known key found for this signature in database
GPG key ID: 54DF06F64B55CBBF
2 changed files with 15 additions and 4 deletions

View file

@ -998,13 +998,24 @@ void CBlockPolicyEstimator::FlushUnconfirmed() {
LogPrint(BCLog::ESTIMATEFEE, "Recorded %u unconfirmed txs from mempool in %gs\n", num_entries, (endclear - startclear)*0.000001);
}
FeeFilterRounder::FeeFilterRounder(const CFeeRate& minIncrementalFee)
static std::set<double> MakeFeeSet(const CFeeRate& minIncrementalFee,
double max_filter_fee_rate,
double fee_filter_spacing)
{
CAmount minFeeLimit = std::max(CAmount(1), minIncrementalFee.GetFeePerK() / 2);
std::set<double> feeset;
const CAmount minFeeLimit{std::max(CAmount(1), minIncrementalFee.GetFeePerK() / 2)};
feeset.insert(0);
for (double bucketBoundary = minFeeLimit; bucketBoundary <= MAX_FILTER_FEERATE; bucketBoundary *= FEE_FILTER_SPACING) {
for (double bucketBoundary = minFeeLimit; bucketBoundary <= max_filter_fee_rate; bucketBoundary *= fee_filter_spacing) {
feeset.insert(bucketBoundary);
}
return feeset;
}
FeeFilterRounder::FeeFilterRounder(const CFeeRate& minIncrementalFee)
: feeset{MakeFeeSet(minIncrementalFee, MAX_FILTER_FEERATE, FEE_FILTER_SPACING)}
{
}
CAmount FeeFilterRounder::round(CAmount currentMinFee)

View file

@ -303,7 +303,7 @@ public:
CAmount round(CAmount currentMinFee);
private:
std::set<double> feeset;
const std::set<double> feeset;
Mutex m_insecure_rand_mutex;
FastRandomContext insecure_rand GUARDED_BY(m_insecure_rand_mutex);
};