Skip to content

Commit f32f7e9

Browse files
committed
Merge #11413: [wallet] [rpc] sendtoaddress/sendmany: Add explicit feerate option
25dac9f doc: add release notes for explicit fee estimators and bumpfee change (Karl-Johan Alm) 05227a3 tests for bumpfee / estimate_modes (Karl-Johan Alm) 3404c1b policy: optional FeeEstimateMode param to CFeeRate::ToString (Karl-Johan Alm) 6fcf448 rpc/wallet: add two explicit modes to estimate_mode (Karl-Johan Alm) b188d80 MOVEONLY: Make FeeEstimateMode available to CFeeRate (Karl-Johan Alm) 5d1a411 fees: add FeeModes doc helper function (Karl-Johan Alm) 91f6d2b rpc/wallet: add conf_target as alias to confTarget in bumpfee (Karl-Johan Alm) 69158b4 added CURRENCY_ATOM to express minimum indivisible unit (Karl-Johan Alm) Pull request description: This lets users pick their own fees when using `sendtoaddress`/`sendmany` if they prefer this over the estimators. ACKs for top commit: Sjors: re-utACK 25dac9f: rebased, more fancy C++, jonatack: ACK 25dac9f I think this should be merged after all this time, even though it looks to me like there are needed follow-ups, fixes and test coverage to be added (see further down), which I don't mind helping out with, if wanted. fjahr: Code review ACK 25dac9f Tree-SHA512: f31177e6cabf3187a43cdfe93477144f8e8385c7344613743cbbd16e8490d53ff5144aec7b9de6c9a65eb855b55e0f99d7f164dee4b6bf3cfea4dce51cf11d33
2 parents 910f046 + 25dac9f commit f32f7e9

File tree

9 files changed

+285
-91
lines changed

9 files changed

+285
-91
lines changed

doc/release-notes-11413.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Updated or changed RPC
2+
----------------------
3+
4+
The `bumpfee`, `fundrawtransaction`, `sendmany`, `sendtoaddress`, and `walletcreatefundedpsbt`
5+
RPC commands have been updated to include two new fee estimation methods "BTC/kB" and "sat/B".
6+
The target is the fee expressed explicitly in the given form. Note that use of this feature
7+
will trigger BIP 125 (replace-by-fee) opt-in.
8+
9+
In addition, the `estimate_mode` parameter is now case insensitive for all of the above RPC commands.
10+
11+
The `bumpfee` command now uses `conf_target` rather than `confTarget` in the options.

src/policy/feerate.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
#include <tinyformat.h>
99

10-
const std::string CURRENCY_UNIT = "BTC";
11-
1210
CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nBytes_)
1311
{
1412
assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max()));
@@ -37,7 +35,10 @@ CAmount CFeeRate::GetFee(size_t nBytes_) const
3735
return nFee;
3836
}
3937

40-
std::string CFeeRate::ToString() const
38+
std::string CFeeRate::ToString(const FeeEstimateMode& fee_estimate_mode) const
4139
{
42-
return strprintf("%d.%08d %s/kB", nSatoshisPerK / COIN, nSatoshisPerK % COIN, CURRENCY_UNIT);
40+
switch (fee_estimate_mode) {
41+
case FeeEstimateMode::SAT_B: return strprintf("%d.%03d %s/B", nSatoshisPerK / 1000, nSatoshisPerK % 1000, CURRENCY_ATOM);
42+
default: return strprintf("%d.%08d %s/kB", nSatoshisPerK / COIN, nSatoshisPerK % COIN, CURRENCY_UNIT);
43+
}
4344
}

src/policy/feerate.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,17 @@
1111

1212
#include <string>
1313

14-
extern const std::string CURRENCY_UNIT;
14+
const std::string CURRENCY_UNIT = "BTC"; // One formatted unit
15+
const std::string CURRENCY_ATOM = "sat"; // One indivisible minimum value unit
16+
17+
/* Used to determine type of fee estimation requested */
18+
enum class FeeEstimateMode {
19+
UNSET, //!< Use default settings based on other criteria
20+
ECONOMICAL, //!< Force estimateSmartFee to use non-conservative estimates
21+
CONSERVATIVE, //!< Force estimateSmartFee to use conservative estimates
22+
BTC_KB, //!< Use explicit BTC/kB fee given in coin control
23+
SAT_B, //!< Use explicit sat/B fee given in coin control
24+
};
1525

1626
/**
1727
* Fee rate in satoshis per kilobyte: CAmount / kB
@@ -46,7 +56,7 @@ class CFeeRate
4656
friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
4757
friend bool operator!=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK != b.nSatoshisPerK; }
4858
CFeeRate& operator+=(const CFeeRate& a) { nSatoshisPerK += a.nSatoshisPerK; return *this; }
49-
std::string ToString() const;
59+
std::string ToString(const FeeEstimateMode& fee_estimate_mode = FeeEstimateMode::BTC_KB) const;
5060

5161
SERIALIZE_METHODS(CFeeRate, obj) { READWRITE(obj.nSatoshisPerK); }
5262
};

src/policy/fees.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ enum class FeeReason {
4545
REQUIRED,
4646
};
4747

48-
/* Used to determine type of fee estimation requested */
49-
enum class FeeEstimateMode {
50-
UNSET, //!< Use default settings based on other criteria
51-
ECONOMICAL, //!< Force estimateSmartFee to use non-conservative estimates
52-
CONSERVATIVE, //!< Force estimateSmartFee to use conservative estimates
53-
};
54-
5548
/* Used to return detailed information about a feerate bucket */
5649
struct EstimatorBucket
5750
{

src/util/fees.cpp

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66
#include <util/fees.h>
77

88
#include <policy/fees.h>
9+
#include <util/strencodings.h>
10+
#include <util/string.h>
911

1012
#include <map>
1113
#include <string>
14+
#include <vector>
15+
#include <utility>
1216

13-
std::string StringForFeeReason(FeeReason reason) {
17+
std::string StringForFeeReason(FeeReason reason)
18+
{
1419
static const std::map<FeeReason, std::string> fee_reason_strings = {
1520
{FeeReason::NONE, "None"},
1621
{FeeReason::HALF_ESTIMATE, "Half Target 60% Threshold"},
@@ -29,16 +34,31 @@ std::string StringForFeeReason(FeeReason reason) {
2934
return reason_string->second;
3035
}
3136

32-
bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode) {
33-
static const std::map<std::string, FeeEstimateMode> fee_modes = {
34-
{"UNSET", FeeEstimateMode::UNSET},
35-
{"ECONOMICAL", FeeEstimateMode::ECONOMICAL},
36-
{"CONSERVATIVE", FeeEstimateMode::CONSERVATIVE},
37+
const std::vector<std::pair<std::string, FeeEstimateMode>>& FeeModeMap()
38+
{
39+
static const std::vector<std::pair<std::string, FeeEstimateMode>> FEE_MODES = {
40+
{"unset", FeeEstimateMode::UNSET},
41+
{"economical", FeeEstimateMode::ECONOMICAL},
42+
{"conservative", FeeEstimateMode::CONSERVATIVE},
43+
{(CURRENCY_UNIT + "/kB"), FeeEstimateMode::BTC_KB},
44+
{(CURRENCY_ATOM + "/B"), FeeEstimateMode::SAT_B},
3745
};
38-
auto mode = fee_modes.find(mode_string);
46+
return FEE_MODES;
47+
}
3948

40-
if (mode == fee_modes.end()) return false;
49+
std::string FeeModes(const std::string& delimiter)
50+
{
51+
return Join(FeeModeMap(), delimiter, [&](const std::pair<std::string, FeeEstimateMode>& i) { return i.first; });
52+
}
4153

42-
fee_estimate_mode = mode->second;
43-
return true;
54+
bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode)
55+
{
56+
auto searchkey = ToUpper(mode_string);
57+
for (const auto& pair : FeeModeMap()) {
58+
if (ToUpper(pair.first) == searchkey) {
59+
fee_estimate_mode = pair.second;
60+
return true;
61+
}
62+
}
63+
return false;
4464
}

src/util/fees.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ enum class FeeReason;
1212

1313
bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode);
1414
std::string StringForFeeReason(FeeReason reason);
15+
std::string FeeModes(const std::string& delimiter);
1516

1617
#endif // BITCOIN_UTIL_FEES_H

0 commit comments

Comments
 (0)