-
-
Notifications
You must be signed in to change notification settings - Fork 311
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
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## unstable #6513 +/- ##
============================================
- Coverage 61.72% 61.55% -0.18%
============================================
Files 555 556 +1
Lines 58302 58586 +284
Branches 1846 1847 +1
============================================
+ Hits 35985 36060 +75
- Misses 22277 22486 +209
Partials 40 40 |
Performance Report✔️ no performance regression detected Full benchmark results
|
packages/light-client/src/index.ts
Outdated
@@ -149,15 +150,16 @@ export class Lightclient { | |||
static async initializeFromCheckpointRoot( | |||
args: Omit<LightclientInitArgs, "bootstrap"> & { | |||
checkpointRoot: phase0.Checkpoint["root"]; | |||
blsImplementation?: Implementation; |
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
setHasher(hasher); |
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.
they introduce fragility and break expectations.
How does this change expectations though? From the code I would expect now I can do this
lc1.initializeFromCheckpointRoot({blsImplementation: "herumi"})
// this light client instance will use different bls implementation
lc2.initializeFromCheckpointRoot({blsImplementation: "blst-native"})
but does this actually work and it that the intended use case?
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.
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.
How does this change expectations though? From the code I would expect now I can do this
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 to karma
). Indeed, some code changes might force init
to be already done before this code is reached.
A better solution might be:
- to remove
init
code fromlight-client
- to address configurability directly in
bls
library
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 see two patterns we can follow here
- either use dependency injection
- or load and set internally
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.
they introduce fragility and break expectations.
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 when setHasher
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.
🎉 This PR is included in v1.18.0 🎉 |
Motivation
Remove
bls
init
code previously required for karma.