loopd: make maximum number of payment parts configurable

pull/185/head
Joost Jager 4 years ago
parent 5588876b48
commit 12ae3d6a40
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

@ -108,6 +108,11 @@ type ClientConfig struct {
// MaxLsatFee is the maximum that we are willing to pay in routing fees // MaxLsatFee is the maximum that we are willing to pay in routing fees
// to obtain the token. // to obtain the token.
MaxLsatFee btcutil.Amount MaxLsatFee btcutil.Amount
// LoopOutMaxParts defines the maximum number of parts that may be used
// for a loop out swap. When greater than one, a multi-part payment may
// be attempted.
LoopOutMaxParts uint32
} }
// NewClient returns a new instance to initiate swaps with. // NewClient returns a new instance to initiate swaps with.
@ -145,6 +150,7 @@ func NewClient(dbDir string, cfg *ClientConfig) (*Client, func(), error) {
store: store, store: store,
sweeper: sweeper, sweeper: sweeper,
createExpiryTimer: config.CreateExpiryTimer, createExpiryTimer: config.CreateExpiryTimer,
loopOutMaxParts: cfg.LoopOutMaxParts,
}) })
client := &Client{ client := &Client{

@ -22,6 +22,8 @@ type executorConfig struct {
store loopdb.SwapStore store loopdb.SwapStore
createExpiryTimer func(expiry time.Duration) <-chan time.Time createExpiryTimer func(expiry time.Duration) <-chan time.Time
loopOutMaxParts uint32
} }
// executor is responsible for executing swaps. // executor is responsible for executing swaps.
@ -109,10 +111,11 @@ func (s *executor) run(mainCtx context.Context,
defer s.wg.Done() defer s.wg.Done()
newSwap.execute(mainCtx, &executeConfig{ newSwap.execute(mainCtx, &executeConfig{
statusChan: statusChan, statusChan: statusChan,
sweeper: s.sweeper, sweeper: s.sweeper,
blockEpochChan: queue.ChanOut(), blockEpochChan: queue.ChanOut(),
timerFactory: s.executorConfig.createExpiryTimer, timerFactory: s.executorConfig.createExpiryTimer,
loopOutMaxParts: s.executorConfig.loopOutMaxParts,
}, height) }, height)
select { select {

@ -15,8 +15,9 @@ var (
defaultLogFilename = "loopd.log" defaultLogFilename = "loopd.log"
defaultLogDir = filepath.Join(loopDirBase, defaultLogDirname) defaultLogDir = filepath.Join(loopDirBase, defaultLogDirname)
defaultMaxLogFiles = 3 defaultMaxLogFiles = 3
defaultMaxLogFileSize = 10 defaultMaxLogFileSize = 10
defaultLoopOutMaxParts = uint32(5)
) )
type lndConfig struct { type lndConfig struct {
@ -45,6 +46,8 @@ type config struct {
MaxLSATCost uint32 `long:"maxlsatcost" description:"Maximum cost in satoshis that loopd is going to pay for an LSAT token automatically. Does not include routing fees."` MaxLSATCost uint32 `long:"maxlsatcost" description:"Maximum cost in satoshis that loopd is going to pay for an LSAT token automatically. Does not include routing fees."`
MaxLSATFee uint32 `long:"maxlsatfee" description:"Maximum routing fee in satoshis that we are willing to pay while paying for an LSAT token."` MaxLSATFee uint32 `long:"maxlsatfee" description:"Maximum routing fee in satoshis that we are willing to pay while paying for an LSAT token."`
LoopOutMaxParts uint32 `long:"loopoutmaxparts" description:"The maximum number of payment parts that may be used for a loop out swap."`
Lnd *lndConfig `group:"lnd" namespace:"lnd"` Lnd *lndConfig `group:"lnd" namespace:"lnd"`
Proxy string `long:"proxy" description:"The host:port of a SOCKS proxy through which all connections to the swap server will be established over."` Proxy string `long:"proxy" description:"The host:port of a SOCKS proxy through which all connections to the swap server will be established over."`
@ -57,16 +60,17 @@ const (
) )
var defaultConfig = config{ var defaultConfig = config{
Network: "mainnet", Network: "mainnet",
RPCListen: "localhost:11010", RPCListen: "localhost:11010",
RESTListen: "localhost:8081", RESTListen: "localhost:8081",
Insecure: false, Insecure: false,
LogDir: defaultLogDir, LogDir: defaultLogDir,
MaxLogFiles: defaultMaxLogFiles, MaxLogFiles: defaultMaxLogFiles,
MaxLogFileSize: defaultMaxLogFileSize, MaxLogFileSize: defaultMaxLogFileSize,
DebugLevel: defaultLogLevel, DebugLevel: defaultLogLevel,
MaxLSATCost: lsat.DefaultMaxCostSats, MaxLSATCost: lsat.DefaultMaxCostSats,
MaxLSATFee: lsat.DefaultMaxRoutingFeeSats, MaxLSATFee: lsat.DefaultMaxRoutingFeeSats,
LoopOutMaxParts: defaultLoopOutMaxParts,
Lnd: &lndConfig{ Lnd: &lndConfig{
Host: "localhost:10009", Host: "localhost:10009",
}, },

@ -45,12 +45,6 @@ var (
paymentTimeout = time.Minute paymentTimeout = time.Minute
) )
const (
// loopOutMaxShards defines that maximum number of shards that may be
// used for a loop out swap.
loopOutMaxShards = 5
)
// loopOutSwap contains all the in-memory state related to a pending loop out // loopOutSwap contains all the in-memory state related to a pending loop out
// swap. // swap.
type loopOutSwap struct { type loopOutSwap struct {
@ -64,10 +58,11 @@ type loopOutSwap struct {
// executeConfig contains extra configuration to execute the swap. // executeConfig contains extra configuration to execute the swap.
type executeConfig struct { type executeConfig struct {
sweeper *sweep.Sweeper sweeper *sweep.Sweeper
statusChan chan<- SwapInfo statusChan chan<- SwapInfo
blockEpochChan <-chan interface{} blockEpochChan <-chan interface{}
timerFactory func(d time.Duration) <-chan time.Time timerFactory func(d time.Duration) <-chan time.Time
loopOutMaxParts uint32
} }
// newLoopOutSwap initiates a new swap with the server and returns a // newLoopOutSwap initiates a new swap with the server and returns a
@ -462,7 +457,7 @@ func (s *loopOutSwap) payInvoiceAsync(ctx context.Context,
Invoice: invoice, Invoice: invoice,
OutgoingChannel: outgoingChannel, OutgoingChannel: outgoingChannel,
Timeout: paymentTimeout, Timeout: paymentTimeout,
MaxParts: loopOutMaxShards, MaxParts: s.executeConfig.loopOutMaxParts,
} }
// Lookup state of the swap payment. // Lookup state of the swap payment.

Loading…
Cancel
Save