Skip to content

Commit 485073b

Browse files
authored
Merge pull request #1606 from lightninglabs/keysend-min-amount
rpcserver: enforce keysend minimum carrier HTLC amount
2 parents ffcc47b + 3696ead commit 485073b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

itest/channels_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package itest
33
import (
44
"context"
55

6+
"github.com/lightninglabs/taproot-assets/internal/test"
7+
"github.com/lightninglabs/taproot-assets/rfqmath"
68
"github.com/lightninglabs/taproot-assets/rfqmsg"
79
tchrpc "github.com/lightninglabs/taproot-assets/taprpc/tapchannelrpc"
810
"github.com/lightningnetwork/lnd/lnrpc"
@@ -66,6 +68,26 @@ func testChannelRPCs(t *harnessTest) {
6668
"payment",
6769
)
6870

71+
// Make sure that the minimum satoshi amount for a keysend payment is
72+
// enforced.
73+
stream, err = t.tapd.SendPayment(ctx, &tchrpc.SendPaymentRequest{
74+
AssetAmount: 123,
75+
AssetId: dummyByteArr[:],
76+
PaymentRequest: &routerrpc.SendPaymentRequest{
77+
Dest: test.RandPubKey(t.t).SerializeCompressed(),
78+
DestCustomRecords: map[uint64][]byte{
79+
record.KeySendType: dummyByteArr[:],
80+
},
81+
Amt: int64(rfqmath.DefaultOnChainHtlcSat - 1),
82+
},
83+
})
84+
require.NoError(t.t, err)
85+
86+
_, err = stream.Recv()
87+
require.ErrorContains(
88+
t.t, err, "keysend payment satoshi amount must be greater",
89+
)
90+
6991
// Now let's also try the invoice path, which should fail because we
7092
// don't have any asset channels with peers that we could ask for a
7193
// quote.

rpcserver.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7798,6 +7798,16 @@ func (r *rpcServer) SendPayment(req *tchrpc.SendPaymentRequest,
77987798
"pubkey: %w", err)
77997799
}
78007800

7801+
// We must enforce a minimum satoshi amount to make sure the
7802+
// carrier HTLC is above dust. This is handled by the traffic
7803+
// shaper for invoice-based payments, but for keysend payments
7804+
// we need to do it here.
7805+
if pReq.Amt < int64(rfqmath.DefaultOnChainHtlcSat) {
7806+
return fmt.Errorf("keysend payment satoshi amount "+
7807+
"must be greater than or equal to %d satoshis",
7808+
rfqmath.DefaultOnChainHtlcSat)
7809+
}
7810+
78017811
// We check that we have the asset amount available in the
78027812
// channel.
78037813
_, err = r.cfg.RfqManager.FetchChannel(

0 commit comments

Comments
 (0)