config+pilot: add flag to specify min confs for autopilot agent

This commit is contained in:
Wilmer Paulino 2018-08-09 19:03:08 -07:00
parent ae3e66dccc
commit 7724d86801
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F
2 changed files with 15 additions and 5 deletions

@ -146,6 +146,7 @@ type autoPilotConfig struct {
MinChannelSize int64 `long:"minchansize" description:"The smallest channel that the autopilot agent should create"` MinChannelSize int64 `long:"minchansize" description:"The smallest channel that the autopilot agent should create"`
MaxChannelSize int64 `long:"maxchansize" description:"The largest channel that the autopilot agent should create"` MaxChannelSize int64 `long:"maxchansize" description:"The largest channel that the autopilot agent should create"`
Private bool `long:"private" description:"Whether the channels created by the autopilot agent should be private or not. Private channels won't be announced to the network."` Private bool `long:"private" description:"Whether the channels created by the autopilot agent should be private or not. Private channels won't be announced to the network."`
MinConfs int32 `long:"minconfs" description:"The minimum number of confirmations each of your inputs in funding transactions created by the autopilot agent must have."`
} }
type torConfig struct { type torConfig struct {
@ -424,6 +425,12 @@ func loadConfig() (*config, error) {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
return nil, err return nil, err
} }
if cfg.Autopilot.MinConfs < 0 {
str := "%s: autopilot.minconfs must be non-negative"
err := fmt.Errorf(str, funcName)
fmt.Fprintln(os.Stderr, err)
return nil, err
}
// Ensure that the specified values for the min and max channel size // Ensure that the specified values for the min and max channel size
// don't are within the bounds of the normal chan size constraints. // don't are within the bounds of the normal chan size constraints.

@ -17,8 +17,9 @@ import (
// chanController is an implementation of the autopilot.ChannelController // chanController is an implementation of the autopilot.ChannelController
// interface that's backed by a running lnd instance. // interface that's backed by a running lnd instance.
type chanController struct { type chanController struct {
server *server server *server
private bool private bool
minConfs int32
} }
// OpenChannel opens a channel to a target peer, with a capacity of the // OpenChannel opens a channel to a target peer, with a capacity of the
@ -48,6 +49,7 @@ func (c *chanController) OpenChannel(target *btcec.PublicKey,
fundingFeePerKw: feePerKw, fundingFeePerKw: feePerKw,
private: c.private, private: c.private,
remoteCsvDelay: 0, remoteCsvDelay: 0,
minConfs: c.minConfs,
} }
updateStream, errChan := c.server.OpenChannel(req) updateStream, errChan := c.server.OpenChannel(req)
@ -110,11 +112,12 @@ func initAutoPilot(svr *server, cfg *autoPilotConfig) (*autopilot.Agent, error)
Self: self, Self: self,
Heuristic: prefAttachment, Heuristic: prefAttachment,
ChanController: &chanController{ ChanController: &chanController{
server: svr, server: svr,
private: cfg.Private, private: cfg.Private,
minConfs: cfg.MinConfs,
}, },
WalletBalance: func() (btcutil.Amount, error) { WalletBalance: func() (btcutil.Amount, error) {
return svr.cc.wallet.ConfirmedBalance(1) return svr.cc.wallet.ConfirmedBalance(cfg.MinConfs)
}, },
Graph: autopilot.ChannelGraphFromDatabase(svr.chanDB.ChannelGraph()), Graph: autopilot.ChannelGraphFromDatabase(svr.chanDB.ChannelGraph()),
MaxPendingOpens: 10, MaxPendingOpens: 10,