Skip to content

Commit

Permalink
Ccip-3606 few fixes (#14644)
Browse files Browse the repository at this point in the history
* few fixes

* more

* generate nops view
  • Loading branch information
AnieeG authored Oct 3, 2024
1 parent 6466bb2 commit 815b2c8
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 5 deletions.
10 changes: 9 additions & 1 deletion integration-tests/deployment/ccip/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,15 @@ func StateView(e deployment.Environment, ab deployment.AddressBook) (view.CCIPVi
if err != nil {
return view.CCIPView{}, err
}
return state.View(e.AllChainSelectors())
ccipView, err := state.View(e.AllChainSelectors())
if err != nil {
return view.CCIPView{}, err
}
ccipView.NodeOperators, err = view.GenerateNopsView(e.NodeIDs, e.Offchain)
if err != nil {
return ccipView, err
}
return ccipView, nil
}

func LoadOnchainState(e deployment.Environment, ab deployment.AddressBook) (CCIPOnChainState, error) {
Expand Down
92 changes: 92 additions & 0 deletions integration-tests/deployment/ccip/view/nops.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package view

import (
"context"
"fmt"

chainsel "github.com/smartcontractkit/chain-selectors"

"github.com/smartcontractkit/chainlink/integration-tests/deployment"
nodev1 "github.com/smartcontractkit/chainlink/integration-tests/deployment/jd/node/v1"
)

type NopsView struct {
Nops map[string]NopView `json:"nops,omitempty"`
}

type NopView struct {
// NodeID is the unique identifier of the node
NodeID string `json:"nodeID"`
IsBootstrap bool `json:"isBootstrap"`
OCRKeys map[string]OCRKeyView `json:"ocrKeys"`
PayeeAddress string `json:"payeeAddress"`
CSAKey string `json:"csaKey"`
IsConnected bool `json:"isConnected"`
IsEnabled bool `json:"isEnabled"`
}

type OCRKeyView struct {
OffchainPublicKey string `json:"offchainPublicKey"`
OnchainPublicKey string `json:"onchainPublicKey"`
PeerID string `json:"peerID"`
TransmitAccount string `json:"transmitAccount"`
ConfigEncryptionPublicKey string `json:"configEncryptionPublicKey"`
KeyBundleID string `json:"keyBundleID"`
}

func NewNopsView() NopsView {
return NopsView{
Nops: make(map[string]NopView),
}
}

func GenerateNopsView(nodeIds []string, oc deployment.OffchainClient) (NopsView, error) {
nops := NewNopsView()
nodes, err := deployment.NodeInfo(nodeIds, oc)
if err != nil {
return nops, err
}
for _, node := range nodes {
// get node info
nodeDetails, err := oc.GetNode(context.Background(), &nodev1.GetNodeRequest{Id: node.NodeID})
if err != nil {
return NopsView{}, err
}
if nodeDetails == nil || nodeDetails.Node == nil {
return NopsView{}, fmt.Errorf("failed to get node details from offchain client for node %s", node.NodeID)
}
nodeName := nodeDetails.Node.Name
if nodeName == "" {
nodeName = node.NodeID
}
nop := NopView{
NodeID: node.NodeID,
IsBootstrap: node.IsBootstrap,
OCRKeys: make(map[string]OCRKeyView),
PayeeAddress: node.AdminAddr,
CSAKey: nodeDetails.Node.PublicKey,
IsConnected: nodeDetails.Node.IsConnected,
IsEnabled: nodeDetails.Node.IsEnabled,
}
for sel, ocrConfig := range node.SelToOCRConfig {
chainid, err := chainsel.ChainIdFromSelector(sel)
if err != nil {
return nops, err
}
chainName, err := chainsel.NameFromChainId(chainid)
if err != nil {
return nops, err
}
nop.OCRKeys[chainName] = OCRKeyView{
OffchainPublicKey: fmt.Sprintf("%x", ocrConfig.OffchainPublicKey[:]),
OnchainPublicKey: fmt.Sprintf("%x", ocrConfig.OnchainPublicKey[:]),
PeerID: ocrConfig.PeerID.String(),
TransmitAccount: string(ocrConfig.TransmitAccount),
ConfigEncryptionPublicKey: fmt.Sprintf("%x", ocrConfig.ConfigEncryptionPublicKey[:]),
KeyBundleID: ocrConfig.KeyBundleID,
}
}
nops.Nops[nodeName] = nop
}
return nops, nil
}
3 changes: 2 additions & 1 deletion integration-tests/deployment/ccip/view/state.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package view

type CCIPView struct {
Chains map[string]ChainView `json:"chains,omitempty"`
Chains map[string]ChainView `json:"chains,omitempty"`
NodeOperators NopsView `json:"nodeOperators,omitempty"`
}

func NewCCIPView() CCIPView {
Expand Down
11 changes: 8 additions & 3 deletions integration-tests/deployment/devenv/jd.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ func NewJDClient(ctx context.Context, cfg JDConfig) (deployment.OffchainClient,
JobServiceClient: jobv1.NewJobServiceClient(conn),
CSAServiceClient: csav1.NewCSAServiceClient(conn),
}
jd.don, err = NewRegisteredDON(ctx, cfg.nodeInfo, *jd)
if err != nil {
return nil, fmt.Errorf("failed to create registered DON: %w", err)
if cfg.nodeInfo != nil && len(cfg.nodeInfo) > 0 {
jd.don, err = NewRegisteredDON(ctx, cfg.nodeInfo, *jd)
if err != nil {
return nil, fmt.Errorf("failed to create registered DON: %w", err)
}
}
return jd, err
}
Expand Down Expand Up @@ -90,6 +92,9 @@ func (jd JobDistributor) ProposeJob(ctx context.Context, in *jobv1.ProposeJobReq
if res.Proposal == nil {
return nil, fmt.Errorf("failed to propose job. err: proposal is nil")
}
if jd.don == nil || len(jd.don.Nodes) == 0 {
return res, nil
}
for _, node := range jd.don.Nodes {
if node.NodeId != in.NodeId {
continue
Expand Down
4 changes: 4 additions & 0 deletions integration-tests/deployment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ type Node struct {
PeerID p2pkey.PeerID
IsBootstrap bool
MultiAddr string
AdminAddr string
}

func (n Node) FirstOCRKeybundle() OCRConfig {
Expand Down Expand Up @@ -208,6 +209,7 @@ func NodeInfo(nodeIDs []string, oc OffchainClient) (Nodes, error) {
bootstrap := false
var peerID p2pkey.PeerID
var multiAddr string
var adminAddr string
for _, chainConfig := range nodeChainConfigs.ChainConfigs {
if chainConfig.Chain.Type == nodev1.ChainType_CHAIN_TYPE_SOLANA {
// Note supported for CCIP yet.
Expand All @@ -217,6 +219,7 @@ func NodeInfo(nodeIDs []string, oc OffchainClient) (Nodes, error) {
// Might make sense to change proto as peerID/multiAddr is 1-1 with nodeID?
peerID = MustPeerIDFromString(chainConfig.Ocr2Config.P2PKeyBundle.PeerId)
multiAddr = chainConfig.Ocr2Config.Multiaddr
adminAddr = chainConfig.AdminAddress
if chainConfig.Ocr2Config.IsBootstrap {
// NOTE: Assume same peerID for all chains.
// Might make sense to change proto as peerID is 1-1 with nodeID?
Expand Down Expand Up @@ -254,6 +257,7 @@ func NodeInfo(nodeIDs []string, oc OffchainClient) (Nodes, error) {
IsBootstrap: bootstrap,
PeerID: peerID,
MultiAddr: multiAddr,
AdminAddr: adminAddr,
})
}

Expand Down

0 comments on commit 815b2c8

Please sign in to comment.