Skip to content

Commit a15db0a

Browse files
authored
Merge pull request #185 from joostjager/config-max-parts
loopd: make maximum number of payment parts configurable
2 parents e99202c + 12ae3d6 commit a15db0a

File tree

9 files changed

+111
-58
lines changed

9 files changed

+111
-58
lines changed

client.go

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,43 @@ type Client struct {
8181
clientConfig
8282
}
8383

84-
// NewClient returns a new instance to initiate swaps with.
85-
func NewClient(dbDir string, serverAddress, proxyAddress string, insecure bool,
86-
tlsPathServer string, lnd *lndclient.LndServices, maxLSATCost,
87-
maxLSATFee btcutil.Amount) (*Client, func(), error) {
84+
// ClientConfig is the exported configuration structure that is required to
85+
// instantiate the loop client.
86+
type ClientConfig struct {
87+
// ServerAddress is the loop server to connect to.
88+
ServerAddress string
89+
90+
// ProxyAddress is the SOCKS proxy that should be used to establish the
91+
// connection.
92+
ProxyAddress string
93+
94+
// Insecure skips TLS when set.
95+
Insecure bool
96+
97+
// TLSPathServer is the path to the TLS certificate that is required to
98+
// connect to the server.
99+
TLSPathServer string
100+
101+
// Lnd is an instance of the lnd proxy.
102+
Lnd *lndclient.LndServices
103+
104+
// MaxLsatCost is the maximum price we are willing to pay to the server
105+
// for the token.
106+
MaxLsatCost btcutil.Amount
107+
108+
// MaxLsatFee is the maximum that we are willing to pay in routing fees
109+
// to obtain the token.
110+
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
116+
}
88117

89-
store, err := loopdb.NewBoltSwapStore(dbDir, lnd.ChainParams)
118+
// NewClient returns a new instance to initiate swaps with.
119+
func NewClient(dbDir string, cfg *ClientConfig) (*Client, func(), error) {
120+
store, err := loopdb.NewBoltSwapStore(dbDir, cfg.Lnd.ChainParams)
90121
if err != nil {
91122
return nil, nil, err
92123
}
@@ -95,16 +126,13 @@ func NewClient(dbDir string, serverAddress, proxyAddress string, insecure bool,
95126
return nil, nil, err
96127
}
97128

98-
swapServerClient, err := newSwapServerClient(
99-
serverAddress, proxyAddress, insecure, tlsPathServer, lsatStore,
100-
lnd, maxLSATCost, maxLSATFee,
101-
)
129+
swapServerClient, err := newSwapServerClient(cfg, lsatStore)
102130
if err != nil {
103131
return nil, nil, err
104132
}
105133

106134
config := &clientConfig{
107-
LndServices: lnd,
135+
LndServices: cfg.Lnd,
108136
Server: swapServerClient,
109137
Store: store,
110138
LsatStore: lsatStore,
@@ -114,20 +142,21 @@ func NewClient(dbDir string, serverAddress, proxyAddress string, insecure bool,
114142
}
115143

116144
sweeper := &sweep.Sweeper{
117-
Lnd: lnd,
145+
Lnd: cfg.Lnd,
118146
}
119147

120148
executor := newExecutor(&executorConfig{
121-
lnd: lnd,
149+
lnd: cfg.Lnd,
122150
store: store,
123151
sweeper: sweeper,
124152
createExpiryTimer: config.CreateExpiryTimer,
153+
loopOutMaxParts: cfg.LoopOutMaxParts,
125154
})
126155

127156
client := &Client{
128157
errChan: make(chan error),
129158
clientConfig: *config,
130-
lndServices: lnd,
159+
lndServices: cfg.Lnd,
131160
sweeper: sweeper,
132161
executor: executor,
133162
resumeReady: make(chan struct{}),

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 {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/grpc-ecosystem/grpc-gateway v1.12.2
1212
github.com/jessevdk/go-flags v1.4.0
1313
github.com/lightninglabs/protobuf-hex-display v1.3.3-0.20191212020323-b444784ce75d
14-
github.com/lightningnetwork/lnd v0.10.0-beta.rc4
14+
github.com/lightningnetwork/lnd v0.10.0-beta.rc5
1515
github.com/lightningnetwork/lnd/queue v1.0.3
1616
github.com/urfave/cli v1.20.0
1717
golang.org/x/net v0.0.0-20191002035440-2ec189313ef0

go.sum

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBA
1616
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
1717
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
1818
github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQYkqmusNa815XgQio277wI47sdRh1dUOLdyC6Q=
19+
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
1920
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
2021
github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0=
2122
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
@@ -64,6 +65,7 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
6465
github.com/coreos/bbolt v1.3.3 h1:n6AiVyVRKQFNb6mJlwESEvvLoDyiTzXX7ORAUlkeBdY=
6566
github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
6667
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
68+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6769
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
6870
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6971
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
@@ -80,6 +82,8 @@ github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm
8082
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
8183
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
8284
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
85+
github.com/go-openapi/errors v0.19.2/go.mod h1:qX0BLWsyaKfvhluLejVpVNwNRdXZhEbTA4kxxpKBC94=
86+
github.com/go-openapi/strfmt v0.19.5/go.mod h1:eftuHTlB/dI8Uq8JJOyRlieZf+WkkxUuk0dgdHXr2Qk=
8387
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
8488
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
8589
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
@@ -92,8 +96,10 @@ github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs
9296
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
9397
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
9498
github.com/google/go-cmp v0.2.1-0.20190312032427-6f77996f0c42/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
99+
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
95100
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
96101
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
102+
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
97103
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 h1:Iju5GlWwrvL6UBg4zJJt3btmonfrMlCDdsejg4CZE7c=
98104
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
99105
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
@@ -107,6 +113,7 @@ github.com/jackpal/gateway v1.0.5 h1:qzXWUJfuMdlLMtt0a3Dgt+xkWQiA5itDEITVJtuSwMc
107113
github.com/jackpal/gateway v1.0.5/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQetPfnjA=
108114
github.com/jackpal/go-nat-pmp v0.0.0-20170405195558-28a68d0c24ad h1:heFfj7z0pGsNCekUlsFhO2jstxO4b5iQ665LjwM5mDc=
109115
github.com/jackpal/go-nat-pmp v0.0.0-20170405195558-28a68d0c24ad/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
116+
github.com/jedib0t/go-pretty v4.3.0+incompatible/go.mod h1:XemHduiw8R651AF9Pt4FwCTKeG3oo7hrHJAoznj9nag=
110117
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
111118
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
112119
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
@@ -148,8 +155,8 @@ github.com/lightninglabs/protobuf-hex-display v1.3.3-0.20191212020323-b444784ce7
148155
github.com/lightninglabs/protobuf-hex-display v1.3.3-0.20191212020323-b444784ce75d/go.mod h1:KDb67YMzoh4eudnzClmvs2FbiLG9vxISmLApUkCa4uI=
149156
github.com/lightningnetwork/lightning-onion v1.0.1 h1:qChGgS5+aPxFeR6JiUsGvanei1bn6WJpYbvosw/1604=
150157
github.com/lightningnetwork/lightning-onion v1.0.1/go.mod h1:rigfi6Af/KqsF7Za0hOgcyq2PNH4AN70AaMRxcJkff4=
151-
github.com/lightningnetwork/lnd v0.10.0-beta.rc4 h1:gFdGWc+1nQDJj3nQZadsJL6Vsl8E6J2UxJUpSWLztug=
152-
github.com/lightningnetwork/lnd v0.10.0-beta.rc4/go.mod h1:vyc0duSWZi+xwk4hC2JqyTOKhVAS3I2/8AArCUdaau4=
158+
github.com/lightningnetwork/lnd v0.10.0-beta.rc5 h1:HcX35Djwk+xoNQe/LA7HnQ11jzbq68TAcpBluhNIKqc=
159+
github.com/lightningnetwork/lnd v0.10.0-beta.rc5/go.mod h1:mEnmP+sSgiKUFBozT3I5xEOgRAREMEWd/3lcWDrB+5E=
153160
github.com/lightningnetwork/lnd/cert v1.0.2/go.mod h1:fmtemlSMf5t4hsQmcprSoOykypAPp+9c+0d0iqTScMo=
154161
github.com/lightningnetwork/lnd/queue v1.0.1 h1:jzJKcTy3Nj5lQrooJ3aaw9Lau3I0IwvQR5sqtjdv2R0=
155162
github.com/lightningnetwork/lnd/queue v1.0.1/go.mod h1:vaQwexir73flPW43Mrm7JOgJHmcEFBWWSl9HlyASoms=
@@ -160,10 +167,12 @@ github.com/lightningnetwork/lnd/ticker v1.0.0/go.mod h1:iaLXJiVgI1sPANIF2qYYUJXj
160167
github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796 h1:sjOGyegMIhvgfq5oaue6Td+hxZuf3tDC8lAPrFldqFw=
161168
github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796/go.mod h1:3p7ZTf9V1sNPI5H8P3NkTFF4LuwMdPl2DodF60qAKqY=
162169
github.com/ltcsuite/ltcutil v0.0.0-20181217130922-17f3b04680b6/go.mod h1:8Vg/LTOO0KYa/vlHWJ6XZAevPQThGH5sufO0Hrou/lA=
170+
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
163171
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
164172
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
165173
github.com/miekg/dns v0.0.0-20171125082028-79bfde677fa8 h1:PRMAcldsl4mXKJeRNB/KVNz6TlbS6hk2Rs42PqgU3Ws=
166174
github.com/miekg/dns v0.0.0-20171125082028-79bfde677fa8/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
175+
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
167176
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
168177
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
169178
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
@@ -192,15 +201,20 @@ github.com/rogpeppe/fastuuid v1.2.0 h1:Ppwyp6VYCF1nvBTXL3trRso7mXMlRrw9ooo375wvi
192201
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
193202
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
194203
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
204+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
195205
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
206+
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
196207
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
208+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
209+
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
197210
github.com/tv42/zbase32 v0.0.0-20160707012821-501572607d02 h1:tcJ6OjwOMvExLlzrAVZute09ocAGa7KqOON60++Gz4E=
198211
github.com/tv42/zbase32 v0.0.0-20160707012821-501572607d02/go.mod h1:tHlrkM198S068ZqfrO6S8HsoJq2bF3ETfTL+kt4tInY=
199212
github.com/urfave/cli v1.18.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
200213
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
201214
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
202215
go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk=
203216
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
217+
go.mongodb.org/mongo-driver v1.0.3/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=
204218
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
205219
golang.org/x/crypto v0.0.0-20180723164146-c126467f60eb/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
206220
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
@@ -242,6 +256,8 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
242256
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
243257
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd h1:DBH9mDw0zluJT/R+nGuV3jWFWLFaHyYZWD4tOT+cjn0=
244258
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
259+
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
260+
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
245261
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
246262
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
247263
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=

lndclient/router_client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ type SendPaymentRequest struct {
9494
// for this payment. If empty, any hop may be used.
9595
LastHopPubkey *route.Vertex
9696

97-
// The maximum number of partial payments that may be used to complete
98-
// the full amount.
99-
MaxShards uint32
97+
// MaxParts is the maximum number of partial payments that may be used
98+
// to complete the full amount.
99+
MaxParts uint32
100100
}
101101

102102
// routerClient is a wrapper around the generated routerrpc proxy.
@@ -124,7 +124,7 @@ func (r *routerClient) SendPayment(ctx context.Context,
124124
FeeLimitSat: int64(request.MaxFee),
125125
PaymentRequest: request.Invoice,
126126
TimeoutSeconds: int32(request.Timeout.Seconds()),
127-
MaxShards: request.MaxShards,
127+
MaxParts: request.MaxParts,
128128
}
129129
if request.MaxCltv != nil {
130130
rpcReq.CltvLimit = *request.MaxCltv

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
},

loopd/utils.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ func getClient(config *config, lnd *lndclient.LndServices) (*loop.Client,
1818
return nil, nil, err
1919
}
2020

21-
swapClient, cleanUp, err := loop.NewClient(
22-
storeDir, config.SwapServer, config.Proxy, config.Insecure,
23-
config.TLSPathSwapSrv, lnd, btcutil.Amount(config.MaxLSATCost),
24-
btcutil.Amount(config.MaxLSATFee),
25-
)
21+
clientConfig := &loop.ClientConfig{
22+
ServerAddress: config.SwapServer,
23+
ProxyAddress: config.Proxy,
24+
Insecure: config.Insecure,
25+
TLSPathServer: config.TLSPathSwapSrv,
26+
Lnd: lnd,
27+
MaxLsatCost: btcutil.Amount(config.MaxLSATCost),
28+
MaxLsatFee: btcutil.Amount(config.MaxLSATFee),
29+
}
30+
31+
swapClient, cleanUp, err := loop.NewClient(storeDir, clientConfig)
2632
if err != nil {
2733
return nil, nil, err
2834
}

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-
MaxShards: loopOutMaxShards,
460+
MaxParts: s.executeConfig.loopOutMaxParts,
466461
}
467462

468463
// Lookup state of the swap payment.

swap_server_client.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
"github.com/btcsuite/btcd/btcec"
1313
"github.com/btcsuite/btcutil"
14-
"github.com/lightninglabs/loop/lndclient"
1514
"github.com/lightninglabs/loop/looprpc"
1615
"github.com/lightninglabs/loop/lsat"
1716
"github.com/lightningnetwork/lnd/lntypes"
@@ -54,17 +53,18 @@ type grpcSwapServerClient struct {
5453

5554
var _ swapServerClient = (*grpcSwapServerClient)(nil)
5655

57-
func newSwapServerClient(address, proxyAddress string, insecure bool,
58-
tlsPath string, lsatStore lsat.Store, lnd *lndclient.LndServices,
59-
maxLSATCost, maxLSATFee btcutil.Amount) (*grpcSwapServerClient, error) {
56+
func newSwapServerClient(cfg *ClientConfig, lsatStore lsat.Store) (
57+
*grpcSwapServerClient, error) {
6058

6159
// Create the server connection with the interceptor that will handle
6260
// the LSAT protocol for us.
6361
clientInterceptor := lsat.NewInterceptor(
64-
lnd, lsatStore, serverRPCTimeout, maxLSATCost, maxLSATFee,
62+
cfg.Lnd, lsatStore, serverRPCTimeout, cfg.MaxLsatCost,
63+
cfg.MaxLsatFee,
6564
)
6665
serverConn, err := getSwapServerConn(
67-
address, proxyAddress, insecure, tlsPath, clientInterceptor,
66+
cfg.ServerAddress, cfg.ProxyAddress, cfg.Insecure,
67+
cfg.TLSPathServer, clientInterceptor,
6868
)
6969
if err != nil {
7070
return nil, err

0 commit comments

Comments
 (0)