-
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
Exposing chain names together with selectors #9
Conversation
0098d2a
to
ad3c880
Compare
ad3c880
to
4261336
Compare
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.
🎉
@@ -46,14 +52,14 @@ func parseYml(ymlFile []byte) map[uint64]uint64 { | |||
func EvmChainIdToChainSelector() map[uint64]uint64 { | |||
copyMap := make(map[uint64]uint64, len(evmChainIdToChainSelector)) | |||
for k, v := range evmChainIdToChainSelector { | |||
copyMap[k] = v | |||
copyMap[k] = v.ChainSelector | |||
} | |||
return copyMap | |||
} | |||
|
|||
func ChainIdFromSelector(chainSelectorId uint64) (uint64, error) { | |||
for k, v := range evmChainIdToChainSelector { |
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.
Nit: since these mappings are all internal/private anyway, should we pre-calculate a chainSelectorToEvmChainId
at init time, and use here? The memory increase should be minimal, but those may be accessed very often
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 think lib users should use accessing functions like ChainIdFromSelector
instead of accessing the map directly. However, if they for some reason need that map then it's rebuilt every time requested because this is a defensive way to prevent altering the internal state. Returning a single precomputed map may lead to a problem in which if users want to add something to this map, they update it for all. A map is passed by a pointer/reference, not a value.
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.
Yes, I expect this to be accessed from the functions. I was not telling about exposing/returning the map, but just pre-calculating a private one from selectors to chainIds (and maybe also chainIds to names for the other function), instead of having to for
-loop it on every function call. It's the classic memory-cpu tradeoff.
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.
Nice! Thank you.
Exposing chain name together with selectors. It will replace hardcoded values used by EngOps and the CCIP
chainId
as a string.yml
file for both chain names and selectorsWe use the following pattern for all names: