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

Move Changeset to use a generic type for the config, to avoid a bunch of boilerplate casting. #15195

Merged
merged 4 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions deployment/ccip/changeset/home_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry"
)

var _ deployment.ChangeSet = DeployHomeChain
var _ deployment.ChangeSet[DeployHomeChainConfig] = DeployHomeChain

// DeployHomeChain is a separate changeset because it is a standalone deployment performed once in home chain for the entire CCIP deployment.
func DeployHomeChain(env deployment.Environment, config interface{}) (deployment.ChangesetOutput, error) {
cfg, ok := config.(DeployHomeChainConfig)
if !ok {
return deployment.ChangesetOutput{}, deployment.ErrInvalidConfig
}
func DeployHomeChain(env deployment.Environment, cfg DeployHomeChainConfig) (deployment.ChangesetOutput, error) {

err := cfg.Validate()
if err != nil {
return deployment.ChangesetOutput{}, errors.Wrapf(deployment.ErrInvalidConfig, "%v", err)
Expand Down
8 changes: 2 additions & 6 deletions deployment/ccip/changeset/initial_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ import (
ccipdeployment "github.com/smartcontractkit/chainlink/deployment/ccip"
)

var _ deployment.ChangeSet = InitialDeploy
var _ deployment.ChangeSet[ccipdeployment.DeployCCIPContractConfig] = InitialDeploy

func InitialDeploy(env deployment.Environment, config interface{}) (deployment.ChangesetOutput, error) {
c, ok := config.(ccipdeployment.DeployCCIPContractConfig)
if !ok {
return deployment.ChangesetOutput{}, deployment.ErrInvalidConfig
}
func InitialDeploy(env deployment.Environment, c ccipdeployment.DeployCCIPContractConfig) (deployment.ChangesetOutput, error) {
newAddresses := deployment.NewMemoryAddressBook()
err := ccipdeployment.DeployCCIPContracts(env, newAddresses, c)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion deployment/changeset.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var (
// Its recommended that changesets operate on a small number of chains (e.g. 1-3)
// to reduce the risk of partial failures.
// If the configuration is unexpected type or format, the changeset should return ErrInvalidConfig.
type ChangeSet func(e Environment, config interface{}) (ChangesetOutput, error)
type ChangeSet[C any] func(e Environment, config C) (ChangesetOutput, error)

// ChangesetOutput is the output of a Changeset function.
// Think of it like a state transition output.
Expand Down
9 changes: 2 additions & 7 deletions deployment/keystone/changeset/append_node_capbilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@ import (
"github.com/smartcontractkit/chainlink/deployment/keystone/changeset/internal"
)

var _ deployment.ChangeSet = AppendNodeCapabilities
var _ deployment.ChangeSet[*AppendNodeCapabilitiesRequest] = AppendNodeCapabilities

// AppendNodeCapabilitiesRequest is a request to add capabilities to the existing capabilities of nodes in the registry
type AppendNodeCapabilitiesRequest = MutateNodeCapabilitiesRequest

// AppendNodeCapabilities adds any new capabilities to the registry, merges the new capabilities with the existing capabilities
// of the node, and updates the nodes in the registry host the union of the new and existing capabilities.
func AppendNodeCapabilities(env deployment.Environment, config any) (deployment.ChangesetOutput, error) {
req, ok := config.(*AppendNodeCapabilitiesRequest)
if !ok {
return deployment.ChangesetOutput{}, fmt.Errorf("invalid config type")
}

func AppendNodeCapabilities(env deployment.Environment, req *AppendNodeCapabilitiesRequest) (deployment.ChangesetOutput, error) {
cfg, err := req.convert(env)
if err != nil {
return deployment.ChangesetOutput{}, err
Expand Down
8 changes: 2 additions & 6 deletions deployment/keystone/changeset/deploy_forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ import (
kslib "github.com/smartcontractkit/chainlink/deployment/keystone"
)

var _ deployment.ChangeSet = DeployForwarder
var _ deployment.ChangeSet[uint64] = DeployForwarder

func DeployForwarder(env deployment.Environment, config interface{}) (deployment.ChangesetOutput, error) {
registryChainSel, ok := config.(uint64)
if !ok {
return deployment.ChangesetOutput{}, deployment.ErrInvalidConfig
}
func DeployForwarder(env deployment.Environment, registryChainSel uint64) (deployment.ChangesetOutput, error) {
lggr := env.Logger
// expect OCR3 to be deployed & capabilities registry
regAddrs, err := env.ExistingAddresses.AddressesForChain(registryChainSel)
Expand Down
7 changes: 3 additions & 4 deletions deployment/keystone/changeset/update_don.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry"
)

var _ deployment.ChangeSet = UpdateDon
var _ deployment.ChangeSet[UpdateDonRequest] = UpdateDon

// CapabilityConfig is a struct that holds a capability and its configuration
type CapabilityConfig = internal.CapabilityConfig
Expand All @@ -22,9 +22,8 @@ type UpdateDonResponse struct {
// UpdateDon updates the capabilities of a Don
// This a complex action in practice that involves registering missing capabilities, adding the nodes, and updating
// the capabilities of the DON
func UpdateDon(env deployment.Environment, cfg any) (deployment.ChangesetOutput, error) {
req := cfg.(*UpdateDonRequest)
_, err := internal.UpdateDon(env.Logger, req)
func UpdateDon(env deployment.Environment, req UpdateDonRequest) (deployment.ChangesetOutput, error) {
_, err := internal.UpdateDon(env.Logger, &req)
if err != nil {
return deployment.ChangesetOutput{}, fmt.Errorf("failed to update don: %w", err)
}
Expand Down
9 changes: 3 additions & 6 deletions deployment/keystone/changeset/update_node_capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

chainsel "github.com/smartcontractkit/chain-selectors"

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/environment/clo/models"
kslib "github.com/smartcontractkit/chainlink/deployment/keystone"
Expand All @@ -14,7 +15,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey"
)

var _ deployment.ChangeSet = UpdateNodeCapabilities
var _ deployment.ChangeSet[MutateNodeCapabilitiesRequest] = UpdateNodeCapabilities

type P2PSignerEnc = internal.P2PSignerEnc

Expand Down Expand Up @@ -84,11 +85,7 @@ func (req *MutateNodeCapabilitiesRequest) updateNodeCapabilitiesImplRequest(e de
}

// UpdateNodeCapabilities updates the capabilities of nodes in the registry
func UpdateNodeCapabilities(env deployment.Environment, config any) (deployment.ChangesetOutput, error) {
req, ok := config.(*MutateNodeCapabilitiesRequest)
if !ok {
return deployment.ChangesetOutput{}, fmt.Errorf("invalid config type. want %T, got %T", &MutateNodeCapabilitiesRequest{}, config)
}
func UpdateNodeCapabilities(env deployment.Environment, req MutateNodeCapabilitiesRequest) (deployment.ChangesetOutput, error) {
c, err := req.updateNodeCapabilitiesImplRequest(env)
if err != nil {
return deployment.ChangesetOutput{}, fmt.Errorf("failed to convert request: %w", err)
Expand Down
Loading