Skip to content
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

Refactor chain-selector to use chain specific chainID #65

Closed
wants to merge 21 commits into from

Conversation

huangzhen1997
Copy link
Collaborator

@huangzhen1997 huangzhen1997 commented Oct 30, 2024

https://smartcontract-it.atlassian.net/browse/NONEVM-827

  • To generalize plugin component to support Solana, we need to help CCIP team to refactor chain-selector. The existing chainID is uint64, this PR converts it to string since for solana we will use genesis hash as chainID.

  • Instead of use previous selector.yml (chainID-> {selector+name}) and selector_families(selector -> family), provides a reconstructed config using selector -> {chainID + name + family}, and making chainID a string instead of uint64.

  • update rest of the code/test to use the selector_restructured.yml config that key by selector. The original selectors.yml and selector_families.yml are left for reference and can be removed in a following PR.

  • preserve the existing functions that use uint64 chainID for backward compatibility, but mark as deprecated

@huangzhen1997 huangzhen1997 changed the title initial work for adding chain family specific id and remove old selec… Refactor chain-selector to use chain specific chainID Oct 30, 2024
@huangzhen1997 huangzhen1997 marked this pull request as ready for review November 2, 2024 01:01
@huangzhen1997 huangzhen1997 requested a review from a team as a code owner November 2, 2024 01:01
@huangzhen1997 huangzhen1997 marked this pull request as draft November 2, 2024 01:05
@huangzhen1997 huangzhen1997 marked this pull request as ready for review November 4, 2024 20:59
@huangzhen1997 huangzhen1997 requested a review from a team as a code owner November 4, 2024 20:59
if exist {
chainIDToSelectorMapForFamily[v.Family][v.ChainID] = k
} else {
chainIDToSelectorMapForFamily[v.Family] = make(map[string]uint64)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to also call the below for this case right:
chainIDToSelectorMapForFamily[v.Family][v.ChainID] = k

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, thanks

selectors.go Outdated
func NameFromChainId(chainId uint64) (string, error) {
details, exist := evmChainIdToChainSelector[chainId]
func NameFromChainIdAndFamily(chainId string, family string) (string, error) {
// if family is missing use EVM as default

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of duplicating all this code from above function, just call that?
SelectorFromChainIdAndFamily()
Then from selector, just fetch details.


for _, v := range selectorToChainDetails {
if v.Name == name && family == v.Family {
return v.ChainID, nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has our schema enforced anywhere that name, family paid must be unique?
I know practically we use unique names, but nothing currently prevents from someone naming say 2 different EVM chains as same?

Just wondering, if we leave that logic as it-is, or add some validation?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could add a unit-test to ensure that name+family combination should not have duplicates, if others agree with this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added TestNoSameChainIDAndFamilyAreGenerated

selectors.go Outdated
if exist {
testChainIDToSelectorMapForFamily[v.Family][v.ChainID] = k
} else {
testChainIDToSelectorMapForFamily[v.Family] = make(map[string]uint64)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, I am actually going to combine regular and test chains, noticed var evmChainIdToChainSelector = loadAllSelectors() has the two combined

@andrevmatos
Copy link
Contributor

The original selectors.yml and selector_families.yml are left for reference and can be removed in a following PR.

Be careful, this project is public, and many internal and external dependents require exact format, and even hardcode the selectors.yml URL from this repo. Any such change should be a major version bump, and we'd be better doing as much as we can to keep backwards compatibility on this.

@huangzhen1997
Copy link
Collaborator Author

The original selectors.yml and selector_families.yml are left for reference and can be removed in a following PR.

Be careful, this project is public, and many internal and external dependents require exact format, and even hardcode the selectors.yml URL from this repo. Any such change should be a major version bump, and we'd be better doing as much as we can to keep backwards compatibility on this.

I kept function like SelectorFromChainId() and ChainIdFromName() for backward compatibility

Copy link
Contributor

@makramkd makramkd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets cut a major version - create a v2 directory and place all these changes there?

@huangzhen1997
Copy link
Collaborator Author

Replaced with #70

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants