Skip to content

Commit

Permalink
htlcswitch: fix missing saving network result for htlcs
Browse files Browse the repository at this point in the history
  • Loading branch information
yyforyongyu committed Nov 6, 2023
1 parent 41e72b1 commit 4491bed
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions htlcswitch/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -1279,16 +1279,33 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
return destination.handleSwitchPacket(packet)

case *lnwire.UpdateFailHTLC, *lnwire.UpdateFulfillHTLC:
// A blank IncomingChanID in a circuit indicates that it is a
// pending user-initiated payment.
localHTLC := packet.incomingChanID == hop.Source

// If the source of this packet has not been set, use the
// circuit map to lookup the origin.
circuit, err := s.closeCircuit(packet)
if err != nil {
return err
}

// closeCircuit returns a nil circuit when a settle packet returns an
// ErrUnknownCircuit error upon the inner call to CloseCircuit.
// closeCircuit returns a nil circuit when a settle packet
// returns an ErrUnknownCircuit error upon the inner call to
// CloseCircuit.
//
// TODO(yy): we should make sure the circuit it not nil here.
if circuit == nil {
// If this is a locally initiated HTLC, we need to
// handle the packet by storing the network result.
//
// TODO(yy): check the effect of re-storing network
// result.
if localHTLC {
s.wg.Add(1)
go s.handleLocalResponse(packet)
}

return nil
}

Expand Down Expand Up @@ -1342,7 +1359,6 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
//
// TODO(roasbeef): only do this once link actually
// fully settles?
localHTLC := packet.incomingChanID == hop.Source
if !localHTLC {
log.Infof("Forwarded HTLC(%x) of %v (fee: %v) "+
"from IncomingChanID(%v) to OutgoingChanID(%v)",
Expand All @@ -1364,9 +1380,9 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
}
}

// A blank IncomingChanID in a circuit indicates that it is a pending
// user-initiated payment.
if packet.incomingChanID == hop.Source {
// If this is a locally initiated HTLC, we need to handle the
// packet by storing the network result.
if localHTLC {
s.wg.Add(1)
go s.handleLocalResponse(packet)
return nil
Expand Down

0 comments on commit 4491bed

Please sign in to comment.