htlcswitch: refactor handleLocalDispatch
Move creation of the goroutine as a preparation for sync local routing
This commit is contained in:
parent
b6915d9fbf
commit
341308327e
@ -774,23 +774,17 @@ func (s *Switch) routeAsync(packet *htlcPacket, errChan chan error,
|
||||
}
|
||||
}
|
||||
|
||||
// handleLocalDispatch is used at the start/end of the htlc update life cycle.
|
||||
// At the start (1) it is used to send the htlc to the channel link without
|
||||
// creation of circuit. At the end (2) it is used to notify the user about the
|
||||
// result of his payment is it was successful or not.
|
||||
//
|
||||
// Alice Bob Carol
|
||||
// o --add----> o ---add----> o
|
||||
// (1)
|
||||
//
|
||||
// (2)
|
||||
// o <-settle-- o <--settle-- o
|
||||
// Alice Bob Carol
|
||||
//
|
||||
func (s *Switch) handleLocalDispatch(pkt *htlcPacket) error {
|
||||
// handleLocalUpdateAddDispatch is used at the start of the htlc update life
|
||||
// cycle. It is used to send the htlc to the channel link without creation of
|
||||
// circuit.
|
||||
func (s *Switch) handleLocalUpdateAddDispatch(pkt *htlcPacket) error {
|
||||
htlc, ok := pkt.htlc.(*lnwire.UpdateAddHTLC)
|
||||
if !ok {
|
||||
return errors.New("not an UpdateAdd packet")
|
||||
}
|
||||
|
||||
// User have created the htlc update therefore we should find the
|
||||
// appropriate channel link and send the payment over this link.
|
||||
if htlc, ok := pkt.htlc.(*lnwire.UpdateAddHTLC); ok {
|
||||
link, err := s.handleLocalAddHTLC(pkt, htlc)
|
||||
if err != nil {
|
||||
// Notify the htlc notifier of a link failure on our
|
||||
@ -811,12 +805,6 @@ func (s *Switch) handleLocalDispatch(pkt *htlcPacket) error {
|
||||
}
|
||||
|
||||
return link.HandleSwitchPacket(pkt)
|
||||
}
|
||||
|
||||
s.wg.Add(1)
|
||||
go s.handleLocalResponse(pkt)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// handleLocalAddHTLC handles the addition of a htlc for a send that
|
||||
@ -1065,7 +1053,7 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
|
||||
if packet.incomingChanID == hop.Source {
|
||||
// A blank incomingChanID indicates that this is
|
||||
// a pending user-initiated payment.
|
||||
return s.handleLocalDispatch(packet)
|
||||
return s.handleLocalUpdateAddDispatch(packet)
|
||||
}
|
||||
|
||||
// Before we attempt to find a non-strict forwarding path for
|
||||
@ -1268,7 +1256,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 {
|
||||
return s.handleLocalDispatch(packet)
|
||||
s.wg.Add(1)
|
||||
go s.handleLocalResponse(packet)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Check to see that the source link is online before removing
|
||||
|
Loading…
Reference in New Issue
Block a user