[feat]: Add Chain ID verification against RPC#37
Conversation
|
This code is not correct, there are 2 main issues:
|
jsanmigimeno
left a comment
There was a problem hiding this comment.
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.
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).
| this.globalConfig = this.loadGlobalConfig(); | ||
| this.chainsConfig = this.loadChainsConfig(); | ||
| this.ambsConfig = this.loadAMBsConfig(); | ||
| this.initialize(); |
There was a problem hiding this comment.
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.
Check if I got the right idea on this comment
There was a problem hiding this comment.
You are missing awaiting the isReady promise on main.ts
There was a problem hiding this comment.
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.