From c7c2e89dae3662722c9aea06ae83c5d9e9a1d4f7 Mon Sep 17 00:00:00 2001 From: Cedric Cordenier Date: Mon, 16 Dec 2024 15:43:33 +0000 Subject: [PATCH] [CAPPL-303] Add commands to deploy the workflow registry --- .../append_node_capabilities_test.go | 19 +-- .../changeset/deploy_forwarder_test.go | 17 +-- .../keystone/changeset/deploy_ocr3_test.go | 17 +-- .../keystone/changeset/internal/test/utils.go | 33 +++++ .../{helpers_test.go => test/helpers.go} | 41 ++----- .../keystone/changeset/test/helpers_test.go | 34 ++++++ .../keystone/changeset/update_don_test.go | 17 +-- .../update_node_capabilities_test.go | 19 +-- .../keystone/changeset/update_nodes_test.go | 29 +++-- .../changeset/workflowregistry/deploy.go | 26 ++++ .../changeset/workflowregistry/deploy_test.go | 38 ++++++ .../changeset/workflowregistry/strategies.go | 86 +++++++++++++ .../workflowregistry/update_allowed_dons.go | 81 +++++++++++++ .../update_allowed_dons_test.go | 111 +++++++++++++++++ .../update_authorized_addresses.go | 106 ++++++++++++++++ .../update_authorized_addresses_test.go | 114 ++++++++++++++++++ deployment/keystone/contract_set.go | 15 +++ deployment/keystone/state.go | 11 ++ deployment/keystone/types.go | 1 + .../keystone/workflow_registry_deployer.go | 65 ++++++++++ 20 files changed, 799 insertions(+), 81 deletions(-) rename deployment/keystone/changeset/{helpers_test.go => test/helpers.go} (93%) create mode 100644 deployment/keystone/changeset/test/helpers_test.go create mode 100644 deployment/keystone/changeset/workflowregistry/deploy.go create mode 100644 deployment/keystone/changeset/workflowregistry/deploy_test.go create mode 100644 deployment/keystone/changeset/workflowregistry/strategies.go create mode 100644 deployment/keystone/changeset/workflowregistry/update_allowed_dons.go create mode 100644 deployment/keystone/changeset/workflowregistry/update_allowed_dons_test.go create mode 100644 deployment/keystone/changeset/workflowregistry/update_authorized_addresses.go create mode 100644 deployment/keystone/changeset/workflowregistry/update_authorized_addresses_test.go create mode 100644 deployment/keystone/workflow_registry_deployer.go diff --git a/deployment/keystone/changeset/append_node_capabilities_test.go b/deployment/keystone/changeset/append_node_capabilities_test.go index bfc01b309f5..cf5bfd6752f 100644 --- a/deployment/keystone/changeset/append_node_capabilities_test.go +++ b/deployment/keystone/changeset/append_node_capabilities_test.go @@ -10,6 +10,7 @@ import ( commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset" "github.com/smartcontractkit/chainlink/deployment/common/proposalutils" "github.com/smartcontractkit/chainlink/deployment/keystone/changeset" + "github.com/smartcontractkit/chainlink/deployment/keystone/changeset/test" kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey" ) @@ -29,10 +30,10 @@ func TestAppendNodeCapabilities(t *testing.T) { caps = []kcr.CapabilitiesRegistryCapability{capA, capB} ) t.Run("no mcms", func(t *testing.T) { - te := SetupTestEnv(t, TestConfig{ - WFDonConfig: DonConfig{N: 4}, - AssetDonConfig: DonConfig{N: 4}, - WriterDonConfig: DonConfig{N: 4}, + te := test.SetupTestEnv(t, test.TestConfig{ + WFDonConfig: test.DonConfig{N: 4}, + AssetDonConfig: test.DonConfig{N: 4}, + WriterDonConfig: test.DonConfig{N: 4}, NumChains: 1, }) @@ -58,10 +59,10 @@ func TestAppendNodeCapabilities(t *testing.T) { }) }) t.Run("with mcms", func(t *testing.T) { - te := SetupTestEnv(t, TestConfig{ - WFDonConfig: DonConfig{N: 4}, - AssetDonConfig: DonConfig{N: 4}, - WriterDonConfig: DonConfig{N: 4}, + te := test.SetupTestEnv(t, test.TestConfig{ + WFDonConfig: test.DonConfig{N: 4}, + AssetDonConfig: test.DonConfig{N: 4}, + WriterDonConfig: test.DonConfig{N: 4}, NumChains: 1, UseMCMS: true, }) @@ -108,7 +109,7 @@ func TestAppendNodeCapabilities(t *testing.T) { } // validateUpdate checks reads nodes from the registry and checks they have the expected updates -func validateCapabilityAppends(t *testing.T, te TestEnv, appended map[p2pkey.PeerID][]kcr.CapabilitiesRegistryCapability) { +func validateCapabilityAppends(t *testing.T, te test.TestEnv, appended map[p2pkey.PeerID][]kcr.CapabilitiesRegistryCapability) { registry := te.ContractSets()[te.RegistrySelector].CapabilitiesRegistry wfP2PIDs := p2pIDs(t, maps.Keys(te.WFNodes)) nodes, err := registry.GetNodesByP2PIds(nil, wfP2PIDs) diff --git a/deployment/keystone/changeset/deploy_forwarder_test.go b/deployment/keystone/changeset/deploy_forwarder_test.go index e04bac6d264..f40b0f560c4 100644 --- a/deployment/keystone/changeset/deploy_forwarder_test.go +++ b/deployment/keystone/changeset/deploy_forwarder_test.go @@ -14,6 +14,7 @@ import ( "github.com/smartcontractkit/chainlink/deployment/common/proposalutils" "github.com/smartcontractkit/chainlink/deployment/environment/memory" "github.com/smartcontractkit/chainlink/deployment/keystone/changeset" + "github.com/smartcontractkit/chainlink/deployment/keystone/changeset/test" ) func TestDeployForwarder(t *testing.T) { @@ -56,10 +57,10 @@ func TestConfigureForwarders(t *testing.T) { for _, nChains := range []int{1, 3} { name := fmt.Sprintf("nChains=%d", nChains) t.Run(name, func(t *testing.T) { - te := SetupTestEnv(t, TestConfig{ - WFDonConfig: DonConfig{N: 4}, - AssetDonConfig: DonConfig{N: 4}, - WriterDonConfig: DonConfig{N: 4}, + te := test.SetupTestEnv(t, test.TestConfig{ + WFDonConfig: test.DonConfig{N: 4}, + AssetDonConfig: test.DonConfig{N: 4}, + WriterDonConfig: test.DonConfig{N: 4}, NumChains: nChains, }) @@ -93,10 +94,10 @@ func TestConfigureForwarders(t *testing.T) { for _, nChains := range []int{1, 3} { name := fmt.Sprintf("nChains=%d", nChains) t.Run(name, func(t *testing.T) { - te := SetupTestEnv(t, TestConfig{ - WFDonConfig: DonConfig{N: 4}, - AssetDonConfig: DonConfig{N: 4}, - WriterDonConfig: DonConfig{N: 4}, + te := test.SetupTestEnv(t, test.TestConfig{ + WFDonConfig: test.DonConfig{N: 4}, + AssetDonConfig: test.DonConfig{N: 4}, + WriterDonConfig: test.DonConfig{N: 4}, NumChains: nChains, UseMCMS: true, }) diff --git a/deployment/keystone/changeset/deploy_ocr3_test.go b/deployment/keystone/changeset/deploy_ocr3_test.go index 7a276886242..1aa8f0a0caa 100644 --- a/deployment/keystone/changeset/deploy_ocr3_test.go +++ b/deployment/keystone/changeset/deploy_ocr3_test.go @@ -17,6 +17,7 @@ import ( "github.com/smartcontractkit/chainlink/deployment/environment/memory" kslib "github.com/smartcontractkit/chainlink/deployment/keystone" "github.com/smartcontractkit/chainlink/deployment/keystone/changeset" + "github.com/smartcontractkit/chainlink/deployment/keystone/changeset/test" ) func TestDeployOCR3(t *testing.T) { @@ -54,10 +55,10 @@ func TestConfigureOCR3(t *testing.T) { t.Run("no mcms", func(t *testing.T) { - te := SetupTestEnv(t, TestConfig{ - WFDonConfig: DonConfig{N: 4}, - AssetDonConfig: DonConfig{N: 4}, - WriterDonConfig: DonConfig{N: 4}, + te := test.SetupTestEnv(t, test.TestConfig{ + WFDonConfig: test.DonConfig{N: 4}, + AssetDonConfig: test.DonConfig{N: 4}, + WriterDonConfig: test.DonConfig{N: 4}, NumChains: 1, }) @@ -85,10 +86,10 @@ func TestConfigureOCR3(t *testing.T) { }) t.Run("mcms", func(t *testing.T) { - te := SetupTestEnv(t, TestConfig{ - WFDonConfig: DonConfig{N: 4}, - AssetDonConfig: DonConfig{N: 4}, - WriterDonConfig: DonConfig{N: 4}, + te := test.SetupTestEnv(t, test.TestConfig{ + WFDonConfig: test.DonConfig{N: 4}, + AssetDonConfig: test.DonConfig{N: 4}, + WriterDonConfig: test.DonConfig{N: 4}, NumChains: 1, UseMCMS: true, }) diff --git a/deployment/keystone/changeset/internal/test/utils.go b/deployment/keystone/changeset/internal/test/utils.go index 0a23f7e60a7..21c1736ac8e 100644 --- a/deployment/keystone/changeset/internal/test/utils.go +++ b/deployment/keystone/changeset/internal/test/utils.go @@ -21,14 +21,47 @@ import ( "github.com/smartcontractkit/chainlink/deployment/keystone/changeset/internal" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry" kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry" + workflow_registry "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/workflow/generated/workflow_registry_wrapper" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey" ) +type SetupTestWorkflowRegistryResponse struct { + Registry *workflow_registry.WorkflowRegistry + Chain deployment.Chain + RegistrySelector uint64 + AddressBook deployment.AddressBook +} + +func SetupTestWorkflowRegistry(t *testing.T, lggr logger.Logger, chainSel uint64) *SetupTestWorkflowRegistryResponse { + chain := testChain(t) + + deployer, err := kslib.NewWorkflowRegistryDeployer() + require.NoError(t, err) + resp, err := deployer.Deploy(kslib.DeployRequest{Chain: chain}) + require.NoError(t, err) + + addressBook := deployment.NewMemoryAddressBookFromMap( + map[uint64]map[string]deployment.TypeAndVersion{ + chainSel: map[string]deployment.TypeAndVersion{ + resp.Address.Hex(): resp.Tv, + }, + }, + ) + + return &SetupTestWorkflowRegistryResponse{ + Registry: deployer.Contract(), + Chain: chain, + RegistrySelector: chain.Selector, + AddressBook: addressBook, + } +} + type Don struct { Name string P2PIDs []p2pkey.PeerID CapabilityConfigs []internal.CapabilityConfig } + type SetupTestRegistryRequest struct { P2pToCapabilities map[p2pkey.PeerID][]kcr.CapabilitiesRegistryCapability NopToNodes map[kcr.CapabilitiesRegistryNodeOperator][]*internal.P2PSignerEnc diff --git a/deployment/keystone/changeset/helpers_test.go b/deployment/keystone/changeset/test/helpers.go similarity index 93% rename from deployment/keystone/changeset/helpers_test.go rename to deployment/keystone/changeset/test/helpers.go index f51a4ed610c..1f16a8ea5c0 100644 --- a/deployment/keystone/changeset/helpers_test.go +++ b/deployment/keystone/changeset/test/helpers.go @@ -1,4 +1,4 @@ -package changeset_test +package test import ( "bytes" @@ -6,18 +6,17 @@ import ( "crypto/sha256" "encoding/hex" "errors" - "fmt" "math" "sort" "testing" - "github.com/smartcontractkit/chainlink-common/pkg/logger" - "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" - "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/node" "github.com/stretchr/testify/require" "go.uber.org/zap/zapcore" "golang.org/x/exp/maps" + "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" + "github.com/smartcontractkit/chainlink/deployment" commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset" "github.com/smartcontractkit/chainlink/deployment/common/proposalutils" @@ -26,33 +25,11 @@ import ( "github.com/smartcontractkit/chainlink/deployment/keystone" kslib "github.com/smartcontractkit/chainlink/deployment/keystone" kschangeset "github.com/smartcontractkit/chainlink/deployment/keystone/changeset" + "github.com/smartcontractkit/chainlink/deployment/keystone/changeset/workflowregistry" kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey" ) -func TestSetupTestEnv(t *testing.T) { - t.Parallel() - ctx := tests.Context(t) - for _, useMCMS := range []bool{true, false} { - te := SetupTestEnv(t, TestConfig{ - WFDonConfig: DonConfig{N: 4}, - AssetDonConfig: DonConfig{N: 4}, - WriterDonConfig: DonConfig{N: 4}, - NumChains: 3, - UseMCMS: useMCMS, - }) - t.Run(fmt.Sprintf("set up test env using MCMS: %t", useMCMS), func(t *testing.T) { - require.NotNil(t, te.Env.ExistingAddresses) - require.Len(t, te.Env.Chains, 3) - require.NotEmpty(t, te.RegistrySelector) - require.NotNil(t, te.Env.Offchain) - r, err := te.Env.Offchain.ListNodes(ctx, &node.ListNodesRequest{}) - require.NoError(t, err) - require.Len(t, r.Nodes, 12) - }) - } -} - type DonConfig struct { N int } @@ -143,6 +120,10 @@ func SetupTestEnv(t *testing.T, c TestConfig) TestEnv { Changeset: commonchangeset.WrapChangeSet(kschangeset.DeployForwarder), Config: registryChainSel, }, + { + Changeset: commonchangeset.WrapChangeSet(workflowregistry.Deploy), + Config: registryChainSel, + }, }) require.NoError(t, err) require.NotNil(t, e) @@ -318,7 +299,7 @@ func validateInitialChainState(t *testing.T, env deployment.Environment, registr // all contracts on registry chain registryChainAddrs, err := ad.AddressesForChain(registryChainSel) require.NoError(t, err) - require.Len(t, registryChainAddrs, 3) // registry, ocr3, forwarder + require.Len(t, registryChainAddrs, 4) // registry, ocr3, forwarder, workflowRegistry // only forwarder on non-home chain for sel := range env.Chains { chainAddrs, err := ad.AddressesForChain(sel) @@ -326,7 +307,7 @@ func validateInitialChainState(t *testing.T, env deployment.Environment, registr if sel != registryChainSel { require.Len(t, chainAddrs, 1) } else { - require.Len(t, chainAddrs, 3) + require.Len(t, chainAddrs, 4) } containsForwarder := false for _, tv := range chainAddrs { diff --git a/deployment/keystone/changeset/test/helpers_test.go b/deployment/keystone/changeset/test/helpers_test.go new file mode 100644 index 00000000000..2d06e087db0 --- /dev/null +++ b/deployment/keystone/changeset/test/helpers_test.go @@ -0,0 +1,34 @@ +package test + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" + "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/node" +) + +func TestSetupTestEnv(t *testing.T) { + t.Parallel() + ctx := tests.Context(t) + for _, useMCMS := range []bool{true, false} { + te := SetupTestEnv(t, TestConfig{ + WFDonConfig: DonConfig{N: 4}, + AssetDonConfig: DonConfig{N: 4}, + WriterDonConfig: DonConfig{N: 4}, + NumChains: 3, + UseMCMS: useMCMS, + }) + t.Run(fmt.Sprintf("set up test env using MCMS: %t", useMCMS), func(t *testing.T) { + require.NotNil(t, te.Env.ExistingAddresses) + require.Len(t, te.Env.Chains, 3) + require.NotEmpty(t, te.RegistrySelector) + require.NotNil(t, te.Env.Offchain) + r, err := te.Env.Offchain.ListNodes(ctx, &node.ListNodesRequest{}) + require.NoError(t, err) + require.Len(t, r.Nodes, 12) + }) + } +} diff --git a/deployment/keystone/changeset/update_don_test.go b/deployment/keystone/changeset/update_don_test.go index 012111c4e62..7572cf93b26 100644 --- a/deployment/keystone/changeset/update_don_test.go +++ b/deployment/keystone/changeset/update_don_test.go @@ -10,6 +10,7 @@ import ( "github.com/smartcontractkit/chainlink/deployment/common/proposalutils" "github.com/smartcontractkit/chainlink/deployment/keystone/changeset" "github.com/smartcontractkit/chainlink/deployment/keystone/changeset/internal" + "github.com/smartcontractkit/chainlink/deployment/keystone/changeset/test" kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey" ) @@ -29,10 +30,10 @@ func TestUpdateDon(t *testing.T) { caps = []kcr.CapabilitiesRegistryCapability{capA, capB} ) t.Run("no mcms", func(t *testing.T) { - te := SetupTestEnv(t, TestConfig{ - WFDonConfig: DonConfig{N: 4}, - AssetDonConfig: DonConfig{N: 4}, - WriterDonConfig: DonConfig{N: 4}, + te := test.SetupTestEnv(t, test.TestConfig{ + WFDonConfig: test.DonConfig{N: 4}, + AssetDonConfig: test.DonConfig{N: 4}, + WriterDonConfig: test.DonConfig{N: 4}, NumChains: 1, }) @@ -70,10 +71,10 @@ func TestUpdateDon(t *testing.T) { }) }) t.Run("with mcms", func(t *testing.T) { - te := SetupTestEnv(t, TestConfig{ - WFDonConfig: DonConfig{N: 4}, - AssetDonConfig: DonConfig{N: 4}, - WriterDonConfig: DonConfig{N: 4}, + te := test.SetupTestEnv(t, test.TestConfig{ + WFDonConfig: test.DonConfig{N: 4}, + AssetDonConfig: test.DonConfig{N: 4}, + WriterDonConfig: test.DonConfig{N: 4}, NumChains: 1, UseMCMS: true, }) diff --git a/deployment/keystone/changeset/update_node_capabilities_test.go b/deployment/keystone/changeset/update_node_capabilities_test.go index 87b49acf614..190bc566e7a 100644 --- a/deployment/keystone/changeset/update_node_capabilities_test.go +++ b/deployment/keystone/changeset/update_node_capabilities_test.go @@ -10,6 +10,7 @@ import ( commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset" "github.com/smartcontractkit/chainlink/deployment/common/proposalutils" "github.com/smartcontractkit/chainlink/deployment/keystone/changeset" + "github.com/smartcontractkit/chainlink/deployment/keystone/changeset/test" kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey" ) @@ -29,10 +30,10 @@ func TestUpdateNodeCapabilities(t *testing.T) { caps = []kcr.CapabilitiesRegistryCapability{capA, capB} ) t.Run("no mcms", func(t *testing.T) { - te := SetupTestEnv(t, TestConfig{ - WFDonConfig: DonConfig{N: 4}, - AssetDonConfig: DonConfig{N: 4}, - WriterDonConfig: DonConfig{N: 4}, + te := test.SetupTestEnv(t, test.TestConfig{ + WFDonConfig: test.DonConfig{N: 4}, + AssetDonConfig: test.DonConfig{N: 4}, + WriterDonConfig: test.DonConfig{N: 4}, NumChains: 1, }) @@ -79,10 +80,10 @@ func TestUpdateNodeCapabilities(t *testing.T) { }) }) t.Run("with mcms", func(t *testing.T) { - te := SetupTestEnv(t, TestConfig{ - WFDonConfig: DonConfig{N: 4}, - AssetDonConfig: DonConfig{N: 4}, - WriterDonConfig: DonConfig{N: 4}, + te := test.SetupTestEnv(t, test.TestConfig{ + WFDonConfig: test.DonConfig{N: 4}, + AssetDonConfig: test.DonConfig{N: 4}, + WriterDonConfig: test.DonConfig{N: 4}, NumChains: 1, UseMCMS: true, }) @@ -140,7 +141,7 @@ func TestUpdateNodeCapabilities(t *testing.T) { } // validateUpdate checks reads nodes from the registry and checks they have the expected updates -func validateCapabilityUpdates(t *testing.T, te TestEnv, expected map[p2pkey.PeerID][]kcr.CapabilitiesRegistryCapability) { +func validateCapabilityUpdates(t *testing.T, te test.TestEnv, expected map[p2pkey.PeerID][]kcr.CapabilitiesRegistryCapability) { registry := te.ContractSets()[te.RegistrySelector].CapabilitiesRegistry wfP2PIDs := p2pIDs(t, maps.Keys(te.WFNodes)) nodes, err := registry.GetNodesByP2PIds(nil, wfP2PIDs) diff --git a/deployment/keystone/changeset/update_nodes_test.go b/deployment/keystone/changeset/update_nodes_test.go index 31f71cd9603..33662aa669d 100644 --- a/deployment/keystone/changeset/update_nodes_test.go +++ b/deployment/keystone/changeset/update_nodes_test.go @@ -11,6 +11,7 @@ import ( commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset" "github.com/smartcontractkit/chainlink/deployment/common/proposalutils" "github.com/smartcontractkit/chainlink/deployment/keystone/changeset" + "github.com/smartcontractkit/chainlink/deployment/keystone/changeset/test" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey" ) @@ -18,10 +19,10 @@ func TestUpdateNodes(t *testing.T) { t.Parallel() t.Run("no mcms", func(t *testing.T) { - te := SetupTestEnv(t, TestConfig{ - WFDonConfig: DonConfig{N: 4}, - AssetDonConfig: DonConfig{N: 4}, - WriterDonConfig: DonConfig{N: 4}, + te := test.SetupTestEnv(t, test.TestConfig{ + WFDonConfig: test.DonConfig{N: 4}, + AssetDonConfig: test.DonConfig{N: 4}, + WriterDonConfig: test.DonConfig{N: 4}, NumChains: 1, }) @@ -54,10 +55,10 @@ func TestUpdateNodes(t *testing.T) { }) t.Run("with mcms", func(t *testing.T) { - te := SetupTestEnv(t, TestConfig{ - WFDonConfig: DonConfig{N: 4}, - AssetDonConfig: DonConfig{N: 4}, - WriterDonConfig: DonConfig{N: 4}, + te := test.SetupTestEnv(t, test.TestConfig{ + WFDonConfig: test.DonConfig{N: 4}, + AssetDonConfig: test.DonConfig{N: 4}, + WriterDonConfig: test.DonConfig{N: 4}, NumChains: 1, UseMCMS: true, }) @@ -114,7 +115,7 @@ func TestUpdateNodes(t *testing.T) { } // validateUpdate checks reads nodes from the registry and checks they have the expected updates -func validateUpdate(t *testing.T, te TestEnv, expected map[p2pkey.PeerID]changeset.NodeUpdate) { +func validateUpdate(t *testing.T, te test.TestEnv, expected map[p2pkey.PeerID]changeset.NodeUpdate) { registry := te.ContractSets()[te.RegistrySelector].CapabilitiesRegistry wfP2PIDs := p2pIDs(t, maps.Keys(te.WFNodes)) nodes, err := registry.GetNodesByP2PIds(nil, wfP2PIDs) @@ -126,3 +127,13 @@ func validateUpdate(t *testing.T, te TestEnv, expected map[p2pkey.PeerID]changes assert.Equal(t, expected[node.P2pId].Signer, node.Signer) } } + +func p2pIDs(t *testing.T, vals []string) [][32]byte { + var out [][32]byte + for _, v := range vals { + id, err := p2pkey.MakePeerID(v) + require.NoError(t, err) + out = append(out, id) + } + return out +} diff --git a/deployment/keystone/changeset/workflowregistry/deploy.go b/deployment/keystone/changeset/workflowregistry/deploy.go new file mode 100644 index 00000000000..352336dd168 --- /dev/null +++ b/deployment/keystone/changeset/workflowregistry/deploy.go @@ -0,0 +1,26 @@ +package workflowregistry + +import ( + "fmt" + + "github.com/smartcontractkit/chainlink/deployment" + kslib "github.com/smartcontractkit/chainlink/deployment/keystone" +) + +var _ deployment.ChangeSet[uint64] = Deploy + +func Deploy(env deployment.Environment, registrySelector uint64) (deployment.ChangesetOutput, error) { + lggr := env.Logger + chain, ok := env.Chains[registrySelector] + if !ok { + return deployment.ChangesetOutput{}, fmt.Errorf("chain not found in environment") + } + ab := deployment.NewMemoryAddressBook() + wrResp, err := kslib.DeployWorkflowRegistry(chain, ab) + if err != nil { + return deployment.ChangesetOutput{}, fmt.Errorf("failed to deploy CapabilitiesRegistry: %w", err) + } + lggr.Infof("Deployed %s chain selector %d addr %s", wrResp.Tv.String(), chain.Selector, wrResp.Address.String()) + + return deployment.ChangesetOutput{AddressBook: ab}, nil +} diff --git a/deployment/keystone/changeset/workflowregistry/deploy_test.go b/deployment/keystone/changeset/workflowregistry/deploy_test.go new file mode 100644 index 00000000000..16eb6fa8512 --- /dev/null +++ b/deployment/keystone/changeset/workflowregistry/deploy_test.go @@ -0,0 +1,38 @@ +package workflowregistry + +import ( + "testing" + + "go.uber.org/zap/zapcore" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink/deployment/environment/memory" +) + +func Test_Deploy(t *testing.T) { + t.Parallel() + lggr := logger.Test(t) + cfg := memory.MemoryEnvironmentConfig{ + Nodes: 1, // nodes unused but required in config + Chains: 2, + } + env := memory.NewMemoryEnvironment(t, lggr, zapcore.DebugLevel, cfg) + + registrySel := env.AllChainSelectors()[0] + + resp, err := Deploy(env, registrySel) + require.NoError(t, err) + require.NotNil(t, resp) + // OCR3 should be deployed on chain 0 + addrs, err := resp.AddressBook.AddressesForChain(registrySel) + require.NoError(t, err) + require.Len(t, addrs, 1) + + // nothing on chain 1 + require.NotEqual(t, registrySel, env.AllChainSelectors()[1]) + oaddrs, _ := resp.AddressBook.AddressesForChain(env.AllChainSelectors()[1]) + assert.Len(t, oaddrs, 0) +} diff --git a/deployment/keystone/changeset/workflowregistry/strategies.go b/deployment/keystone/changeset/workflowregistry/strategies.go new file mode 100644 index 00000000000..f799092d4ce --- /dev/null +++ b/deployment/keystone/changeset/workflowregistry/strategies.go @@ -0,0 +1,86 @@ +package workflowregistry + +import ( + "math/big" + + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + + "github.com/smartcontractkit/ccip-owner-contracts/pkg/gethwrappers" + "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/mcms" + "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock" + + "github.com/smartcontractkit/chainlink/deployment" + "github.com/smartcontractkit/chainlink/deployment/common/proposalutils" + kslib "github.com/smartcontractkit/chainlink/deployment/keystone" + "github.com/smartcontractkit/chainlink/deployment/keystone/changeset" +) + +type strategy interface { + Apply(callFn func(opts *bind.TransactOpts) (*types.Transaction, error)) (deployment.ChangesetOutput, error) +} + +type simpleTransaction struct { + chain deployment.Chain +} + +func (s *simpleTransaction) Apply(callFn func(opts *bind.TransactOpts) (*types.Transaction, error)) (deployment.ChangesetOutput, error) { + tx, err := callFn(s.chain.DeployerKey) + if err != nil { + return deployment.ChangesetOutput{}, err + } + + _, err = s.chain.Confirm(tx) + return deployment.ChangesetOutput{}, err +} + +type mcmsTransaction struct { + Config *changeset.MCMSConfig + Description string + Address common.Address + ChainSel uint64 + ContractSet *kslib.ContractSet +} + +func (m *mcmsTransaction) Apply(callFn func(opts *bind.TransactOpts) (*types.Transaction, error)) (deployment.ChangesetOutput, error) { + opts := deployment.SimTransactOpts() + + tx, err := callFn(opts) + if err != nil { + return deployment.ChangesetOutput{}, err + } + + op := timelock.BatchChainOperation{ + ChainIdentifier: mcms.ChainIdentifier(m.ChainSel), + Batch: []mcms.Operation{ + { + Data: tx.Data(), + To: m.Address, + Value: big.NewInt(0), + }, + }, + } + + timelocksPerChain := map[uint64]common.Address{ + m.ChainSel: m.ContractSet.Timelock.Address(), + } + proposerMCMSes := map[uint64]*gethwrappers.ManyChainMultiSig{ + m.ChainSel: m.ContractSet.ProposerMcm, + } + + proposal, err := proposalutils.BuildProposalFromBatches( + timelocksPerChain, + proposerMCMSes, + []timelock.BatchChainOperation{op}, + m.Description, + m.Config.MinDuration, + ) + if err != nil { + return deployment.ChangesetOutput{}, err + } + + return deployment.ChangesetOutput{ + Proposals: []timelock.MCMSWithTimelockProposal{*proposal}, + }, nil +} diff --git a/deployment/keystone/changeset/workflowregistry/update_allowed_dons.go b/deployment/keystone/changeset/workflowregistry/update_allowed_dons.go new file mode 100644 index 00000000000..b07414221dd --- /dev/null +++ b/deployment/keystone/changeset/workflowregistry/update_allowed_dons.go @@ -0,0 +1,81 @@ +package workflowregistry + +import ( + "errors" + "fmt" + + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/core/types" + + "github.com/smartcontractkit/chainlink/deployment" + + kslib "github.com/smartcontractkit/chainlink/deployment/keystone" + "github.com/smartcontractkit/chainlink/deployment/keystone/changeset" + workflow_registry "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/workflow/generated/workflow_registry_wrapper" +) + +var _ deployment.ChangeSet[*UpdateAllowedDonsRequest] = UpdateAllowedDons + +type UpdateAllowedDonsRequest struct { + RegistryChainSel uint64 + DonIDs []uint32 + Allowed bool + + MCMSConfig *changeset.MCMSConfig +} + +func (r *UpdateAllowedDonsRequest) Validate() error { + if len(r.DonIDs) == 0 { + return errors.New("Must provide at least one DonID") + } + return nil +} + +// UpdateAllowedDons updates the list of DONs that workflows can be sent to. +func UpdateAllowedDons(env deployment.Environment, req *UpdateAllowedDonsRequest) (deployment.ChangesetOutput, error) { + if err := req.Validate(); err != nil { + return deployment.ChangesetOutput{}, err + } + + resp, err := kslib.GetContractSets(env.Logger, &kslib.GetContractSetsRequest{ + Chains: env.Chains, + AddressBook: env.ExistingAddresses, + }) + if err != nil { + return deployment.ChangesetOutput{}, fmt.Errorf("failed to get contract sets: %w", err) + } + + cs := resp.ContractSets[req.RegistryChainSel] + if cs.WorkflowRegistry == nil { + return deployment.ChangesetOutput{}, errors.New("could not find workflow registry") + } + registry := cs.WorkflowRegistry + + chain, ok := env.Chains[req.RegistryChainSel] + if !ok { + return deployment.ChangesetOutput{}, fmt.Errorf("registry chain selector %d does not exist in environment", req.RegistryChainSel) + } + + var s strategy + if req.MCMSConfig != nil { + s = &mcmsTransaction{ + Config: req.MCMSConfig, + Description: "proposal to update allowed dons", + Address: registry.Address(), + ChainSel: req.RegistryChainSel, + ContractSet: &cs, + } + } else { + s = &simpleTransaction{ + chain: chain, + } + } + + return s.Apply(func(opts *bind.TransactOpts) (*types.Transaction, error) { + tx, err := registry.UpdateAllowedDONs(opts, req.DonIDs, req.Allowed) + if err != nil { + err = kslib.DecodeErr(workflow_registry.WorkflowRegistryABI, err) + } + return tx, err + }) +} diff --git a/deployment/keystone/changeset/workflowregistry/update_allowed_dons_test.go b/deployment/keystone/changeset/workflowregistry/update_allowed_dons_test.go new file mode 100644 index 00000000000..bb17a85b1aa --- /dev/null +++ b/deployment/keystone/changeset/workflowregistry/update_allowed_dons_test.go @@ -0,0 +1,111 @@ +package workflowregistry_test + +import ( + "testing" + + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/smartcontractkit/chainlink-common/pkg/logger" + + chain_selectors "github.com/smartcontractkit/chain-selectors" + + "github.com/smartcontractkit/chainlink/deployment" + commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset" + "github.com/smartcontractkit/chainlink/deployment/common/proposalutils" + "github.com/smartcontractkit/chainlink/deployment/keystone/changeset" + kstest "github.com/smartcontractkit/chainlink/deployment/keystone/changeset/internal/test" + "github.com/smartcontractkit/chainlink/deployment/keystone/changeset/test" + "github.com/smartcontractkit/chainlink/deployment/keystone/changeset/workflowregistry" +) + +func TestUpdateAllowedDons(t *testing.T) { + lggr := logger.Test(t) + + chainSel := chain_selectors.ETHEREUM_TESTNET_SEPOLIA.Selector + resp := kstest.SetupTestWorkflowRegistry(t, lggr, chainSel) + registry := resp.Registry + + dons, err := registry.GetAllAllowedDONs(&bind.CallOpts{}) + require.NoError(t, err) + + assert.Len(t, dons, 0) + + env := deployment.Environment{ + Logger: lggr, + Chains: map[uint64]deployment.Chain{ + chainSel: resp.Chain, + }, + ExistingAddresses: resp.AddressBook, + } + + _, err = workflowregistry.UpdateAllowedDons( + env, + &workflowregistry.UpdateAllowedDonsRequest{ + RegistryChainSel: chainSel, + DonIDs: []uint32{1}, + Allowed: true, + }, + ) + require.NoError(t, err) + + dons, err = registry.GetAllAllowedDONs(&bind.CallOpts{}) + require.NoError(t, err) + + assert.Len(t, dons, 1) + assert.Equal(t, dons[0], uint32(1)) + + _, err = workflowregistry.UpdateAllowedDons( + env, + &workflowregistry.UpdateAllowedDonsRequest{ + RegistryChainSel: chainSel, + DonIDs: []uint32{1}, + Allowed: false, + }, + ) + require.NoError(t, err) + + dons, err = registry.GetAllAllowedDONs(&bind.CallOpts{}) + require.NoError(t, err) + + assert.Len(t, dons, 0) +} + +func Test_UpdateAllowedDons_WithMCMS(t *testing.T) { + te := test.SetupTestEnv(t, test.TestConfig{ + WFDonConfig: test.DonConfig{N: 4}, + AssetDonConfig: test.DonConfig{N: 4}, + WriterDonConfig: test.DonConfig{N: 4}, + NumChains: 1, + UseMCMS: true, + }) + + req := &workflowregistry.UpdateAllowedDonsRequest{ + RegistryChainSel: te.RegistrySelector, + DonIDs: []uint32{1}, + Allowed: true, + MCMSConfig: &changeset.MCMSConfig{MinDuration: 0}, + } + + out, err := workflowregistry.UpdateAllowedDons(te.Env, req) + require.NoError(t, err) + require.Len(t, out.Proposals, 1) + require.Nil(t, out.AddressBook) + + contracts := te.ContractSets()[te.RegistrySelector] + timelockContracts := map[uint64]*proposalutils.TimelockExecutionContracts{ + te.RegistrySelector: { + Timelock: contracts.Timelock, + CallProxy: contracts.CallProxy, + }, + } + + _, err = commonchangeset.ApplyChangesets(t, te.Env, timelockContracts, []commonchangeset.ChangesetApplication{ + { + Changeset: commonchangeset.WrapChangeSet(workflowregistry.UpdateAllowedDons), + Config: req, + }, + }) + require.NoError(t, err) +} diff --git a/deployment/keystone/changeset/workflowregistry/update_authorized_addresses.go b/deployment/keystone/changeset/workflowregistry/update_authorized_addresses.go new file mode 100644 index 00000000000..f05c6cd58c9 --- /dev/null +++ b/deployment/keystone/changeset/workflowregistry/update_authorized_addresses.go @@ -0,0 +1,106 @@ +package workflowregistry + +import ( + "errors" + "fmt" + + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + + "github.com/smartcontractkit/chainlink/deployment" + + kslib "github.com/smartcontractkit/chainlink/deployment/keystone" + "github.com/smartcontractkit/chainlink/deployment/keystone/changeset" + workflow_registry "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/workflow/generated/workflow_registry_wrapper" +) + +var _ deployment.ChangeSet[*UpdateAuthorizedAddressesRequest] = UpdateAuthorizedAddresses + +type UpdateAuthorizedAddressesRequest struct { + RegistryChainSel uint64 + + Addresses []string + Allowed bool + + MCMSConfig *changeset.MCMSConfig +} + +func (r *UpdateAuthorizedAddressesRequest) Validate() error { + if len(r.Addresses) == 0 { + return errors.New("Must provide at least 1 address") + } + + return nil +} + +func getWorkflowRegistry(env deployment.Environment, chainSel uint64) (*workflow_registry.WorkflowRegistry, error) { + resp, err := kslib.GetContractSets(env.Logger, &kslib.GetContractSetsRequest{ + Chains: env.Chains, + AddressBook: env.ExistingAddresses, + }) + if err != nil { + return nil, fmt.Errorf("failed to get contract sets: %w", err) + } + + cs := resp.ContractSets[chainSel] + if cs.WorkflowRegistry == nil { + return nil, errors.New("could not find workflow registry") + } + + return cs.WorkflowRegistry, nil +} + +// UpdateAuthorizedAddresses updates the list of DONs that workflows can be sent to. +func UpdateAuthorizedAddresses(env deployment.Environment, req *UpdateAuthorizedAddressesRequest) (deployment.ChangesetOutput, error) { + if err := req.Validate(); err != nil { + return deployment.ChangesetOutput{}, err + } + + resp, err := kslib.GetContractSets(env.Logger, &kslib.GetContractSetsRequest{ + Chains: env.Chains, + AddressBook: env.ExistingAddresses, + }) + if err != nil { + return deployment.ChangesetOutput{}, fmt.Errorf("failed to get contract sets: %w", err) + } + + cs := resp.ContractSets[req.RegistryChainSel] + if cs.WorkflowRegistry == nil { + return deployment.ChangesetOutput{}, errors.New("could not find workflow registry") + } + registry := cs.WorkflowRegistry + + chain, ok := env.Chains[req.RegistryChainSel] + if !ok { + return deployment.ChangesetOutput{}, fmt.Errorf("registry chain selector %d does not exist in environment", req.RegistryChainSel) + } + + var addr []common.Address + for _, a := range req.Addresses { + addr = append(addr, common.HexToAddress(a)) + } + + var s strategy + if req.MCMSConfig != nil { + s = &mcmsTransaction{ + Config: req.MCMSConfig, + Description: "proposal to update authorized addresses", + Address: registry.Address(), + ChainSel: chain.Selector, + ContractSet: &cs, + } + } else { + s = &simpleTransaction{ + chain: chain, + } + } + + return s.Apply(func(opts *bind.TransactOpts) (*types.Transaction, error) { + tx, err := registry.UpdateAuthorizedAddresses(opts, addr, req.Allowed) + if err != nil { + err = kslib.DecodeErr(workflow_registry.WorkflowRegistryABI, err) + } + return tx, err + }) +} diff --git a/deployment/keystone/changeset/workflowregistry/update_authorized_addresses_test.go b/deployment/keystone/changeset/workflowregistry/update_authorized_addresses_test.go new file mode 100644 index 00000000000..36dfd4371b1 --- /dev/null +++ b/deployment/keystone/changeset/workflowregistry/update_authorized_addresses_test.go @@ -0,0 +1,114 @@ +package workflowregistry_test + +import ( + "testing" + + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + chain_selectors "github.com/smartcontractkit/chain-selectors" + + "github.com/smartcontractkit/chainlink-common/pkg/logger" + + "github.com/smartcontractkit/chainlink/deployment" + commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset" + "github.com/smartcontractkit/chainlink/deployment/common/proposalutils" + "github.com/smartcontractkit/chainlink/deployment/keystone/changeset" + kstest "github.com/smartcontractkit/chainlink/deployment/keystone/changeset/internal/test" + "github.com/smartcontractkit/chainlink/deployment/keystone/changeset/test" + "github.com/smartcontractkit/chainlink/deployment/keystone/changeset/workflowregistry" +) + +func TestUpdateAuthorizedAddresses(t *testing.T) { + lggr := logger.Test(t) + + chainSel := chain_selectors.ETHEREUM_TESTNET_SEPOLIA.Selector + resp := kstest.SetupTestWorkflowRegistry(t, lggr, chainSel) + registry := resp.Registry + + dons, err := registry.GetAllAuthorizedAddresses(&bind.CallOpts{}) + require.NoError(t, err) + + assert.Len(t, dons, 0) + + env := deployment.Environment{ + Logger: lggr, + Chains: map[uint64]deployment.Chain{ + chainSel: resp.Chain, + }, + ExistingAddresses: resp.AddressBook, + } + + addr := "0xc0ffee254729296a45a3885639AC7E10F9d54979" + _, err = workflowregistry.UpdateAuthorizedAddresses( + env, + &workflowregistry.UpdateAuthorizedAddressesRequest{ + RegistryChainSel: chainSel, + Addresses: []string{addr}, + Allowed: true, + }, + ) + require.NoError(t, err) + + dons, err = registry.GetAllAuthorizedAddresses(&bind.CallOpts{}) + require.NoError(t, err) + + assert.Len(t, dons, 1) + assert.Equal(t, dons[0], common.HexToAddress(addr)) + + _, err = workflowregistry.UpdateAuthorizedAddresses( + env, + &workflowregistry.UpdateAuthorizedAddressesRequest{ + RegistryChainSel: chainSel, + Addresses: []string{addr}, + Allowed: false, + }, + ) + require.NoError(t, err) + + dons, err = registry.GetAllAuthorizedAddresses(&bind.CallOpts{}) + require.NoError(t, err) + + assert.Len(t, dons, 0) +} + +func Test_UpdateAuthorizedAddresses_WithMCMS(t *testing.T) { + te := test.SetupTestEnv(t, test.TestConfig{ + WFDonConfig: test.DonConfig{N: 4}, + AssetDonConfig: test.DonConfig{N: 4}, + WriterDonConfig: test.DonConfig{N: 4}, + NumChains: 1, + UseMCMS: true, + }) + + addr := "0xc0ffee254729296a45a3885639AC7E10F9d54979" + req := &workflowregistry.UpdateAuthorizedAddressesRequest{ + RegistryChainSel: te.RegistrySelector, + Addresses: []string{addr}, + Allowed: true, + MCMSConfig: &changeset.MCMSConfig{MinDuration: 0}, + } + + out, err := workflowregistry.UpdateAuthorizedAddresses(te.Env, req) + require.NoError(t, err) + require.Len(t, out.Proposals, 1) + require.Nil(t, out.AddressBook) + + contracts := te.ContractSets()[te.RegistrySelector] + timelockContracts := map[uint64]*proposalutils.TimelockExecutionContracts{ + te.RegistrySelector: { + Timelock: contracts.Timelock, + CallProxy: contracts.CallProxy, + }, + } + + _, err = commonchangeset.ApplyChangesets(t, te.Env, timelockContracts, []commonchangeset.ChangesetApplication{ + { + Changeset: commonchangeset.WrapChangeSet(workflowregistry.UpdateAuthorizedAddresses), + Config: req, + }, + }) + require.NoError(t, err) +} diff --git a/deployment/keystone/contract_set.go b/deployment/keystone/contract_set.go index ee503a54b4d..51b5c823600 100644 --- a/deployment/keystone/contract_set.go +++ b/deployment/keystone/contract_set.go @@ -58,6 +58,21 @@ func DeployCapabilitiesRegistry(chain deployment.Chain, ab deployment.AddressBoo return capabilitiesRegistryResp, nil } +// DeployWorkflowRegistry deploys the WorkflowRegistry contract to the chain +// and saves the address in the address book. This mutates the address book. +func DeployWorkflowRegistry(chain deployment.Chain, ab deployment.AddressBook) (*DeployResponse, error) { + deployer, err := NewWorkflowRegistryDeployer() + resp, err := deployer.Deploy(DeployRequest{Chain: chain}) + if err != nil { + return nil, fmt.Errorf("failed to deploy WorkflowRegistry: %w", err) + } + err = ab.Save(chain.Selector, resp.Address.String(), resp.Tv) + if err != nil { + return nil, fmt.Errorf("failed to save WorkflowRegistry: %w", err) + } + return resp, nil +} + // DeployOCR3 deploys the OCR3Capability contract to the chain // and saves the address in the address book. This mutates the address book. func DeployOCR3(chain deployment.Chain, ab deployment.AddressBook) (*DeployResponse, error) { diff --git a/deployment/keystone/state.go b/deployment/keystone/state.go index 0ac7cdc89ed..38b89b792c7 100644 --- a/deployment/keystone/state.go +++ b/deployment/keystone/state.go @@ -14,6 +14,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/forwarder" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/ocr3_capability" + workflow_registry "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/workflow/generated/workflow_registry_wrapper" ) type GetContractSetsRequest struct { @@ -30,6 +31,7 @@ type ContractSet struct { OCR3 *ocr3_capability.OCR3Capability Forwarder *forwarder.KeystoneForwarder CapabilitiesRegistry *capabilities_registry.CapabilitiesRegistry + WorkflowRegistry *workflow_registry.WorkflowRegistry } func (cs ContractSet) TransferableContracts() []common.Address { @@ -43,6 +45,9 @@ func (cs ContractSet) TransferableContracts() []common.Address { if cs.CapabilitiesRegistry != nil { out = append(out, cs.CapabilitiesRegistry.Address()) } + if cs.WorkflowRegistry != nil { + out = append(out, cs.WorkflowRegistry.Address()) + } return out } @@ -105,6 +110,12 @@ func loadContractSet(lggr logger.Logger, chain deployment.Chain, addresses map[s return nil, fmt.Errorf("failed to create OCR3Capability contract from address %s: %w", addr, err) } out.OCR3 = c + case WorkflowRegistry: + c, err := workflow_registry.NewWorkflowRegistry(common.HexToAddress(addr), chain.Client) + if err != nil { + return nil, fmt.Errorf("failed to create OCR3Capability contract from address %s: %w", addr, err) + } + out.WorkflowRegistry = c default: lggr.Warnw("unknown contract type", "type", tv.Type) // ignore unknown contract types diff --git a/deployment/keystone/types.go b/deployment/keystone/types.go index d406487043c..cb1373d446c 100644 --- a/deployment/keystone/types.go +++ b/deployment/keystone/types.go @@ -21,6 +21,7 @@ import ( var ( CapabilitiesRegistry deployment.ContractType = "CapabilitiesRegistry" // https://github.com/smartcontractkit/chainlink/blob/50c1b3dbf31bd145b312739b08967600a5c67f30/contracts/src/v0.8/keystone/CapabilitiesRegistry.sol#L392 + WorkflowRegistry deployment.ContractType = "WorkflowRegistry" // https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/workflow/dev/WorkflowRegistry.sol KeystoneForwarder deployment.ContractType = "KeystoneForwarder" // https://github.com/smartcontractkit/chainlink/blob/50c1b3dbf31bd145b312739b08967600a5c67f30/contracts/src/v0.8/keystone/KeystoneForwarder.sol#L90 OCR3Capability deployment.ContractType = "OCR3Capability" // https://github.com/smartcontractkit/chainlink/blob/50c1b3dbf31bd145b312739b08967600a5c67f30/contracts/src/v0.8/keystone/OCR3Capability.sol#L12 FeedConsumer deployment.ContractType = "FeedConsumer" // no type and a version in contract https://github.com/smartcontractkit/chainlink/blob/89183a8a5d22b1aeca0ade3b76d16aa84067aa57/contracts/src/v0.8/keystone/KeystoneFeedsConsumer.sol#L1 diff --git a/deployment/keystone/workflow_registry_deployer.go b/deployment/keystone/workflow_registry_deployer.go new file mode 100644 index 00000000000..794e6ad0202 --- /dev/null +++ b/deployment/keystone/workflow_registry_deployer.go @@ -0,0 +1,65 @@ +package keystone + +import ( + "fmt" + + "github.com/ethereum/go-ethereum/accounts/abi/bind" + + "github.com/smartcontractkit/chainlink-common/pkg/logger" + + "github.com/smartcontractkit/chainlink/deployment" + workflow_registry "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/workflow/generated/workflow_registry_wrapper" +) + +type WorkflowRegistryDeployer struct { + lggr logger.Logger + contract *workflow_registry.WorkflowRegistry +} + +func NewWorkflowRegistryDeployer() (*WorkflowRegistryDeployer, error) { + lggr, err := logger.New() + if err != nil { + return nil, err + } + return &WorkflowRegistryDeployer{lggr: lggr}, nil +} + +func (c *WorkflowRegistryDeployer) Contract() *workflow_registry.WorkflowRegistry { + return c.contract +} + +func (c *WorkflowRegistryDeployer) Deploy(req DeployRequest) (*DeployResponse, error) { + est, err := estimateDeploymentGas(req.Chain.Client, workflow_registry.WorkflowRegistryABI) + if err != nil { + return nil, fmt.Errorf("failed to estimate gas: %w", err) + } + c.lggr.Debugf("WorkflowRegistry estimated gas: %d", est) + + addr, tx, wr, err := workflow_registry.DeployWorkflowRegistry( + req.Chain.DeployerKey, + req.Chain.Client) + if err != nil { + return nil, DecodeErr(workflow_registry.WorkflowRegistryABI, err) + } + + _, err = req.Chain.Confirm(tx) + if err != nil { + return nil, fmt.Errorf("failed to confirm and save WorkflowRegistry: %w", err) + } + tvStr, err := wr.TypeAndVersion(&bind.CallOpts{}) + if err != nil { + return nil, fmt.Errorf("failed to get type and version: %w", err) + } + + tv, err := deployment.TypeAndVersionFromString(tvStr) + if err != nil { + return nil, fmt.Errorf("failed to parse type and version from %s: %w", tvStr, err) + } + resp := &DeployResponse{ + Address: addr, + Tx: tx.Hash(), + Tv: tv, + } + c.contract = wr + return resp, nil +}