htlcswitch: ensure we don't dispatch local HTLC's to link that aren't eligible to forward

This commit fixes an existing bug wherein we would incorrectly attempt
to forward and HTLC to a link that wasn’t yet eligible for forwarding.
This would occur when we’ve added a link to the switch, but haven’t yet
received a FundingLocked message for the channel. As a result, the
channel won’t have the next revocation point available. A logic error
prior to this commit would skip tallying the largest bandwidth rather
than skipping examining the link all together.

Fixes #464.
This commit is contained in:
Olaoluwa Osuntokun 2017-12-07 19:03:22 -08:00
parent ce6dee6ee4
commit 8a7085f8b4
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

View File

@ -365,9 +365,14 @@ func (s *Switch) handleLocalDispatch(payment *pendingPayment, packet *htlcPacket
largestBandwidth lnwire.MilliSatoshi
)
for _, link := range links {
// We'll skip any links that aren't yet eligible for
// forwarding.
if !link.EligibleToForward() {
continue
}
bandwidth := link.Bandwidth()
if link.EligibleToForward() &&
bandwidth > largestBandwidth {
if bandwidth > largestBandwidth {
largestBandwidth = bandwidth
}
@ -490,8 +495,13 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
// bandwidth.
var destination ChannelLink
for _, link := range interfaceLinks {
if link.EligibleToForward() &&
link.Bandwidth() >= htlc.Amount {
// We'll skip any links that aren't yet eligible for
// forwarding.
if !link.EligibleToForward() {
continue
}
if link.Bandwidth() >= htlc.Amount {
destination = link
break