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.
This commit is contained in:
parent
241c79397f
commit
263d6b9c1f
@ -3465,12 +3465,6 @@ func genHtlcSigValidationJobs(localCommitmentView *commitment,
|
|||||||
keyRing *CommitmentKeyRing, htlcSigs []lnwire.Sig,
|
keyRing *CommitmentKeyRing, htlcSigs []lnwire.Sig,
|
||||||
localChanCfg, remoteChanCfg *channeldb.ChannelConfig) ([]verifyJob, error) {
|
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()
|
txHash := localCommitmentView.txn.TxHash()
|
||||||
feePerKw := localCommitmentView.feePerKw
|
feePerKw := localCommitmentView.feePerKw
|
||||||
|
|
||||||
|
@ -1530,6 +1530,30 @@ func TestHTLCSigNumber(t *testing.T) {
|
|||||||
t.Fatalf("Expected Bob to reject signatures")
|
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
|
// TestChannelBalanceDustLimit tests the condition when the remaining balance
|
||||||
|
Loading…
Reference in New Issue
Block a user