From 263d6b9c1fbeb67319dda5dee806c47c46534ea5 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Thu, 22 Mar 2018 12:59:11 +0100 Subject: [PATCH] lnwallet/channel: don't accept immediately on empty htlc sigs This commit fixes an issue where we would blindly accept a commitment which came without any accompanying HTLC signatures. A test exercising the scenario is added. --- lnwallet/channel.go | 6 ------ lnwallet/channel_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 496425e6..eb0adeaf 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -3465,12 +3465,6 @@ func genHtlcSigValidationJobs(localCommitmentView *commitment, keyRing *CommitmentKeyRing, htlcSigs []lnwire.Sig, localChanCfg, remoteChanCfg *channeldb.ChannelConfig) ([]verifyJob, error) { - // If this new commitment state doesn't have any HTLC's that are to be - // signed, then we'll return a nil slice. - if len(htlcSigs) == 0 { - return nil, nil - } - txHash := localCommitmentView.txn.TxHash() feePerKw := localCommitmentView.feePerKw diff --git a/lnwallet/channel_test.go b/lnwallet/channel_test.go index cd56e0e8..01e158d8 100644 --- a/lnwallet/channel_test.go +++ b/lnwallet/channel_test.go @@ -1530,6 +1530,30 @@ func TestHTLCSigNumber(t *testing.T) { t.Fatalf("Expected Bob to reject signatures") } + // =================================================================== + // Test that Bob will reject a commitment if Alice doesn't send any + // HTLC signatures. + // =================================================================== + aliceChannel, bobChannel, cleanUp = createChanWithHTLC(aboveDust) + defer cleanUp() + + aliceSig, aliceHtlcSigs, err = aliceChannel.SignNextCommitment() + if err != nil { + t.Fatalf("Error signing next commitment: %v", err) + } + + if len(aliceHtlcSigs) != 1 { + t.Fatalf("expected 1 htlc sig, instead got %v", + len(aliceHtlcSigs)) + } + + // Now just give Bob an empty htlcSig slice. He should reject the + // commitment because of this. + err = bobChannel.ReceiveNewCommitment(aliceSig, []lnwire.Sig{}) + if err == nil { + t.Fatalf("Expected Bob to reject signatures") + } + } // TestChannelBalanceDustLimit tests the condition when the remaining balance