htlcswitch: fix returned failure for insufficient balance

In the scenario where the requested channel does not have enough balance
and another channel towards the same node generates a different failure,
we erroneously returned UnknownNextPeer instead of the expected
TemporaryChannelFailure.

This commit rewrites the non-strict forwarding logic in the switch to
return the proper failure message. Part of this is moving the link
balance check inside the link.
This commit is contained in:
Joost Jager committed 2019-10-23 09:57:34 +02:00
1 parent e1b7cfe2e5
commit 200be87212
4 files changed
+48 -71

No files matched your search

+9
View File
@@ -2341,6 +2341,15 @@ func (l *channelLink) canSendHtlc(policy ForwardingPolicy,
return &lnwire.FailExpiryTooFar{}
}
// Check to see if there is enough balance in this channel.
if amt > l.Bandwidth() {
return l.createFailureWithUpdate(
func(upd *lnwire.ChannelUpdate) lnwire.FailureMessage {
return lnwire.NewTemporaryChannelFailure(upd)
},
)
}
return nil
}