Skip to content

Commit

Permalink
deployment: Changes for keystone (#14837)
Browse files Browse the repository at this point in the history
* deployment: Support other chain types in CreateCCIPOCRSupportedChains

* nix: Upgrade to postgres 15

* keystone: Migrate from CLO to JD

* CLO compat

* Allow setting labels on nodes

* Rename function

* Tag nodes with p2p_id for easy lookup

* Lookup nodes according to p2p_id

* Implement label & id filtering in the memory job client

* Update the CLO job client as well

* go mod tidy

* Fix DeployCLO

* Fix CLO job client test

* add TODOs

* fix up tests again

---------

Co-authored-by: krehermann <[email protected]>
  • Loading branch information
archseer and krehermann authored Nov 8, 2024
1 parent 53ab9cf commit 5db63e7
Show file tree
Hide file tree
Showing 23 changed files with 1,233 additions and 686 deletions.
1 change: 1 addition & 0 deletions core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ 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: 0 additions & 137 deletions deployment/environment/clo/env.go

This file was deleted.

84 changes: 64 additions & 20 deletions deployment/environment/clo/offchain_client_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ 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 @@ -60,39 +65,64 @@ 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{}
include := func(id string) bool {
if in.Filter == nil || len(in.Filter.Ids) == 0 {
include := func(node *nodev1.Node) bool {
if in.Filter == nil {
return true
}
// lazy init
if len(fiterIds) == 0 {
for _, id := range in.Filter.Ids {
fiterIds[id] = struct{}{}
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
}
}
_, ok := fiterIds[id]
return ok
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
}
var nodes []*nodev1.Node
for _, nop := range j.NodeOperators {
for _, n := range nop.Nodes {
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,
})
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)
}
}
}
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 @@ -184,10 +214,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
32 changes: 32 additions & 0 deletions deployment/environment/clo/offchain_client_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ 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 @@ -135,6 +137,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"),
},
},
},
},
},
Expand All @@ -155,12 +163,24 @@ 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 @@ -181,12 +201,24 @@ 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

0 comments on commit 5db63e7

Please sign in to comment.