@@ -16,6 +16,7 @@ import (
16
16
"github.com/lightninglabs/loop/loopdb"
17
17
"github.com/lightninglabs/loop/swap"
18
18
"github.com/lightninglabs/loop/utils"
19
+ "github.com/lightningnetwork/lnd/clock"
19
20
"github.com/lightningnetwork/lnd/input"
20
21
"github.com/lightningnetwork/lnd/lntypes"
21
22
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
@@ -253,6 +254,9 @@ type Batcher struct {
253
254
// exit.
254
255
wg sync.WaitGroup
255
256
257
+ // clock provides methods to work with time and timers.
258
+ clock clock.Clock
259
+
256
260
// customFeeRate provides custom min fee rate per swap. The batch uses
257
261
// max of the fee rates of its swaps. In this mode confTarget is
258
262
// ignored and fee bumping by sweepbatcher is disabled.
@@ -267,6 +271,9 @@ type Batcher struct {
267
271
268
272
// BatcherConfig holds batcher configuration.
269
273
type BatcherConfig struct {
274
+ // clock provides methods to work with time and timers.
275
+ clock clock.Clock
276
+
270
277
// customFeeRate provides custom min fee rate per swap. The batch uses
271
278
// max of the fee rates of its swaps. In this mode confTarget is
272
279
// ignored and fee bumping by sweepbatcher is disabled.
@@ -282,6 +289,14 @@ type BatcherConfig struct {
282
289
// BatcherOption configures batcher behaviour.
283
290
type BatcherOption func (* BatcherConfig )
284
291
292
+ // WithClock sets the clock used by sweepbatcher and its batches. It is needed
293
+ // to manipulate time in tests.
294
+ func WithClock (clock clock.Clock ) BatcherOption {
295
+ return func (cfg * BatcherConfig ) {
296
+ cfg .clock = clock
297
+ }
298
+ }
299
+
285
300
// WithCustomFeeRate instructs sweepbatcher not to fee bump itself and rely on
286
301
// external source of fee rates (FeeRateProvider). To apply a fee rate change,
287
302
// the caller should re-add the sweep by calling AddSweep.
@@ -315,6 +330,11 @@ func NewBatcher(wallet lndclient.WalletKitClient,
315
330
opt (& cfg )
316
331
}
317
332
333
+ // If WithClock was not provided, use default clock.
334
+ if cfg .clock == nil {
335
+ cfg .clock = clock .NewDefaultClock ()
336
+ }
337
+
318
338
if cfg .customMuSig2Signer != nil && musig2ServerSigner != nil {
319
339
panic ("customMuSig2Signer must not be used with " +
320
340
"musig2ServerSigner" )
@@ -334,6 +354,7 @@ func NewBatcher(wallet lndclient.WalletKitClient,
334
354
chainParams : chainparams ,
335
355
store : store ,
336
356
sweepStore : sweepStore ,
357
+ clock : cfg .clock ,
337
358
customFeeRate : cfg .customFeeRate ,
338
359
customMuSig2Signer : cfg .customMuSig2Signer ,
339
360
}
@@ -934,6 +955,7 @@ func (b *Batcher) newBatchConfig(maxTimeoutDistance int32) batchConfig {
934
955
maxTimeoutDistance : maxTimeoutDistance ,
935
956
noBumping : b .customFeeRate != nil ,
936
957
customMuSig2Signer : b .customMuSig2Signer ,
958
+ clock : b .clock ,
937
959
}
938
960
}
939
961
0 commit comments