-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
channeldb: avoid creating empty buckets #1745
Conversation
Needs a rebase! |
There was a problem hiding this 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.
befdf47
to
82bd43a
Compare
Rebased! |
82bd43a
to
9f7daea
Compare
return err | ||
nodes := tx.Bucket(nodeBucket) | ||
if nodes == nil { | ||
return ErrSourceNodeNotSet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong error returned?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
Avoids creating a bucket unneccessarily.
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.
9f7daea
to
70aeda1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎢
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: