Skip to content

Commit aaaa987

Browse files
author
MarcoFalke
committed
refactor: Use C++17 std::array deduction for ALL_FEE_ESTIMATE_HORIZONS
1 parent fa39cdd commit aaaa987

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

src/policy/fees.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <random.h>
1212
#include <sync.h>
1313

14+
#include <array>
1415
#include <map>
1516
#include <memory>
1617
#include <string>
@@ -25,9 +26,15 @@ class TxConfirmStats;
2526
/* Identifier for each of the 3 different TxConfirmStats which will track
2627
* history over different time horizons. */
2728
enum class FeeEstimateHorizon {
28-
SHORT_HALFLIFE = 0,
29-
MED_HALFLIFE = 1,
30-
LONG_HALFLIFE = 2
29+
SHORT_HALFLIFE,
30+
MED_HALFLIFE,
31+
LONG_HALFLIFE,
32+
};
33+
34+
static constexpr auto ALL_FEE_ESTIMATE_HORIZONS = std::array{
35+
FeeEstimateHorizon::SHORT_HALFLIFE,
36+
FeeEstimateHorizon::MED_HALFLIFE,
37+
FeeEstimateHorizon::LONG_HALFLIFE,
3138
};
3239

3340
std::string StringForFeeEstimateHorizon(FeeEstimateHorizon horizon);

src/rpc/mining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ static RPCHelpMan estimaterawfee()
11601160

11611161
UniValue result(UniValue::VOBJ);
11621162

1163-
for (const FeeEstimateHorizon horizon : {FeeEstimateHorizon::SHORT_HALFLIFE, FeeEstimateHorizon::MED_HALFLIFE, FeeEstimateHorizon::LONG_HALFLIFE}) {
1163+
for (const FeeEstimateHorizon horizon : ALL_FEE_ESTIMATE_HORIZONS) {
11641164
CFeeRate feeRate;
11651165
EstimationResult buckets;
11661166

src/test/fuzz/kitchen_sink.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ constexpr TransactionError ALL_TRANSACTION_ERROR[] = {
2828
TransactionError::SIGHASH_MISMATCH,
2929
TransactionError::MAX_FEE_EXCEEDED,
3030
};
31-
32-
constexpr FeeEstimateHorizon ALL_FEE_EST_HORIZON[] = {
33-
FeeEstimateHorizon::SHORT_HALFLIFE,
34-
FeeEstimateHorizon::MED_HALFLIFE,
35-
FeeEstimateHorizon::LONG_HALFLIFE,
36-
};
3731
}; // namespace
3832

3933
// The fuzzing kitchen sink: Fuzzing harness for functions that need to be
@@ -48,7 +42,7 @@ FUZZ_TARGET(kitchen_sink)
4842
(void)RPCErrorFromTransactionError(transaction_error);
4943
(void)TransactionErrorString(transaction_error);
5044

51-
(void)StringForFeeEstimateHorizon(fuzzed_data_provider.PickValueInArray(ALL_FEE_EST_HORIZON));
45+
(void)StringForFeeEstimateHorizon(fuzzed_data_provider.PickValueInArray(ALL_FEE_ESTIMATE_HORIZONS));
5246

5347
const OutputType output_type = fuzzed_data_provider.PickValueInArray(OUTPUT_TYPES);
5448
const std::string& output_type_string = FormatOutputType(output_type);

src/test/fuzz/policy_estimator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ FUZZ_TARGET_INIT(policy_estimator, initialize_policy_estimator)
6666
}
6767
(void)block_policy_estimator.estimateFee(fuzzed_data_provider.ConsumeIntegral<int>());
6868
EstimationResult result;
69-
(void)block_policy_estimator.estimateRawFee(fuzzed_data_provider.ConsumeIntegral<int>(), fuzzed_data_provider.ConsumeFloatingPoint<double>(), fuzzed_data_provider.PickValueInArray({FeeEstimateHorizon::SHORT_HALFLIFE, FeeEstimateHorizon::MED_HALFLIFE, FeeEstimateHorizon::LONG_HALFLIFE}), fuzzed_data_provider.ConsumeBool() ? &result : nullptr);
69+
(void)block_policy_estimator.estimateRawFee(fuzzed_data_provider.ConsumeIntegral<int>(), fuzzed_data_provider.ConsumeFloatingPoint<double>(), fuzzed_data_provider.PickValueInArray(ALL_FEE_ESTIMATE_HORIZONS), fuzzed_data_provider.ConsumeBool() ? &result : nullptr);
7070
FeeCalculation fee_calculation;
7171
(void)block_policy_estimator.estimateSmartFee(fuzzed_data_provider.ConsumeIntegral<int>(), fuzzed_data_provider.ConsumeBool() ? &fee_calculation : nullptr, fuzzed_data_provider.ConsumeBool());
72-
(void)block_policy_estimator.HighestTargetTracked(fuzzed_data_provider.PickValueInArray({FeeEstimateHorizon::SHORT_HALFLIFE, FeeEstimateHorizon::MED_HALFLIFE, FeeEstimateHorizon::LONG_HALFLIFE}));
72+
(void)block_policy_estimator.HighestTargetTracked(fuzzed_data_provider.PickValueInArray(ALL_FEE_ESTIMATE_HORIZONS));
7373
}
7474
{
7575
FuzzedAutoFileProvider fuzzed_auto_file_provider = ConsumeAutoFile(fuzzed_data_provider);

0 commit comments

Comments
 (0)