From 4b738abd19b7765fe7fe0beeb4072b21a640c2a4 Mon Sep 17 00:00:00 2001 From: krehermann <16602512+krehermann@users.noreply.github.com> Date: Fri, 6 Dec 2024 11:25:09 -0700 Subject: [PATCH] support mcms in forwarder contract config changeset (#15533) * support mcms in ocr3 contract config changeset * test working for ocr3 config with mcms * migrate deployment test to setup test env * fix test * refactor forwarder configuration changeset for mcms --- .../keystone/changeset/deploy_forwarder.go | 42 +++++- .../changeset/deploy_forwarder_test.go | 90 +++++++++++ deployment/keystone/changeset/helpers_test.go | 74 ++++----- deployment/keystone/deploy.go | 140 +++++++++--------- deployment/keystone/deploy_test.go | 5 +- deployment/keystone/forwarder_deployer.go | 41 +++++ deployment/keystone/types.go | 46 +++++- 7 files changed, 326 insertions(+), 112 deletions(-) diff --git a/deployment/keystone/changeset/deploy_forwarder.go b/deployment/keystone/changeset/deploy_forwarder.go index 5207d99aacd..cf116decd54 100644 --- a/deployment/keystone/changeset/deploy_forwarder.go +++ b/deployment/keystone/changeset/deploy_forwarder.go @@ -11,7 +11,8 @@ var _ deployment.ChangeSet[uint64] = DeployForwarder // DeployForwarder deploys the KeystoneForwarder contract to all chains in the environment // callers must merge the output addressbook with the existing one -func DeployForwarder(env deployment.Environment, registryChainSel uint64) (deployment.ChangesetOutput, error) { +// TODO: add selectors to deploy only to specific chains +func DeployForwarder(env deployment.Environment, _ uint64) (deployment.ChangesetOutput, error) { lggr := env.Logger ab := deployment.NewMemoryAddressBook() for _, chain := range env.Chains { @@ -25,3 +26,42 @@ func DeployForwarder(env deployment.Environment, registryChainSel uint64) (deplo return deployment.ChangesetOutput{AddressBook: ab}, nil } + +var _ deployment.ChangeSet[ConfigureForwardContractsRequest] = ConfigureForwardContracts + +type ConfigureForwardContractsRequest struct { + WFDonName string + // workflow don node ids in the offchain client. Used to fetch and derive the signer keys + WFNodeIDs []string + RegistryChainSel uint64 + + UseMCMS bool +} + +func (r ConfigureForwardContractsRequest) Validate() error { + if len(r.WFNodeIDs) == 0 { + return fmt.Errorf("WFNodeIDs must not be empty") + } + return nil +} + +func ConfigureForwardContracts(env deployment.Environment, req ConfigureForwardContractsRequest) (deployment.ChangesetOutput, error) { + wfDon, err := kslib.NewRegisteredDon(env, kslib.RegisteredDonConfig{ + NodeIDs: req.WFNodeIDs, + Name: req.WFDonName, + RegistryChainSel: req.RegistryChainSel, + }) + if err != nil { + return deployment.ChangesetOutput{}, fmt.Errorf("failed to create registered don: %w", err) + } + r, err := kslib.ConfigureForwardContracts(&env, kslib.ConfigureForwarderContractsRequest{ + Dons: []kslib.RegisteredDon{*wfDon}, + UseMCMS: req.UseMCMS, + }) + if err != nil { + return deployment.ChangesetOutput{}, fmt.Errorf("failed to configure forward contracts: %w", err) + } + return deployment.ChangesetOutput{ + Proposals: r.Proposals, + }, nil +} diff --git a/deployment/keystone/changeset/deploy_forwarder_test.go b/deployment/keystone/changeset/deploy_forwarder_test.go index b6d8ec8f753..32a53f1cf08 100644 --- a/deployment/keystone/changeset/deploy_forwarder_test.go +++ b/deployment/keystone/changeset/deploy_forwarder_test.go @@ -1,14 +1,17 @@ package changeset_test import ( + "fmt" "testing" "go.uber.org/zap/zapcore" "github.com/stretchr/testify/require" + "github.com/smartcontractkit/ccip-owner-contracts/pkg/gethwrappers" "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/environment/memory" "github.com/smartcontractkit/chainlink/deployment/keystone/changeset" ) @@ -45,3 +48,90 @@ func TestDeployForwarder(t *testing.T) { require.Len(t, oaddrs, 1) }) } + +func TestConfigureForwarders(t *testing.T) { + t.Parallel() + + t.Run("no mcms ", func(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}, + NumChains: nChains, + }) + + var wfNodes []string + for id, _ := range te.WFNodes { + wfNodes = append(wfNodes, id) + } + + cfg := changeset.ConfigureForwardContractsRequest{ + WFDonName: "test-wf-don", + WFNodeIDs: wfNodes, + RegistryChainSel: te.RegistrySelector, + } + csOut, err := changeset.ConfigureForwardContracts(te.Env, cfg) + require.NoError(t, err) + require.Nil(t, csOut.AddressBook) + require.Len(t, csOut.Proposals, 0) + // check that forwarder + // TODO set up a listener to check that the forwarder is configured + contractSet := te.ContractSets() + for selector := range te.Env.Chains { + cs, ok := contractSet[selector] + require.True(t, ok) + require.NotNil(t, cs.Forwarder) + } + }) + } + }) + + t.Run("with mcms", func(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}, + NumChains: nChains, + UseMCMS: true, + }) + + var wfNodes []string + for id, _ := range te.WFNodes { + wfNodes = append(wfNodes, id) + } + + cfg := changeset.ConfigureForwardContractsRequest{ + WFDonName: "test-wf-don", + WFNodeIDs: wfNodes, + RegistryChainSel: te.RegistrySelector, + UseMCMS: true, + } + csOut, err := changeset.ConfigureForwardContracts(te.Env, cfg) + require.NoError(t, err) + require.Len(t, csOut.Proposals, nChains) + require.Nil(t, csOut.AddressBook) + + timelocks := make(map[uint64]*gethwrappers.RBACTimelock) + for selector, contractSet := range te.ContractSets() { + require.NotNil(t, contractSet.Timelock) + timelocks[selector] = contractSet.Timelock + } + _, err = commonchangeset.ApplyChangesets(t, te.Env, timelocks, []commonchangeset.ChangesetApplication{ + { + Changeset: commonchangeset.WrapChangeSet(changeset.ConfigureForwardContracts), + Config: cfg, + }, + }) + require.NoError(t, err) + + }) + } + }) + +} diff --git a/deployment/keystone/changeset/helpers_test.go b/deployment/keystone/changeset/helpers_test.go index 85e69507009..d4435d8f7a6 100644 --- a/deployment/keystone/changeset/helpers_test.go +++ b/deployment/keystone/changeset/helpers_test.go @@ -96,6 +96,7 @@ func (c TestConfig) Validate() error { } type TestEnv struct { + t *testing.T Env deployment.Environment RegistrySelector uint64 @@ -104,6 +105,15 @@ type TestEnv struct { AssetNodes map[string]memory.Node } +func (te TestEnv) ContractSets() map[uint64]kslib.ContractSet { + r, err := kslib.GetContractSets(te.Env.Logger, &kslib.GetContractSetsRequest{ + Chains: te.Env.Chains, + AddressBook: te.Env.ExistingAddresses, + }) + require.NoError(te.t, err) + return r.ContractSets +} + // SetupTestEnv sets up a keystone test environment with the given configuration func SetupTestEnv(t *testing.T, c TestConfig) TestEnv { require.NoError(t, c.Validate()) @@ -250,57 +260,51 @@ func SetupTestEnv(t *testing.T, c TestConfig) TestEnv { if c.UseMCMS { // TODO: mcms on all the chains, currently only on the registry chain. need to fix this for forwarders - t.Logf("Enabling MCMS registry chain %d", registryChainSel) // deploy, configure and xfer ownership of MCMS + timelockCfgs := make(map[uint64]commontypes.MCMSWithTimelockConfig) + for sel := range env.Chains { + t.Logf("Enabling MCMS on chain %d", sel) + timelockCfgs[sel] = commontypes.MCMSWithTimelockConfig{ + Canceller: commonchangeset.SingleGroupMCMS(t), + Bypasser: commonchangeset.SingleGroupMCMS(t), + Proposer: commonchangeset.SingleGroupMCMS(t), + TimelockExecutors: env.AllDeployerKeys(), + TimelockMinDelay: big.NewInt(0), + } + } env, err = commonchangeset.ApplyChangesets(t, env, nil, []commonchangeset.ChangesetApplication{ { Changeset: commonchangeset.WrapChangeSet(commonchangeset.DeployMCMSWithTimelock), - Config: map[uint64]commontypes.MCMSWithTimelockConfig{ - registryChainSel: { - Canceller: commonchangeset.SingleGroupMCMS(t), - Bypasser: commonchangeset.SingleGroupMCMS(t), - Proposer: commonchangeset.SingleGroupMCMS(t), - TimelockExecutors: env.AllDeployerKeys(), - TimelockMinDelay: big.NewInt(0), - }, - }, + Config: timelockCfgs, }, }) require.NoError(t, err) // extract the MCMS address r, err := kslib.GetContractSets(lggr, &kslib.GetContractSetsRequest{ - Chains: map[uint64]deployment.Chain{ - registryChainSel: env.Chains[registryChainSel], - }, + Chains: env.Chains, AddressBook: env.ExistingAddresses, }) require.NoError(t, err) - mcms := r.ContractSets[registryChainSel].MCMSWithTimelockState - require.NotNil(t, mcms) - // transfer ownership of all contracts to the MCMS - env, err = commonchangeset.ApplyChangesets(t, env, map[uint64]*gethwrappers.RBACTimelock{registryChainSel: mcms.Timelock}, []commonchangeset.ChangesetApplication{ - { - Changeset: commonchangeset.WrapChangeSet(kschangeset.AcceptAllOwnershipsProposal), - Config: &kschangeset.AcceptAllOwnershipRequest{ - ChainSelector: registryChainSel, - MinDelay: 0, + for sel := range env.Chains { + mcms := r.ContractSets[sel].MCMSWithTimelockState + require.NotNil(t, mcms, "MCMS not found on chain %d", sel) + require.NoError(t, mcms.Validate()) + + // transfer ownership of all contracts to the MCMS + env, err = commonchangeset.ApplyChangesets(t, env, map[uint64]*gethwrappers.RBACTimelock{sel: mcms.Timelock}, []commonchangeset.ChangesetApplication{ + { + Changeset: commonchangeset.WrapChangeSet(kschangeset.AcceptAllOwnershipsProposal), + Config: &kschangeset.AcceptAllOwnershipRequest{ + ChainSelector: sel, + MinDelay: 0, + }, }, - }, - }) - require.NoError(t, err) - // ensure the MCMS is deployed - req = &keystone.GetContractSetsRequest{ - Chains: env.Chains, - AddressBook: env.ExistingAddresses, + }) + require.NoError(t, err) } - contractSetsResp, err = keystone.GetContractSets(lggr, req) - require.NoError(t, err) - require.Len(t, contractSetsResp.ContractSets, len(env.Chains)) - // check the mcms contract on registry chain - gotMCMS := contractSetsResp.ContractSets[registryChainSel].MCMSWithTimelockState - require.NoError(t, gotMCMS.Validate()) } return TestEnv{ + t: t, Env: env, RegistrySelector: registryChainSel, WFNodes: wfNodes, diff --git a/deployment/keystone/deploy.go b/deployment/keystone/deploy.go index 0370cc54ba9..da277bc3497 100644 --- a/deployment/keystone/deploy.go +++ b/deployment/keystone/deploy.go @@ -7,18 +7,23 @@ import ( "encoding/hex" "errors" "fmt" + "math/big" "sort" "strconv" "strings" "time" "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/rpc" "golang.org/x/exp/maps" + "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" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/durationpb" @@ -77,22 +82,7 @@ func ConfigureContracts(ctx context.Context, lggr logger.Logger, req ConfigureCo return nil, fmt.Errorf("invalid request: %w", err) } - addrBook := req.Env.ExistingAddresses - // TODO: KS-rm_deploy_opt remove this option; it's not used - if req.DoContractDeploy { - contractDeployCS, err := DeployContracts(req.Env, req.RegistryChainSel) - if err != nil { - return nil, fmt.Errorf("failed to deploy contracts: %w", err) - } - addrBook = contractDeployCS.AddressBook - } else { - lggr.Debug("skipping contract deployment") - } - if addrBook == nil { - return nil, errors.New("address book is nil") - } - - cfgRegistryResp, err := ConfigureRegistry(ctx, lggr, req, addrBook) + cfgRegistryResp, err := ConfigureRegistry(ctx, lggr, req, req.Env.ExistingAddresses) if err != nil { return nil, fmt.Errorf("failed to configure registry: %w", err) } @@ -107,21 +97,22 @@ func ConfigureContracts(ctx context.Context, lggr logger.Logger, req ConfigureCo if err != nil { return nil, fmt.Errorf("failed to assimilate registry to Dons: %w", err) } - err = ConfigureForwardContracts(req.Env, dons, addrBook) + // ignore response because we are not using mcms here and therefore no proposals are returned + _, err = ConfigureForwardContracts(req.Env, ConfigureForwarderContractsRequest{ + Dons: dons, + }) if err != nil { return nil, fmt.Errorf("failed to configure forwarder contracts: %w", err) } - err = ConfigureOCR3Contract(req.Env, req.RegistryChainSel, dons, addrBook, req.OCR3Config) + err = ConfigureOCR3Contract(req.Env, req.RegistryChainSel, dons, req.OCR3Config) if err != nil { return nil, fmt.Errorf("failed to configure OCR3 contract: %w", err) } return &ConfigureContractsResponse{ - Changeset: &deployment.ChangesetOutput{ - AddressBook: addrBook, - }, - DonInfos: cfgRegistryResp.DonInfos, + Changeset: &deployment.ChangesetOutput{}, // no new addresses, proposals etc + DonInfos: cfgRegistryResp.DonInfos, }, nil } @@ -306,47 +297,14 @@ func ConfigureRegistry(ctx context.Context, lggr logger.Logger, req ConfigureCon lggr.Infow("registered DONs", "dons", len(donsResp.DonInfos)) return &ConfigureContractsResponse{ - Changeset: &deployment.ChangesetOutput{ - AddressBook: addrBook, - }, - DonInfos: donsResp.DonInfos, + Changeset: &deployment.ChangesetOutput{}, // no new addresses, proposals etc + DonInfos: donsResp.DonInfos, }, nil } -// ConfigureForwardContracts configures the forwarder contracts on all chains for the given DONS -// the address book is required to contain the an address of the deployed forwarder contract for every chain in the environment -func ConfigureForwardContracts(env *deployment.Environment, dons []RegisteredDon, addrBook deployment.AddressBook) error { - contractSetsResp, err := GetContractSets(env.Logger, &GetContractSetsRequest{ - Chains: env.Chains, - AddressBook: addrBook, - }) - if err != nil { - return fmt.Errorf("failed to get contract sets: %w", err) - } - - // configure forwarders on all chains - for _, chain := range env.Chains { - // get the forwarder contract for the chain - contracts, ok := contractSetsResp.ContractSets[chain.Selector] - if !ok { - return fmt.Errorf("failed to get contract set for chain %d", chain.Selector) - } - fwrd := contracts.Forwarder - if fwrd == nil { - return fmt.Errorf("no forwarder contract found for chain %d", chain.Selector) - } - - err := configureForwarder(env.Logger, chain, fwrd, dons) - if err != nil { - return fmt.Errorf("failed to configure forwarder for chain selector %d: %w", chain.Selector, err) - } - } - return nil -} - // Depreciated: use changeset.ConfigureOCR3Contract instead // ocr3 contract on the registry chain for the wf dons -func ConfigureOCR3Contract(env *deployment.Environment, chainSel uint64, dons []RegisteredDon, addrBook deployment.AddressBook, cfg *OracleConfigWithSecrets) error { +func ConfigureOCR3Contract(env *deployment.Environment, chainSel uint64, dons []RegisteredDon, cfg *OracleConfigWithSecrets) error { registryChain, ok := env.Chains[chainSel] if !ok { return fmt.Errorf("chain %d not found in environment", chainSel) @@ -354,7 +312,7 @@ func ConfigureOCR3Contract(env *deployment.Environment, chainSel uint64, dons [] contractSetsResp, err := GetContractSets(env.Logger, &GetContractSetsRequest{ Chains: env.Chains, - AddressBook: addrBook, + AddressBook: env.ExistingAddresses, }) if err != nil { return fmt.Errorf("failed to get contract sets: %w", err) @@ -978,27 +936,67 @@ func containsAllDONs(donInfos []kcr.CapabilitiesRegistryDONInfo, p2pIdsToDon map // configureForwarder sets the config for the forwarder contract on the chain for all Dons that accept workflows // dons that don't accept workflows are not registered with the forwarder -func configureForwarder(lggr logger.Logger, chain deployment.Chain, fwdr *kf.KeystoneForwarder, dons []RegisteredDon) error { - if fwdr == nil { - return errors.New("nil forwarder contract") - } +func configureForwarder(lggr logger.Logger, chain deployment.Chain, contractSet ContractSet, dons []RegisteredDon, useMCMS bool) ([]timelock.MCMSWithTimelockProposal, error) { + if contractSet.Forwarder == nil { + return nil, errors.New("nil forwarder contract") + } + var ( + fwdr = contractSet.Forwarder + proposals []timelock.MCMSWithTimelockProposal + ) for _, dn := range dons { if !dn.Info.AcceptsWorkflows { continue } ver := dn.Info.ConfigCount // note config count on the don info is the version on the forwarder - signers := dn.signers(chainsel.FamilyEVM) - tx, err := fwdr.SetConfig(chain.DeployerKey, dn.Info.Id, ver, dn.Info.F, signers) - if err != nil { - err = DecodeErr(kf.KeystoneForwarderABI, err) - return fmt.Errorf("failed to call SetConfig for forwarder %s on chain %d: %w", fwdr.Address().String(), chain.Selector, err) + signers := dn.Signers(chainsel.FamilyEVM) + txOpts := chain.DeployerKey + if useMCMS { + txOpts = deployment.SimTransactOpts() } - _, err = chain.Confirm(tx) + tx, err := fwdr.SetConfig(txOpts, dn.Info.Id, ver, dn.Info.F, signers) if err != nil { err = DecodeErr(kf.KeystoneForwarderABI, err) - return fmt.Errorf("failed to confirm SetConfig for forwarder %s: %w", fwdr.Address().String(), err) + return nil, fmt.Errorf("failed to call SetConfig for forwarder %s on chain %d: %w", fwdr.Address().String(), chain.Selector, err) + } + if !useMCMS { + _, err = chain.Confirm(tx) + if err != nil { + err = DecodeErr(kf.KeystoneForwarderABI, err) + return nil, fmt.Errorf("failed to confirm SetConfig for forwarder %s: %w", fwdr.Address().String(), err) + } + } else { + // create the mcms proposals + ops := timelock.BatchChainOperation{ + ChainIdentifier: mcms.ChainIdentifier(chain.Selector), + Batch: []mcms.Operation{ + { + To: fwdr.Address(), + Data: tx.Data(), + Value: big.NewInt(0), + }, + }, + } + timelocksPerChain := map[uint64]common.Address{ + chain.Selector: contractSet.Timelock.Address(), + } + proposerMCMSes := map[uint64]*gethwrappers.ManyChainMultiSig{ + chain.Selector: contractSet.ProposerMcm, + } + + proposal, err := proposalutils.BuildProposalFromBatches( + timelocksPerChain, + proposerMCMSes, + []timelock.BatchChainOperation{ops}, + "proposal to set forward config", + 0, + ) + if err != nil { + return nil, fmt.Errorf("failed to build proposal: %w", err) + } + proposals = append(proposals, *proposal) } lggr.Debugw("configured forwarder", "forwarder", fwdr.Address().String(), "donId", dn.Info.Id, "version", ver, "f", dn.Info.F, "signers", signers) } - return nil + return proposals, nil } diff --git a/deployment/keystone/deploy_test.go b/deployment/keystone/deploy_test.go index fd59f3007fd..715f8b7aba7 100644 --- a/deployment/keystone/deploy_test.go +++ b/deployment/keystone/deploy_test.go @@ -142,10 +142,7 @@ func TestDeployCLO(t *testing.T) { } deployResp, err := keystone.ConfigureContracts(ctx, lggr, deployReq) require.NoError(t, err) - ad := deployResp.Changeset.AddressBook - addrs, err := ad.Addresses() - require.NoError(t, err) - lggr.Infow("Deployed Keystone contracts", "address book", addrs) + ad := env.ExistingAddresses // all contracts on home chain homeChainAddrs, err := ad.AddressesForChain(registryChainSel) diff --git a/deployment/keystone/forwarder_deployer.go b/deployment/keystone/forwarder_deployer.go index cf29b20c693..d7cfa7991f4 100644 --- a/deployment/keystone/forwarder_deployer.go +++ b/deployment/keystone/forwarder_deployer.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock" "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink/deployment" @@ -56,3 +57,43 @@ func (c *KeystoneForwarderDeployer) deploy(req DeployRequest) (*DeployResponse, c.contract = forwarder return resp, nil } + +type ConfigureForwarderContractsRequest struct { + Dons []RegisteredDon + + UseMCMS bool +} +type ConfigureForwarderContractsResponse struct { + Proposals []timelock.MCMSWithTimelockProposal +} + +// Depreciated: use [changeset.ConfigureForwarders] instead +// ConfigureForwardContracts configures the forwarder contracts on all chains for the given DONS +// the address book is required to contain the an address of the deployed forwarder contract for every chain in the environment +func ConfigureForwardContracts(env *deployment.Environment, req ConfigureForwarderContractsRequest) (*ConfigureForwarderContractsResponse, error) { + contractSetsResp, err := GetContractSets(env.Logger, &GetContractSetsRequest{ + Chains: env.Chains, + AddressBook: env.ExistingAddresses, + }) + if err != nil { + return nil, fmt.Errorf("failed to get contract sets: %w", err) + } + + var allProposals []timelock.MCMSWithTimelockProposal + // configure forwarders on all chains + for _, chain := range env.Chains { + // get the forwarder contract for the chain + contracts, ok := contractSetsResp.ContractSets[chain.Selector] + if !ok { + return nil, fmt.Errorf("failed to get contract set for chain %d", chain.Selector) + } + proposals, err := configureForwarder(env.Logger, chain, contracts, req.Dons, req.UseMCMS) + if err != nil { + return nil, fmt.Errorf("failed to configure forwarder for chain selector %d: %w", chain.Selector, err) + } + allProposals = append(allProposals, proposals...) + } + return &ConfigureForwarderContractsResponse{ + Proposals: allProposals, + }, nil +} diff --git a/deployment/keystone/types.go b/deployment/keystone/types.go index 52620a52a0e..d406487043c 100644 --- a/deployment/keystone/types.go +++ b/deployment/keystone/types.go @@ -230,7 +230,51 @@ type RegisteredDon struct { Nodes []deployment.Node } -func (d RegisteredDon) signers(chainFamily string) []common.Address { +type RegisteredDonConfig struct { + Name string + NodeIDs []string // ids in the offchain client + RegistryChainSel uint64 +} + +func NewRegisteredDon(env deployment.Environment, cfg RegisteredDonConfig) (*RegisteredDon, error) { + // load the don info from the capabilities registry + r, err := GetContractSets(env.Logger, &GetContractSetsRequest{ + Chains: env.Chains, + AddressBook: env.ExistingAddresses, + }) + if err != nil { + return nil, fmt.Errorf("failed to get contract sets: %w", err) + } + capReg := r.ContractSets[cfg.RegistryChainSel].CapabilitiesRegistry + + di, err := capReg.GetDONs(nil) + if err != nil { + return nil, fmt.Errorf("failed to get dons: %w", err) + } + // load the nodes from the offchain client + nodes, err := deployment.NodeInfo(cfg.NodeIDs, env.Offchain) + if err != nil { + return nil, fmt.Errorf("failed to get node info: %w", err) + } + want := sortedHash(nodes.PeerIDs()) + var don *kcr.CapabilitiesRegistryDONInfo + for i, d := range di { + got := sortedHash(d.NodeP2PIds) + if got == want { + don = &di[i] + } + } + if don == nil { + return nil, fmt.Errorf("don not found in registry") + } + return &RegisteredDon{ + Name: cfg.Name, + Info: *don, + Nodes: nodes, + }, nil +} + +func (d RegisteredDon) Signers(chainFamily string) []common.Address { sort.Slice(d.Nodes, func(i, j int) bool { return d.Nodes[i].PeerID.String() < d.Nodes[j].PeerID.String() })