lnwallet/channel: correct dust calculation on incoming HTLC

Similar to the previous commit, we fix a bug resulting in the wrong
commit weight being calculated when an HTLC just above the remote's
duslimit was added from the remote. This was a result of using the
successFee instead of the timeoutFee when checking whether it was dust,
making us consider it dust when it shouldn't have been.
This commit is contained in:
Johan T. Halseth 2020-11-13 11:48:45 +01:00
parent e0b133297d
commit 953443e10c
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
2 changed files with 28 additions and 1 deletions

@ -4031,7 +4031,7 @@ func (lc *LightningChannel) computeView(view *htlcView, remoteChain bool,
}
for _, htlc := range filteredHTLCView.theirUpdates {
if htlcIsDust(
lc.channelState.ChanType, !remoteChain, !remoteChain,
lc.channelState.ChanType, true, !remoteChain,
feePerKw, htlc.Amount.ToSatoshis(), dustLimit,
) {
continue

@ -5347,6 +5347,9 @@ func TestChanCommitWeightDustHtlcs(t *testing.T) {
}
defer cleanUp()
aliceDustlimit := lnwire.NewMSatFromSatoshis(
aliceChannel.channelState.LocalChanCfg.DustLimit,
)
bobDustlimit := lnwire.NewMSatFromSatoshis(
bobChannel.channelState.LocalChanCfg.DustLimit,
)
@ -5354,6 +5357,9 @@ func TestChanCommitWeightDustHtlcs(t *testing.T) {
feeRate := chainfee.SatPerKWeight(
aliceChannel.channelState.LocalCommitment.FeePerKw,
)
htlcTimeoutFee := lnwire.NewMSatFromSatoshis(
HtlcTimeoutFee(aliceChannel.channelState.ChanType, feeRate),
)
htlcSuccessFee := lnwire.NewMSatFromSatoshis(
HtlcSuccessFee(aliceChannel.channelState.ChanType, feeRate),
)
@ -5436,6 +5442,27 @@ func TestChanCommitWeightDustHtlcs(t *testing.T) {
// Settle the HTLC, bringing commitment weight back to base.
settleHtlc(preimg)
// Now we do a similar check from Bob's POV. Start with getting his
// current view of Alice's commitment weight.
weight1 = remoteCommitWeight(bobChannel)
// We'll add an HTLC from Alice to Bob, that is just above dust on
// Alice's commitment. Now we'll use the timeout fee.
aliceDustHtlc := aliceDustlimit + htlcTimeoutFee
preimg = addHtlc(aliceDustHtlc)
// Get the current remote commitment weight from Bob's POV, and ensure
// it is now heavier, since Alice added a non-dust HTLC.
weight2 = remoteCommitWeight(bobChannel)
require.Greater(t, weight2, weight1)
// Ensure the current remote commit has the expected commitfee.
calcFee = feeRate.FeeForWeight(weight2)
remoteCommitFee = bobChannel.channelState.RemoteCommitment.CommitFee
require.Equal(t, calcFee, remoteCommitFee)
settleHtlc(preimg)
}
// TestSignCommitmentFailNotLockedIn tests that a channel will not attempt to