Skip to content

Commit

Permalink
type version fixes (#15042)
Browse files Browse the repository at this point in the history
* type version fixes

* fix test

* simplify
  • Loading branch information
krehermann authored Oct 31, 2024
1 parent 0900637 commit 8a9dbf4
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 33 deletions.
17 changes: 11 additions & 6 deletions deployment/keystone/capability_registry_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
Expand All @@ -25,11 +26,6 @@ func (c *CapabilitiesRegistryDeployer) Contract() *capabilities_registry.Capabil
return c.contract
}

var CapabilityRegistryTypeVersion = deployment.TypeAndVersion{
Type: CapabilitiesRegistry,
Version: deployment.Version1_0_0,
}

func (c *CapabilitiesRegistryDeployer) Deploy(req DeployRequest) (*DeployResponse, error) {
est, err := estimateDeploymentGas(req.Chain.Client, capabilities_registry.CapabilitiesRegistryABI)
if err != nil {
Expand All @@ -48,10 +44,19 @@ func (c *CapabilitiesRegistryDeployer) Deploy(req DeployRequest) (*DeployRespons
if err != nil {
return nil, fmt.Errorf("failed to confirm and save CapabilitiesRegistry: %w", err)
}
tvStr, err := capabilitiesRegistry.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: capabilitiesRegistryAddr,
Tx: tx.Hash(),
Tv: CapabilityRegistryTypeVersion,
Tv: tv,
}
c.contract = capabilitiesRegistry
return resp, nil
Expand Down
8 changes: 4 additions & 4 deletions deployment/keystone/changeset/configure_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ func ConfigureInitialContracts(lggr logger.Logger, req *kslib.ConfigureContracts
foundForwarder := false
for _, addr := range regAddrs {
switch addr.Type {
case kslib.CapabilityRegistryTypeVersion.Type:
case kslib.CapabilitiesRegistry:
foundRegistry = true
case kslib.OCR3CapabilityTypeVersion.Type:
case kslib.OCR3Capability:
foundOCR3 = true
case kslib.ForwarderTypeVersion.Type:
case kslib.KeystoneForwarder:
foundForwarder = true
}
}
Expand All @@ -43,7 +43,7 @@ func ConfigureInitialContracts(lggr logger.Logger, req *kslib.ConfigureContracts
return deployment.ChangesetOutput{}, fmt.Errorf("no addresses found for chain %d: %w", c.Selector, err2)
}
for _, addr := range addrs {
if addr.Type == kslib.ForwarderTypeVersion.Type {
if addr.Type == kslib.KeystoneForwarder {
foundForwarder = true
break
}
Expand Down
13 changes: 9 additions & 4 deletions deployment/keystone/changeset/deploy_forwarder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ func TestDeployForwarder(t *testing.T) {
}
env := memory.NewMemoryEnvironment(t, lggr, zapcore.DebugLevel, cfg)

var (
ocrTV = deployment.NewTypeAndVersion(kslb.OCR3Capability, deployment.Version1_0_0)
crTV = deployment.NewTypeAndVersion(kslb.CapabilitiesRegistry, deployment.Version1_0_0)
)

registrySel := env.AllChainSelectors()[0]
t.Run("err if no capabilities registry on registry chain", func(t *testing.T) {
ab := deployment.NewMemoryAddressBook()
m := make(map[uint64]map[string]deployment.TypeAndVersion)
m[registrySel] = map[string]deployment.TypeAndVersion{
"0x0000000000000000000000000000000000000002": kslb.OCR3CapabilityTypeVersion,
"0x0000000000000000000000000000000000000002": ocrTV,
}
deployment.NewMemoryAddressBookFromMap(m)
// capabilities registry and ocr3 must be deployed on registry chain
Expand All @@ -41,7 +46,7 @@ func TestDeployForwarder(t *testing.T) {
ab := deployment.NewMemoryAddressBook()
m := make(map[uint64]map[string]deployment.TypeAndVersion)
m[registrySel] = map[string]deployment.TypeAndVersion{
"0x0000000000000000000000000000000000000001": kslb.CapabilityRegistryTypeVersion,
"0x0000000000000000000000000000000000000001": crTV,
}
deployment.NewMemoryAddressBookFromMap(m)
// capabilities registry and ocr3 must be deployed on registry chain
Expand All @@ -52,11 +57,11 @@ func TestDeployForwarder(t *testing.T) {
t.Run("should deploy forwarder", func(t *testing.T) {
ab := deployment.NewMemoryAddressBook()
// fake capabilities registry
err := ab.Save(registrySel, "0x0000000000000000000000000000000000000001", kslb.CapabilityRegistryTypeVersion)
err := ab.Save(registrySel, "0x0000000000000000000000000000000000000001", crTV)
require.NoError(t, err)

// fake ocr3
err = ab.Save(registrySel, "0x0000000000000000000000000000000000000002", kslb.OCR3CapabilityTypeVersion)
err = ab.Save(registrySel, "0x0000000000000000000000000000000000000002", ocrTV)
require.NoError(t, err)
// deploy forwarder
resp, err := changeset.DeployForwarder(lggr, env, ab, registrySel)
Expand Down
2 changes: 1 addition & 1 deletion deployment/keystone/contract_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func DeployCapabilitiesRegistry(lggr logger.Logger, chain deployment.Chain, ab d
if err != nil {
return fmt.Errorf("failed to save CapabilitiesRegistry: %w", err)
}
lggr.Infof("Deployed %s chain selector %d addr %s", CapabilityRegistryTypeVersion.String(), chain.Selector, capabilitiesRegistryResp.Address.String())
lggr.Infof("Deployed %s chain selector %d addr %s", capabilitiesRegistryResp.Tv.String(), chain.Selector, capabilitiesRegistryResp.Address.String())
return nil
}

Expand Down
16 changes: 10 additions & 6 deletions deployment/keystone/forwarder_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keystone
import (
"fmt"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/forwarder"
Expand All @@ -13,11 +14,6 @@ type KeystoneForwarderDeployer struct {
contract *forwarder.KeystoneForwarder
}

var ForwarderTypeVersion = deployment.TypeAndVersion{
Type: KeystoneForwarder,
Version: deployment.Version1_0_0,
}

func (c *KeystoneForwarderDeployer) deploy(req DeployRequest) (*DeployResponse, error) {
est, err := estimateDeploymentGas(req.Chain.Client, forwarder.KeystoneForwarderABI)
if err != nil {
Expand All @@ -36,10 +32,18 @@ func (c *KeystoneForwarderDeployer) deploy(req DeployRequest) (*DeployResponse,
if err != nil {
return nil, fmt.Errorf("failed to confirm and save KeystoneForwarder: %w", err)
}
tvStr, err := forwarder.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: forwarderAddr,
Tx: tx.Hash(),
Tv: ForwarderTypeVersion,
Tv: tv,
}
c.contract = forwarder
return resp, nil
Expand Down
16 changes: 10 additions & 6 deletions deployment/keystone/ocr3_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keystone
import (
"fmt"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/ocr3_capability"
Expand All @@ -13,11 +14,6 @@ type OCR3Deployer struct {
contract *ocr3_capability.OCR3Capability
}

var OCR3CapabilityTypeVersion = deployment.TypeAndVersion{
Type: OCR3Capability,
Version: deployment.Version1_0_0,
}

func (c *OCR3Deployer) deploy(req DeployRequest) (*DeployResponse, error) {
est, err := estimateDeploymentGas(req.Chain.Client, ocr3_capability.OCR3CapabilityABI)
if err != nil {
Expand All @@ -36,10 +32,18 @@ func (c *OCR3Deployer) deploy(req DeployRequest) (*DeployResponse, error) {
if err != nil {
return nil, fmt.Errorf("failed to confirm transaction %s: %w", tx.Hash().String(), err)
}
tvStr, err := ocr3.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: ocr3Addr,
Tx: tx.Hash(),
Tv: OCR3CapabilityTypeVersion,
Tv: tv,
}
c.contract = ocr3
return resp, nil
Expand Down
3 changes: 0 additions & 3 deletions deployment/keystone/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ func loadContractSet(chain deployment.Chain, addresses map[string]deployment.Typ

for addr, tv := range addresses {
// todo handle versions
if !tv.Version.Equal(&deployment.Version1_0_0) {
return nil, fmt.Errorf("unsupported version %s", tv.Version.String())
}
switch tv.Type {
case CapabilitiesRegistry:
c, err := capabilities_registry.NewCapabilitiesRegistry(common.HexToAddress(addr), chain.Client)
Expand Down
7 changes: 4 additions & 3 deletions deployment/keystone/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import (
)

var (
CapabilitiesRegistry deployment.ContractType = "CapabilitiesRegistry"
KeystoneForwarder deployment.ContractType = "KeystoneForwarder"
OCR3Capability deployment.ContractType = "OCR3Capability"
CapabilitiesRegistry deployment.ContractType = "CapabilitiesRegistry" // https://github.com/smartcontractkit/chainlink/blob/50c1b3dbf31bd145b312739b08967600a5c67f30/contracts/src/v0.8/keystone/CapabilitiesRegistry.sol#L392
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
)

type DeployResponse struct {
Expand Down

0 comments on commit 8a9dbf4

Please sign in to comment.