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

deployment: Changes for keystone #14837

Merged
merged 18 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
136 changes: 0 additions & 136 deletions deployment/environment/clo/env.go

This file was deleted.

21 changes: 18 additions & 3 deletions deployment/environment/clo/offchain_client_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package clo

import (
"context"
"fmt"

"go.uber.org/zap"
"google.golang.org/grpc"
Expand Down Expand Up @@ -61,7 +62,7 @@ func (j JobClient) GetNode(ctx context.Context, in *nodev1.GetNodeRequest, opts

func (j JobClient) ListNodes(ctx context.Context, in *nodev1.ListNodesRequest, opts ...grpc.CallOption) (*nodev1.ListNodesResponse, error) {
//TODO CCIP-3108
var fiterIds map[string]struct{}
fiterIds := make(map[string]any)
include := func(id string) bool {
if in.Filter == nil || len(in.Filter.Ids) == 0 {
return true
Expand All @@ -82,7 +83,7 @@ func (j JobClient) ListNodes(ctx context.Context, in *nodev1.ListNodesRequest, o
nodes = append(nodes, &nodev1.Node{
Id: n.ID,
Name: n.Name,
PublicKey: *n.PublicKey, // is this the correct val?
PublicKey: *n.PublicKey,
IsEnabled: n.Enabled,
IsConnected: n.Connected,
})
Expand Down Expand Up @@ -184,10 +185,24 @@ func cloNodeToChainConfigs(n *models.Node) []*nodev1.ChainConfig {
}

func cloChainCfgToJDChainCfg(ccfg *models.NodeChainConfig) *nodev1.ChainConfig {
var ctype nodev1.ChainType
switch ccfg.Network.ChainType {
case models.ChainTypeEvm:
ctype = nodev1.ChainType_CHAIN_TYPE_EVM
case models.ChainTypeSolana:
ctype = nodev1.ChainType_CHAIN_TYPE_SOLANA
case models.ChainTypeStarknet:
ctype = nodev1.ChainType_CHAIN_TYPE_STARKNET
case models.ChainTypeAptos:
ctype = nodev1.ChainType_CHAIN_TYPE_APTOS
default:
panic(fmt.Sprintf("Unsupported chain family %v", ccfg.Network.ChainType))
}

return &nodev1.ChainConfig{
Chain: &nodev1.Chain{
Id: ccfg.Network.ChainID,
Type: nodev1.ChainType_CHAIN_TYPE_EVM, // TODO: write conversion func from clo to jd tyes
Type: ctype,
},
AccountAddress: ccfg.AccountAddress,
AdminAddress: ccfg.AdminAddress,
Expand Down
47 changes: 36 additions & 11 deletions deployment/environment/devenv/don.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type NodeInfo struct {
Name string // name of the node, used to identify the node, helpful in logs
AdminAddr string // admin address to send payments to, applicable only for non-bootstrap nodes
MultiAddr string // multi address denoting node's FQN (needed for deriving P2PBootstrappers in OCR), applicable only for bootstrap nodes
Labels map[string]string // labels to use when registering the node with job distributor
}

type DON struct {
Expand Down Expand Up @@ -104,6 +105,12 @@ func NewRegisteredDON(ctx context.Context, nodeInfo []NodeInfo, jd JobDistributo
return nil, fmt.Errorf("failed to create node %d: %w", i, err)
}
// node Labels so that it's easier to query them
for key, value := range info.Labels {
node.labels = append(node.labels, &ptypes.Label{
Key: key,
Value: pointer.ToString(value),
})
}
if info.IsBootstrap {
// create multi address for OCR2, applicable only for bootstrap nodes
if info.MultiAddr == "" {
Expand Down Expand Up @@ -181,17 +188,35 @@ type JDChainConfigInput struct {
func (n *Node) CreateCCIPOCRSupportedChains(ctx context.Context, chains []JDChainConfigInput, jd JobDistributor) error {
for i, chain := range chains {
chainId := strconv.FormatUint(chain.ChainID, 10)
accountAddr, err := n.gqlClient.FetchAccountAddress(ctx, chainId)
if err != nil {
return fmt.Errorf("failed to fetch account address for node %s: %w", n.Name, err)
}
if accountAddr == nil {
return fmt.Errorf("no account address found for node %s", n.Name)
}
if n.AccountAddr == nil {
n.AccountAddr = make(map[uint64]string)
var account string
switch chain.ChainType {
case "EVM":
accountAddr, err := n.gqlClient.FetchAccountAddress(ctx, chainId)
if err != nil {
return fmt.Errorf("failed to fetch account address for node %s: %w", n.Name, err)
}
if accountAddr == nil {
return fmt.Errorf("no account address found for node %s", n.Name)
}
if n.AccountAddr == nil {
n.AccountAddr = make(map[uint64]string)
}
n.AccountAddr[chain.ChainID] = *accountAddr
account = *accountAddr
case "APTOS", "SOLANA":
accounts, err := n.gqlClient.FetchKeys(ctx, chain.ChainType)
if err != nil {
return fmt.Errorf("failed to fetch account address for node %s: %w", n.Name, err)
}
if len(accounts) == 0 {
return fmt.Errorf("no account address found for node %s", n.Name)
}

account = accounts[0]
default:
return fmt.Errorf("unsupported chainType %v", chain.ChainType)
}
n.AccountAddr[chain.ChainID] = *accountAddr

peerID, err := n.gqlClient.FetchP2PPeerID(ctx)
if err != nil {
return fmt.Errorf("failed to fetch peer id for node %s: %w", n.Name, err)
Expand Down Expand Up @@ -221,7 +246,7 @@ func (n *Node) CreateCCIPOCRSupportedChains(ctx context.Context, chains []JDChai
JobDistributorID: n.JDId,
ChainID: chainId,
ChainType: chain.ChainType,
AccountAddr: pointer.GetString(accountAddr),
AccountAddr: account,
AdminAddr: n.adminAddr,
Ocr2Enabled: true,
Ocr2IsBootstrap: isBootstrap,
Expand Down
2 changes: 1 addition & 1 deletion deployment/environment/memory/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func GenerateChainsWithIds(t *testing.T, chainIDs []uint64) map[uint64]EVMChain
owner, err := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
require.NoError(t, err)
backend := backends.NewSimulatedBackend(core.GenesisAlloc{
owner.From: {Balance: big.NewInt(0).Mul(big.NewInt(100), big.NewInt(params.Ether))}}, 10000000)
owner.From: {Balance: big.NewInt(0).Mul(big.NewInt(700000), big.NewInt(params.Ether))}}, 50000000)
tweakChainTimestamp(t, backend, time.Hour*8)
chains[chainID] = EVMChain{
Backend: backend,
Expand Down
29 changes: 15 additions & 14 deletions deployment/environment/memory/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/core/types"
"github.com/hashicorp/consul/sdk/freeport"
"github.com/stretchr/testify/require"
Expand All @@ -29,6 +29,18 @@ type MemoryEnvironmentConfig struct {
RegistryConfig deployment.CapabilityRegistryConfig
}

// For placeholders like aptos
func NewMemoryChain(t *testing.T, selector uint64) deployment.Chain {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note TODO here regarding the thinking for non-evms

// TODO: Add SolChains, AptosChain etc.
. Fine if we intend to come back to it, but intention is we'd add some aptos go sdk based Chain there (will require bumping geth to 1.14, which I'm working on with @jmank88)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up not even using this in the tests since chain-selectors doesn't support non-EVMs, but most other chains don't have a simulated backend. We'd need to start a local node and test against that. For Keystone tests at the moment we don't actually need a fully configured node, just an instance of the node with the Aptos keys available so we can configure the contracts.

Copy link
Contributor

@connorwstein connorwstein Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chain-selectors fully was intended to support non-evms, should be fixed soon.

but most other chains don't have a simulated backend. We'd need to start a local node and test against that.

The onchain interface isn't tied to a simulated backend. The intention there is to use the docker based environment for families where that doesn't exist. The AptosOnchainClient or w/e interface would just have an implementation only in the devenv not memory

return deployment.Chain{
Selector: selector,
Client: nil,
DeployerKey: &bind.TransactOpts{},
Confirm: func(tx *types.Transaction) (uint64, error) {
return 0, nil
},
}
}

// Needed for environment variables on the node which point to prexisitng addresses.
// i.e. CapReg.
func NewMemoryChains(t *testing.T, numChains int) map[uint64]deployment.Chain {
Expand Down Expand Up @@ -78,30 +90,19 @@ func generateMemoryChain(t *testing.T, inputs map[uint64]EVMChain) map[uint64]de
}

func NewNodes(t *testing.T, logLevel zapcore.Level, chains map[uint64]deployment.Chain, numNodes, numBootstraps int, registryConfig deployment.CapabilityRegistryConfig) map[string]Node {
mchains := make(map[uint64]EVMChain)
for _, chain := range chains {
evmChainID, err := chainsel.ChainIdFromSelector(chain.Selector)
if err != nil {
t.Fatal(err)
}
mchains[evmChainID] = EVMChain{
Backend: chain.Client.(*backends.SimulatedBackend),
DeployerKey: chain.DeployerKey,
}
}
nodesByPeerID := make(map[string]Node)
ports := freeport.GetN(t, numBootstraps+numNodes)
// bootstrap nodes must be separate nodes from plugin nodes,
// since we won't run a bootstrapper and a plugin oracle on the same
// chainlink node in production.
for i := 0; i < numBootstraps; i++ {
node := NewNode(t, ports[i], mchains, logLevel, true /* bootstrap */, registryConfig)
node := NewNode(t, ports[i], chains, logLevel, true /* bootstrap */, registryConfig)
nodesByPeerID[node.Keys.PeerID.String()] = *node
// Note in real env, this ID is allocated by JD.
}
for i := 0; i < numNodes; i++ {
// grab port offset by numBootstraps, since above loop also takes some ports.
node := NewNode(t, ports[numBootstraps+i], mchains, logLevel, false /* bootstrap */, registryConfig)
node := NewNode(t, ports[numBootstraps+i], chains, logLevel, false /* bootstrap */, registryConfig)
nodesByPeerID[node.Keys.PeerID.String()] = *node
// Note in real env, this ID is allocated by JD.
}
Expand Down
Loading
Loading