hedera-json-rpc-relay
hedera-json-rpc-relay copied to clipboard
feat: capture env variables into sigleton and reusable constants
Description:
Currently, we are dynamically getting the environment variables and parsing/casting them every time. This is inefficient and also, more importantly, allows env configurations to be dynamically changed, which can modify the behavior of the relay based on the current values of the env vars, which can be a potential exploit.
Solution:
We should change this to only capture them once when the relay is initialized and reuse those as constants
Related issue(s):
Fixes #2686
Notes for reviewer:
- created a new package that holds the
env-provider
singleton - the
env-provider
package is added as a dependency torelay
,server
, andws-server
- in the perfect world, the
env-provider
must be immutable and should not provide an interface for overriding or extending once-loaded environment variables but there are many tests where we dynamically override envs in order to test specific cases so we should add these interfaces as well - the main review should be applied to the
env-provider
package - almost all of the changes are just replaced values from
process.env.<VAR_NAME>
toEnvProviderService.getInstance().get(<VAR_NAME>)
- in the test cases if overrides are needed, they are done like that -
process.env.CHAIN_ID = '0x160c'
is transformed toEnvProviderService.getInstance().dynamicOverride('CHAIN_ID', '0x160c')
Checklist
- [ ] Documented (Code comments, README, etc.)
- [ ] Tested (unit, integration, etc.)