You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Found out during the testing that on some environment top-level-await are not properly supported. Which are used to initialize the BLS object if the package is imported directly.
Describe the solution you'd like
The best approach to fit in all cases is to import the BLS from the switchable. And when is appropriate use the init to initialize the object.
importbls,{init}from"@chainsafe/bls/switchable";
That init does accept one parameter and it's redundant to identify and pass the parameter for the right implementation. This logic of detecting is already part of the package so we can reuse here. We can provide third option here auto which could be the default value as well. So user don't need to write custom logic and switchable will detect the right implementation.
Describe alternatives you've considered
The alternative safe approach is to use the await import. But that can't be done with correct user experience as code outside that block will not access to the bls object.
As far as the title of the issue, definitely agree, the switchable thing could/should have an 'auto' setting that is default.
As far as refactoring lodestar to use the switchable thing, I'm more hesitant, would like to have more info first.
I'd like to know which environments don't support top-level-await. According to https://caniuse.com/?search=top%20level%20await it seems that all modern browsers support it? What exactly are we missing by using top-level-await? This is a feature we would have liked to have in our pocket and possibly use elsewhere. Which packages in the lodestar monorepo need to be changed to support these environments?
We originally used the switchable thing everywhere and there are tradeoffs to this approach. Basically boils down to the pattern (explicit initialization + singleton) being non-standard, unintuitive, and more verbose. That isn't just a code hygiene issue, it manifests in different ways during debugging and in downstream use.
Some consumable modules (validator and beacon node) required bls initialization before use - unintuitive for us and for downstream use
All tests that use bls directly or indirectly need to initialize bls - added some bloat to the tests and was a common troubleshooting timesink (eg: a new test failed, was bls properly initialized?)
Is your feature request related to a problem? Please describe.
Found out during the testing that on some environment
top-level-await
are not properly supported. Which are used to initialize the BLS object if the package is imported directly.Describe the solution you'd like
The best approach to fit in all cases is to import the
BLS
from theswitchable
. And when is appropriate use theinit
to initialize the object.That
init
does accept one parameter and it's redundant to identify and pass the parameter for the right implementation. This logic of detecting is already part of the package so we can reuse here. We can provide third option hereauto
which could be the default value as well. So user don't need to write custom logic andswitchable
will detect the right implementation.Describe alternatives you've considered
The alternative safe approach is to use the
await import
. But that can't be done with correct user experience as code outside that block will not access to thebls
object.Additional context
ChainSafe/lodestar#2723
The text was updated successfully, but these errors were encountered: