diff --git a/liquidity/liquidity.go b/liquidity/liquidity.go index 54f3935..511db6a 100644 --- a/liquidity/liquidity.go +++ b/liquidity/liquidity.go @@ -193,6 +193,10 @@ type Config struct { // MinimumConfirmations is the minimum number of confirmations we allow // setting for sweep target. MinimumConfirmations int32 + + // LiquidityParamsPath specifies a filepath that's used to save the + // manager's `Parameters` on disk. + LiquidityParamsPath string } // Parameters is a set of parameters provided by the user which guide diff --git a/loopd/config.go b/loopd/config.go index b3460e3..666d461 100644 --- a/loopd/config.go +++ b/loopd/config.go @@ -87,6 +87,16 @@ var ( // certificate. The value corresponds to 14 months // (14 months * 30 days * 24 hours). DefaultAutogenValidity = 14 * 30 * 24 * time.Hour + + // defaultLiquidityParamsFilename specifies the filename used to store + // the liquidity params. + defaultLiquidityParamsFilename = "liquidity_params.gob" + + // defaultLiquidityParamsPath specifies the default filepath used to + // store the liquidity params. + defaultLiquidityParamsPath = filepath.Join( + LoopDirBase, DefaultNetwork, defaultLiquidityParamsFilename, + ) ) type lndConfig struct { @@ -154,6 +164,8 @@ type Config struct { Server *loopServerConfig `group:"server" namespace:"server"` View viewParameters `command:"view" alias:"v" description:"View all swaps in the database. This command can only be executed when loopd is not running."` + + LiquidityParamsPath string `long:"liquidityparamspath" description:"Path to save the liquidity parameters specified by users."` } const ( @@ -189,6 +201,7 @@ func DefaultConfig() Config { Host: "localhost:10009", MacaroonPath: DefaultLndMacaroonPath, }, + LiquidityParamsPath: defaultLiquidityParamsPath, } } @@ -201,6 +214,9 @@ func Validate(cfg *Config) error { cfg.TLSCertPath = lncfg.CleanAndExpandPath(cfg.TLSCertPath) cfg.TLSKeyPath = lncfg.CleanAndExpandPath(cfg.TLSKeyPath) cfg.MacaroonPath = lncfg.CleanAndExpandPath(cfg.MacaroonPath) + cfg.LiquidityParamsPath = lncfg.CleanAndExpandPath( + cfg.LiquidityParamsPath, + ) // Since our loop directory overrides our log/data dir values, make sure // that they are not set when loop dir is set. We hard here rather than @@ -233,6 +249,12 @@ func Validate(cfg *Config) error { "please only set one value") } + if cfg.LiquidityParamsPath != defaultLiquidityParamsPath { + return fmt.Errorf("loopdir overwrites " + + "liquidityparamspath, please only set one " + + "value") + } + // Once we are satisfied that no other config value was set, we // replace them with our loop dir. cfg.DataDir = cfg.LoopDir @@ -262,6 +284,11 @@ func Validate(cfg *Config) error { cfg.DataDir, DefaultMacaroonFilename, ) } + if cfg.LiquidityParamsPath != defaultLiquidityParamsPath { + cfg.LiquidityParamsPath = filepath.Join( + cfg.DataDir, defaultLiquidityParamsFilename, + ) + } // If the user doesn't specify Lnd.MacaroonPath, we'll reassemble it // with the passed Network options. diff --git a/loopd/daemon.go b/loopd/daemon.go index 71f1a6b..6a7484c 100644 --- a/loopd/daemon.go +++ b/loopd/daemon.go @@ -419,7 +419,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error { d.swapClientServer = swapClientServer{ network: lndclient.Network(d.cfg.Network), impl: swapclient, - liquidityMgr: getLiquidityManager(swapclient), + liquidityMgr: getLiquidityManager(swapclient, d.cfg), lnd: &d.lnd.LndServices, swaps: make(map[lntypes.Hash]loop.SwapInfo), subscribers: make(map[int]chan<- interface{}), diff --git a/loopd/utils.go b/loopd/utils.go index ebf349a..322781d 100644 --- a/loopd/utils.go +++ b/loopd/utils.go @@ -37,7 +37,7 @@ func getClient(config *Config, lnd *lndclient.LndServices) (*loop.Client, return swapClient, cleanUp, nil } -func getLiquidityManager(client *loop.Client) *liquidity.Manager { +func getLiquidityManager(client *loop.Client, cfg *Config) *liquidity.Manager { mngrCfg := &liquidity.Config{ AutoloopTicker: ticker.NewForce(liquidity.DefaultAutoloopTicker), LoopOut: client.LoopOut, @@ -72,6 +72,7 @@ func getLiquidityManager(client *loop.Client) *liquidity.Manager { ListLoopOut: client.Store.FetchLoopOutSwaps, ListLoopIn: client.Store.FetchLoopInSwaps, MinimumConfirmations: minConfTarget, + LiquidityParamsPath: cfg.LiquidityParamsPath, } return liquidity.NewManager(mngrCfg)