Skip to content

Commit d4b621b

Browse files
committed
Merge branch 'v0.14.2-beta-6226' into v0-14-2-branch-rc1
2 parents 2508177 + 11c5704 commit d4b621b

File tree

8 files changed

+97
-11
lines changed

8 files changed

+97
-11
lines changed

cmd/lncli/cmd_payments.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/lightningnetwork/lnd/lnrpc"
2323
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
2424
"github.com/lightningnetwork/lnd/lntypes"
25+
"github.com/lightningnetwork/lnd/lnwallet"
2526
"github.com/lightningnetwork/lnd/lnwire"
2627
"github.com/lightningnetwork/lnd/record"
2728
"github.com/lightningnetwork/lnd/routing/route"
@@ -217,8 +218,10 @@ func retrieveFeeLimit(ctx *cli.Context, amt int64) (int64, error) {
217218
return feeLimitRoundedUp, nil
218219
}
219220

220-
// If no fee limit is set, use the payment amount as a limit (100%).
221-
return amt, nil
221+
// If no fee limit is set, use a default value based on the amount.
222+
amtMsat := lnwire.NewMSatFromSatoshis(btcutil.Amount(amt))
223+
limitMsat := lnwallet.DefaultRoutingFeeLimitForAmount(amtMsat)
224+
return int64(limitMsat.ToSatoshis()), nil
222225
}
223226

