autopilot: revert passing ctx to Start methods

This commit is contained in:
Elle Mouton
2025-04-11 09:57:24 +02:00
parent c68a19c0ba
commit 95d34be0d3
5 changed files with 10 additions and 19 deletions

View File

@@ -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)

View File

@@ -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)
}

View File

@@ -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
}
}
}()

2
lnd.go
View File

@@ -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)
}
}

View File

@@ -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()
}