Branch data Line data Source code
1 : : // Copyright (c) 2009-2010 Satoshi Nakamoto
2 : : // Copyright (c) 2009-present The Bitcoin Core developers
3 : : // Distributed under the MIT software license, see the accompanying
4 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 : :
6 : : #include <common/messages.h>
7 : : #include <common/types.h>
8 : : #include <node/types.h>
9 : : #include <policy/fees/block_policy_estimator.h>
10 : : #include <tinyformat.h>
11 : : #include <util/fees.h>
12 : : #include <util/strencodings.h>
13 : : #include <util/string.h>
14 : : #include <util/translation.h>
15 : :
16 : : #include <cassert>
17 : : #include <map>
18 : : #include <string>
19 : : #include <string_view>
20 : : #include <utility>
21 : : #include <vector>
22 : :
23 : : using node::TransactionError;
24 : : using util::Join;
25 : :
26 : : namespace common {
27 : 3512 : std::string StringForFeeReason(FeeReason reason)
28 : : {
29 : 3512 : static const std::map<FeeReason, std::string> fee_reason_strings = {
30 [ + - ]: 114 : {FeeReason::NONE, "None"},
31 : 114 : {FeeReason::HALF_ESTIMATE, "Half Target 60% Threshold"},
32 : 114 : {FeeReason::FULL_ESTIMATE, "Target 85% Threshold"},
33 : 114 : {FeeReason::DOUBLE_ESTIMATE, "Double Target 95% Threshold"},
34 : 114 : {FeeReason::CONSERVATIVE, "Conservative Double Target longer horizon"},
35 : 114 : {FeeReason::MEMPOOL_MIN, "Mempool Min Fee"},
36 : 114 : {FeeReason::FALLBACK, "Fallback fee"},
37 : 114 : {FeeReason::REQUIRED, "Minimum Required Fee"},
38 [ + + + - : 5736 : };
+ + - - ]
39 : 3512 : auto reason_string = fee_reason_strings.find(reason);
40 : :
41 [ - + ]: 3512 : if (reason_string == fee_reason_strings.end()) return "Unknown";
42 : :
43 [ - + ]: 3512 : return reason_string->second;
44 [ + - + - : 912 : }
+ - + - +
- + - + -
- + - - ]
45 : :
46 : 27525 : const std::vector<std::pair<std::string, FeeEstimateMode>>& FeeModeMap()
47 : : {
48 : 27525 : static const std::vector<std::pair<std::string, FeeEstimateMode>> FEE_MODES = {
49 [ + - ]: 1198 : {"unset", FeeEstimateMode::UNSET},
50 : 1198 : {"economical", FeeEstimateMode::ECONOMICAL},
51 : 1198 : {"conservative", FeeEstimateMode::CONSERVATIVE},
52 [ + + + - : 32317 : };
+ + - - ]
53 : 27525 : return FEE_MODES;
54 [ + - + - : 1198 : }
- + - - ]
55 : :
56 : 40899 : std::string FeeModeInfo(const std::pair<std::string, FeeEstimateMode>& mode, std::string& default_info)
57 : : {
58 [ + + + - ]: 40899 : switch (mode.second) {
59 : 13633 : case FeeEstimateMode::UNSET:
60 : 13633 : return strprintf("%s means no mode set (%s). \n", mode.first, default_info);
61 : 13633 : case FeeEstimateMode::ECONOMICAL:
62 : 13633 : return strprintf("%s estimates use a shorter time horizon, making them more\n"
63 : : "responsive to short-term drops in the prevailing fee market. This mode\n"
64 : 13633 : "potentially returns a lower fee rate estimate.\n", mode.first);
65 : 13633 : case FeeEstimateMode::CONSERVATIVE:
66 : 13633 : return strprintf("%s estimates use a longer time horizon, making them\n"
67 : : "less responsive to short-term drops in the prevailing fee market. This mode\n"
68 : 13633 : "potentially returns a higher fee rate estimate.\n", mode.first);
69 : 0 : default:
70 : 0 : assert(false);
71 : : }
72 : : }
73 : :
74 : 13633 : std::string FeeModesDetail(std::string default_info)
75 : : {
76 [ + - ]: 13633 : std::string info;
77 [ + - + + ]: 54532 : for (const auto& fee_mode : FeeModeMap()) {
78 [ + - ]: 81798 : info += FeeModeInfo(fee_mode, default_info);
79 : : }
80 [ + - + - : 27266 : return strprintf("%s \n%s", FeeModes(", "), info);
+ - ]
81 : 13633 : }
82 : :
83 : 13661 : std::string FeeModes(const std::string& delimiter)
84 : : {
85 [ - + - + ]: 95627 : return Join(FeeModeMap(), delimiter, [&](const std::pair<std::string, FeeEstimateMode>& i) { return i.first; });
86 : : }
87 : :
88 : 28 : std::string InvalidEstimateModeErrorMessage()
89 : : {
90 [ + - + - ]: 56 : return "Invalid estimate_mode parameter, must be one of: \"" + FeeModes("\", \"") + "\"";
91 : : }
92 : :
93 : 231 : bool FeeModeFromString(std::string_view mode_string, FeeEstimateMode& fee_estimate_mode)
94 : : {
95 : 231 : auto searchkey = ToUpper(mode_string);
96 [ + - + + ]: 526 : for (const auto& pair : FeeModeMap()) {
97 [ - + + - : 498 : if (ToUpper(pair.first) == searchkey) {
+ + ]
98 : 203 : fee_estimate_mode = pair.second;
99 : 203 : return true;
100 : : }
101 : : }
102 : : return false;
103 : 231 : }
104 : :
105 : 15 : bilingual_str PSBTErrorString(PSBTError err)
106 : : {
107 [ - + + - : 15 : switch (err) {
- - - - ]
108 : 0 : case PSBTError::MISSING_INPUTS:
109 [ # # ]: 0 : return Untranslated("Inputs missing or spent");
110 : 14 : case PSBTError::SIGHASH_MISMATCH:
111 [ + - ]: 28 : return Untranslated("Specified sighash value does not match value stored in PSBT");
112 : 1 : case PSBTError::EXTERNAL_SIGNER_NOT_FOUND:
113 [ + - ]: 2 : return Untranslated("External signer not found");
114 : 0 : case PSBTError::EXTERNAL_SIGNER_FAILED:
115 [ # # ]: 0 : return Untranslated("External signer failed to sign");
116 : 0 : case PSBTError::UNSUPPORTED:
117 [ # # ]: 0 : return Untranslated("Signer does not support PSBT");
118 : 0 : case PSBTError::INCOMPLETE:
119 [ # # ]: 0 : return Untranslated("Input needs additional signatures or other data");
120 : 0 : case PSBTError::OK:
121 [ # # ]: 0 : return Untranslated("No errors");
122 : : // no default case, so the compiler can warn about missing cases
123 : : }
124 : 0 : assert(false);
125 : : }
126 : :
127 : 30 : bilingual_str TransactionErrorString(const TransactionError err)
128 : : {
129 [ - - + - : 30 : switch (err) {
- + + -
- ]
130 : 0 : case TransactionError::OK:
131 [ # # ]: 0 : return Untranslated("No error");
132 : 0 : case TransactionError::MISSING_INPUTS:
133 [ # # ]: 0 : return Untranslated("Inputs missing or spent");
134 : 3 : case TransactionError::ALREADY_IN_UTXO_SET:
135 [ + - ]: 6 : return Untranslated("Transaction outputs already in utxo set");
136 : 0 : case TransactionError::MEMPOOL_REJECTED:
137 [ # # ]: 0 : return Untranslated("Transaction rejected by mempool");
138 : 0 : case TransactionError::MEMPOOL_ERROR:
139 [ # # ]: 0 : return Untranslated("Mempool internal error");
140 : 22 : case TransactionError::MAX_FEE_EXCEEDED:
141 [ + - ]: 44 : return Untranslated("Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)");
142 : 5 : case TransactionError::MAX_BURN_EXCEEDED:
143 [ + - ]: 10 : return Untranslated("Unspendable output exceeds maximum configured by user (maxburnamount)");
144 : 0 : case TransactionError::INVALID_PACKAGE:
145 [ # # ]: 0 : return Untranslated("Transaction rejected due to invalid package");
146 : : // no default case, so the compiler can warn about missing cases
147 : : }
148 : 0 : assert(false);
149 : : }
150 : :
151 : 3 : bilingual_str ResolveErrMsg(const std::string& optname, const std::string& strBind)
152 : : {
153 : 3 : return strprintf(_("Cannot resolve -%s address: '%s'"), optname, strBind);
154 : : }
155 : :
156 : 9 : bilingual_str InvalidPortErrMsg(const std::string& optname, const std::string& invalid_value)
157 : : {
158 : 9 : return strprintf(_("Invalid port specified in %s: '%s'"), optname, invalid_value);
159 : : }
160 : :
161 : 6 : bilingual_str AmountHighWarn(const std::string& optname)
162 : : {
163 : 6 : return strprintf(_("%s is set very high!"), optname);
164 : : }
165 : :
166 : 0 : bilingual_str AmountErrMsg(const std::string& optname, const std::string& strValue)
167 : : {
168 : 0 : return strprintf(_("Invalid amount for -%s=<amount>: '%s'"), optname, strValue);
169 : : }
170 : : } // namespace common
|