lnwallet: ensure MayAddOutgoingHtlc doesn't add zero-value HTLCs

In this commit, in order to allow the test added in the prior commit to
pass, we'll increment the mockHTLCAmt value by 1 to ensure we never
attempt to add a zero value HTLC.

Fixes #5468
This commit is contained in:
Olaoluwa Osuntokun 2021-07-06 16:37:20 -07:00
parent 49b18b4d35
commit af43a863cb
No known key found for this signature in database
GPG Key ID: 3BBD59E99B280306

@ -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{},
) )