Merge pull request #5478 from Roasbeef/fix-may-add-htlc
lnwallet: fix payment regression introduced by MayAddOutgoingHtlc
This commit is contained in:
commit
9c9f821ded
@ -4940,13 +4940,22 @@ func (lc *LightningChannel) MayAddOutgoingHtlc() error {
|
|||||||
lc.Lock()
|
lc.Lock()
|
||||||
defer lc.Unlock()
|
defer lc.Unlock()
|
||||||
|
|
||||||
|
// As this is a mock HTLC, we'll attempt to add the smallest possible
|
||||||
|
// HTLC permitted in the channel. However certain implementations may
|
||||||
|
// set this value to zero, so we'll catch that and increment things so
|
||||||
|
// we always use a non-zero value.
|
||||||
|
mockHtlcAmt := lc.channelState.LocalChanCfg.MinHTLC
|
||||||
|
if mockHtlcAmt == 0 {
|
||||||
|
mockHtlcAmt++
|
||||||
|
}
|
||||||
|
|
||||||
// Create a "mock" outgoing htlc, using the smallest amount we can add
|
// Create a "mock" outgoing htlc, using the smallest amount we can add
|
||||||
// to the commitment so that we validate commitment slots rather than
|
// to the commitment so that we validate commitment slots rather than
|
||||||
// available balance, since our actual htlc amount is unknown at this
|
// available balance, since our actual htlc amount is unknown at this
|
||||||
// stage.
|
// stage.
|
||||||
pd := lc.htlcAddDescriptor(
|
pd := lc.htlcAddDescriptor(
|
||||||
&lnwire.UpdateAddHTLC{
|
&lnwire.UpdateAddHTLC{
|
||||||
Amount: lc.channelState.LocalChanCfg.MinHTLC,
|
Amount: mockHtlcAmt,
|
||||||
},
|
},
|
||||||
&channeldb.CircuitKey{},
|
&channeldb.CircuitKey{},
|
||||||
)
|
)
|
||||||
|
@ -9648,3 +9648,24 @@ func TestChannelSignedAckRegression(t *testing.T) {
|
|||||||
err = aliceChannel.ReceiveNewCommitment(bobSig, bobHtlcSigs)
|
err = aliceChannel.ReceiveNewCommitment(bobSig, bobHtlcSigs)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestMayAddOutgoingHtlcZeroValue tests that if the minHTLC value of the
|
||||||
|
// channel is zero, then the MayAddOutgoingHtlc doesn't exit early due to
|
||||||
|
// running into a zero valued HTLC.
|
||||||
|
func TestMayAddOutgoingHtlcZeroValue(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
// The default channel created as a part of the test fixture already
|
||||||
|
// has a MinHTLC value of zero, so we don't need to do anything here
|
||||||
|
// other than create it.
|
||||||
|
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
|
||||||
|
channeldb.SingleFunderTweaklessBit,
|
||||||
|
)
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer cleanUp()
|
||||||
|
|
||||||
|
// The channels start out with a 50/50 balance, so both sides should be
|
||||||
|
// able to add an outgoing HTLC.
|
||||||
|
require.NoError(t, aliceChannel.MayAddOutgoingHtlc())
|
||||||
|
require.NoError(t, bobChannel.MayAddOutgoingHtlc())
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user