Skip to content

Commit 12ae3d6

Browse files
committed
loopd: make maximum number of payment parts configurable
1 parent 5588876 commit 12ae3d6

File tree

4 files changed

+35
-27
lines changed

4 files changed

+35
-27
lines changed

client.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ type ClientConfig struct {
108108
// MaxLsatFee is the maximum that we are willing to pay in routing fees
109109
// to obtain the token.
110110
MaxLsatFee btcutil.Amount
111+
112+
// LoopOutMaxParts defines the maximum number of parts that may be used
113+
// for a loop out swap. When greater than one, a multi-part payment may
114+
// be attempted.
115+
LoopOutMaxParts uint32
111116
}
112117

113118
// NewClient returns a new instance to initiate swaps with.
@@ -145,6 +150,7 @@ func NewClient(dbDir string, cfg *ClientConfig) (*Client, func(), error) {
145150
store: store,
146151
sweeper: sweeper,
147152
createExpiryTimer: config.CreateExpiryTimer,
153+
loopOutMaxParts: cfg.LoopOutMaxParts,
148154
})
149155

150156
client := &Client{

executor.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ type executorConfig struct {
2222
store loopdb.SwapStore
2323

2424
createExpiryTimer func(expiry time.Duration) <-chan time.Time
25+
26+
loopOutMaxParts uint32
2527
}
2628

2729
// executor is responsible for executing swaps.
@@ -109,10 +111,11 @@ func (s *executor) run(mainCtx context.Context,
109111
defer s.wg.Done()
110112

111113
newSwap.execute(mainCtx, &executeConfig{
112-
statusChan: statusChan,
113-
sweeper: s.sweeper,
114-
blockEpochChan: queue.ChanOut(),
115-
timerFactory: s.executorConfig.createExpiryTimer,
114+
statusChan: statusChan,
115+
sweeper: s.sweeper,
116+
blockEpochChan: queue.ChanOut(),
117+
timerFactory: s.executorConfig.createExpiryTimer,
118+
loopOutMaxParts: s.executorConfig.loopOutMaxParts,
116119
}, height)
117120

118121
select {

loopd/config.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ var (
1515
defaultLogFilename = "loopd.log"
1616
defaultLogDir = filepath.Join(loopDirBase, defaultLogDirname)
1717

18-
defaultMaxLogFiles = 3
19-
defaultMaxLogFileSize = 10
18+
defaultMaxLogFiles = 3
19+
defaultMaxLogFileSize = 10
20+
defaultLoopOutMaxParts = uint32(5)
2021
)
2122

2223
type lndConfig struct {
@@ -45,6 +46,8 @@ type config struct {
4546
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."`
4647
MaxLSATFee uint32 `long:"maxlsatfee" description:"Maximum routing fee in satoshis that we are willing to pay while paying for an LSAT token."`
4748

49+
LoopOutMaxParts uint32 `long:"loopoutmaxparts" description:"The maximum number of payment parts that may be used for a loop out swap."`
50+
4851
Lnd *lndConfig `group:"lnd" namespace:"lnd"`
4952
Proxy string `long:"proxy" description:"The host:port of a SOCKS proxy through which all connections to the swap server will be established over."`
5053

@@ -57,16 +60,17 @@ const (
5760
)
5861

5962
var defaultConfig = config{
60-
Network: "mainnet",
61-
RPCListen: "localhost:11010",
62-
RESTListen: "localhost:8081",
63-
Insecure: false,
64-
LogDir: defaultLogDir,
65-
MaxLogFiles: defaultMaxLogFiles,
66-
MaxLogFileSize: defaultMaxLogFileSize,
67-
DebugLevel: defaultLogLevel,
68-
MaxLSATCost: lsat.DefaultMaxCostSats,
69-
MaxLSATFee: lsat.DefaultMaxRoutingFeeSats,
63+
Network: "mainnet",
64+
RPCListen: "localhost:11010",
65+
RESTListen: "localhost:8081",
66+
Insecure: false,
67+
LogDir: defaultLogDir,
68+
MaxLogFiles: defaultMaxLogFiles,
69+
MaxLogFileSize: defaultMaxLogFileSize,
70+
DebugLevel: defaultLogLevel,
71+
MaxLSATCost: lsat.DefaultMaxCostSats,
72+
MaxLSATFee: lsat.DefaultMaxRoutingFeeSats,
73+
LoopOutMaxParts: defaultLoopOutMaxParts,
7074
Lnd: &lndConfig{
7175
Host: "localhost:10009",
7276
},

loopout.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ var (
4545
paymentTimeout = time.Minute
4646
)
4747

48-
const (
49-
// loopOutMaxShards defines that maximum number of shards that may be
50-
// used for a loop out swap.
51-
loopOutMaxShards = 5
52-
)
53-
5448
// loopOutSwap contains all the in-memory state related to a pending loop out
5549
// swap.
5650
type loopOutSwap struct {
@@ -64,10 +58,11 @@ type loopOutSwap struct {
6458

6559
// executeConfig contains extra configuration to execute the swap.
6660
type executeConfig struct {
67-
sweeper *sweep.Sweeper
68-
statusChan chan<- SwapInfo
69-
blockEpochChan <-chan interface{}
70-
timerFactory func(d time.Duration) <-chan time.Time
61+
sweeper *sweep.Sweeper
62+
statusChan chan<- SwapInfo
63+
blockEpochChan <-chan interface{}
64+
timerFactory func(d time.Duration) <-chan time.Time
65+
loopOutMaxParts uint32
7166
}
7267

7368
// newLoopOutSwap initiates a new swap with the server and returns a
@@ -462,7 +457,7 @@ func (s *loopOutSwap) payInvoiceAsync(ctx context.Context,
462457
Invoice: invoice,
463458
OutgoingChannel: outgoingChannel,
464459
Timeout: paymentTimeout,
465-
MaxParts: loopOutMaxShards,
460+
MaxParts: s.executeConfig.loopOutMaxParts,
466461
}
467462

468463
// Lookup state of the swap payment.

0 commit comments

Comments
 (0)