diff --git a/go.mod b/go.mod index 9b1a502052..47c6c14292 100644 --- a/go.mod +++ b/go.mod @@ -207,6 +207,8 @@ replace github.com/gogo/protobuf => github.com/gogo/protobuf v1.3.2 // allows us to specify that as an option. replace google.golang.org/protobuf => github.com/lightninglabs/protobuf-go-hex-display v1.30.0-hex-display +replace github.com/lightningnetwork/lnd/fn/v2 => github.com/starius/lnd/fn/v2 v2.0.7-optcg + // If you change this please also update docs/INSTALL.md and GO_VERSION in // Makefile (then run `make lint` to see where else it needs to be updated as // well). diff --git a/go.sum b/go.sum index 2a2ffeb04c..a8fa74252f 100644 --- a/go.sum +++ b/go.sum @@ -456,8 +456,6 @@ github.com/lightningnetwork/lnd/cert v1.2.2 h1:71YK6hogeJtxSxw2teq3eGeuy4rHGKcFf github.com/lightningnetwork/lnd/cert v1.2.2/go.mod h1:jQmFn/Ez4zhDgq2hnYSw8r35bqGVxViXhX6Cd7HXM6U= github.com/lightningnetwork/lnd/clock v1.1.1 h1:OfR3/zcJd2RhH0RU+zX/77c0ZiOnIMsDIBjgjWdZgA0= github.com/lightningnetwork/lnd/clock v1.1.1/go.mod h1:mGnAhPyjYZQJmebS7aevElXKTFDuO+uNFFfMXK1W8xQ= -github.com/lightningnetwork/lnd/fn/v2 v2.0.4 h1:DiC/AEa7DhnY4qOEQBISu1cp+1+51LjbVDzNLVBwNjI= -github.com/lightningnetwork/lnd/fn/v2 v2.0.4/go.mod h1:TOzwrhjB/Azw1V7aa8t21ufcQmdsQOQMDtxVOQWNl8s= github.com/lightningnetwork/lnd/healthcheck v1.2.6 h1:1sWhqr93GdkWy4+6U7JxBfcyZIE78MhIHTJZfPx7qqI= github.com/lightningnetwork/lnd/healthcheck v1.2.6/go.mod h1:Mu02um4CWY/zdTOvFje7WJgJcHyX2zq/FG3MhOAiGaQ= github.com/lightningnetwork/lnd/kvdb v1.4.12 h1:Y0WY5Tbjyjn6eCYh068qkWur5oFtioJlfxc8w5SlJeQ= @@ -588,6 +586,8 @@ github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/starius/lnd/fn/v2 v2.0.7-optcg h1:20scsrug8GKihMQ0UbCsTlRuo2rbKjXShOqFDb9z6p8= +github.com/starius/lnd/fn/v2 v2.0.7-optcg/go.mod h1:TOzwrhjB/Azw1V7aa8t21ufcQmdsQOQMDtxVOQWNl8s= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 6e67e87def..508a73522e 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -2,6 +2,7 @@ package htlcswitch import ( "bytes" + "context" crand "crypto/rand" "crypto/sha256" "errors" @@ -596,7 +597,7 @@ func (l *channelLink) Start() error { l.updateFeeTimer = time.NewTimer(l.randomFeeUpdateTimeout()) - l.Wg.Add(1) + l.WgAdd(1) go l.htlcManager() return nil @@ -636,8 +637,8 @@ func (l *channelLink) Stop() { l.hodlQueue.Stop() } - close(l.Quit) - l.Wg.Wait() + l.Quit() + l.WgWait() // Now that the htlcManager has completely exited, reset the packet // courier. This allows the mailbox to revaluate any lingering Adds that @@ -662,7 +663,7 @@ func (l *channelLink) Stop() { // WaitForShutdown blocks until the link finishes shutting down, which includes // termination of all dependent goroutines. func (l *channelLink) WaitForShutdown() { - l.Wg.Wait() + l.WgWait() } // EligibleToForward returns a bool indicating if the channel is able to @@ -740,7 +741,7 @@ func (l *channelLink) IsFlushing(linkDirection LinkDirection) bool { func (l *channelLink) OnFlushedOnce(hook func()) { select { case l.flushHooks.newTransients <- hook: - case <-l.Quit: + case <-l.Done(): } } @@ -759,7 +760,7 @@ func (l *channelLink) OnCommitOnce(direction LinkDirection, hook func()) { select { case queue <- hook: - case <-l.Quit: + case <-l.Done(): } } @@ -777,7 +778,7 @@ func (l *channelLink) InitStfu() <-chan fn.Result[lntypes.ChannelParty] { select { case l.quiescenceReqs <- req: - case <-l.Quit: + case <-l.Done(): req.Resolve(fn.Err[lntypes.ChannelParty](ErrLinkShuttingDown)) } @@ -989,7 +990,7 @@ func (l *channelLink) syncChanStates() error { // We've just received a ChanSync message from the remote // party, so we'll process the message in order to determine // if we need to re-transmit any messages to the remote party. - ctx, cancel := l.WithCtxQuitNoTimeout() + ctx, cancel := l.Create(context.Background()) defer cancel() msgsToReSend, openedCircuits, closedCircuits, err = l.channel.ProcessChanSyncMsg(ctx, remoteChanSyncMsg) @@ -1021,7 +1022,7 @@ func (l *channelLink) syncChanStates() error { l.cfg.Peer.SendMessage(false, msg) } - case <-l.Quit: + case <-l.Done(): return ErrLinkShuttingDown } @@ -1111,7 +1112,7 @@ func (l *channelLink) resolveFwdPkg(fwdPkg *channeldb.FwdPkg) error { // // NOTE: This MUST be run as a goroutine. func (l *channelLink) fwdPkgGarbager() { - defer l.Wg.Done() + defer l.WgDone() l.cfg.FwdPkgGCTicker.Resume() defer l.cfg.FwdPkgGCTicker.Stop() @@ -1128,7 +1129,7 @@ func (l *channelLink) fwdPkgGarbager() { err) continue } - case <-l.Quit: + case <-l.Done(): return } } @@ -1251,7 +1252,7 @@ func (l *channelLink) handleChanSyncErr(err error) { func (l *channelLink) htlcManager() { defer func() { l.cfg.BatchTicker.Stop() - l.Wg.Done() + l.WgDone() l.log.Infof("exited") }() @@ -1345,7 +1346,7 @@ func (l *channelLink) htlcManager() { // With our link's in-memory state fully reconstructed, spawn a // goroutine to manage the reclamation of disk space occupied by // completed forwarding packages. - l.Wg.Add(1) + l.WgAdd(1) go l.fwdPkgGarbager() } @@ -1543,7 +1544,7 @@ func (l *channelLink) htlcManager() { } } - case <-l.Quit: + case <-l.Done(): return } } @@ -2418,7 +2419,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) { } select { - case <-l.Quit: + case <-l.Done(): return default: } @@ -2488,7 +2489,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) { } select { - case <-l.Quit: + case <-l.Done(): return default: } @@ -2782,7 +2783,7 @@ func (l *channelLink) updateCommitTx() error { return nil } - ctx, done := l.WithCtxQuitNoTimeout() + ctx, done := l.Create(context.Background()) defer done() newCommit, err := l.channel.SignNextCommitment(ctx) @@ -2822,7 +2823,7 @@ func (l *channelLink) updateCommitTx() error { } select { - case <-l.Quit: + case <-l.Done(): return ErrLinkShuttingDown default: } @@ -3529,7 +3530,7 @@ func (l *channelLink) handleSwitchPacket(pkt *htlcPacket) error { // NOTE: Part of the ChannelLink interface. func (l *channelLink) HandleChannelUpdate(message lnwire.Message) { select { - case <-l.Quit: + case <-l.Done(): // Return early if the link is already in the process of // quitting. It doesn't make sense to hand the message to the // mailbox here. @@ -4290,7 +4291,7 @@ func (l *channelLink) forwardBatch(replay bool, packets ...*htlcPacket) { filteredPkts = append(filteredPkts, pkt) } - err := l.cfg.ForwardPackets(l.Quit, replay, filteredPkts...) + err := l.cfg.ForwardPackets(l.Done(), replay, filteredPkts...) if err != nil { log.Errorf("Unhandled error while reforwarding htlc "+ "settle/fail over htlcswitch: %v", err) diff --git a/htlcswitch/test_utils.go b/htlcswitch/test_utils.go index 2123465884..943f8cabb5 100644 --- a/htlcswitch/test_utils.go +++ b/htlcswitch/test_utils.go @@ -1190,7 +1190,7 @@ func (h *hopNetwork) createChannelLink(server, peer *mockServer, for { select { case <-notifyUpdateChan: - case <-chanLink.Quit: + case <-chanLink.Done(): close(doneChan) return }