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 with family specific chain selector support and added solana #70

Merged

Conversation

huangzhen1997
Copy link
Collaborator

@huangzhen1997 huangzhen1997 commented Nov 6, 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.

  • Refactor selector.yml to evm specific, and moved evm specific util function into evm.go. Created ymal for solana and test coverage. Chain agnostic function will be put under selector.go

  • Removed selector_family.yml, family specific yaml file will be used to infer the chain family

@huangzhen1997 huangzhen1997 marked this pull request as ready for review November 6, 2024 21:53
@huangzhen1997 huangzhen1997 requested review from a team as code owners November 6, 2024 21:53
@huangzhen1997 huangzhen1997 changed the title Nonevm 827/add family specific chain selector support Refactor with family specific chain selector support and added solana Nov 6, 2024
SOLANA_TESTNET = SolanaChain{ChainID: "4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY", Selector: 6302590918974934319, Name: "solana-testnet"}
)

var SolanaALL = []SolanaChain{
Copy link
Collaborator Author

@huangzhen1997 huangzhen1997 Nov 6, 2024

Choose a reason for hiding this comment

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

Not used, and not sure that's going to be useful in the future. We might consider just keep the code gen for evm

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason we don't rename this to selectors_evm.yml?

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't believe the file is part of the public API of this package.

Copy link
Contributor

Choose a reason for hiding this comment

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

test_selectors_evm.yml?

@@ -1,3 +1,5 @@
# EVM selectors.
# File doesn't have a family suffix for backwards compatibility.
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't fully understand this comment, this file is not part of the public API of this package?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think for non-Go based applications it is, RMN + some observability afaik @andrevmatos might know more

@@ -0,0 +1,11 @@
selectors:
"5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d":
Copy link
Contributor

Choose a reason for hiding this comment

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

What kind of string is this? Are there any docs we can link to in solana.go?

Copy link
Collaborator

Choose a reason for hiding this comment

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

its a base58 encoded 32 byte hash. +1 we should add a link to where it came from and some comments explaining that

return copyMap
}

func ChainIdFromSelector(chainSelectorId uint64) (uint64, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Recommendation: mark this function as deprecated and create a parallel func EVMChainIDFromChainSelector to make it clear this is EVM which should be used instead. The "chain ID" concept should now be abstract and be more scoped with the chain family that you want a chain ID for. Feels like someone can easily use this without intending to and run into issues.

func EVMChainIDFromSelector(chainSelector uint64) (*big.Int, error) {
// .. impl
// btw, chain IDs are technically uint256
}

// Deprecated: use EVMChainIDFromSelector instead
func ChainIdFromSelector(chainSelectorId uint64) (uint64, error) {
// ...
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if it might be easier conceptually to just leave it as "Chain" is an EVM chain and then otherwise have a family prefix like SolXXX?

return 0, fmt.Errorf("chain not found for chain selector %d", chainSelectorId)
}

func SelectorFromChainId(chainId uint64) (uint64, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto here re: deprecation see above.

return 0, fmt.Errorf("chain selector not found for chain %d", chainId)
}

func NameFromChainId(chainId uint64) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto here re: deprecation

return details.ChainName, nil
}

func ChainIdFromName(name string) (uint64, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto here re: deprecation

return 0, fmt.Errorf("chain not found for name %s", name)
}

func TestChainIds() []uint64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto here re: deprecation

return chainIds
}

func ChainBySelector(sel uint64) (Chain, bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto here re: deprecation

Comment on lines +137 to +138
// We always return true since only evm chains are supported atm.
return true, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

This is incorrect, should return false if its solana

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the condition is a bit confusing but still looks correct to me. ChainBySelector is EVM only, so if it does exist there it is EVM

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops you're right, misread ChainBySelector already. Was already thinking it'd be chain agnostic hehe

@makramkd
Copy link
Contributor

makramkd commented Nov 7, 2024

I think this is OK, v2 package and a clean break seems better to me though.

if err != nil {
panic(err)
}
return data.SelectorsBySolanaChainId
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's add a genesis hash validation like:

	for genesisHash := range data.SelectorsBySolanaChainId {
		b, err := base58.Decode(genesisHash)
		if err != nil {
			panic(fmt.Errorf("failed to decode base58 genesis hash %s: %w", genesisHash, err))
		}
		if len(b) != 32 {
			panic(fmt.Errorf("decoded genesis hash %s is not 32 bytes long", genesisHash))
		}
	}

Copy link
Collaborator

Choose a reason for hiding this comment

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

can use github.com/mr-tron/base58

connorwstein
connorwstein previously approved these changes Nov 7, 2024
Copy link
Collaborator

@connorwstein connorwstein left a comment

Choose a reason for hiding this comment

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

Should add validation for the genesis hashes and documentation for them o/w lgtm.

@connorwstein connorwstein merged commit 611fd57 into main Nov 7, 2024
1 check passed
@connorwstein connorwstein deleted the NONEVM-827/add-family-specific-chain-selector-support branch November 7, 2024 18:59
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.

3 participants