224227
func confirmPayReq(resp *lnrpc.PayReq, amt, feeLimit int64) error {

docs/release-notes/release-notes-0.14.2.md

+12
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ connection from the watch-only node.
3232
[These premature messages are now saved into a cache and processed once the
3333
height has reached.](https://github.com/lightningnetwork/lnd/pull/6054)
3434

35+
* A bug that allowed fees to be up to 100% of the payment amount was fixed by
36+
[introducing a more sane default
37+
value](https://github.com/lightningnetwork/lnd/pull/6226) of 5% routing fees
38+
(except for small amounts <= 50 satoshis where the 100% routing fees are kept
39+
to accommodate for the base fee in channels). To avoid falling back to a
40+
default value, users should always set their own fee limits by using the
41+
`--fee_limit` or `--fee_limit_percent` flags on the `lncli payinvoice`,
42+
`lncli sendpayment` and `lncli queryroutes` commands. Users of the gRPC or
43+
REST API should set the `fee_limit` field on the corresponding calls
44+
(`SendPayment`, `SendPaymentSync`, `QueryRoutes`).
45+
3546
## Database
3647

3748
* [Speed up graph cache loading on startup with
@@ -181,4 +192,5 @@ Postgres](https://github.com/lightningnetwork/lnd/pull/6111)
181192
* Martin Habovštiak
182193
* Naveen Srinivasan
183194
* Oliver Gugger
195+
* Olaoluwa Osuntokun
184196
* Yong Yu

lnrpc/lightning.pb.go

+4-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lnrpc/lightning.proto

+4-2
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,8 @@ message SendRequest {
753753
The maximum number of satoshis that will be paid as a fee of the payment.
754754
This value can be represented either as a percentage of the amount being
755755
sent, or as a fixed amount of the maximum fee the user is willing the pay to
756-
send the payment.
756+
send the payment. If not specified, lnd will use a default value of 100%
757+
fees for small amounts (<=50 sat) or 5% fees for larger amounts.
757758
*/
758759
FeeLimit fee_limit = 8;
759760

@@ -2571,7 +2572,8 @@ message QueryRoutesRequest {
25712572
The maximum number of satoshis that will be paid as a fee of the payment.
25722573
This value can be represented either as a percentage of the amount being
25732574
sent, or as a fixed amount of the maximum fee the user is willing the pay to
2574-
send the payment.
2575+
send the payment. If not specified, lnd will use a default value of 100%
2576+
fees for small amounts (<=50 sat) or 5% fees for larger amounts.
25752577
*/
25762578
FeeLimit fee_limit = 5;
25772579

lnrpc/lightning.swagger.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6234,7 +6234,7 @@
62346234
},
62356235
"fee_limit": {
62366236
"$ref": "#/definitions/lnrpcFeeLimit",
6237-
"description": "The maximum number of satoshis that will be paid as a fee of the payment.\nThis value can be represented either as a percentage of the amount being\nsent, or as a fixed amount of the maximum fee the user is willing the pay to\nsend the payment."
6237+
"description": "The maximum number of satoshis that will be paid as a fee of the payment.\nThis value can be represented either as a percentage of the amount being\nsent, or as a fixed amount of the maximum fee the user is willing the pay to\nsend the payment. If not specified, lnd will use a default value of 100%\nfees for small amounts (\u003c=50 sat) or 5% fees for larger amounts."
62386238
},
62396239
"outgoing_chan_id": {
62406240
"type": "string",

lnrpc/marshall_utils.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ func CalculateFeeLimit(feeLimit *FeeLimit,
4040
return amount * lnwire.MilliSatoshi(feeLimit.GetPercent()) / 100
4141

4242
default:
43-
// If a fee limit was not specified, we'll use the payment's
44-
// amount as an upper bound in order to avoid payment attempts
45-
// from incurring fees higher than the payment amount itself.
46-
return amount
43+
// Fall back to a sane default value that is based on the amount
44+
// itself.
45+
return lnwallet.DefaultRoutingFeeLimitForAmount(amount)
4746
}
4847
}
4948

lnwallet/parameters.go

+29
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,37 @@ import (
55
"github.com/btcsuite/btcd/wire"
66
"github.com/btcsuite/btcutil"
77
"github.com/lightningnetwork/lnd/input"
8+
"github.com/lightningnetwork/lnd/lnwire"
89
)
910

11+
const (
12+
// RoutingFee100PercentUpTo is the cut-off amount we allow 100% fees to
13+
// be charged up to.
14+
RoutingFee100PercentUpTo lnwire.MilliSatoshi = 50_000
15+
16+
// DefaultRoutingFeePercentage is the default off-chain routing fee we
17+
// allow to be charged for a payment over the RoutingFee100PercentUpTo
18+
// size.
19+
DefaultRoutingFeePercentage lnwire.MilliSatoshi = 5
20+
)
21+
22+
// DefaultRoutingFeeLimitForAmount returns the default off-chain routing fee
23+
// limit lnd uses if the user does not specify a limit manually. The fee is
24+
// amount dependent because of the base routing fee that is set on many
25+
// channels. For example the default base fee is 1 satoshi. So sending a payment
26+
// of one satoshi will cost 1 satoshi in fees over most channels, which comes to
27+
// a fee of 100%. That's why for very small amounts we allow 100% fee.
28+
func DefaultRoutingFeeLimitForAmount(a lnwire.MilliSatoshi) lnwire.MilliSatoshi {
29+
// Allow 100% fees up to a certain amount to accommodate for base fees.
30+
if a <= RoutingFee100PercentUpTo {
31+
return a
32+
}
33+
34+
// Everything larger than the cut-off amount will get a default fee
35+
// percentage.
36+
return a * DefaultRoutingFeePercentage / 100
37+
}
38+
1039
// DustLimitForSize retrieves the dust limit for a given pkscript size. Given
1140
// the size, it automatically determines whether the script is a witness script
1241
// or not. It calls btcd's GetDustThreshold method under the hood. It must be

lnwallet/parameters_test.go

+39
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,52 @@
11
package lnwallet
22

33
import (
4+
"fmt"
45
"testing"
56

67
"github.com/btcsuite/btcutil"
78
"github.com/lightningnetwork/lnd/input"
9+
"github.com/lightningnetwork/lnd/lnwire"
810
"github.com/stretchr/testify/require"
911
)
1012

13+
// TestDefaultRoutingFeeLimitForAmount tests that we use the correct default
14+
// routing fee depending on the amount.
15+
func TestDefaultRoutingFeeLimitForAmount(t *testing.T) {
16+
t.Parallel()
17+
18+
tests := []struct {
19+
amount lnwire.MilliSatoshi
20+
expectedLimit lnwire.MilliSatoshi
21+
}{
22+
{
23+
amount: 1,
24+
expectedLimit: 1,
25+
},
26+
{
27+
amount: 50_000,
28+
expectedLimit: 50_000,
29+
},
30+
{
31+
amount: 50_001,
32+
expectedLimit: 2_500,
33+
},
34+
{
35+
amount: 5_000_000_000,
36+
expectedLimit: 250_000_000,
37+
},
38+
}
39+
40+
for _, test := range tests {
41+
test := test
42+
43+
t.Run(fmt.Sprintf("%d sats", test.amount), func(t *testing.T) {
44+
feeLimit := DefaultRoutingFeeLimitForAmount(test.amount)
45+
require.Equal(t, test.expectedLimit, feeLimit)
46+
})
47+
}
48+
}
49+
1150
// TestDustLimitForSize tests that we receive the expected dust limits for
1251
// various script types from btcd's GetDustThreshold function.
1352
func TestDustLimitForSize(t *testing.T) {

0 commit comments

Comments
 (0)