lnwallet/channel: reject received commitment with too many htlc sigs

This commit adds a check that will make LightningChannel reject a
received commitment if it is accompanied with too many HTLC signatures.
This enforces the requirement in BOLT-2, saying:

if num_htlcs is not equal to the number of HTLC outputs in the local commitment transaction:
    * MUST fail the channel.

A test exercising the behaviour is added.
This commit is contained in:
Johan T. Halseth 2018-03-22 13:23:23 +01:00
parent 70b86e596e
commit a6e7dce7b7
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
2 changed files with 36 additions and 0 deletions

View File

@ -3606,6 +3606,13 @@ func genHtlcSigValidationJobs(localCommitmentView *commitment,
i++
}
// If we received a number of HTLC signatures that doesn't match our
// commitment, we'll return an error now.
if len(htlcSigs) != i {
return nil, fmt.Errorf("number of htlc sig mismatch. "+
"Expected %v sigs, got %v", i, len(htlcSigs))
}
return verifyJobs, nil
}

View File

@ -1601,6 +1601,35 @@ func TestHTLCSigNumber(t *testing.T) {
t.Fatalf("Bob failed receiving commitment: %v", err)
}
// ====================================================================
// Test that Bob will not validate a received commitment if Alice sends
// signatures for HTLCs below the dust limit.
// ====================================================================
aliceChannel, bobChannel, cleanUp = createChanWithHTLC(belowDust,
aboveDust)
defer cleanUp()
// Alice should produce only one signature, since one HTLC is below
// dust.
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))
}
// Add an extra signature.
aliceHtlcSigs = append(aliceHtlcSigs, aliceHtlcSigs[0])
// Bob should reject these signatures since they don't match the number
// of HTLCs above dust.
err = bobChannel.ReceiveNewCommitment(aliceSig, aliceHtlcSigs)
if err == nil {
t.Fatalf("Expected Bob to reject signatures")
}
}
// TestChannelBalanceDustLimit tests the condition when the remaining balance