diff --git a/chainregistry.go b/chainregistry.go index 66f7b3ce..6b864652 100644 --- a/chainregistry.go +++ b/chainregistry.go @@ -2,6 +2,7 @@ package lnd import ( "encoding/hex" + "errors" "fmt" "io/ioutil" "net" @@ -249,16 +250,15 @@ func newChainControlFromConfig(cfg *Config, localDB, remoteDB *channeldb.DB, return nil, err } - // If the user provided an API for fee estimation, activate it now. + // Map the deprecated neutrino feeurl flag to the general fee + // url. if cfg.NeutrinoMode.FeeURL != "" { - ltndLog.Infof("Using API fee estimator!") + if cfg.FeeURL != "" { + return nil, errors.New("feeurl and " + + "neutrino.feeurl are mutually exclusive") + } - cc.feeEstimator = chainfee.NewWebAPIEstimator( - chainfee.SparseConfFeeSource{ - URL: cfg.NeutrinoMode.FeeURL, - }, - false, - ) + cfg.FeeURL = cfg.NeutrinoMode.FeeURL } walletConfig.ChainSource = chain.NewNeutrinoClient( @@ -485,6 +485,23 @@ func newChainControlFromConfig(cfg *Config, localDB, remoteDB *channeldb.DB, homeChainConfig.Node) } + // Override default fee estimator if an external service is specified. + if cfg.FeeURL != "" { + // Do not cache fees on regtest to make it easier to execute + // manual or automated test cases. + cacheFees := !cfg.Bitcoin.RegTest + + ltndLog.Infof("Using external fee estimator %v: cached=%v", + cfg.FeeURL, cacheFees) + + cc.feeEstimator = chainfee.NewWebAPIEstimator( + chainfee.SparseConfFeeSource{ + URL: cfg.FeeURL, + }, + !cacheFees, + ) + } + // Start fee estimator. if err := cc.feeEstimator.Start(); err != nil { return nil, err diff --git a/config.go b/config.go index 7df5adcd..0a30773f 100644 --- a/config.go +++ b/config.go @@ -210,6 +210,8 @@ type Config struct { MaxPendingChannels int `long:"maxpendingchannels" description:"The maximum number of incoming pending channels permitted per peer."` BackupFilePath string `long:"backupfilepath" description:"The target location of the channel backup file"` + FeeURL string `long:"feeurl" description:"Optional URL for external fee estimation. If no URL is specified, the method for fee estimation will depend on the chosen backend and network."` + Bitcoin *lncfg.Chain `group:"Bitcoin" namespace:"bitcoin"` BtcdMode *lncfg.Btcd `group:"btcd" namespace:"btcd"` BitcoindMode *lncfg.Bitcoind `group:"bitcoind" namespace:"bitcoind"` diff --git a/lncfg/neutrino.go b/lncfg/neutrino.go index b6f892bf..db4c3d4d 100644 --- a/lncfg/neutrino.go +++ b/lncfg/neutrino.go @@ -10,6 +10,6 @@ type Neutrino struct { MaxPeers int `long:"maxpeers" description:"Max number of inbound and outbound peers"` BanDuration time.Duration `long:"banduration" description:"How long to ban misbehaving peers. Valid time units are {s, m, h}. Minimum 1 second"` BanThreshold uint32 `long:"banthreshold" description:"Maximum allowed ban score before disconnecting and banning misbehaving peers."` - FeeURL string `long:"feeurl" description:"Optional URL for fee estimation. If a URL is not specified, static fees will be used for estimation."` + FeeURL string `long:"feeurl" description:"DEPRECATED: Optional URL for fee estimation. If a URL is not specified, static fees will be used for estimation."` AssertFilterHeader string `long:"assertfilterheader" description:"Optional filter header in height:hash format to assert the state of neutrino's filter header chain on startup. If the assertion does not hold, then the filter header chain will be re-synced from the genesis block."` }