DynComms [0/n]: fn package additions#8653
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
464abe1 to
22b714d
Compare
ziggie1984
left a comment
There was a problem hiding this comment.
LGTM, I wonder where you get the inspiration for these library functions, these functions are almost suitable for a general golang library using generics ?
There was a problem hiding this comment.
Seems like the TestProp prefix makes sense to be generalized in our docs, as soon as we do prop testing ? So we have a consistent way throughout the codebase ?
There was a problem hiding this comment.
Yeah I agree. Our prop testing is pretty sparse at the moment but it's my preferred form of testing.
There was a problem hiding this comment.
ok sounds good, will also create property tests next time, they seem to include also the fuzzing component by creating a whole range of input values.
Maybe we can come up with a nice doc guide in the near future what we expect in general from unit tests in the LND codebase.
There was a problem hiding this comment.
Yeah what's also nice about them is that it forces you to think more clearly about what the precise requirements of the system are, as opposed to eyeballing a few test cases and hoping that those cases are enough to make reasonable implementations likely. It's a brittle assumption.
There was a problem hiding this comment.
wondering if it makes sense to generalize it ?
There was a problem hiding this comment.
Generalize what?
There was a problem hiding this comment.
mapping a tuple to an Option Tuple to a value: [T2[A, B]] -> Option[T2[A, B]] -> Option[B], could be part of the tuple definition ?
There was a problem hiding this comment.
I don't think it should be. However, I do think that maybe exporting functions for Fst and Snd is a good idea.
Years of writing Haskell as my native language. Yeah this would be better suited for a golang general lib but I have no desire to do ongoing maintenance of go libraries for the whole golang ecosystem. Further, @Roasbeef doesn't want to depend on external libraries for this kind of thing due to OSS maintainer risk (either malice or just disappearing), which is why we invented the Generally speaking, the |
There was a problem hiding this comment.
Q: what does the comment mean smh ?
There was a problem hiding this comment.
"Shake my head", means disappointment. I was making some commentary about how I couldn't just put len in the field as the type func(string) int even though it would be a sensible thing to be able to do. append has similar issues. Perhaps I should either remove the snarky comment or be more explicit about warning people not to try and refactor it away.
There was a problem hiding this comment.
ok sounds good, will also create property tests next time, they seem to include also the fuzzing component by creating a whole range of input values.
Maybe we can come up with a nice doc guide in the near future what we expect in general from unit tests in the LND codebase.
There was a problem hiding this comment.
mapping a tuple to an Option Tuple to a value: [T2[A, B]] -> Option[T2[A, B]] -> Option[B], could be part of the tuple definition ?
dff47f3 to
728055a
Compare
0398ffe to
f6f92d6
Compare
yyforyongyu
left a comment
There was a problem hiding this comment.
Will review the following PRs to understand the usage.
| // WhenLeft executes the given function if the Either is left. | ||
| func (e Either[L, R]) WhenLeft(f func(L)) { | ||
| e.left.WhenSome(f) | ||
| if !e.isRight { |
There was a problem hiding this comment.
So there's no feedback when calling these WhenLeft or WhenRight? How do the callers know an effect has been applied to an Either obj or not?
There was a problem hiding this comment.
Correct. This function should only be used if we want to conditionally run actions using the inner value on one side. If you need to somehow introspect this value to understand whether the closure was run or not, it's probably better to use ElimEither
| } | ||
| } | ||
|
|
||
| // Iden is the lef and right identity of Comp. It is a function that simply |
There was a problem hiding this comment.
| // Iden is the lef and right identity of Comp. It is a function that simply | |
| // Iden is the left and right identity of Comp. It is a function that simply |
There was a problem hiding this comment.
And would be nice to just name it Identity.
There was a problem hiding this comment.
We can do so but I'd like to offer a couple of reasons I chose Iden instead.
- We have an 80 column limit. This space is quite scarce and
Identakes 5% of it whereasIdentitywould take 10%. - Simplicity opts for the names
idenandcompinstead ofidentityandcompose. Given that it is a well-known Bitcoin project I figured it would provide good intuition
| // contributors may be used to endorse or promote products derived from | ||
| // this software without specific prior written permission. | ||
|
|
||
| // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
There was a problem hiding this comment.
Q: what is this license stuff, or why here but not in other places?
There was a problem hiding this comment.
I source ripped the golang std List and the BSD License they include stipulates that we have to reproduce the license.
|
|
||
| // List represents a doubly linked list. | ||
| // The zero value for List is an empty list ready to use. | ||
| type List[A any] struct { |
There was a problem hiding this comment.
hmm there's already lru.List and lru.Cache tho, and we would prefer lru.Cache as it's memory safe.
There was a problem hiding this comment.
I couldn't find "List". I did find lru.Cache[K, V any], but I fail to understand precisely how that substitutes here.
There was a problem hiding this comment.
Yeah I ripped this in the LRU package for neutrino: https://github.com/lightninglabs/neutrino/blob/master/cache/lru/list.go
| i, a := i, a | ||
| wait.Add(1) | ||
| go func() { | ||
| bs[i] = f(a) |
There was a problem hiding this comment.
I don't understand how it would given that each thread's landing zone is preallocated and distinct.
| bs := make([]B, len(as)) | ||
|
|
||
| for i, a := range as { | ||
| i, a := i, a |
There was a problem hiding this comment.
not sure I understand this swap
There was a problem hiding this comment.
What swap? I think this is just the required loopvar aliasing because go is strange in this way.
There was a problem hiding this comment.
We can drop this safely now (latest Go version).
a5f5c21 to
0a4b0f3
Compare
|
@yyforyongyu: review reminder |
| bs := make([]B, len(as)) | ||
|
|
||
| for i, a := range as { | ||
| i, a := i, a |
There was a problem hiding this comment.
We can drop this safely now (latest Go version).
|
|
||
| // List represents a doubly linked list. | ||
| // The zero value for List is an empty list ready to use. | ||
| type List[A any] struct { |
There was a problem hiding this comment.
Yeah I ripped this in the LRU package for neutrino: https://github.com/lightninglabs/neutrino/blob/master/cache/lru/list.go
This commit removes Reduce since we already have both Foldl and Foldr.
| go 1.19 | ||
|
|
||
| require ( | ||
| github.com/lightninglabs/neutrino/cache v1.1.2 |
NOTE: This change is part of a series implementing Dynamic Commitments.
Change Description
This adds some useful library functions that will allow us to capture patterns we often use throughout the codebase. None of the code in this PR has any direct bearing on Dynamic Commitments but it is generally useful infrastructure that will be assumed to be available in future PRs in the series.
Steps to Test
N/A
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.