@@ -17,6 +17,8 @@ import (
17
17
"github.com/lightninglabs/loop/loopdb"
18
18
"github.com/lightninglabs/loop/swap"
19
19
"github.com/lightninglabs/loop/sweep"
20
+ "github.com/lightninglabs/loop/sweepbatcher"
21
+ "github.com/lightninglabs/loop/utils"
20
22
"github.com/lightningnetwork/lnd/lntypes"
21
23
"github.com/lightningnetwork/lnd/routing/route"
22
24
"google.golang.org/grpc"
60
62
// probeTimeout is the maximum time until a probe is allowed to take.
61
63
probeTimeout = 3 * time .Minute
62
64
63
- republishDelay = 10 * time .Second
65
+ repushDelay = 1 * time .Second
64
66
65
67
// MinerFeeEstimationFailed is a magic number that is returned in a
66
68
// quote call as the miner fee if the fee estimation in lnd's wallet
@@ -133,7 +135,8 @@ type ClientConfig struct {
133
135
134
136
// NewClient returns a new instance to initiate swaps with.
135
137
func NewClient (dbDir string , loopDB loopdb.SwapStore ,
136
- cfg * ClientConfig ) (* Client , func (), error ) {
138
+ sweeperDb sweepbatcher.BatcherStore , cfg * ClientConfig ) (
139
+ * Client , func (), error ) {
137
140
138
141
lsatStore , err := lsat .NewFileStore (dbDir )
139
142
if err != nil {
@@ -161,27 +164,36 @@ func NewClient(dbDir string, loopDB loopdb.SwapStore,
161
164
Lnd : cfg .Lnd ,
162
165
}
163
166
167
+ verifySchnorrSig := func (pubKey * btcec.PublicKey , hash , sig []byte ) error {
168
+ schnorrSig , err := schnorr .ParseSignature (sig )
169
+ if err != nil {
170
+ return err
171
+ }
172
+
173
+ if ! schnorrSig .Verify (hash , pubKey ) {
174
+ return fmt .Errorf ("invalid signature" )
175
+ }
176
+
177
+ return nil
178
+ }
179
+
180
+ batcher := sweepbatcher .NewBatcher (
181
+ cfg .Lnd .WalletKit , cfg .Lnd .ChainNotifier , cfg .Lnd .Signer ,
182
+ swapServerClient .MultiMuSig2SignSweep , verifySchnorrSig ,
183
+ cfg .Lnd .ChainParams , sweeperDb , loopDB ,
184
+ )
185
+
164
186
executor := newExecutor (& executorConfig {
165
187
lnd : cfg .Lnd ,
166
188
store : loopDB ,
167
189
sweeper : sweeper ,
190
+ batcher : batcher ,
168
191
createExpiryTimer : config .CreateExpiryTimer ,
169
192
loopOutMaxParts : cfg .LoopOutMaxParts ,
170
193
totalPaymentTimeout : cfg .TotalPaymentTimeout ,
171
194
maxPaymentRetries : cfg .MaxPaymentRetries ,
172
195
cancelSwap : swapServerClient .CancelLoopOutSwap ,
173
- verifySchnorrSig : func (pubKey * btcec.PublicKey , hash , sig []byte ) error {
174
- schnorrSig , err := schnorr .ParseSignature (sig )
175
- if err != nil {
176
- return err
177
- }
178
-
179
- if ! schnorrSig .Verify (hash , pubKey ) {
180
- return fmt .Errorf ("invalid signature" )
181
- }
182
-
183
- return nil
184
- },
196
+ verifySchnorrSig : verifySchnorrSig ,
185
197
})
186
198
187
199
client := & Client {
@@ -232,7 +244,7 @@ func (s *Client) FetchSwaps(ctx context.Context) ([]*SwapInfo, error) {
232
244
LastUpdate : swp .LastUpdateTime (),
233
245
}
234
246
235
- htlc , err := GetHtlc (
247
+ htlc , err := utils . GetHtlc (
236
248
swp .Hash , & swp .Contract .SwapContract ,
237
249
s .lndServices .ChainParams ,
238
250
)
@@ -265,7 +277,7 @@ func (s *Client) FetchSwaps(ctx context.Context) ([]*SwapInfo, error) {
265
277
LastUpdate : swp .LastUpdateTime (),
266
278
}
267
279
268
- htlc , err := GetHtlc (
280
+ htlc , err := utils . GetHtlc (
269
281
swp .Hash , & swp .Contract .SwapContract ,
270
282
s .lndServices .ChainParams ,
271
283
)
@@ -540,7 +552,7 @@ func (s *Client) getLoopOutSweepFee(ctx context.Context, confTarget int32) (
540
552
return 0 , err
541
553
}
542
554
543
- scriptVersion := GetHtlcScriptVersion (
555
+ scriptVersion := utils . GetHtlcScriptVersion (
544
556
loopdb .CurrentProtocolVersion (),
545
557
)
546
558
@@ -731,7 +743,7 @@ func (s *Client) estimateFee(ctx context.Context, amt btcutil.Amount,
731
743
// Generate a dummy address for fee estimation.
732
744
witnessProg := [32 ]byte {}
733
745
734
- scriptVersion := GetHtlcScriptVersion (
746
+ scriptVersion := utils . GetHtlcScriptVersion (
735
747
loopdb .CurrentProtocolVersion (),
736
748
)
737
749
0 commit comments