lnwallet/channel: use remote dustlimit when generating HTLC sigs

This commit fixes an issue which would arise in some cases when the
local and remote dust limits would differ, resulting in lnd not
producing the expected number of HTLC signatures. This was a result of
checking dust against the local instead of the remote dust limit.

A test exercising the scenario is added.
This commit is contained in:
Johan T. Halseth 2018-03-22 13:04:57 +01:00
parent 263d6b9c1f
commit 70b86e596e
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
2 changed files with 48 additions and 1 deletions

@ -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

@ -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