-
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
Refactor with family specific chain selector support and added solana #70
Refactor with family specific chain selector support and added solana #70
Conversation
SOLANA_TESTNET = SolanaChain{ChainID: "4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY", Selector: 6302590918974934319, Name: "solana-testnet"} | ||
) | ||
|
||
var SolanaALL = []SolanaChain{ |
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.
Not used, and not sure that's going to be useful in the future. We might consider just keep the code gen for evm
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.
Is there a reason we don't rename this to selectors_evm.yml?
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.
Don't believe the file is part of the public API of this package.
test_selectors.yml
Outdated
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.
test_selectors_evm.yml?
@@ -1,3 +1,5 @@ | |||
# EVM selectors. | |||
# File doesn't have a family suffix for backwards compatibility. |
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.
Don't fully understand this comment, this file is not part of the public API of this package?
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 for non-Go based applications it is, RMN + some observability afaik @andrevmatos might know more
selectors_solana.yml
Outdated
@@ -0,0 +1,11 @@ | |||
selectors: | |||
"5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d": |
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.
What kind of string is this? Are there any docs we can link to in solana.go?
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.
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) { |
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.
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) {
// ...
}
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 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) { |
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.
Ditto here re: deprecation see above.
return 0, fmt.Errorf("chain selector not found for chain %d", chainId) | ||
} | ||
|
||
func NameFromChainId(chainId uint64) (string, error) { |
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.
Ditto here re: deprecation
return details.ChainName, nil | ||
} | ||
|
||
func ChainIdFromName(name string) (uint64, error) { |
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.
Ditto here re: deprecation
return 0, fmt.Errorf("chain not found for name %s", name) | ||
} | ||
|
||
func TestChainIds() []uint64 { |
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.
Ditto here re: deprecation
return chainIds | ||
} | ||
|
||
func ChainBySelector(sel uint64) (Chain, bool) { |
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.
Ditto here re: deprecation
// We always return true since only evm chains are supported atm. | ||
return true, nil |
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.
This is incorrect, should return false if its solana
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 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
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.
Oops you're right, misread ChainBySelector already. Was already thinking it'd be chain agnostic hehe
I think this is OK, v2 package and a clean break seems better to me though. |
if err != nil { | ||
panic(err) | ||
} | ||
return data.SelectorsBySolanaChainId |
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.
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))
}
}
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.
can use github.com/mr-tron/base58
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.
Should add validation for the genesis hashes and documentation for them o/w lgtm.
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