mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-11 14:48:14 +01:00
autopilot: revert passing ctx to Start methods
This commit is contained in:
@@ -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
|
// Start starts the agent along with any goroutines it needs to perform its
|
||||||
// normal duties.
|
// normal duties.
|
||||||
func (a *Agent) Start(ctx context.Context) error {
|
func (a *Agent) Start() error {
|
||||||
var err error
|
var err error
|
||||||
a.started.Do(func() {
|
a.started.Do(func() {
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
a.cancel = fn.Some(cancel)
|
a.cancel = fn.Some(cancel)
|
||||||
|
|
||||||
err = a.start(ctx)
|
err = a.start(ctx)
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ func setup(t *testing.T, initialChans []LocalChannel) *testContext {
|
|||||||
|
|
||||||
// With the autopilot agent and all its dependencies we'll start the
|
// With the autopilot agent and all its dependencies we'll start the
|
||||||
// primary controller goroutine.
|
// 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)
|
t.Fatalf("unable to start agent: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/fn/v2"
|
|
||||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
@@ -57,7 +56,6 @@ type Manager struct {
|
|||||||
|
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
cancel fn.Option[context.CancelFunc]
|
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +81,6 @@ func (m *Manager) Stop() error {
|
|||||||
log.Errorf("Unable to stop pilot: %v", err)
|
log.Errorf("Unable to stop pilot: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
m.cancel.WhenSome(func(fn context.CancelFunc) { fn() })
|
|
||||||
close(m.quit)
|
close(m.quit)
|
||||||
m.wg.Wait()
|
m.wg.Wait()
|
||||||
})
|
})
|
||||||
@@ -100,7 +97,7 @@ func (m *Manager) IsActive() bool {
|
|||||||
|
|
||||||
// StartAgent creates and starts an autopilot agent from the Manager's
|
// StartAgent creates and starts an autopilot agent from the Manager's
|
||||||
// config.
|
// config.
|
||||||
func (m *Manager) StartAgent(ctx context.Context) error {
|
func (m *Manager) StartAgent() error {
|
||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
|
|
||||||
@@ -108,8 +105,6 @@ func (m *Manager) StartAgent(ctx context.Context) error {
|
|||||||
if m.pilot != nil {
|
if m.pilot != nil {
|
||||||
return 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
|
// Next, we'll fetch the current state of open channels from the
|
||||||
// database to use as initial state for the auto-pilot agent.
|
// 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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pilot.Start(ctx); err != nil {
|
if err := pilot.Start(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,8 +164,6 @@ func (m *Manager) StartAgent(ctx context.Context) error {
|
|||||||
return
|
return
|
||||||
case <-m.quit:
|
case <-m.quit:
|
||||||
return
|
return
|
||||||
case <-ctx.Done():
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,8 +234,6 @@ func (m *Manager) StartAgent(ctx context.Context) error {
|
|||||||
return
|
return
|
||||||
case <-m.quit:
|
case <-m.quit:
|
||||||
return
|
return
|
||||||
case <-ctx.Done():
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|||||||
2
lnd.go
2
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
|
// active, then we'll start the autopilot agent immediately. It will be
|
||||||
// stopped together with the autopilot service.
|
// stopped together with the autopilot service.
|
||||||
if cfg.Autopilot.Active {
|
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)
|
return mkErr("unable to start autopilot agent", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -198,14 +198,14 @@ func (s *Server) Status(ctx context.Context,
|
|||||||
// ModifyStatus activates the current autopilot agent, if active.
|
// ModifyStatus activates the current autopilot agent, if active.
|
||||||
//
|
//
|
||||||
// NOTE: Part of the AutopilotServer interface.
|
// NOTE: Part of the AutopilotServer interface.
|
||||||
func (s *Server) ModifyStatus(ctx context.Context,
|
func (s *Server) ModifyStatus(_ context.Context,
|
||||||
in *ModifyStatusRequest) (*ModifyStatusResponse, error) {
|
in *ModifyStatusRequest) (*ModifyStatusResponse, error) {
|
||||||
|
|
||||||
log.Debugf("Setting agent enabled=%v", in.Enable)
|
log.Debugf("Setting agent enabled=%v", in.Enable)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if in.Enable {
|
if in.Enable {
|
||||||
err = s.manager.StartAgent(ctx)
|
err = s.manager.StartAgent()
|
||||||
} else {
|
} else {
|
||||||
err = s.manager.StopAgent()
|
err = s.manager.StopAgent()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user