Skip to content

Commit

Permalink
Merge bitcoin#20771: refactor: Enable -Wswitch for FeeEstimateHorizon
Browse files Browse the repository at this point in the history
faccf8b refactor: Enable -Wswitch for FeeEstimateHorizon (MarcoFalke)

Pull request description:

  This enables the `-Wswitch` compiler warning for `FeeEstimateHorizon` by removing the `default` case in `switch` statements.

ACKs for top commit:
  practicalswift:
    cr ACK faccf8b
  jonatack:
    ACK faccf8b
  hebasto:
    ACK faccf8b, I have reviewed the code and it looks OK, I agree it can be merged.

Tree-SHA512: 63a8dff6e8dead149ec2fa8319e7ff41022c9534d423d3086fd8f22be073dc4915f74c7fe9139ee681a8204730cf58c80ef40c93fb33032d586e68b4f78f557d
  • Loading branch information
fanquake committed Dec 28, 2020
2 parents 0e1b57b + faccf8b commit 4a8f4ac
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions src/policy/fees.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,18 @@
#include <txmempool.h>
#include <util/system.h>

static const char* FEE_ESTIMATES_FILENAME="fee_estimates.dat";
static const char* FEE_ESTIMATES_FILENAME = "fee_estimates.dat";

static constexpr double INF_FEERATE = 1e99;

std::string StringForFeeEstimateHorizon(FeeEstimateHorizon horizon) {
static const std::map<FeeEstimateHorizon, std::string> horizon_strings = {
{FeeEstimateHorizon::SHORT_HALFLIFE, "short"},
{FeeEstimateHorizon::MED_HALFLIFE, "medium"},
{FeeEstimateHorizon::LONG_HALFLIFE, "long"},
};
auto horizon_string = horizon_strings.find(horizon);

if (horizon_string == horizon_strings.end()) return "unknown";

return horizon_string->second;
std::string StringForFeeEstimateHorizon(FeeEstimateHorizon horizon)
{
switch (horizon) {
case FeeEstimateHorizon::SHORT_HALFLIFE: return "short";
case FeeEstimateHorizon::MED_HALFLIFE: return "medium";
case FeeEstimateHorizon::LONG_HALFLIFE: return "long";
} // no default case, so the compiler can warn about missing cases
assert(false);
}

/**
Expand Down Expand Up @@ -644,7 +641,7 @@ CFeeRate CBlockPolicyEstimator::estimateFee(int confTarget) const

CFeeRate CBlockPolicyEstimator::estimateRawFee(int confTarget, double successThreshold, FeeEstimateHorizon horizon, EstimationResult* result) const
{
TxConfirmStats* stats;
TxConfirmStats* stats = nullptr;
double sufficientTxs = SUFFICIENT_FEETXS;
switch (horizon) {
case FeeEstimateHorizon::SHORT_HALFLIFE: {
Expand All @@ -660,10 +657,8 @@ CFeeRate CBlockPolicyEstimator::estimateRawFee(int confTarget, double successThr
stats = longStats.get();
break;
}
default: {
throw std::out_of_range("CBlockPolicyEstimator::estimateRawFee unknown FeeEstimateHorizon");
}
}
} // no default case, so the compiler can warn about missing cases
assert(stats);

LOCK(m_cs_fee_estimator);
// Return failure if trying to analyze a target we're not tracking
Expand Down Expand Up @@ -693,10 +688,8 @@ unsigned int CBlockPolicyEstimator::HighestTargetTracked(FeeEstimateHorizon hori
case FeeEstimateHorizon::LONG_HALFLIFE: {
return longStats->GetMaxConfirms();
}
default: {
throw std::out_of_range("CBlockPolicyEstimator::HighestTargetTracked unknown FeeEstimateHorizon");
}
}
} // no default case, so the compiler can warn about missing cases
assert(false);
}

unsigned int CBlockPolicyEstimator::BlockSpan() const
Expand Down

0 comments on commit 4a8f4ac

Please sign in to comment.