loopd+liquidity: add new config `LiquidityParamsPath`

This commit adds a new config option that's used by the liquidity
manager to save the customized liquidity parameters.
pull/490/head
yyforyongyu 2 years ago
parent 1741896e33
commit 5205622eb2
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868

@ -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

@ -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.

@ -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{}),

@ -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)

Loading…
Cancel
Save