-
Notifications
You must be signed in to change notification settings - Fork 0
refactor(mcms): inline set-config sequences and add idempotency keys #94
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
Open
graham-chainlink
wants to merge
1
commit into
main
Choose a base branch
from
ggoh/refactor-set-config-sequence-cleanup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ package evmsetconfig | |
| import ( | ||
| "fmt" | ||
| "math/big" | ||
| "strconv" | ||
|
|
||
| "github.com/Masterminds/semver/v3" | ||
| "github.com/ethereum/go-ethereum/common" | ||
|
|
@@ -11,75 +12,11 @@ import ( | |
| cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" | ||
| cldfproposalutils "github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/mcms/proposalutils" | ||
| "github.com/smartcontractkit/chainlink-deployments-framework/operations" | ||
| mcmsTypes "github.com/smartcontractkit/mcms/types" | ||
| mcmstypes "github.com/smartcontractkit/mcms/types" | ||
|
|
||
| setconfig "github.com/smartcontractkit/cld-changesets/mcms/changesets/set-config" | ||
| ) | ||
|
|
||
| // SeqEVMSetConfigInput is the input for the generic EVM set-config sequence. | ||
| type SeqEVMSetConfigInput struct { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. flattening this sequence into the parent sequence as this adds unnecessary extra layer of sequence |
||
| ChainSelector uint64 `json:"chainSelector"` | ||
| NoSend bool `json:"noSend"` | ||
| GasBoostConfig *cldfproposalutils.GasBoostConfig `json:"gasBoostConfig,omitempty"` | ||
| Targets []MCMSetConfigTarget `json:"targets"` | ||
| } | ||
|
|
||
| // SeqEVMSetConfig sets config on each provided MCM contract via OpEVMSetConfigMCM. | ||
| var SeqEVMSetConfig = operations.NewSequence( | ||
| "seq-evm-mcm-set-config", | ||
| semver.MustParse("1.0.0"), | ||
| "Sets MCMS config on one or more MCM contracts", | ||
| func(b operations.Bundle, deps cldf_evm.Chain, in SeqEVMSetConfigInput) (sequenceutils.OnChainOutput, error) { | ||
| if in.ChainSelector != deps.Selector { | ||
| return sequenceutils.OnChainOutput{}, fmt.Errorf("mismatch between inputted chain selector and selector defined within dependencies: %d != %d", in.ChainSelector, deps.Selector) | ||
| } | ||
|
|
||
| var outs []EVMCallOutput | ||
| if in.NoSend { | ||
| outs = make([]EVMCallOutput, 0, len(in.Targets)) | ||
| } | ||
|
|
||
| for _, target := range in.Targets { | ||
| opReport, err := operations.ExecuteOperation( | ||
| b, | ||
| OpEVMSetConfigMCM, | ||
| deps, | ||
| OpEVMSetConfigInput{ | ||
| Target: target, | ||
| NoSend: in.NoSend, | ||
| }, | ||
| retrySetConfigWithGasBoost(in.GasBoostConfig), | ||
| ) | ||
| if err != nil { | ||
| return sequenceutils.OnChainOutput{}, err | ||
| } | ||
|
|
||
| if !in.NoSend { | ||
| continue | ||
| } | ||
|
|
||
| out := opReport.Output | ||
| out.ContractType = target.ContractType | ||
| outs = append(outs, out) | ||
| } | ||
|
|
||
| out := sequenceutils.OnChainOutput{} | ||
| if !in.NoSend { | ||
| return out, nil | ||
| } | ||
|
|
||
| batch, err := evmCallOutputsToBatch(in.ChainSelector, outs) | ||
| if err != nil { | ||
| return sequenceutils.OnChainOutput{}, err | ||
| } | ||
| if len(batch.Transactions) > 0 { | ||
| out.BatchOps = []mcmsTypes.BatchOperation{batch} | ||
| } | ||
|
|
||
| return out, nil | ||
| }, | ||
| ) | ||
|
|
||
| var seqSetConfig = operations.NewSequence( | ||
| "seq-evm-set-config-mcms", | ||
| semver.MustParse("1.0.0"), | ||
|
|
@@ -102,21 +39,52 @@ func runEVMSetConfig( | |
| return sequenceutils.OnChainOutput{}, err | ||
| } | ||
|
|
||
| seqReport, err := operations.ExecuteSequence( | ||
| b, | ||
| SeqEVMSetConfig, | ||
| chain, | ||
| SeqEVMSetConfigInput{ | ||
| ChainSelector: in.ChainSelector, | ||
| NoSend: in.MCMS != nil, | ||
| Targets: targets, | ||
| }, | ||
| ) | ||
| useMCMS := in.MCMS != nil | ||
|
|
||
| var outs []EVMCallOutput | ||
| if useMCMS { | ||
| outs = make([]EVMCallOutput, 0, len(targets)) | ||
| } | ||
|
|
||
| for _, target := range targets { | ||
| opReport, execErr := operations.ExecuteOperation( | ||
| b, | ||
| OpEVMSetConfigMCM, | ||
| chain, | ||
| OpEVMSetConfigInput{ | ||
| Target: target, | ||
| NoSend: useMCMS, | ||
| }, | ||
| retrySetConfigWithGasBoost(nil), | ||
| operations.WithIdempotencyKey[OpEVMSetConfigInput, cldf_evm.Chain](strconv.FormatUint(chain.Selector, 10)+":"+target.Address.Hex()), | ||
| ) | ||
| if execErr != nil { | ||
| return sequenceutils.OnChainOutput{}, execErr | ||
| } | ||
|
|
||
| if !useMCMS { | ||
| continue | ||
| } | ||
|
|
||
| out := opReport.Output | ||
| out.ContractType = target.ContractType | ||
| outs = append(outs, out) | ||
| } | ||
|
|
||
| out := sequenceutils.OnChainOutput{} | ||
| if !useMCMS { | ||
| return out, nil | ||
| } | ||
|
|
||
| batch, err := evmCallOutputsToBatch(in.ChainSelector, outs) | ||
| if err != nil { | ||
| return sequenceutils.OnChainOutput{}, fmt.Errorf("failed to execute EVM set config sequence: %w", err) | ||
| return sequenceutils.OnChainOutput{}, err | ||
| } | ||
| if len(batch.Transactions) > 0 { | ||
| out.BatchOps = []mcmstypes.BatchOperation{batch} | ||
| } | ||
|
|
||
| return seqReport.Output, nil | ||
| return out, nil | ||
| } | ||
|
|
||
| func setConfigTargets(e cldf.Environment, configs []setconfig.ContractSetConfig) ([]MCMSetConfigTarget, error) { | ||
|
|
@@ -141,10 +109,10 @@ func setConfigTargets(e cldf.Environment, configs []setconfig.ContractSetConfig) | |
| return targets, nil | ||
| } | ||
|
|
||
| func evmCallOutputsToBatch(chainSelector uint64, outs []EVMCallOutput) (mcmsTypes.BatchOperation, error) { | ||
| result := mcmsTypes.BatchOperation{ | ||
| ChainSelector: mcmsTypes.ChainSelector(chainSelector), | ||
| Transactions: []mcmsTypes.Transaction{}, | ||
| func evmCallOutputsToBatch(chainSelector uint64, outs []EVMCallOutput) (mcmstypes.BatchOperation, error) { | ||
| result := mcmstypes.BatchOperation{ | ||
| ChainSelector: mcmstypes.ChainSelector(chainSelector), | ||
| Transactions: []mcmstypes.Transaction{}, | ||
| } | ||
|
|
||
| for _, out := range outs { | ||
|
|
@@ -161,7 +129,7 @@ func evmCallOutputsToBatch(chainSelector uint64, outs []EVMCallOutput) (mcmsType | |
| []string{}, | ||
| ) | ||
| if err != nil { | ||
| return mcmsTypes.BatchOperation{}, fmt.Errorf("failed to create batch operation for chain %d: %w", chainSelector, err) | ||
| return mcmstypes.BatchOperation{}, fmt.Errorf("failed to create batch operation for chain %d: %w", chainSelector, err) | ||
| } | ||
| result.Transactions = append(result.Transactions, batchOperation.Transactions...) | ||
| } | ||
|
|
||
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
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.
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.
after discussion, we decided to not use operations-gen cli for setconfig but instead use the mcms sdk