-
Notifications
You must be signed in to change notification settings - Fork 4
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
[feat]: Add Chain ID verification against RPC #37
[feat]: Add Chain ID verification against RPC #37
Conversation
This code is not correct, there are 2 main issues:
|
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.
The current solution can result in inconsistent execution of the Relayer on startup, as you've wrapped the setting of the chainConfig
within a promise on the loadChainsConfig()
function. Since loadChainsConfig()
is not an asynchronous function, and you're not awaiting the new logic, there is no guarantee that by the time loadChainsConfig()
returns the config will be loaded. As a matter of fact, the configuration will not be set (you can verify this by setting a breakpoint after the call to loadChainsConfig()
and inspecting the function output). The code does work, but just because the rest of the Relayer services take just enough time for the promise to resolve, but there is no guarantee that all the launched services will have had accessed the correct configuration. Such code creates bugs that are very hard to debug and should be avoided at all costs.
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.
The code now works and is close to be ready. Requested changes are to include code quality improvements, and to make sure that the result of the newly introduced initialize()
function is awaited (with the current version of the code this is strictly not required, but it can be confusing in the future that changes made within the initialize()
function are not final before the Relayer intiates).
src/config/config.service.ts
Outdated
@@ -24,6 +25,11 @@ export class ConfigService { | |||
this.globalConfig = this.loadGlobalConfig(); | |||
this.chainsConfig = this.loadChainsConfig(); | |||
this.ambsConfig = this.loadAMBsConfig(); | |||
this.initialize(); |
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.
Save the promise to a this.isReady
readonly
variable and await that promise before the app initialization (i.e. before the line await app.listen(...)
on main.ts
)
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.
Check if I got the right idea on this comment
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.
You are missing awaiting the isReady
promise on main.ts
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.
Check if now is what you are saying. I think i got it but I'm no 100% sure
d6ae723
to
fba4ada
Compare
This pull request introduces a new method to validate the Chain ID obtained from a given RPC endpoint against an expected Chain ID. The aim is to ensure that the application is connected to the correct blockchain network.