Skip to content

Commit a2a250c

Browse files
committed
Merge #19743: -maxapsfee follow-up
7e31ea9 -maxapsfee: follow-up fixes (Karl-Johan Alm) 9f77b82 doc: release notes for -maxapsfee (Karl-Johan Alm) Pull request description: Addresses feedback from jonatack and meshcollider in #14582. ACKs for top commit: jonatack: ACK 7e31ea9 meshcollider: re-ACK 7e31ea9 Tree-SHA512: 5d159d78e917e41140e1394bef05e821430dbeac585e9bd708f897041dd7104c2a6b563bfab8b2c85e6d923441160a3880d7864d768aa8e0e66860e0a2c4f56b
2 parents e6e277f + 7e31ea9 commit a2a250c

File tree

3 files changed

+61
-15
lines changed

3 files changed

+61
-15
lines changed

doc/release-notes-14582.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Configuration
2+
-------------
3+
4+
A new configuration flag `-maxapsfee` has been added, which sets the max allowed
5+
avoid partial spends (APS) fee. It defaults to 0 (i.e. fee is the same with
6+
and without APS). Setting it to -1 will disable APS, unless `-avoidpartialspends`
7+
is set. (#14582)
8+
9+
Wallet
10+
------
11+
12+
The wallet will now avoid partial spends (APS) by default, if this does not result
13+
in a difference in fees compared to the non-APS variant. The allowed fee threshold
14+
can be adjusted using the new `-maxapsfee` configuration option. (#14582)

src/wallet/wallet.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3890,16 +3890,17 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
38903890
}
38913891

38923892
if (gArgs.IsArgSet("-maxapsfee")) {
3893+
const std::string max_aps_fee{gArgs.GetArg("-maxapsfee", "")};
38933894
CAmount n = 0;
3894-
if (gArgs.GetArg("-maxapsfee", "") == "-1") {
3895+
if (max_aps_fee == "-1") {
38953896
n = -1;
3896-
} else if (!ParseMoney(gArgs.GetArg("-maxapsfee", ""), n)) {
3897-
error = AmountErrMsg("maxapsfee", gArgs.GetArg("-maxapsfee", ""));
3897+
} else if (!ParseMoney(max_aps_fee, n)) {
3898+
error = AmountErrMsg("maxapsfee", max_aps_fee);
38983899
return nullptr;
38993900
}
39003901
if (n > HIGH_APS_FEE) {
39013902
warnings.push_back(AmountHighWarn("-maxapsfee") + Untranslated(" ") +
3902-
_("This is the maximum transaction fee you pay to prioritize partial spend avoidance over regular coin selection."));
3903+
_("This is the maximum transaction fee you pay (in addition to the normal fee) to prioritize partial spend avoidance over regular coin selection."));
39033904
}
39043905
walletInstance->m_max_aps_fee = n;
39053906
}

test/functional/wallet_groups.py

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@
1515
class WalletGroupTest(BitcoinTestFramework):
1616
def set_test_params(self):
1717
self.setup_clean_chain = True
18-
self.num_nodes = 4
19-
self.extra_args = [[], [], ['-avoidpartialspends'], ["-maxapsfee=0.0001"]]
18+
self.num_nodes = 5
19+
self.extra_args = [
20+
[],
21+
[],
22+
["-avoidpartialspends"],
23+
["-maxapsfee=0.00002719"],
24+
["-maxapsfee=0.00002720"],
25+
]
2026
self.rpc_timeout = 480
2127

2228
def skip_test_if_missing_module(self):
@@ -50,8 +56,8 @@ def run_test(self):
5056
# one output should be 0.2, the other should be ~0.3
5157
v = [vout["value"] for vout in tx1["vout"]]
5258
v.sort()
53-
assert_approx(v[0], 0.2)
54-
assert_approx(v[1], 0.3, 0.0001)
59+
assert_approx(v[0], vexp=0.2, vspan=0.0001)
60+
assert_approx(v[1], vexp=0.3, vspan=0.0001)
5561

5662
txid2 = self.nodes[2].sendtoaddress(self.nodes[0].getnewaddress(), 0.2)
5763
tx2 = self.nodes[2].getrawtransaction(txid2, True)
@@ -61,8 +67,8 @@ def run_test(self):
6167
# one output should be 0.2, the other should be ~1.3
6268
v = [vout["value"] for vout in tx2["vout"]]
6369
v.sort()
64-
assert_approx(v[0], 0.2)
65-
assert_approx(v[1], 1.3, 0.0001)
70+
assert_approx(v[0], vexp=0.2, vspan=0.0001)
71+
assert_approx(v[1], vexp=1.3, vspan=0.0001)
6672

6773
# Test 'avoid partial if warranted, even if disabled'
6874
self.sync_all()
@@ -75,8 +81,8 @@ def run_test(self):
7581
# - C0 1.0 - E1 0.5
7682
# - C1 0.5 - F ~1.3
7783
# - D ~0.3
78-
assert_approx(self.nodes[1].getbalance(), 4.3, 0.0001)
79-
assert_approx(self.nodes[2].getbalance(), 4.3, 0.0001)
84+
assert_approx(self.nodes[1].getbalance(), vexp=4.3, vspan=0.0001)
85+
assert_approx(self.nodes[2].getbalance(), vexp=4.3, vspan=0.0001)
8086
# Sending 1.4 btc should pick one 1.0 + one more. For node #1,
8187
# this could be (A / B0 / C0) + (B1 / C1 / D). We ensure that it is
8288
# B0 + B1 or C0 + C1, because this avoids partial spends while not being
@@ -90,8 +96,8 @@ def run_test(self):
9096
# ~0.1 and 1.4 and should come from the same destination
9197
values = [vout["value"] for vout in tx3["vout"]]
9298
values.sort()
93-
assert_approx(values[0], 0.1, 0.0001)
94-
assert_approx(values[1], 1.4)
99+
assert_approx(values[0], vexp=0.1, vspan=0.0001)
100+
assert_approx(values[1], vexp=1.4, vspan=0.0001)
95101

96102
input_txids = [vin["txid"] for vin in tx3["vin"]]
97103
input_addrs = [self.nodes[1].gettransaction(txid)['details'][0]['address'] for txid in input_txids]
@@ -104,13 +110,38 @@ def run_test(self):
104110
self.nodes[0].sendtoaddress(addr_aps, 1.0)
105111
self.nodes[0].generate(1)
106112
self.sync_all()
107-
txid4 = self.nodes[3].sendtoaddress(self.nodes[0].getnewaddress(), 0.1)
113+
with self.nodes[3].assert_debug_log(['Fee non-grouped = 2820, grouped = 4160, using grouped']):
114+
txid4 = self.nodes[3].sendtoaddress(self.nodes[0].getnewaddress(), 0.1)
108115
tx4 = self.nodes[3].getrawtransaction(txid4, True)
109116
# tx4 should have 2 inputs and 2 outputs although one output would
110117
# have been enough and the transaction caused higher fees
111118
assert_equal(2, len(tx4["vin"]))
112119
assert_equal(2, len(tx4["vout"]))
113120

121+
addr_aps2 = self.nodes[3].getnewaddress()
122+
[self.nodes[0].sendtoaddress(addr_aps2, 1.0) for _ in range(5)]
123+
self.nodes[0].generate(1)
124+
self.sync_all()
125+
with self.nodes[3].assert_debug_log(['Fee non-grouped = 5520, grouped = 8240, using non-grouped']):
126+
txid5 = self.nodes[3].sendtoaddress(self.nodes[0].getnewaddress(), 2.95)
127+
tx5 = self.nodes[3].getrawtransaction(txid5, True)
128+
# tx5 should have 3 inputs (1.0, 1.0, 1.0) and 2 outputs
129+
assert_equal(3, len(tx5["vin"]))
130+
assert_equal(2, len(tx5["vout"]))
131+
132+
# Test wallet option maxapsfee with node 4, which sets maxapsfee
133+
# 1 sat higher, crossing the threshold from non-grouped to grouped.
134+
addr_aps3 = self.nodes[4].getnewaddress()
135+
[self.nodes[0].sendtoaddress(addr_aps3, 1.0) for _ in range(5)]
136+
self.nodes[0].generate(1)
137+
self.sync_all()
138+
with self.nodes[4].assert_debug_log(['Fee non-grouped = 5520, grouped = 8240, using grouped']):
139+
txid6 = self.nodes[4].sendtoaddress(self.nodes[0].getnewaddress(), 2.95)
140+
tx6 = self.nodes[4].getrawtransaction(txid6, True)
141+
# tx6 should have 5 inputs and 2 outputs
142+
assert_equal(5, len(tx6["vin"]))
143+
assert_equal(2, len(tx6["vout"]))
144+
114145
# Empty out node2's wallet
115146
self.nodes[2].sendtoaddress(address=self.nodes[0].getnewaddress(), amount=self.nodes[2].getbalance(), subtractfeefromamount=True)
116147
self.sync_all()

0 commit comments

Comments
 (0)