-
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
tlv: Added bool to primitive #8057
Conversation
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.
Thanks for the PR!
Did a quick pass and approved the CI run.
Just a reminder to everyone that these are changes in a submodule, so they will only be accessible in the main lnd
code once we merge the PR and push a new tag for the submodule.
Thanks @guggero for the review, as per your comment on it being accessible only after there is a tagged release for lnd, would that mean my next PR on persisting channel force close issue on DB which depends on this change would have to wait? |
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.
Two more requests, otherwise looks good!
Also why can't we just use the local tlv package in development, why wait for release?
I didn't mean we have to wait for a release of lnd
itself. I just have to push a new tag for the tlv
package after this PR was merged. Like this for example: https://github.com/lightningnetwork/lnd/releases/tag/tlv%2Fv1.1.1
In the other PR you can temporarily use a replace directive in the go.mod
file:
replace github.com/lightningnetwork/lnd/tlv => ./tlv
That will cause the linter to fail but should allow you access to the changed code. And when the tag is pushed after merging this PR, you simply remove the replace
and instead update the entry for github.com/lightningnetwork/lnd/tlv
to the new version (will likely be v1.1.2
).
@@ -134,6 +134,11 @@ None | |||
is updated](https://github.com/lightningnetwork/lnd/pull/7788) so that LND can | |||
take advantage of the latest filter fetching performance improvements. | |||
|
|||
### Tlv |
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.
The v0.17.0-beta
version has already been released, please move this to the file for 0.18.
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.
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.
Ah, that's only in the staging branch. We'll need to wait for this to be merged: #8059.
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.
Should we change the base branch to 0-18-staging ?
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.
The staging branch is about to be merged into master
, so I think we can just wait a moment and then re-base on master
.
Or if you want to update this PR without waiting, you can change the base to 0-18-staging-rebased
instead.
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.
Can be updated now, the 0.18 staging branch was merged into master
.
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.
thanks, done
tlv/primitive.go
Outdated
@@ -362,3 +362,29 @@ func SizeBigSize(val interface{}) SizeFunc { | |||
return size | |||
} | |||
} | |||
|
|||
// EBool encodes a boolean. An error is returned if val is not a boolean. | |||
func EBool(w io.Writer, val interface{}, buf *[8]byte) error { |
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.
Can we move this primitive type to the types above in the file where all the integers are defined (first the Encoding and followed by the Encoding functions), and also include a EBoolT for custom-like boolean types or is this not really necessary ?
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.
Thanks for the review. I noticed that the new functions I added in this file should be above the SizeBigSize
function, is that what you are referring to? as for EBoolT
, never thought about that if you feel that there will be a good use case fir that, I will include it.
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.
Yes either before SízeBigSize
but I even recommend to sort it anywhere after the func DUint64
and before func EBytes32
because to me a bool is way more equal to the basic type like the integers rather than bytes (arrays) and custom types which follow after them.
Yeah I mean I would add EBoolT
because if you know you are encoding a boolean you could save a heap allocation as well so better have it and stay inline with the other primitive golang types, but I have not strong feeling about it.
Thanks @guggero really appreciate your explanation. What I want to know is why we cannot make the replace directive for internal packages like |
The problem with using a replace directive permanently (which we used to have a couple of years back) is that those are ignored if you pull in |
120e552
to
76b8755
Compare
Thank you |
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.
Nice PR, 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.
For testing completeness, perhaps we should extend the new TLV fuzz tests in tlv/fuzz_test.go
for the new bool primitive.
if _, err := io.ReadFull(r, buf[:1]); err != nil { | ||
return err | ||
} | ||
*i = buf[0] != 0 |
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.
Maybe we should return an error if val
is not 0 or 1... If that happens when decoding from the DB it's a strong indication that there's a bug or data corruption somewhere.
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.
Thanks for the review, pushed new changes with respect to this.
tlv/fuzz_test.go
Outdated
@@ -97,6 +97,13 @@ func FuzzVarBytes(f *testing.F) { | |||
}) | |||
} | |||
|
|||
func FuzzBool(f *testing.F) { | |||
f.Fuzz(func(t *testing.T, data []byte) { | |||
var val []byte |
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.
val
needs to be a bool
, otherwise this won't go past the first if
in EBool
. The rest looks good!
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.
Thanks all done
Signed-off-by: Ononiwu Maureen <[email protected]>
Signed-off-by: Ononiwu Maureen <[email protected]>
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.
Thanks, 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
@Chinwendu20 I pushed a new tag |
Woohoo! thanks! |
Change Description
This pull request adds bool to the primitive type in tlv as per @guggero's comment in this PR:
https://github.com/lightningnetwork/lnd/pull/7787/files#r1317199032
to persist new data structure in the DB using tlv. While doing that I noticed that one of the data types in the
LocalCloseInfo
type is boolean so that motivated that change.I know we could just change the bool type to an existing integer primitive type and indicate true as 1 and false as 0 but
since bool is part of the primitive data types in golang, it would make sense to include it here.
Made a comment about it in the PR that introduced tlv to lnd 3 weeks ago: #3061 (comment)
to get your thoughts and perspective, yet to receive a reply.
If the concept is acked, I will go ahead to add the release notes to make the CI happy.
I would be happy to close this PR if this makes no sense.
Pull Request Checklist
Testing
Code Style and Documentation
[skip ci]
in the commit message for small changes.📝 Please see our Contribution Guidelines for further guidance.