diff --git a/docs/release-notes/release-notes-0.19.0.md b/docs/release-notes/release-notes-0.19.0.md index ee36d17d11..116e7ddc66 100644 --- a/docs/release-notes/release-notes-0.19.0.md +++ b/docs/release-notes/release-notes-0.19.0.md @@ -121,6 +121,9 @@ when running LND with an aux component injected (custom channels). * [Fixed a bug](https://github.com/lightningnetwork/lnd/pull/9750): if a Taproot address is added to LND using the `ImportTapscript` RPC, LND previously failed to perform a cooperative close to that address. +* [Fixed a bug](https://github.com/lightningnetwork/lnd/pull/9744) where unnecessary + warnings about existing bbolt database files would appear when using SQLite backend + with already migrated databases. # New Features diff --git a/lncfg/db.go b/lncfg/db.go index b45ee6dab2..f087662dc9 100644 --- a/lncfg/db.go +++ b/lncfg/db.go @@ -3,6 +3,7 @@ package lncfg import ( "context" "fmt" + "os" "path" "path/filepath" "time" @@ -68,6 +69,10 @@ const ( // NSNeutrinoDB is the namespace name that we use for the neutrino DB. NSNeutrinoDB = "neutrinodb" + + // MigrationMarkerFile is a marker file created by lndinit migrate-db + // that indicates successful database migration. + MigrationMarkerFile = ".migration-complete" ) // DB holds database configuration for LND. @@ -484,6 +489,13 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath, warnExistingBoltDBs( logger, "postgres", chanDBPath, ChannelDBName, ) + // Also check for macaroons.db and sphinxreplay.db bbolt files + warnExistingBoltDBs( + logger, "postgres", walletDBPath, MacaroonDBName, + ) + warnExistingBoltDBs( + logger, "postgres", chanDBPath, DecayedLogDbName, + ) returnEarly = false @@ -599,14 +611,29 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath, closeFuncs[SqliteBackend] = nativeSQLiteStore.Close } - // Warn if the user is trying to switch over to a sqlite DB - // while there is a wallet or channel bbolt DB still present. - warnExistingBoltDBs( - logger, "sqlite", walletDBPath, WalletDBName, - ) - warnExistingBoltDBs( - logger, "sqlite", chanDBPath, ChannelDBName, - ) + // Check if migration has been completed before warning about + // existing bbolt databases + migrationComplete := hasMigrationCompleted(walletDBPath) || + hasMigrationCompleted(chanDBPath) + + // Only show warnings if migration hasn't been completed + if !migrationComplete { + // Warn if the user is trying to switch over to a sqlite DB + // while there is a wallet or channel bbolt DB still present. + warnExistingBoltDBs( + logger, "sqlite", walletDBPath, WalletDBName, + ) + warnExistingBoltDBs( + logger, "sqlite", chanDBPath, ChannelDBName, + ) + // Also check for macaroons.db and sphinxreplay.db bbolt files + warnExistingBoltDBs( + logger, "sqlite", walletDBPath, MacaroonDBName, + ) + warnExistingBoltDBs( + logger, "sqlite", chanDBPath, DecayedLogDbName, + ) + } returnEarly = false @@ -735,6 +762,30 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath, }, nil } +// hasMigrationCompleted checks if migration has been completed by looking for +// SQLite files with substantial size or a migration marker file. +func hasMigrationCompleted(dbPath string) bool { + // Check for marker file (which lndinit could create after migration) + markerPath := filepath.Join(dbPath, MigrationMarkerFile) + if _, err := os.Stat(markerPath); err == nil { + return true + } + + // Check for non-empty SQLite files + sqliteFiles := []string{SqliteChainDBName, SqliteChannelDBName} + for _, fileName := range sqliteFiles { + filePath := filepath.Join(dbPath, fileName) + fileInfo, err := os.Stat(filePath) + + // If file exists and has substantial size (not just created empty) + if err == nil && fileInfo.Size() > 1024 { + return true + } + } + + return false +} + // warnExistingBoltDBs checks if there is an existing bbolt database in the // given location and logs a warning if so. func warnExistingBoltDBs(log btclog.Logger, dbType, dir, fileName string) {