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

Revert "deployment: Changes for keystone" #15170

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
github.com/AlekSi/pointer v1.1.0 // indirect
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 // indirect
github.com/ChainSafe/go-schnorrkel v1.0.0 // indirect
github.com/CosmWasm/wasmd v0.40.1 // indirect
Expand Down
137 changes: 137 additions & 0 deletions deployment/environment/clo/env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package clo

import (
"strconv"
"testing"

"github.com/test-go/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/environment/clo/models"
"github.com/smartcontractkit/chainlink/deployment/environment/memory"
)

type DonEnvConfig struct {
DonName string
Chains map[uint64]deployment.Chain
Logger logger.Logger
Nops []*models.NodeOperator
}

func NewDonEnv(t *testing.T, cfg DonEnvConfig) *deployment.Environment {
// no bootstraps in the don as far as capabilities registry is concerned
for _, nop := range cfg.Nops {
for _, node := range nop.Nodes {
for _, chain := range node.ChainConfigs {
if chain.Ocr2Config.IsBootstrap {
t.Fatalf("Don nodes should not be bootstraps nop %s node %s chain %s", nop.ID, node.ID, chain.Network.ChainID)
}
}
}
}
out := deployment.NewEnvironment(
cfg.DonName,
cfg.Logger,
deployment.NewMemoryAddressBook(),
cfg.Chains,
make([]string, 0),
NewJobClient(cfg.Logger, cfg.Nops),
)
// assume that all the nodes in the provided input nops are part of the don
for _, nop := range cfg.Nops {
for _, node := range nop.Nodes {
out.NodeIDs = append(out.NodeIDs, node.ID)
}
}

return out
}

func NewDonEnvWithMemoryChains(t *testing.T, cfg DonEnvConfig, ignore func(*models.NodeChainConfig) bool) *deployment.Environment {
e := NewDonEnv(t, cfg)
// overwrite the chains with memory chains
chains := make(map[uint64]struct{})
for _, nop := range cfg.Nops {
for _, node := range nop.Nodes {
for _, chain := range node.ChainConfigs {
if ignore(chain) {
continue
}
id, err := strconv.ParseUint(chain.Network.ChainID, 10, 64)
require.NoError(t, err, "failed to parse chain id to uint64")
chains[id] = struct{}{}
}
}
}
var cs []uint64
for c := range chains {
cs = append(cs, c)
}
memoryChains := memory.NewMemoryChainsWithChainIDs(t, cs)
e.Chains = memoryChains
return e
}

// MultiDonEnvironment is a single logical deployment environment (like dev, testnet, prod,...).
// It represents the idea that different nodesets host different capabilities.
// Each element in the DonEnv is a logical set of nodes that host the same capabilities.
// This model allows us to reuse the existing Environment abstraction while supporting multiple nodesets at
// expense of slightly abusing the original abstraction. Specifically, the abuse is that
// each Environment in the DonToEnv map is a subset of the target deployment environment.
// One element cannot represent dev and other testnet for example.
type MultiDonEnvironment struct {
donToEnv map[string]*deployment.Environment
Logger logger.Logger
// hacky but temporary to transition to Environment abstraction. set by New
Chains map[uint64]deployment.Chain
}

func (mde MultiDonEnvironment) Flatten(name string) *deployment.Environment {
// TODO: KS-460 integrate with the clo offchain client impl
// may need to extend the Environment abstraction use maps rather than slices for Nodes
// somehow we need to capture the fact that each nodes belong to nodesets which have different capabilities
// purposely nil to catch misuse until we do that work
return deployment.NewEnvironment(
name,
mde.Logger,
deployment.NewMemoryAddressBook(),
mde.Chains,
nil,
nil,
)
}

func newMultiDonEnvironment(logger logger.Logger, donToEnv map[string]*deployment.Environment) *MultiDonEnvironment {
chains := make(map[uint64]deployment.Chain)
for _, env := range donToEnv {
for sel, chain := range env.Chains {
if _, exists := chains[sel]; !exists {
chains[sel] = chain
}
}
}
return &MultiDonEnvironment{
donToEnv: donToEnv,
Logger: logger,
Chains: chains,
}
}

func NewTestEnv(t *testing.T, lggr logger.Logger, dons map[string]*deployment.Environment) *MultiDonEnvironment {
for _, don := range dons {
//don := don
seen := make(map[uint64]deployment.Chain)
// ensure that generated chains are the same for all environments. this ensures that he in memory representation
// points to a common object for all dons given the same selector.
for sel, chain := range don.Chains {
c, exists := seen[sel]
if exists {
don.Chains[sel] = c
} else {
seen[sel] = chain
}
}
}
return newMultiDonEnvironment(lggr, dons)
}
84 changes: 20 additions & 64 deletions deployment/environment/clo/offchain_client_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@ package clo

import (
"context"
"fmt"
"slices"
"strings"

"go.uber.org/zap"
"google.golang.org/grpc"

"github.com/AlekSi/pointer"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
csav1 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/csa"
jobv1 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/job"
nodev1 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/node"
"github.com/smartcontractkit/chainlink-protos/job-distributor/v1/shared/ptypes"
"github.com/smartcontractkit/chainlink/deployment/environment/clo/models"
)

