mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-21 22:57:10 +02:00
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:
@@ -365,9 +365,14 @@ func (s *Switch) handleLocalDispatch(payment *pendingPayment, packet *htlcPacket
|
|||||||
largestBandwidth lnwire.MilliSatoshi
|
largestBandwidth lnwire.MilliSatoshi
|
||||||
)
|
)
|
||||||
for _, link := range links {
|
for _, link := range links {
|
||||||
|
// We'll skip any links that aren't yet eligible for
|
||||||
|
// forwarding.
|
||||||
|
if !link.EligibleToForward() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
bandwidth := link.Bandwidth()
|
bandwidth := link.Bandwidth()
|
||||||
if link.EligibleToForward() &&
|
if bandwidth > largestBandwidth {
|
||||||
bandwidth > largestBandwidth {
|
|
||||||
|
|
||||||
largestBandwidth = bandwidth
|
largestBandwidth = bandwidth
|
||||||
}
|
}
|
||||||
@@ -490,8 +495,13 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
|
|||||||
// bandwidth.
|
// bandwidth.
|
||||||
var destination ChannelLink
|
var destination ChannelLink
|
||||||
for _, link := range interfaceLinks {
|
for _, link := range interfaceLinks {
|
||||||
if link.EligibleToForward() &&
|
// We'll skip any links that aren't yet eligible for
|
||||||
link.Bandwidth() >= htlc.Amount {
|
// forwarding.
|
||||||
|
if !link.EligibleToForward() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if link.Bandwidth() >= htlc.Amount {
|
||||||
|
|
||||||
destination = link
|
destination = link
|
||||||
break
|
break
|
||||||
|
Reference in New Issue
Block a user