From 9a7f24d2d3a29d76bc0b3a73c591198732d4815d Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Fri, 26 Apr 2019 15:32:29 +0200 Subject: [PATCH 1/2] autopilot: extract default fee estimate target conf into constant --- autopilot/interface.go | 5 +++++ pilot.go | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/autopilot/interface.go b/autopilot/interface.go index 1886929af..34ef75978 100644 --- a/autopilot/interface.go +++ b/autopilot/interface.go @@ -9,6 +9,11 @@ import ( "github.com/lightningnetwork/lnd/lnwire" ) +// DefaultConfTarget is the default confirmation target for autopilot channels. +// TODO(halseth): possibly make dynamic, going aggressive->lax as more channels +// are opened. +const DefaultConfTarget = 3 + // Node node is an interface which represents n abstract vertex within the // channel graph. All nodes should have at least a single edge to/from them // within the graph. diff --git a/pilot.go b/pilot.go index b8f3831ad..ad8eeab7b 100644 --- a/pilot.go +++ b/pilot.go @@ -84,7 +84,9 @@ func (c *chanController) OpenChannel(target *btcec.PublicKey, // With the connection established, we'll now establish our connection // to the target peer, waiting for the first update before we exit. - feePerKw, err := c.server.cc.feeEstimator.EstimateFeePerKW(3) + feePerKw, err := c.server.cc.feeEstimator.EstimateFeePerKW( + autopilot.DefaultConfTarget, + ) if err != nil { return err } From 187c8bc0b5c3535285e7e3de9f3c5749148a1c13 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Sat, 8 Jun 2019 17:29:33 +0200 Subject: [PATCH 2/2] config+autopilot: make conftarget configurable --- config.go | 9 +++++++++ pilot.go | 16 +++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/config.go b/config.go index 090776205..5193f48e2 100644 --- a/config.go +++ b/config.go @@ -21,6 +21,7 @@ import ( "github.com/btcsuite/btcutil" flags "github.com/jessevdk/go-flags" + "github.com/lightningnetwork/lnd/autopilot" "github.com/lightningnetwork/lnd/build" "github.com/lightningnetwork/lnd/chanbackup" "github.com/lightningnetwork/lnd/channeldb" @@ -205,6 +206,7 @@ type autoPilotConfig struct { 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."` MinConfs int32 `long:"minconfs" description:"The minimum number of confirmations each of your inputs in funding transactions created by the autopilot agent must have."` + ConfTarget uint32 `long:"conftarget" description:"The confirmation target (in blocks) for channels opened by autopilot."` } type torConfig struct { @@ -379,6 +381,7 @@ func loadConfig() (*config, error) { Allocation: 0.6, MinChannelSize: int64(minChanFundingSize), MaxChannelSize: int64(MaxFundingAmount), + ConfTarget: autopilot.DefaultConfTarget, Heuristic: map[string]float64{ "preferential": 1.0, }, @@ -536,6 +539,12 @@ func loadConfig() (*config, error) { fmt.Fprintln(os.Stderr, err) return nil, err } + if cfg.Autopilot.ConfTarget < 1 { + str := "%s: autopilot.conftarget must be positive" + 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 // don't are within the bounds of the normal chan size constraints. diff --git a/pilot.go b/pilot.go index ad8eeab7b..5748cf974 100644 --- a/pilot.go +++ b/pilot.go @@ -71,9 +71,10 @@ func validateAtplCfg(cfg *autoPilotConfig) ([]*autopilot.WeightedHeuristic, // chanController is an implementation of the autopilot.ChannelController // interface that's backed by a running lnd instance. type chanController struct { - server *server - private bool - minConfs int32 + server *server + private bool + minConfs int32 + confTarget uint32 } // OpenChannel opens a channel to a target peer, with a capacity of the @@ -85,7 +86,7 @@ func (c *chanController) OpenChannel(target *btcec.PublicKey, // With the connection established, we'll now establish our connection // to the target peer, waiting for the first update before we exit. feePerKw, err := c.server.cc.feeEstimator.EstimateFeePerKW( - autopilot.DefaultConfTarget, + c.confTarget, ) if err != nil { return err @@ -169,9 +170,10 @@ func initAutoPilot(svr *server, cfg *autoPilotConfig) (*autopilot.ManagerCfg, er Self: self, Heuristic: weightedAttachment, ChanController: &chanController{ - server: svr, - private: cfg.Private, - minConfs: cfg.MinConfs, + server: svr, + private: cfg.Private, + minConfs: cfg.MinConfs, + confTarget: cfg.ConfTarget, }, WalletBalance: func() (btcutil.Amount, error) { return svr.cc.wallet.ConfirmedBalance(cfg.MinConfs)