Skip to content

Commit

Permalink
(squash commit) launch handleLocalResponse in GM
Browse files Browse the repository at this point in the history
  • Loading branch information
starius committed Nov 21, 2024
1 parent 3e60524 commit deeacc6
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions htlcswitch/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,6 @@ type Switch struct {
// This will be retrieved by the registered links atomically.
bestHeight uint32

// TODO(yy): remove handleLocalResponseWG, once handleLocalResponse runs
// without a goroutine. Currently we can't run handleLocalResponse in
// gm, since if gm is stopping, the goroutine won't start and it is
// unclear if it safe to skip handleLocalResponse.
handleLocalResponseWG sync.WaitGroup

// gm starts and stops tasks in goroutines and waits for them.
gm *fn.GoroutineManager

Expand Down Expand Up @@ -957,8 +951,6 @@ func (s *Switch) getLocalLink(pkt *htlcPacket, htlc *lnwire.UpdateAddHTLC) (
//
// NOTE: This method MUST be spawned as a goroutine.
func (s *Switch) handleLocalResponse(pkt *htlcPacket) {
defer s.handleLocalResponseWG.Done()

attemptID := pkt.incomingHTLCID

// The error reason will be unencypted in case this a local
Expand Down Expand Up @@ -2025,9 +2017,6 @@ func (s *Switch) Stop() error {
// Ask running goroutines to stop and wait for them.
s.gm.Stop()

// TODO(yy): remove this, when s.handleLocalResponseWG is removed.
s.handleLocalResponseWG.Wait()

// Wait until all active goroutines have finished exiting before
// stopping the mailboxes, otherwise the mailbox map could still be
// accessed and modified.
Expand Down Expand Up @@ -3054,8 +3043,12 @@ func (s *Switch) handlePacketSettle(packet *htlcPacket) error {
// NOTE: `closeCircuit` modifies the state of `packet`.
if localHTLC {
// TODO(yy): remove the goroutine and send back the error here.
s.handleLocalResponseWG.Add(1)
go s.handleLocalResponse(packet)
err = s.gm.Go(func(ctx context.Context) {
s.handleLocalResponse(packet)
})
if err != nil {
return err
}

// If this is a locally initiated HTLC, there's no need to
// forward it so we exit.
Expand Down Expand Up @@ -3110,8 +3103,12 @@ func (s *Switch) handlePacketFail(packet *htlcPacket,
// NOTE: `closeCircuit` modifies the state of `packet`.
if packet.incomingChanID == hop.Source {
// TODO(yy): remove the goroutine and send back the error here.
s.handleLocalResponseWG.Add(1)
go s.handleLocalResponse(packet)
err = s.gm.Go(func(ctx context.Context) {
s.handleLocalResponse(packet)
})
if err != nil {
return err
}

// If this is a locally initiated HTLC, there's no need to
// forward it so we exit.
Expand Down

0 comments on commit deeacc6

Please sign in to comment.