Skip to content

Commit 6a4c25a

Browse files
committed
rpcserver+itest: enforce keysend minimum carrier HTLC amount
Fixes an issue where attempting to pay a below-dust carrier HTLC satoshi amount would knock a channel offline.
1 parent ffcc47b commit 6a4c25a

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

itest/channels_test.go

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

6+
"github.com/lightninglabs/taproot-assets/internal/test"
67
"github.com/lightninglabs/taproot-assets/rfqmsg"
78
tchrpc "github.com/lightninglabs/taproot-assets/taprpc/tapchannelrpc"
89
"github.com/lightningnetwork/lnd/lnrpc"
@@ -66,6 +67,25 @@ func testChannelRPCs(t *harnessTest) {
6667
"payment",
6768
)
6869

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