Skip to content

lncfg: don't warn user about existing bbolt DB if SQLite files exist #9744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Dhiren-Mhatre
Copy link

Change Description

Fix issue #9708 by checking for existing SQLite database files before warning about bbolt files.

Currently, when users start LND with the SQLite backend, they see warnings about existing bbolt database files even if they've already migrated their data using lndinit migrate-db. This PR enhances the warning system to only display these messages when a SQLite file doesn't exist yet, reducing confusion for users who have already completed migration.

Steps to Test

  1. Create a test environment with bbolt database files:

    mkdir -p ~/lnd-test-bolt
    lnd --lnddir=~/lnd-test-bolt --datadir=~/lnd-test-bolt
    # Create and fund a wallet
    lncli --lnddir=~/lnd-test-bolt create
    
  2. Migrate to SQLite:

    lndinit --lnddir=~/lnd-test-bolt migrate-db
    
  3. Run with SQLite backend before applying this fix:

    lnd --lnddir=~/lnd-test-bolt --db.backend=sqlite --db.use-native-sql
    

    Observe the warnings about existing bbolt files.

  4. Run with SQLite backend after applying this fix:

    lnd --lnddir=~/lnd-test-bolt --db.backend=sqlite --db.use-native-sql
    

    No warnings should appear since SQLite files exist.

  5. Delete the SQLite files and run again:

    rm ~/lnd-test-bolt/data/chain/bitcoin/regtest/chain.sqlite
    rm ~/lnd-test-bolt/data/graph/regtest/channel.sqlite
    lnd --lnddir=~/lnd-test-bolt --db.backend=sqlite --db.use-native-sql
    

    Warnings should reappear because bbolt files exist but SQLite files don't.

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.
  • Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

Copy link
Contributor

coderabbitai bot commented Apr 20, 2025

Important

Review skipped

Auto reviews are limited to specific labels.

🏷️ Labels to auto review (1)
  • llm-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Dhiren-Mhatre Dhiren-Mhatre force-pushed the fix-unnecessary-db-warnings branch from d204fa4 to 39dc89d Compare April 22, 2025 09:40
Copy link
Contributor

@NishantBansal2003 NishantBansal2003 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dhiren-Mhatre Dhiren-Mhatre force-pushed the fix-unnecessary-db-warnings branch 2 times, most recently from a309cb7 to 6ef656c Compare April 26, 2025 09:04
@Dhiren-Mhatre
Copy link
Author

Please read the contribution guidelines. https://github.com/lightningnetwork/lnd/blob/master/docs/development_guidelines.md#ideal-git-commit-structure

I've updated my commit messages as per the contribution guidelines.Thank you for pointing this out!

@Dhiren-Mhatre Dhiren-Mhatre changed the title [bug]: don't warn user about existing bbolt DB if SQLite files exist lncfg: don't warn user about existing bbolt DB if SQLite files exist Apr 26, 2025
Copy link
Contributor

@NishantBansal2003 NishantBansal2003 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested the PR locally? I tried testing it, and here are the results:

  1. Running with SQLite only (no bbolt and no existing SQLite data) → warning does not show up (test passed).
  2. Running with SQLite only (no bbolt but with existing SQLite data) → warning does not show up (test passed).
  3. Running with SQLite (with bbolt data and no existing SQLite data) → warning does not show up (test failed).
  4. Running with SQLite (with bbolt data and with existing SQLite data) → warning does not show up (test passed).

The warning does not appear in any of these cases. I believe that, if the .sqlite file does not exist, it is created automatically, so your check !lnrpc.FileExists(sqlitePath) is never executed.

Additionally, I noticed that we are only checking here:

lnd/lncfg/db.go

Lines 604 to 609 in 7e50b84

warnExistingBoltDBs(
logger, "sqlite", walletDBPath, WalletDBName,
)
warnExistingBoltDBs(
logger, "sqlite", chanDBPath, ChannelDBName,
)

So, currently no warnings are thrown for macaroons.db and sphinxreplay.db.

@Dhiren-Mhatre
Copy link
Author

Have you tested the PR locally? I tried testing it, and here are the results:

  1. Running with SQLite only (no bbolt and no existing SQLite data) → warning does not show up (test passed).
  2. Running with SQLite only (no bbolt but with existing SQLite data) → warning does not show up (test passed).
  3. Running with SQLite (with bbolt data and no existing SQLite data) → warning does not show up (test failed).
  4. Running with SQLite (with bbolt data and with existing SQLite data) → warning does not show up (test passed).

The warning does not appear in any of these cases. I believe that, if the .sqlite file does not exist, it is created automatically, so your check !lnrpc.FileExists(sqlitePath) is never executed.

Additionally, I noticed that we are only checking here:

lnd/lncfg/db.go

Lines 604 to 609 in 7e50b84

warnExistingBoltDBs(
logger, "sqlite", walletDBPath, WalletDBName,
)
warnExistingBoltDBs(
logger, "sqlite", chanDBPath, ChannelDBName,
)

So, currently no warnings are thrown for macaroons.db and sphinxreplay.db.

You're right about those points. I was worried about the FileExists check, but I wasn't sure if the SQLite files would be auto-created. Based on your testing, it seems like my implementation isn't behaving as expected.
For the macaroons.db and sphinxreplay.db checks, I thought I was handling them in the switch statement, but you're right that they're not being checked in the main function calls.
I'll update the PR to:
Fix the logic to ensure warnings appear only when appropriate
Add explicit checks for macaroons.db and sphinxreplay.db
Thanks for the thorough review

@Dhiren-Mhatre Dhiren-Mhatre force-pushed the fix-unnecessary-db-warnings branch from 6ef656c to 4db2891 Compare April 28, 2025 14:22
@NishantBansal2003
Copy link
Contributor

Did a quick pass: Could you explain what .migration-complete is? I couldn't find any such file.

Also, I think the code shouldn't be specific to migration but should handle general scenarios (including the migration case as well). wdyt?

@Dhiren-Mhatre
Copy link
Author

The .migration-complete file was intended as a theoretical enhancement that doesn't actually exist yet. I added that check thinking it could be a reliable way to detect completed migrations (since SQLite files are auto-created even without migration).

I agree the code shouldn't be migration-specific. The simple approach in my second commit (just adding checks for macaroons.db and sphinxreplay.db) addresses what's actually needed:

  1. It checks for all database types mentioned in the issue
  2. It follows the existing pattern without introducing complex migration detection

I can update the PR to remove the migration-specific code and focus only on adding the additional file checks, which is what users need right now. Would that approach work better?

@NishantBansal2003
Copy link
Contributor

I think it would be better if the approach focused on solving the original issue:

  1. I think it should only look for a bbolt DB and inform the user of its existence if the user has requested a SQLite DB AND the SQLite DB does not actually exist
  2. Also, if we do do these checks because the SQLite DB doesn't exist and we are trying to warn the user of what they actually have, we should also check for macaroons.db and sphinxreplay.db

I believe there are some straightforward ways to solve this issue using general logic.

Suggestion: It would be better if you push fully working and tested code that reflects the intended behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants