Skip to content

Commit 41fdc4b

Browse files
committed
channeldb+lncfg: add config flag to skip pending close cleanup
Add a new configuration option `db.skip-pending-close-cleanup` that allows users to skip the cleanup of pending channel closes at startup. This is useful when users want to start their node quickly and defer the cleanup to a later restart. The cleanup of closed channel data (revocation logs, forwarding packages) can take a while if there are many channels pending cleanup. By setting this flag, users can trade startup latency for a faster boot time when needed. Usage: lnd --db.skip-pending-close-cleanup=true Or in lnd.conf: [db] skip-pending-close-cleanup=true
1 parent 929e68b commit 41fdc4b

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

channeldb/db.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,12 +439,17 @@ func CreateWithBackend(backend kvdb.Backend, modifiers ...OptionModifier) (*DB,
439439
// Clean up any channels that were closed but whose data has not yet
440440
// been fully deleted. This is deferred to startup to avoid blocking
441441
// the channel close operation.
442-
err := chanDB.channelStateDB.CleanupPendingCloses()
443-
if err != nil {
444-
backend.Close()
442+
if !opts.SkipPendingCloseCleanup {
443+
err := chanDB.channelStateDB.CleanupPendingCloses()
444+
if err != nil {
445+
backend.Close()
445446

446-
return nil, fmt.Errorf("unable to cleanup pending "+
447-
"channel closes: %w", err)
447+
return nil, fmt.Errorf("unable to cleanup pending "+
448+
"channel closes: %w", err)
449+
}
450+
} else {
451+
log.Info("Skipping pending channel close cleanup as " +
452+
"configured")
448453
}
449454

450455
return chanDB, nil

channeldb/options.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ type Options struct {
7171
// storeFinalHtlcResolutions determines whether to persistently store
7272
// the final resolution of incoming htlcs.
7373
storeFinalHtlcResolutions bool
74+
75+
// SkipPendingCloseCleanup when set to true, skips the cleanup of
76+
// pending channel closes at startup. This can be useful if the user
77+
// wants to start the node quickly and defer the cleanup to a later
78+
// restart.
79+
SkipPendingCloseCleanup bool
7480
}
7581

7682
// DefaultOptions returns an Options populated with default values.
@@ -151,3 +157,11 @@ func OptionGcDecayedLog(noGc bool) OptionModifier {
151157
o.OptionalMiragtionConfig.MigrationFlags[1] = !noGc
152158
}
153159
}
160+
161+
// OptionSkipPendingCloseCleanup controls whether to skip the cleanup of
162+
// pending channel closes at startup.
163+
func OptionSkipPendingCloseCleanup(skip bool) OptionModifier {
164+
return func(o *Options) {
165+
o.SkipPendingCloseCleanup = skip
166+
}
167+
}

config_builder.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,9 @@ func (d *DefaultDatabaseBuilder) BuildDatabase(
10711071
channeldb.OptionNoRevLogAmtData(cfg.DB.NoRevLogAmtData),
10721072
channeldb.OptionGcDecayedLog(cfg.DB.NoGcDecayedLog),
10731073
channeldb.OptionWithDecayedLogDB(dbs.DecayedLogDB),
1074+
channeldb.OptionSkipPendingCloseCleanup(
1075+
cfg.DB.SkipPendingCloseCleanup,
1076+
),
10741077
}
10751078

10761079
// Otherwise, we'll open two instances, one for the state we only need

lncfg/db.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ type DB struct {
9797
NoRevLogAmtData bool `long:"no-rev-log-amt-data" description:"If set, the to-local and to-remote output amounts of revoked commitment transactions will not be stored in the revocation log. Note that once this data is lost, a watchtower client will not be able to back up the revoked state."`
9898

9999
NoGcDecayedLog bool `long:"no-gc-decayed-log" description:"Do not run the optional migration that garbage collects the decayed log to save disk space."`
100+
101+
SkipPendingCloseCleanup bool `long:"skip-pending-close-cleanup" description:"Skip cleanup of pending channel closes at startup. This can be useful for faster startup when there are many channels pending cleanup, deferring the cleanup to a later restart."`
100102
}
101103

102104
// DefaultDB creates and returns a new default DB config.

sample-lnd.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,11 @@
15111511
; the future.
15121512
; db.no-rev-log-amt-data=false
15131513

1514+
; If set to true, skip cleanup of pending channel closes at startup. This can
1515+
; be useful for faster startup when there are many channels pending cleanup,
1516+
; deferring the cleanup to a later restart.
1517+
; db.skip-pending-close-cleanup=false
1518+
15141519
; If set to true, native SQL will be used instead of KV emulation for tables
15151520
; that support it.
15161521
; Subsystems which support native SQL tables:

0 commit comments

Comments
 (0)