@@ -17,6 +17,8 @@ import (
1717 "github.com/lightninglabs/loop/loopdb"
1818 "github.com/lightninglabs/loop/swap"
1919 "github.com/lightninglabs/loop/sweep"
20+ "github.com/lightninglabs/loop/sweepbatcher"
21+ "github.com/lightninglabs/loop/utils"
2022 "github.com/lightningnetwork/lnd/lntypes"
2123 "github.com/lightningnetwork/lnd/routing/route"
2224 "google.golang.org/grpc"
6062 // probeTimeout is the maximum time until a probe is allowed to take.
6163 probeTimeout = 3 * time .Minute
6264
63- republishDelay = 10 * time .Second
65+ repushDelay = 1 * time .Second
6466
6567 // MinerFeeEstimationFailed is a magic number that is returned in a
6668 // quote call as the miner fee if the fee estimation in lnd's wallet
@@ -133,7 +135,8 @@ type ClientConfig struct {
133135
134136// NewClient returns a new instance to initiate swaps with.
135137func NewClient (dbDir string , loopDB loopdb.SwapStore ,
136- cfg * ClientConfig ) (* Client , func (), error ) {
138+ sweeperDb sweepbatcher.BatcherStore , cfg * ClientConfig ) (
139+ * Client , func (), error ) {
137140
138141 lsatStore , err := lsat .NewFileStore (dbDir )
139142 if err != nil {
@@ -161,27 +164,36 @@ func NewClient(dbDir string, loopDB loopdb.SwapStore,
161164 Lnd : cfg .Lnd ,
162165 }
163166
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+
164186 executor := newExecutor (& executorConfig {
165187 lnd : cfg .Lnd ,
166188 store : loopDB ,
167189 sweeper : sweeper ,
190+ batcher : batcher ,
168191 createExpiryTimer : config .CreateExpiryTimer ,
169192 loopOutMaxParts : cfg .LoopOutMaxParts ,
170193 totalPaymentTimeout : cfg .TotalPaymentTimeout ,
171194 maxPaymentRetries : cfg .MaxPaymentRetries ,
172195 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 ,
185197 })
186198
187199 client := & Client {
@@ -232,7 +244,7 @@ func (s *Client) FetchSwaps(ctx context.Context) ([]*SwapInfo, error) {
232244 LastUpdate : swp .LastUpdateTime (),
233245 }
234246
235- htlc , err := GetHtlc (
247+ htlc , err := utils . GetHtlc (
236248 swp .Hash , & swp .Contract .SwapContract ,
237249 s .lndServices .ChainParams ,
238250 )
@@ -265,7 +277,7 @@ func (s *Client) FetchSwaps(ctx context.Context) ([]*SwapInfo, error) {
265277 LastUpdate : swp .LastUpdateTime (),
266278 }
267279
268- htlc , err := GetHtlc (
280+ htlc , err := utils . GetHtlc (
269281 swp .Hash , & swp .Contract .SwapContract ,
270282 s .lndServices .ChainParams ,
271283 )
@@ -540,7 +552,7 @@ func (s *Client) getLoopOutSweepFee(ctx context.Context, confTarget int32) (
540552 return 0 , err
541553 }
542554
543- scriptVersion := GetHtlcScriptVersion (
555+ scriptVersion := utils . GetHtlcScriptVersion (
544556 loopdb .CurrentProtocolVersion (),
545557 )
546558
@@ -731,7 +743,7 @@ func (s *Client) estimateFee(ctx context.Context, amt btcutil.Amount,
731743 // Generate a dummy address for fee estimation.
732744 witnessProg := [32 ]byte {}
733745
734- scriptVersion := GetHtlcScriptVersion (
746+ scriptVersion := utils . GetHtlcScriptVersion (
735747 loopdb .CurrentProtocolVersion (),
736748 )
737749
0 commit comments