diff --git a/lnwallet/channel.go b/lnwallet/channel.go index eb0adeaf7..4f69ed2a1 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -2540,7 +2540,7 @@ func genRemoteHtlcSigJobs(keyRing *CommitmentKeyRing, remoteCommitView *commitment) ([]signJob, chan struct{}, error) { txHash := remoteCommitView.txn.TxHash() - dustLimit := localChanCfg.DustLimit + dustLimit := remoteChanCfg.DustLimit feePerKw := remoteCommitView.feePerKw // With the keys generated, we'll make a slice with enough capacity to diff --git a/lnwallet/channel_test.go b/lnwallet/channel_test.go index 01e158d8f..2046ed3ad 100644 --- a/lnwallet/channel_test.go +++ b/lnwallet/channel_test.go @@ -1503,6 +1503,7 @@ func TestHTLCSigNumber(t *testing.T) { } feePerKw := feePerVSize.FeePerKWeight() + belowDust := btcutil.Amount(500) + htlcTimeoutFee(feePerKw) aboveDust := btcutil.Amount(1400) + htlcSuccessFee(feePerKw) // =================================================================== @@ -1554,6 +1555,52 @@ func TestHTLCSigNumber(t *testing.T) { t.Fatalf("Expected Bob to reject signatures") } + // ============================================================== + // Test that sigs are not returned for HTLCs below dust limit. + // ============================================================== + aliceChannel, bobChannel, cleanUp = createChanWithHTLC(belowDust) + defer cleanUp() + + aliceSig, aliceHtlcSigs, err = aliceChannel.SignNextCommitment() + if err != nil { + t.Fatalf("Error signing next commitment: %v", err) + } + + // Since the HTLC is below Bob's dust limit, Alice won't need to send + // any signatures for this HTLC. + if len(aliceHtlcSigs) != 0 { + t.Fatalf("expected no htlc sigs, instead got %v", + len(aliceHtlcSigs)) + } + + err = bobChannel.ReceiveNewCommitment(aliceSig, aliceHtlcSigs) + if err != nil { + t.Fatalf("Bob failed receiving commitment: %v", err) + } + + // ================================================================ + // Test that sigs are correctly returned for HTLCs above dust limit. + // ================================================================ + aliceChannel, bobChannel, cleanUp = createChanWithHTLC(aboveDust) + defer cleanUp() + + aliceSig, aliceHtlcSigs, err = aliceChannel.SignNextCommitment() + if err != nil { + t.Fatalf("Error signing next commitment: %v", err) + } + + // Since the HTLC is above Bob's dust limit, Alice should send a + // signature for this HTLC. + if len(aliceHtlcSigs) != 1 { + t.Fatalf("expected 1 htlc sig, instead got %v", + len(aliceHtlcSigs)) + } + + err = bobChannel.ReceiveNewCommitment(aliceSig, aliceHtlcSigs) + if err != nil { + t.Fatalf("Bob failed receiving commitment: %v", err) + } + } // TestChannelBalanceDustLimit tests the condition when the remaining balance