Expand Down Expand Up @@ -65,64 +60,39 @@ 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) {
include := func(node *nodev1.Node) bool {
if in.Filter == nil {
//TODO CCIP-3108
var fiterIds map[string]struct{}
include := func(id string) bool {
if in.Filter == nil || len(in.Filter.Ids) == 0 {
return true
}
if len(in.Filter.Ids) > 0 {
idx := slices.IndexFunc(in.Filter.Ids, func(id string) bool {
return node.Id == id
})
if idx < 0 {
return false
// lazy init
if len(fiterIds) == 0 {
for _, id := range in.Filter.Ids {
fiterIds[id] = struct{}{}
}
}
for _, selector := range in.Filter.Selectors {
idx := slices.IndexFunc(node.Labels, func(label *ptypes.Label) bool {
return label.Key == selector.Key
})
if idx < 0 {
return false
}
label := node.Labels[idx]

switch selector.Op {
case ptypes.SelectorOp_IN:
values := strings.Split(*selector.Value, ",")
found := slices.Contains(values, *label.Value)
if !found {
return false
}
default:
panic("unimplemented selector")
}
}
return true
_, ok := fiterIds[id]
return ok
}
var nodes []*nodev1.Node
for _, nop := range j.NodeOperators {
for _, n := range nop.Nodes {
node := &nodev1.Node{
Id: n.ID,
Name: n.Name,
PublicKey: *n.PublicKey,
IsEnabled: n.Enabled,
IsConnected: n.Connected,
Labels: []*ptypes.Label{
{
Key: "p2p_id",
Value: pointer.ToString(n.ID), // here n.ID is also peer ID
},
},
}
if include(node) {
nodes = append(nodes, node)
if include(n.ID) {
nodes = append(nodes, &nodev1.Node{
Id: n.ID,
Name: n.Name,
PublicKey: *n.PublicKey, // is this the correct val?
IsEnabled: n.Enabled,
IsConnected: n.Connected,
})
}
}
}
return &nodev1.ListNodesResponse{
Nodes: nodes,
}, nil

}

func (j JobClient) ListNodeChainConfigs(ctx context.Context, in *nodev1.ListNodeChainConfigsRequest, opts ...grpc.CallOption) (*nodev1.ListNodeChainConfigsResponse, error) {
Expand Down Expand Up @@ -214,24 +184,10 @@ 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: ctype,
Type: nodev1.ChainType_CHAIN_TYPE_EVM, // TODO: write conversion func from clo to jd tyes
},
AccountAddress: ccfg.AccountAddress,
AdminAddress: ccfg.AdminAddress,
Expand Down
32 changes: 0 additions & 32 deletions deployment/environment/clo/offchain_client_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import (
"reflect"
"testing"

"github.com/AlekSi/pointer"
"github.com/test-go/testify/require"
"google.golang.org/grpc"

nodev1 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/node"
"github.com/smartcontractkit/chainlink-protos/job-distributor/v1/shared/ptypes"
"github.com/smartcontractkit/chainlink/deployment/environment/clo"
"github.com/smartcontractkit/chainlink/deployment/environment/clo/models"
"github.com/smartcontractkit/chainlink/v2/core/logger"
Expand Down Expand Up @@ -137,12 +135,6 @@ func TestJobClient_ListNodes(t *testing.T) {
Name: "Chainlink Sepolia Prod Keystone One 9",
PublicKey: "412dc6fe48ea4e34baaa77da2e3b032d39b938597b6f3d61fe7ed183a827a431",
IsConnected: true,
Labels: []*ptypes.Label{
{
Key: "p2p_id",
Value: pointer.ToString("780"),
},
},
},
},
},
Expand All @@ -163,24 +155,12 @@ func TestJobClient_ListNodes(t *testing.T) {
Name: "Chainlink Sepolia Prod Keystone One 9",
PublicKey: "412dc6fe48ea4e34baaa77da2e3b032d39b938597b6f3d61fe7ed183a827a431",
IsConnected: true,
Labels: []*ptypes.Label{
{
Key: "p2p_id",
Value: pointer.ToString("780"),
},
},
},
{
Id: "781",
Name: "Chainlink Sepolia Prod Keystone One 8",
PublicKey: "1141dd1e46797ced9b0fbad49115f18507f6f6e6e3cc86e7e5ba169e58645adc",
IsConnected: true,
Labels: []*ptypes.Label{
{
Key: "p2p_id",
Value: pointer.ToString("781"),
},
},
},
},
},
Expand All @@ -201,24 +181,12 @@ func TestJobClient_ListNodes(t *testing.T) {
Name: "Chainlink Sepolia Prod Keystone One 999",
PublicKey: "9991dd1e46797ced9b0fbad49115f18507f6f6e6e3cc86e7e5ba169e58999999",
IsConnected: true,
Labels: []*ptypes.Label{
{
Key: "p2p_id",
Value: pointer.ToString("999"),
},
},
},
{
Id: "1000",
Name: "Chainlink Sepolia Prod Keystone One 1000",
PublicKey: "1000101e46797ced9b0fbad49115f18507f6f6e6e3cc86e7e5ba169e58641000",
IsConnected: true,
Labels: []*ptypes.Label{
{
Key: "p2p_id",
Value: pointer.ToString("1000"),
},
},
},
},
},
Expand Down
Loading
Loading