Skip to content

Commit 3f56345

Browse files
committed
sweepbatcher: add option WithPublishDelay
WithPublishDelay sets the delay of batch publishing that is applied in the beginning, after the appearance of a new block in the network or after the end of initial delay (see WithInitialDelay). It is needed to prevent unnecessary transaction publishments when a spend is detected on that block. Default value depends on the network: 5 seconds in mainnet, 0.5s in testnet. For batches recovered from DB this value is always 0s.
1 parent e178d32 commit 3f56345

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

sweepbatcher/sweep_batcher.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ type Batcher struct {
265265
// skipped.
266266
initialDelay time.Duration
267267

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+
268274
// customFeeRate provides custom min fee rate per swap. The batch uses
269275
// max of the fee rates of its swaps. In this mode confTarget is
270276
// ignored and fee bumping by sweepbatcher is disabled.
@@ -290,6 +296,12 @@ type BatcherConfig struct {
290296
// skipped.
291297
initialDelay time.Duration
292298

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+
293305
// customFeeRate provides custom min fee rate per swap. The batch uses
294306
// max of the fee rates of its swaps. In this mode confTarget is
295307
// ignored and fee bumping by sweepbatcher is disabled.
@@ -324,6 +336,18 @@ func WithInitialDelay(initialDelay time.Duration) BatcherOption {
324336
}
325337
}
326338

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+
327351
// WithCustomFeeRate instructs sweepbatcher not to fee bump itself and rely on
328352
// external source of fee rates (FeeRateProvider). To apply a fee rate change,
329353
// the caller should re-add the sweep by calling AddSweep.
@@ -383,6 +407,7 @@ func NewBatcher(wallet lndclient.WalletKitClient,
383407
sweepStore: sweepStore,
384408
clock: cfg.clock,
385409
initialDelay: cfg.initialDelay,
410+
publishDelay: cfg.publishDelay,
386411
customFeeRate: cfg.customFeeRate,
387412
customMuSig2Signer: cfg.customMuSig2Signer,
388413
}
@@ -588,6 +613,14 @@ func (b *Batcher) spinUpBatch(ctx context.Context) (*batch, error) {
588613
cfg.batchPublishDelay = defaultTestnetPublishDelay
589614
}
590615

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+
591624
if b.initialDelay < 0 {
592625
return nil, fmt.Errorf("negative initialDelay: %v",
593626
b.initialDelay)

0 commit comments

Comments
 (0)