lnd: initialize an autopilot.Agent instance if set in the config file

This commit is contained in:
Olaoluwa Osuntokun 2017-08-10 21:40:15 -07:00
parent ba5ed9e8d2
commit ece1d09a9f
No known key found for this signature in database
GPG Key ID: 3D0A94DB79743DF5

23
lnd.go

@ -19,6 +19,7 @@ import (
flags "github.com/btcsuite/go-flags" flags "github.com/btcsuite/go-flags"
proxy "github.com/grpc-ecosystem/grpc-gateway/runtime" proxy "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/lightningnetwork/lnd/autopilot"
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet"
@ -286,11 +287,33 @@ func lndMain() error {
return err return err
} }
// Now that the server has started, if the autopilot mode is currently
// active, then we'll initialize a fresh instance of it and start it.
var pilot *autopilot.Agent
if cfg.Autopilot.Active {
pilot, err := initAutoPilot(server, cfg.Autopilot)
if err != nil {
ltndLog.Errorf("unable to create autopilot agent: %v",
err)
return err
}
if err := pilot.Start(); err != nil {
ltndLog.Errorf("unable to start autopilot agent: %v",
err)
return err
}
}
addInterruptHandler(func() { addInterruptHandler(func() {
ltndLog.Infof("Gracefully shutting down the server...") ltndLog.Infof("Gracefully shutting down the server...")
rpcServer.Stop() rpcServer.Stop()
fundingMgr.Stop() fundingMgr.Stop()
server.Stop() server.Stop()
if pilot != nil {
pilot.Stop()
}
server.WaitForShutdown() server.WaitForShutdown()
}) })