lnd icon indicating copy to clipboard operation
lnd copied to clipboard

channeldb: fix db name in test

Open matheusd opened this issue 1 year ago • 9 comments

Prior to this change, two database files were actually initialized (cdb and channel.db), therefore the test was not actually exercising what it meant to.

!lightninglabs-deploy mute

matheusd avatar Feb 05 '24 19:02 matheusd

[!IMPORTANT]

Auto Review Skipped

Auto reviews are limited to the following labels: llm-review. Please add one of these labels to enable auto reviews.

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.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

coderabbitai[bot] avatar Feb 05 '24 19:02 coderabbitai[bot]

Ok, so the kvdb_sqlite is failing because... Open() only ever opens bbolt dbs. Should this test also be skipped in sqlite mode?

matheusd avatar Feb 05 '24 19:02 matheusd

It's approved already, I'm not sure I'm not sure I'm supposed to do anything else?

matheusd avatar Feb 26 '24 10:02 matheusd

In https://github.com/lightningnetwork/lnd/blob/master/channeldb/db.go#L348-L355:

Try to use

https://github.com/lightningnetwork/lnd/blob/master/kvdb/backend.go#L247

so that we don't have to skip any backends, wdyt ?

ziggie1984 avatar Feb 26 '24 15:02 ziggie1984

In https://github.com/lightningnetwork/lnd/blob/master/channeldb/db.go#L348-L355:

Try to use

https://github.com/lightningnetwork/lnd/blob/master/kvdb/backend.go#L247

so that we don't have to skip any backends, wdyt ?

See my other comment too, but the PR is good as is, as it creates the test backend and uses that backend to create the channeldb (db_test:40).

bhandras avatar Feb 28 '24 06:02 bhandras

so that we don't have to skip any backends, wdyt ?

If I understand what you're suggesting and you mean modifying channeldb.Open() to support all backends, then it seems correct to me (Open() should support all backends).

However that's a much bigger change than the one intended for this PR, because all call sites assume a bolt backend so a lot of things (and even external user code using channeldb) could break with this change.

matheusd avatar Feb 28 '24 10:02 matheusd

so that we don't have to skip any backends, wdyt ?

If I understand what you're suggesting and you mean modifying channeldb.Open() to support all backends, then it seems correct to me (Open() should support all backends).

However that's a much bigger change than the one intended for this PR, because all call sites assume a bolt backend so a lot of things (and even external user code using channeldb) could break with this change.

channeldb already has CreateWithBackend() which we already use in this test (and elsewhere).

bhandras avatar Feb 28 '24 13:02 bhandras

See my other comment too, but the PR is good as is, as it creates the test backend and uses that backend to create the channeldb (db_test:40).

Are you sure? This test fails because of what I was referring to:

make unit-debug tags=kvdb_sqlite timeout=5m pkg=channeldb case=TestOpenWithCreate

because we open by default with the bbolt db (which does not exist) thats why I was suggesting removing this in: https://github.com/lightningnetwork/lnd/blob/master/channeldb/db.go#L348-L355

    db_test.go:54:
        	Error Trace:	/Users/ziggie-pro/working_freetime/lnd/channeldb/db_test.go:54
        	Error:      	Received unexpected error:
        	            	file size too small
        	Test:       	TestOpenWithCreate
        	Messages:   	unable to create channeldb
--- FAIL: TestOpenWithCreate (0.01s)

I think we can just replace the Bolt db call:

	// Next, create channeldb for the first time.
	backend, backendCleanup, err := kvdb.GetTestBackend(dbPath, dbName)
	if err != nil {
		backendCleanup()
		return nil, err
	}

	// backend, err := kvdb.GetBoltBackend(&kvdb.BoltBackendConfig{
	// 	DBPath:            dbPath,
	// 	DBFileName:        dbName,
	// 	NoFreelistSync:    opts.NoFreelistSync,
	// 	AutoCompact:       opts.AutoCompact,
	// 	AutoCompactMinAge: opts.AutoCompactMinAge,
	// 	DBTimeout:         opts.DBTimeout,
	// })
	// if err != nil {
	// 	return nil, err
	// }

but yeah need to analyse for potential side effects, wdyt @bhandras ?

ziggie1984 avatar Feb 28 '24 20:02 ziggie1984

@matheusd, remember to re-request review from reviewers when ready

lightninglabs-deploy avatar May 09 '24 02:05 lightninglabs-deploy

I will take this PR over if its ok for you @matheusd

ziggie1984 avatar May 09 '24 14:05 ziggie1984

I will take this PR over if its ok for you @matheusd

Feel free.

matheusd avatar May 09 '24 14:05 matheusd