Skip to content

Commit b4e91c2

Browse files
Remove top level contract set (#17701)
* Removes top level contract set usage - WIP * Removes top level contract set * Fixes lint * Renames map
1 parent a6b3ca6 commit b4e91c2

File tree

6 files changed

+66
-228
lines changed

6 files changed

+66
-228
lines changed

deployment/keystone/changeset/accept_ownership.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,13 @@ var _ cldf.ChangeSet[*AcceptAllOwnershipRequest] = AcceptAllOwnershipsProposal
2121
// AcceptAllOwnershipsProposal creates a MCMS proposal to call accept ownership on all the Keystone contracts in the address book.
2222
func AcceptAllOwnershipsProposal(e cldf.Environment, req *AcceptAllOwnershipRequest) (cldf.ChangesetOutput, error) {
2323
chainSelector := req.ChainSelector
24-
minDelay := req.MinDelay
25-
chain := e.Chains[chainSelector]
26-
addrBook := e.ExistingAddresses
27-
28-
r, err := getContractSetsV2(e.Logger, getContractSetsRequestV2{
29-
Chains: map[uint64]cldf.Chain{
30-
req.ChainSelector: chain,
31-
},
32-
AddressBook: addrBook,
33-
})
34-
if err != nil {
35-
return cldf.ChangesetOutput{}, err
36-
}
37-
contracts := r.ContractSets[chainSelector]
3824

3925
// Construct the configuration
4026
cfg := changeset.TransferToMCMSWithTimelockConfig{
4127
ContractsByChain: map[uint64][]common.Address{
42-
chainSelector: contracts.transferableContracts(),
28+
chainSelector: getTransferableContracts(e.DataStore.Addresses(), chainSelector),
4329
},
44-
MCMSConfig: proposalutils.TimelockConfig{MinDelay: minDelay},
30+
MCMSConfig: proposalutils.TimelockConfig{MinDelay: req.MinDelay},
4531
}
4632

4733
// Create and return the changeset

deployment/keystone/changeset/contract_set.go

Lines changed: 0 additions & 166 deletions
This file was deleted.

deployment/keystone/changeset/contracts.go

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -340,31 +340,36 @@ func loadCapabilityRegistry(registryChain cldf.Chain, env cldf.Environment, ref
340340
if err != nil {
341341
return nil, fmt.Errorf("failed to check registry ref: %w", err)
342342
}
343+
343344
var cr *OwnedContract[*capabilities_registry.CapabilitiesRegistry]
344-
if ref != nil {
345-
a, err := env.DataStore.Addresses().Get(ref)
346-
if err != nil {
347-
return nil, fmt.Errorf("failed to get address: %w", err)
348-
}
349-
cr, err = GetOwnedContractV2[*capabilities_registry.CapabilitiesRegistry](env.DataStore.Addresses(), registryChain, a.Address)
350-
if err != nil {
351-
return nil, fmt.Errorf("failed to get owned contract: %w", err)
352-
}
353-
} else {
354-
// TODO: CRE-400 remove this once we have migrated all environments to use datastore
355-
// This is a temporary backward compatibility until all the CLD environments are migrated to use datastore
356-
cs, err := getContractSetsV2(env.Logger, getContractSetsRequestV2{
357-
Chains: map[uint64]cldf.Chain{registryChain.Selector: registryChain},
358-
AddressBook: env.ExistingAddresses, //nolint:staticcheck // TODO CRE-400 remove this once we have migrated all environments to use datastore
359-
})
360-
if err != nil {
361-
return nil, fmt.Errorf("failed to get contract sets: %w", err)
362-
}
363-
contractSet, exists := cs.ContractSets[registryChain.Selector]
364-
if !exists {
365-
return nil, fmt.Errorf("contract set not found for chain %d", registryChain.Selector)
366-
}
367-
cr = contractSet.CapabilitiesRegistry
345+
346+
// `shouldUseDatastore` is already checking for the nil ref, no need to `ref == nil` here
347+
a, err := env.DataStore.Addresses().Get(ref)
348+
if err != nil {
349+
return nil, fmt.Errorf("failed to get address: %w", err)
350+
}
351+
cr, err = GetOwnedContractV2[*capabilities_registry.CapabilitiesRegistry](env.DataStore.Addresses(), registryChain, a.Address)
352+
if err != nil {
353+
return nil, fmt.Errorf("failed to get owned contract: %w", err)
368354
}
355+
369356
return cr, nil
370357
}
358+
359+
func getTransferableContracts(addressStore datastore.AddressRefStore, chainSelector uint64) []common.Address {
360+
var transferableContracts []common.Address
361+
362+
addresses := addressStore.Filter(datastore.AddressRefByChainSelector(chainSelector))
363+
for _, addr := range addresses {
364+
isOCR3Capability := addr.Type == datastore.ContractType(OCR3Capability)
365+
isWorkflowRegistry := addr.Type == datastore.ContractType(WorkflowRegistry)
366+
isKeystoneForwarder := addr.Type == datastore.ContractType(KeystoneForwarder)
367+
isCapabilityRegistry := addr.Type == datastore.ContractType(CapabilitiesRegistry)
368+
369+
if isCapabilityRegistry || isWorkflowRegistry || isKeystoneForwarder || isOCR3Capability {
370+
transferableContracts = append(transferableContracts, common.HexToAddress(addr.Address))
371+
}
372+
}
373+
374+
return transferableContracts
375+
}

deployment/keystone/changeset/deploy_forwarder.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
mcmstypes "github.com/smartcontractkit/mcms/types"
1111

1212
"github.com/smartcontractkit/chainlink-deployments-framework/datastore"
13-
1413
cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment"
14+
forwarder "github.com/smartcontractkit/chainlink-evm/gethwrappers/keystone/generated/forwarder_1_0_0"
1515

1616
"github.com/smartcontractkit/chainlink/deployment/common/proposalutils"
1717
"github.com/smartcontractkit/chainlink/deployment/keystone/changeset/internal"
@@ -129,26 +129,28 @@ func ConfigureForwardContracts(env cldf.Environment, req ConfigureForwardContrac
129129
return cldf.ChangesetOutput{}, fmt.Errorf("failed to configure forward contracts: %w", err)
130130
}
131131

132-
cresp, err := getContractSetsV2(env.Logger, getContractSetsRequestV2{
133-
Chains: env.Chains,
134-
AddressBook: env.ExistingAddresses,
135-
})
136-
if err != nil {
137-
return cldf.ChangesetOutput{}, fmt.Errorf("failed to get contract sets: %w", err)
138-
}
139-
140132
var out cldf.ChangesetOutput
141133
if req.UseMCMS() {
142134
if len(r.OpsPerChain) == 0 {
143135
return out, errors.New("expected MCMS operation to be non-nil")
144136
}
145137
for chainSelector, op := range r.OpsPerChain {
146-
contracts := cresp.ContractSets[chainSelector]
138+
fwrAddr, ok := r.ForwarderAddresses[chainSelector]
139+
if !ok {
140+
return out, fmt.Errorf("expected configured forwarder address for chain selector %d", chainSelector)
141+
}
142+
fwr, err := GetOwnedContractV2[*forwarder.KeystoneForwarder](env.DataStore.Addresses(), env.Chains[chainSelector], fwrAddr.String())
143+
if err != nil {
144+
return out, fmt.Errorf("failed to get forwarder contract for chain selector %d: %w", chainSelector, err)
145+
}
146+
if fwr.McmsContracts == nil {
147+
return out, fmt.Errorf("expected forwarder contract %s to be owned by MCMS for chain selector %d", fwrAddr.String(), chainSelector)
148+
}
147149
timelocksPerChain := map[uint64]string{
148-
chainSelector: contracts.Forwarder.McmsContracts.Timelock.Address().Hex(),
150+
chainSelector: fwr.McmsContracts.Timelock.Address().Hex(),
149151
}
150152
proposerMCMSes := map[uint64]string{
151-
chainSelector: contracts.Forwarder.McmsContracts.ProposerMcm.Address().Hex(),
153+
chainSelector: fwr.McmsContracts.ProposerMcm.Address().Hex(),
152154
}
153155
inspector, err := proposalutils.McmsInspectorForChain(env, chainSelector)
154156
if err != nil {

deployment/keystone/changeset/deploy_ocr3.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io"
88

99
"github.com/ethereum/go-ethereum/common"
10+
ocr3_capability "github.com/smartcontractkit/chainlink-evm/gethwrappers/keystone/generated/ocr3_capability_1_0_0"
1011

1112
cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment"
1213

@@ -82,19 +83,22 @@ func ConfigureOCR3Contract(env cldf.Environment, cfg ConfigureOCR3Config) (cldf.
8283
if resp.Ops == nil {
8384
return out, errors.New("expected MCMS operation to be non-nil")
8485
}
85-
r, err := getContractSetsV2(env.Logger, getContractSetsRequestV2{
86-
Chains: env.Chains,
87-
AddressBook: env.ExistingAddresses,
88-
})
86+
87+
chain, ok := env.Chains[cfg.ChainSel]
88+
if !ok {
89+
return out, fmt.Errorf("chain %d not found in environment", cfg.ChainSel)
90+
}
91+
92+
contract, err := GetOwnedContractV2[*ocr3_capability.OCR3Capability](env.DataStore.Addresses(), chain, cfg.Address.Hex())
8993
if err != nil {
90-
return out, fmt.Errorf("failed to get contract sets: %w", err)
94+
return out, fmt.Errorf("failed to get OCR3 contract: %w", err)
9195
}
92-
contracts := r.ContractSets[cfg.ChainSel]
96+
9397
timelocksPerChain := map[uint64]string{
94-
cfg.ChainSel: contracts.OCR3[*cfg.Address].McmsContracts.Timelock.Address().Hex(),
98+
cfg.ChainSel: contract.McmsContracts.Timelock.Address().Hex(),
9599
}
96100
proposerMCMSes := map[uint64]string{
97-
cfg.ChainSel: contracts.OCR3[*cfg.Address].McmsContracts.ProposerMcm.Address().Hex(),
101+
cfg.ChainSel: contract.McmsContracts.ProposerMcm.Address().Hex(),
98102
}
99103

100104
inspector, err := proposalutils.McmsInspectorForChain(env, cfg.ChainSel)

deployment/keystone/changeset/internal/forwarder_deployer.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66

77
"github.com/ethereum/go-ethereum/accounts/abi/bind"
8+
"github.com/ethereum/go-ethereum/common"
89
mcmstypes "github.com/smartcontractkit/mcms/types"
910

1011
"github.com/smartcontractkit/chainlink-common/pkg/logger"
@@ -80,7 +81,10 @@ type ConfigureForwarderContractsRequest struct {
8081
UseMCMS bool
8182
}
8283
type ConfigureForwarderContractsResponse struct {
83-
OpsPerChain map[uint64]mcmstypes.BatchOperation
84+
// ForwarderAddresses is a map of chain selector to forwarder contract address that has been configured (non-MCMS),
85+
// or will be configured (MCMS).
86+
ForwarderAddresses map[uint64]common.Address
87+
OpsPerChain map[uint64]mcmstypes.BatchOperation
8488
}
8589

8690
// Depreciated: use [changeset.ConfigureForwardContracts] instead
@@ -96,6 +100,7 @@ func ConfigureForwardContracts(env *cldf.Environment, req ConfigureForwarderCont
96100
}
97101

98102
opPerChain := make(map[uint64]mcmstypes.BatchOperation)
103+
forwarderAddresses := make(map[uint64]common.Address)
99104
// configure forwarders on all chains
100105
for _, chain := range env.Chains {
101106
if _, shouldInclude := req.Chains[chain.Selector]; len(req.Chains) > 0 && !shouldInclude {
@@ -113,8 +118,10 @@ func ConfigureForwardContracts(env *cldf.Environment, req ConfigureForwarderCont
113118
for k, op := range ops {
114119
opPerChain[k] = op
115120
}
121+
forwarderAddresses[chain.Selector] = contracts.Forwarder.Address()
116122
}
117123
return &ConfigureForwarderContractsResponse{
118-
OpsPerChain: opPerChain,
124+
ForwarderAddresses: forwarderAddresses,
125+
OpsPerChain: opPerChain,
119126
}, nil
120127
}

0 commit comments

Comments
 (0)