-
Notifications
You must be signed in to change notification settings - Fork 3
refactor(mcms): split chain helpers #921
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package mcms | ||
|
|
||
| import ( | ||
| chainsel "github.com/smartcontractkit/chain-selectors" | ||
| "github.com/smartcontractkit/mcms/chainwrappers" | ||
| "github.com/smartcontractkit/mcms/sdk" | ||
| mcmsaptos "github.com/smartcontractkit/mcms/sdk/aptos" | ||
| "github.com/smartcontractkit/mcms/types" | ||
|
|
||
| cldfmcmsadapters "github.com/smartcontractkit/chainlink-deployments-framework/chain/mcms/adapters" | ||
| ) | ||
|
|
||
| func init() { | ||
| registerChainFamilyBuilders( | ||
| chainsel.FamilyAptos, | ||
| buildAptosInspector, | ||
| buildAptosExecutor, | ||
| buildAptosTimelockExecutor, | ||
| ) | ||
| } | ||
|
|
||
| // aptosRoleFromProposal maps the timelock action to the Aptos MCMS role. Use this (or extend it) | ||
| // when CLDF needs Aptos-specific role logic without going through chainwrappers. | ||
| func aptosRoleFromProposal(action types.TimelockAction) (mcmsaptos.TimelockRole, error) { | ||
| return mcmsaptos.AptosRoleFromAction(action) | ||
| } | ||
|
|
||
| func buildAptosInspector( | ||
| acc *cldfmcmsadapters.ChainAccessAdapter, | ||
| action types.TimelockAction, | ||
| chainSelector types.ChainSelector, | ||
| chainMetadata types.ChainMetadata, | ||
| ) (sdk.Inspector, error) { | ||
| if _, err := aptosRoleFromProposal(action); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return chainwrappers.BuildInspector(acc, chainSelector, action, chainMetadata) | ||
| } | ||
|
|
||
| func buildAptosExecutor( | ||
| acc *cldfmcmsadapters.ChainAccessAdapter, | ||
| action types.TimelockAction, | ||
| chainSelector types.ChainSelector, | ||
| encoder sdk.Encoder, | ||
| chainMetadata types.ChainMetadata, | ||
| ) (sdk.Executor, error) { | ||
| if _, err := aptosRoleFromProposal(action); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return chainwrappers.BuildExecutor(acc, chainSelector, encoder, action, chainMetadata) | ||
| } | ||
|
|
||
| func buildAptosTimelockExecutor( | ||
| acc *cldfmcmsadapters.ChainAccessAdapter, | ||
| action types.TimelockAction, | ||
| chainSelector types.ChainSelector, | ||
| chainMetadata types.ChainMetadata, | ||
| ) (sdk.TimelockExecutor, error) { | ||
| if _, err := aptosRoleFromProposal(action); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return chainwrappers.BuildTimelockExecutor(acc, chainSelector, action, chainMetadata) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package mcms | ||
|
|
||
| import ( | ||
| chainsel "github.com/smartcontractkit/chain-selectors" | ||
| "github.com/smartcontractkit/mcms/chainwrappers" | ||
| "github.com/smartcontractkit/mcms/sdk" | ||
| "github.com/smartcontractkit/mcms/types" | ||
|
|
||
| cldfmcmsadapters "github.com/smartcontractkit/chainlink-deployments-framework/chain/mcms/adapters" | ||
| ) | ||
|
|
||
| func init() { | ||
| registerChainFamilyBuilders( | ||
| chainsel.FamilyEVM, | ||
| buildEVMInspector, | ||
| buildEVMExecutor, | ||
| buildEVMTimelockExecutor, | ||
| ) | ||
| } | ||
|
|
||
| func buildEVMInspector( | ||
| acc *cldfmcmsadapters.ChainAccessAdapter, | ||
| action types.TimelockAction, | ||
| chainSelector types.ChainSelector, | ||
| chainMetadata types.ChainMetadata, | ||
| ) (sdk.Inspector, error) { | ||
| return chainwrappers.BuildInspector(acc, chainSelector, action, chainMetadata) | ||
| } | ||
|
|
||
| func buildEVMExecutor( | ||
| acc *cldfmcmsadapters.ChainAccessAdapter, | ||
| action types.TimelockAction, | ||
| chainSelector types.ChainSelector, | ||
| encoder sdk.Encoder, | ||
| chainMetadata types.ChainMetadata, | ||
| ) (sdk.Executor, error) { | ||
| return chainwrappers.BuildExecutor(acc, chainSelector, encoder, action, chainMetadata) | ||
| } | ||
|
|
||
| func buildEVMTimelockExecutor( | ||
| acc *cldfmcmsadapters.ChainAccessAdapter, | ||
| action types.TimelockAction, | ||
| chainSelector types.ChainSelector, | ||
| chainMetadata types.ChainMetadata, | ||
| ) (sdk.TimelockExecutor, error) { | ||
| return chainwrappers.BuildTimelockExecutor(acc, chainSelector, action, chainMetadata) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package mcms | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/smartcontractkit/mcms/sdk" | ||
| "github.com/smartcontractkit/mcms/types" | ||
|
|
||
| cldfmcmsadapters "github.com/smartcontractkit/chainlink-deployments-framework/chain/mcms/adapters" | ||
| ) | ||
|
|
||
| type chainInspectorBuilder func( | ||
| acc *cldfmcmsadapters.ChainAccessAdapter, | ||
| action types.TimelockAction, | ||
| chainSelector types.ChainSelector, | ||
| chainMetadata types.ChainMetadata, | ||
| ) (sdk.Inspector, error) | ||
|
|
||
| type chainExecutorBuilder func( | ||
| acc *cldfmcmsadapters.ChainAccessAdapter, | ||
| action types.TimelockAction, | ||
| chainSelector types.ChainSelector, | ||
| encoder sdk.Encoder, | ||
| chainMetadata types.ChainMetadata, | ||
| ) (sdk.Executor, error) | ||
|
|
||
| type chainTimelockExecutorBuilder func( | ||
| acc *cldfmcmsadapters.ChainAccessAdapter, | ||
| action types.TimelockAction, | ||
| chainSelector types.ChainSelector, | ||
| chainMetadata types.ChainMetadata, | ||
| ) (sdk.TimelockExecutor, error) | ||
|
|
||
| var ( | ||
| chainFamilyInspectorBuilders = map[string]chainInspectorBuilder{} | ||
| chainFamilyExecutorBuilders = map[string]chainExecutorBuilder{} | ||
| chainFamilyTimelockExecutorBuilders = map[string]chainTimelockExecutorBuilder{} | ||
| ) | ||
|
|
||
| // registerChainFamilyBuilders wires one chain family's builders into the dispatch maps. | ||
| // Call from init() in each chain_helpers_<family>.go file. | ||
| func registerChainFamilyBuilders( | ||
| family string, | ||
| inspector chainInspectorBuilder, | ||
| executor chainExecutorBuilder, | ||
| timelockExecutor chainTimelockExecutorBuilder, | ||
| ) { | ||
| if _, dup := chainFamilyInspectorBuilders[family]; dup { | ||
| panic(fmt.Sprintf("mcms: duplicate chain family registration: %q", family)) | ||
| } | ||
| chainFamilyInspectorBuilders[family] = inspector | ||
| chainFamilyExecutorBuilders[family] = executor | ||
| chainFamilyTimelockExecutorBuilders[family] = timelockExecutor | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package mcms | ||
|
|
||
| import ( | ||
| chainsel "github.com/smartcontractkit/chain-selectors" | ||
| "github.com/smartcontractkit/mcms/chainwrappers" | ||
| "github.com/smartcontractkit/mcms/sdk" | ||
| "github.com/smartcontractkit/mcms/types" | ||
|
|
||
| cldfmcmsadapters "github.com/smartcontractkit/chainlink-deployments-framework/chain/mcms/adapters" | ||
| ) | ||
|
|
||
| func init() { | ||
| registerChainFamilyBuilders( | ||
| chainsel.FamilySolana, | ||
| buildSolanaInspector, | ||
| buildSolanaExecutor, | ||
| buildSolanaTimelockExecutor, | ||
| ) | ||
| } | ||
|
|
||
| func buildSolanaInspector( | ||
| acc *cldfmcmsadapters.ChainAccessAdapter, | ||
| action types.TimelockAction, | ||
| chainSelector types.ChainSelector, | ||
| chainMetadata types.ChainMetadata, | ||
| ) (sdk.Inspector, error) { | ||
| return chainwrappers.BuildInspector(acc, chainSelector, action, chainMetadata) | ||
| } | ||
|
|
||
| func buildSolanaExecutor( | ||
| acc *cldfmcmsadapters.ChainAccessAdapter, | ||
| action types.TimelockAction, | ||
| chainSelector types.ChainSelector, | ||
| encoder sdk.Encoder, | ||
| chainMetadata types.ChainMetadata, | ||
| ) (sdk.Executor, error) { | ||
| return chainwrappers.BuildExecutor(acc, chainSelector, encoder, action, chainMetadata) | ||
| } | ||
|
|
||
| func buildSolanaTimelockExecutor( | ||
| acc *cldfmcmsadapters.ChainAccessAdapter, | ||
| action types.TimelockAction, | ||
| chainSelector types.ChainSelector, | ||
| chainMetadata types.ChainMetadata, | ||
| ) (sdk.TimelockExecutor, error) { | ||
| return chainwrappers.BuildTimelockExecutor(acc, chainSelector, action, chainMetadata) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package mcms | ||
|
|
||
| import ( | ||
| chainsel "github.com/smartcontractkit/chain-selectors" | ||
| "github.com/smartcontractkit/mcms/chainwrappers" | ||
| "github.com/smartcontractkit/mcms/sdk" | ||
| mcmssui "github.com/smartcontractkit/mcms/sdk/sui" | ||
| "github.com/smartcontractkit/mcms/types" | ||
|
|
||
| cldfmcmsadapters "github.com/smartcontractkit/chainlink-deployments-framework/chain/mcms/adapters" | ||
| ) | ||
|
|
||
| func init() { | ||
| registerChainFamilyBuilders( | ||
| chainsel.FamilySui, | ||
| buildSuiInspector, | ||
| buildSuiExecutor, | ||
| buildSuiTimelockExecutor, | ||
| ) | ||
| } | ||
|
|
||
| // suiMetadataFromProposal parses Sui-specific fields from MCMS chain metadata. | ||
| func suiMetadataFromProposal(metadata types.ChainMetadata) (mcmssui.AdditionalFieldsMetadata, error) { | ||
| return mcmssui.SuiMetadata(metadata) | ||
| } | ||
|
|
||
| func buildSuiInspector( | ||
| acc *cldfmcmsadapters.ChainAccessAdapter, | ||
| action types.TimelockAction, | ||
| chainSelector types.ChainSelector, | ||
| chainMetadata types.ChainMetadata, | ||
| ) (sdk.Inspector, error) { | ||
| if _, err := suiMetadataFromProposal(chainMetadata); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return chainwrappers.BuildInspector(acc, chainSelector, action, chainMetadata) | ||
| } | ||
|
|
||
| func buildSuiExecutor( | ||
| acc *cldfmcmsadapters.ChainAccessAdapter, | ||
| action types.TimelockAction, | ||
| chainSelector types.ChainSelector, | ||
| encoder sdk.Encoder, | ||
| chainMetadata types.ChainMetadata, | ||
| ) (sdk.Executor, error) { | ||
| if _, err := suiMetadataFromProposal(chainMetadata); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return chainwrappers.BuildExecutor(acc, chainSelector, encoder, action, chainMetadata) | ||
| } | ||
|
|
||
| func buildSuiTimelockExecutor( | ||
| acc *cldfmcmsadapters.ChainAccessAdapter, | ||
| action types.TimelockAction, | ||
| chainSelector types.ChainSelector, | ||
| chainMetadata types.ChainMetadata, | ||
| ) (sdk.TimelockExecutor, error) { | ||
| if _, err := suiMetadataFromProposal(chainMetadata); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return chainwrappers.BuildTimelockExecutor(acc, chainSelector, action, chainMetadata) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.