diff --git a/autopilot/agent.go b/autopilot/agent.go index 95e95c55f..1b70580a3 100644 --- a/autopilot/agent.go +++ b/autopilot/agent.go @@ -202,10 +202,10 @@ func New(cfg Config, initialState []LocalChannel) (*Agent, error) { // Start starts the agent along with any goroutines it needs to perform its // normal duties. -func (a *Agent) Start(ctx context.Context) error { +func (a *Agent) Start() error { var err error a.started.Do(func() { - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := context.WithCancel(context.Background()) a.cancel = fn.Some(cancel) err = a.start(ctx) diff --git a/autopilot/agent_test.go b/autopilot/agent_test.go index 47305a2eb..82c21a2ff 100644 --- a/autopilot/agent_test.go +++ b/autopilot/agent_test.go @@ -221,7 +221,7 @@ func setup(t *testing.T, initialChans []LocalChannel) *testContext { // With the autopilot agent and all its dependencies we'll start the // primary controller goroutine. - if err := agent.Start(context.Background()); err != nil { + if err := agent.Start(); err != nil { t.Fatalf("unable to start agent: %v", err) } diff --git a/autopilot/manager.go b/autopilot/manager.go index c0ca40b55..600a1055b 100644 --- a/autopilot/manager.go +++ b/autopilot/manager.go @@ -7,7 +7,6 @@ import ( "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/wire" - "github.com/lightningnetwork/lnd/fn/v2" graphdb "github.com/lightningnetwork/lnd/graph/db" "github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwire" @@ -55,9 +54,8 @@ type Manager struct { // disabled. pilot *Agent - quit chan struct{} - wg sync.WaitGroup - cancel fn.Option[context.CancelFunc] + quit chan struct{} + wg sync.WaitGroup sync.Mutex } @@ -83,7 +81,6 @@ func (m *Manager) Stop() error { log.Errorf("Unable to stop pilot: %v", err) } - m.cancel.WhenSome(func(fn context.CancelFunc) { fn() }) close(m.quit) m.wg.Wait() }) @@ -100,7 +97,7 @@ func (m *Manager) IsActive() bool { // StartAgent creates and starts an autopilot agent from the Manager's // config. -func (m *Manager) StartAgent(ctx context.Context) error { +func (m *Manager) StartAgent() error { m.Lock() defer m.Unlock() @@ -108,8 +105,6 @@ func (m *Manager) StartAgent(ctx context.Context) error { if m.pilot != nil { return nil } - ctx, cancel := context.WithCancel(ctx) - m.cancel = fn.Some(cancel) // Next, we'll fetch the current state of open channels from the // database to use as initial state for the auto-pilot agent. @@ -125,7 +120,7 @@ func (m *Manager) StartAgent(ctx context.Context) error { return err } - if err := pilot.Start(ctx); err != nil { + if err := pilot.Start(); err != nil { return err } @@ -169,8 +164,6 @@ func (m *Manager) StartAgent(ctx context.Context) error { return case <-m.quit: return - case <-ctx.Done(): - return } } @@ -241,8 +234,6 @@ func (m *Manager) StartAgent(ctx context.Context) error { return case <-m.quit: return - case <-ctx.Done(): - return } } }() diff --git a/lnd.go b/lnd.go index 41bd3ca4b..3afa8c2fb 100644 --- a/lnd.go +++ b/lnd.go @@ -788,7 +788,7 @@ func Main(cfg *Config, lisCfg ListenerCfg, implCfg *ImplementationCfg, // active, then we'll start the autopilot agent immediately. It will be // stopped together with the autopilot service. if cfg.Autopilot.Active { - if err := atplManager.StartAgent(ctx); err != nil { + if err := atplManager.StartAgent(); err != nil { return mkErr("unable to start autopilot agent", err) } } diff --git a/lnrpc/autopilotrpc/autopilot_server.go b/lnrpc/autopilotrpc/autopilot_server.go index 67e6c283a..e5952949e 100644 --- a/lnrpc/autopilotrpc/autopilot_server.go +++ b/lnrpc/autopilotrpc/autopilot_server.go @@ -198,14 +198,14 @@ func (s *Server) Status(ctx context.Context, // ModifyStatus activates the current autopilot agent, if active. // // NOTE: Part of the AutopilotServer interface. -func (s *Server) ModifyStatus(ctx context.Context, +func (s *Server) ModifyStatus(_ context.Context, in *ModifyStatusRequest) (*ModifyStatusResponse, error) { log.Debugf("Setting agent enabled=%v", in.Enable) var err error if in.Enable { - err = s.manager.StartAgent(ctx) + err = s.manager.StartAgent() } else { err = s.manager.StopAgent() }