-
-
Notifications
You must be signed in to change notification settings - Fork 266
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
chore: remove now useless bls init #6513
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Having an internal implementation as part of arguments seems bit strange to me, if this is really required can't we follow same approach used in ssz and discv5, i.e. using a setter function
another example
lodestar/packages/cli/src/applyPreset.ts
Line 9 in 918924e
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.
setHasher
is setting some global then? I think we should move away from those, they introduce fragility and break expectations.e.g.
setImplementation
could be called after the init is done, making it void.There is a similar issue with the active preset, where you have to do things in the right order or it breaks. It also introduces coupling (or forces lack of coupling) between dependencies.
In general I fell like explicit is better over implicit (env variable, global variable), and letting user decide of implementation sounds like 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.
How does this change expectations though? From the code I would expect now I can do this
but does this actually work and it that the intended use case?
This is a protection that ensures preset values can't be modified after those are loaded, much better to throw an error explicitly than to risk inconsistencies.
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.
It looks marginally better to me but indeed there is still room to shoot yourself in the foot.
Your comment made me realize that having explicit
init
specifically here is probably wrong (and hopefully not required anymore as related tokarma
). Indeed, some code changes might forceinit
to be already done before this code is reached.A better solution might be:
init
code fromlight-client
bls
libraryThere 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.
I see two patterns we can follow here
If we wanna use dependency injection, the whole implementation should be passed imo and not just a name which then causing the library to be loaded internally.
I feel like the change in this PR was mixing both concepts.
I think the safest approach is to allow setter to be called exactly once to ensure same implementation is used globally. Dependency injection gives more flexibility but also has the risk that you have to pass the implementation in possibly multiple places and you might accidentally miss one and it implicitly uses a default / fallback implementation.
That's how
setHasher
works and I think it's good for this use case as you would usually wanna use same hashing implementation across the whole project.maybe @wemeetagain can give some more insights on this
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.
I shared some ideas here: ChainSafe/bls#157
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.
With
setHasher
, user must ensure that the call is made at the right moment or there is a risk of having some default implementation being used (the one that kicks in whensetHasher
is not called).Combined with other libs being intertwined, this looks a bit fragile to me (and hard to know for sure the call has been properly taken into consideration).
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.
Removed the implementation selection, this code was specific to karma anyway.