@@ -265,6 +265,12 @@ type Batcher struct {
265
265
// skipped.
266
266
initialDelay time.Duration
267
267
268
+ // publishDelay is the delay of batch publishing that is applied in the
269
+ // beginning, after the appearance of a new block in the network or
270
+ // after the end of initial delay. For batches recovered from DB this
271
+ // value is always 0s, regardless of this setting.
272
+ publishDelay time.Duration
273
+
268
274
// customFeeRate provides custom min fee rate per swap. The batch uses
269
275
// max of the fee rates of its swaps. In this mode confTarget is
270
276
// ignored and fee bumping by sweepbatcher is disabled.
@@ -290,6 +296,12 @@ type BatcherConfig struct {
290
296
// skipped.
291
297
initialDelay time.Duration
292
298
299
+ // publishDelay is the delay of batch publishing that is applied in the
300
+ // beginning, after the appearance of a new block in the network or
301
+ // after the end of initial delay. For batches recovered from DB this
302
+ // value is always 0s, regardless of this setting.
303
+ publishDelay time.Duration
304
+
293
305
// customFeeRate provides custom min fee rate per swap. The batch uses
294
306
// max of the fee rates of its swaps. In this mode confTarget is
295
307
// ignored and fee bumping by sweepbatcher is disabled.
@@ -324,6 +336,18 @@ func WithInitialDelay(initialDelay time.Duration) BatcherOption {
324
336
}
325
337
}
326
338
339
+ // WithPublishDelay sets the delay of batch publishing that is applied in the
340
+ // beginning, after the appearance of a new block in the network or after the
341
+ // end of initial delay (see WithInitialDelay). It is needed to prevent
342
+ // unnecessary transaction publishments when a spend is detected on that block.
343
+ // Default value depends on the network: 5 seconds in mainnet, 0.5s in testnet.
344
+ // For batches recovered from DB this value is always 0s.
345
+ func WithPublishDelay (publishDelay time.Duration ) BatcherOption {
346
+ return func (cfg * BatcherConfig ) {
347
+ cfg .publishDelay = publishDelay
348
+ }
349
+ }
350
+
327
351
// WithCustomFeeRate instructs sweepbatcher not to fee bump itself and rely on
328
352
// external source of fee rates (FeeRateProvider). To apply a fee rate change,
329
353
// the caller should re-add the sweep by calling AddSweep.
@@ -383,6 +407,7 @@ func NewBatcher(wallet lndclient.WalletKitClient,
383
407
sweepStore : sweepStore ,
384
408
clock : cfg .clock ,
385
409
initialDelay : cfg .initialDelay ,
410
+ publishDelay : cfg .publishDelay ,
386
411
customFeeRate : cfg .customFeeRate ,
387
412
customMuSig2Signer : cfg .customMuSig2Signer ,
388
413
}
@@ -588,6 +613,14 @@ func (b *Batcher) spinUpBatch(ctx context.Context) (*batch, error) {
588
613
cfg .batchPublishDelay = defaultTestnetPublishDelay
589
614
}
590
615
616
+ if b .publishDelay != 0 {
617
+ if b .publishDelay < 0 {
618
+ return nil , fmt .Errorf ("negative publishDelay: %v" ,
619
+ b .publishDelay )
620
+ }
621
+ cfg .batchPublishDelay = b .publishDelay
622
+ }
623
+
591
624
if b .initialDelay < 0 {
592
625
return nil , fmt .Errorf ("negative initialDelay: %v" ,
593
626
b .initialDelay )
0 commit comments