Skip to content

Commit 4a8f4ac

Browse files
committed
Merge #20771: refactor: Enable -Wswitch for FeeEstimateHorizon
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
2 parents 0e1b57b + faccf8b commit 4a8f4ac

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

src/policy/fees.cpp

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,18 @@
1212
#include <txmempool.h>
1313
#include <util/system.h>
1414

15-
static const char* FEE_ESTIMATES_FILENAME="fee_estimates.dat";
15+
static const char* FEE_ESTIMATES_FILENAME = "fee_estimates.dat";
1616

1717
static constexpr double INF_FEERATE = 1e99;
1818

19-
std::string StringForFeeEstimateHorizon(FeeEstimateHorizon horizon) {
20-
static const std::map<FeeEstimateHorizon, std::string> horizon_strings = {
21-
{FeeEstimateHorizon::SHORT_HALFLIFE, "short"},
22-
{FeeEstimateHorizon::MED_HALFLIFE, "medium"},
23-
{FeeEstimateHorizon::LONG_HALFLIFE, "long"},
24-
};
25-
auto horizon_string = horizon_strings.find(horizon);
26-
27-
if (horizon_string == horizon_strings.end()) return "unknown";
28-
29-
return horizon_string->second;
19+
std::string StringForFeeEstimateHorizon(FeeEstimateHorizon horizon)
20+
{
21+
switch (horizon) {
22+
case FeeEstimateHorizon::SHORT_HALFLIFE: return "short";
23+
case FeeEstimateHorizon::MED_HALFLIFE: return "medium";
24+
case FeeEstimateHorizon::LONG_HALFLIFE: return "long";
25+
} // no default case, so the compiler can warn about missing cases
26+
assert(false);
3027
}
3128

3229
/**
@@ -644,7 +641,7 @@ CFeeRate CBlockPolicyEstimator::estimateFee(int confTarget) const
644641

645642
CFeeRate CBlockPolicyEstimator::estimateRawFee(int confTarget, double successThreshold, FeeEstimateHorizon horizon, EstimationResult* result) const
646643
{
647-
TxConfirmStats* stats;
644+
TxConfirmStats* stats = nullptr;
648645
double sufficientTxs = SUFFICIENT_FEETXS;
649646
switch (horizon) {
650647
case FeeEstimateHorizon::SHORT_HALFLIFE: {
@@ -660,10 +657,8 @@ CFeeRate CBlockPolicyEstimator::estimateRawFee(int confTarget, double successThr
660657
stats = longStats.get();
661658
break;
662659
}
663-
default: {
664-
throw std::out_of_range("CBlockPolicyEstimator::estimateRawFee unknown FeeEstimateHorizon");
665-
}
666-
}
660+
} // no default case, so the compiler can warn about missing cases
661+
assert(stats);
667662

668663
LOCK(m_cs_fee_estimator);
669664
// Return failure if trying to analyze a target we're not tracking
@@ -693,10 +688,8 @@ unsigned int CBlockPolicyEstimator::HighestTargetTracked(FeeEstimateHorizon hori
693688
case FeeEstimateHorizon::LONG_HALFLIFE: {
694689
return longStats->GetMaxConfirms();
695690
}
696-
default: {
697-
throw std::out_of_range("CBlockPolicyEstimator::HighestTargetTracked unknown FeeEstimateHorizon");
698-
}
699-
}
691+
} // no default case, so the compiler can warn about missing cases
692+
assert(false);
700693
}
701694

702695
unsigned int CBlockPolicyEstimator::BlockSpan() const

0 commit comments

Comments
 (0)