Skip to content
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

channeldb: avoid creating empty buckets #1745

Merged

Conversation

halseth
Copy link
Contributor

@halseth halseth commented Aug 17, 2018

This PR removes several cases of the call to CreateBucketIfNotExists within the channel database, from calls where we were not adding anything to the buckets, but rather querying or deleting. This ensures we are not creating empty buckets unnecessarily, and makes it easier to keep track of where the different buckets are initially created.

Note that this change shouldn't alter behaviour of the DB, and aims to return the same errors as would have been returned even when the buckets were created.

TODO:

@halseth halseth added the P3 might get fixed, nice to have label Aug 17, 2018
@Roasbeef
Copy link
Member

Needs a rebase!

Roasbeef
Roasbeef previously approved these changes Dec 4, 2018
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 🎏

Ready to land after a rebase.

@halseth halseth force-pushed the channeldb-avoid-create-buckets branch 3 times, most recently from befdf47 to 82bd43a Compare December 4, 2018 10:25
@halseth
Copy link
Contributor Author

halseth commented Dec 4, 2018

Rebased!

channeldb/graph.go Outdated Show resolved Hide resolved
@halseth halseth force-pushed the channeldb-avoid-create-buckets branch from 82bd43a to 9f7daea Compare December 5, 2018 13:34
return err
nodes := tx.Bucket(nodeBucket)
if nodes == nil {
return ErrSourceNodeNotSet
Copy link
Contributor

Choose a reason for hiding this comment

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

Wrong error returned?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same answer as above :)

nodes, err := tx.CreateBucketIfNotExists(nodeBucket)
if err != nil {
return err
nodes := tx.Bucket(nodeBucket)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the buckets above also don't need to be created.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, but it will change the behavior of the method slightly, which cascades into tests etc.. Tried to keep behavior changes minimal for now :)

It would return ErrEdgeNotFound when edge not found in bucket anyway.
Instead return ErrEdgeNotFound if buckets don't exist. This would be
returned anyway, when the chanIndex is checked for the channel point in
question.
Instead return ErrGraphNodeNotFound directly. If the node bucket was
created it would be empty, and the call delChannelByEdge ->
fetchChanEdgePolicies -> fetchChanEdgePolicy ->
deserializeChanEdgePolicy -> fetchLightningNode would return this error
anyway.
instead return ErEdgeNotFound, which would be returned anyway when
querying the edgeIndex for the channel.
We are deleting what's in the bucket, so if it doesn't exist, just
return early with a non-error.
Lets us avoid passing the tx from pruneGraphNodes
Instead return ErrSourceNodeNotSet directly. This would be returned from
the call pruneGraphNodes -> sourceNode anyway.
@halseth halseth force-pushed the channeldb-avoid-create-buckets branch from 9f7daea to 70aeda1 Compare December 6, 2018 09:26
Copy link
Contributor

@wpaulino wpaulino left a comment

Choose a reason for hiding this comment

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

LGTM 🎯

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 🎢

@Roasbeef Roasbeef merged commit 11c24d3 into lightningnetwork:master Dec 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 might get fixed, nice to have
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants