Skip to content

Commit

Permalink
add gateway connector capability config
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidOrchard committed Sep 3, 2024
1 parent a234e14 commit fc3bc6b
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 5 deletions.
25 changes: 25 additions & 0 deletions core/config/capabilities_config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package config

// import cycle not allowed in testgo list

import (
"math/big"

"github.com/smartcontractkit/chainlink-common/pkg/types"
// import cycle not allowedgo list
"github.com/smartcontractkit/chainlink/v2/core/services/gateway/network"
)

type CapabilitiesExternalRegistry interface {
Expand All @@ -11,8 +17,27 @@ type CapabilitiesExternalRegistry interface {
RelayID() types.RelayID
}

type GatewayConnectorConfig interface {
NodeAddress() string
DonId() string
Gateways() []ConnectorGatewayConfig
WsClientConfig() network.WebSocketClientConfig
AuthMinChallengeLen() int
AuthTimestampToleranceSec() uint32
}

type ConnectorGatewayConfig interface {
Id() string
URL() string
}

type WorkflowConnectorConfig interface {
ChainIDForNodeKey() big.Int
GatewayConnectorConfig() GatewayConnectorConfig
}
type Capabilities interface {
Peering() P2P
Dispatcher() Dispatcher
ExternalRegistry() CapabilitiesExternalRegistry
WorkflowConnectorConfig() WorkflowConnectorConfig
}
68 changes: 65 additions & 3 deletions core/config/toml/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import (
"fmt"
"net"
"net/url"
"reflect"
"regexp"
"strings"

"math/big"

"github.com/google/uuid"
"go.uber.org/multierr"
"go.uber.org/zap/zapcore"
Expand All @@ -20,11 +23,13 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/config"
"github.com/smartcontractkit/chainlink/v2/core/config/parse"
"github.com/smartcontractkit/chainlink/v2/core/services/gateway/network"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey"
"github.com/smartcontractkit/chainlink/v2/core/sessions"
"github.com/smartcontractkit/chainlink/v2/core/store/dialects"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
"github.com/smartcontractkit/chainlink/v2/core/utils"

configutils "github.com/smartcontractkit/chainlink/v2/core/utils/config"
)

Expand Down Expand Up @@ -1478,16 +1483,73 @@ func (drl *DispatcherRateLimit) setFrom(f *DispatcherRateLimit) {
}
}

type GatewayConnectorConfig struct {
NodeAddress *string
DonId *string
Gateways []ConnectorGatewayConfig
WsClientConfig *network.WebSocketClientConfig
AuthMinChallengeLen *int
AuthTimestampToleranceSec *uint32
}

func (r *GatewayConnectorConfig) setFrom(f *GatewayConnectorConfig) {
if f.NodeAddress != nil {
r.NodeAddress = f.NodeAddress
}

if f.DonId != nil {
r.DonId = f.DonId
}

// TODO: verify this copy by reference is ok, or does array need to be copied by value
if f.Gateways != nil {
r.Gateways = f.Gateways
}

if !reflect.ValueOf(f.WsClientConfig).IsZero() {
r.WsClientConfig = f.WsClientConfig
}

if f.AuthMinChallengeLen != nil {
r.AuthMinChallengeLen = f.AuthMinChallengeLen
}

if f.AuthTimestampToleranceSec != nil {
r.AuthTimestampToleranceSec = f.AuthTimestampToleranceSec
}
}

type ConnectorGatewayConfig struct {
Id *string
URL *string
}
type WorkflowConnectorConfig struct {
ChainIDForNodeKey *big.Int
GatewayConnectorConfig *GatewayConnectorConfig `json:"gatewayConnectorConfig"`
}

func (r *WorkflowConnectorConfig) setFrom(f *WorkflowConnectorConfig) {
if len(f.ChainIDForNodeKey.Bits()) != 0 {
r.ChainIDForNodeKey = f.ChainIDForNodeKey
}

if !reflect.ValueOf(f.GatewayConnectorConfig).IsZero() {
r.GatewayConnectorConfig.setFrom(f.GatewayConnectorConfig)
}
}

type Capabilities struct {
Peering P2P `toml:",omitempty"`
Dispatcher Dispatcher `toml:",omitempty"`
ExternalRegistry ExternalRegistry `toml:",omitempty"`
Peering P2P `toml:",omitempty"`
Dispatcher Dispatcher `toml:",omitempty"`
ExternalRegistry ExternalRegistry `toml:",omitempty"`
WorkflowConnectorConfig WorkflowConnectorConfig `toml:", omitempty"`
}

func (c *Capabilities) setFrom(f *Capabilities) {
c.Peering.setFrom(&f.Peering)
c.ExternalRegistry.setFrom(&f.ExternalRegistry)
c.Dispatcher.setFrom(&f.Dispatcher)
c.WorkflowConnectorConfig.setFrom(&f.WorkflowConnectorConfig)
}

type ThresholdKeyShareSecrets struct {
Expand Down
70 changes: 68 additions & 2 deletions core/services/chainlink/config_capabilities.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package chainlink

import (
"github.com/smartcontractkit/chainlink/v2/core/config"
"github.com/smartcontractkit/chainlink/v2/core/config/toml"
"math/big"

"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink/v2/core/config"
"github.com/smartcontractkit/chainlink/v2/core/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/services/gateway/network"
)

var _ config.Capabilities = (*capabilitiesConfig)(nil)
Expand Down Expand Up @@ -63,6 +65,12 @@ func (r *dispatcherRateLimit) PerSenderBurst() int {
return *r.r.PerSenderBurst
}

func (c *capabilitiesConfig) WorkflowConnectorConfig() config.WorkflowConnectorConfig {
return &workflowConnectorConfig{
c: c.c.WorkflowConnectorConfig,
}
}

type capabilitiesExternalRegistry struct {
c toml.ExternalRegistry
}
Expand All @@ -82,3 +90,61 @@ func (c *capabilitiesExternalRegistry) ChainID() string {
func (c *capabilitiesExternalRegistry) Address() string {
return *c.c.Address
}

type workflowConnectorConfig struct {
c toml.WorkflowConnectorConfig
}

func (c *workflowConnectorConfig) ChainIDForNodeKey() big.Int {
return *c.c.ChainIDForNodeKey
}

func (c *workflowConnectorConfig) GatewayConnectorConfig() config.GatewayConnectorConfig {
return &gatewayConnectorConfig{
c: *c.c.GatewayConnectorConfig,
}
}

type gatewayConnectorConfig struct {
c toml.GatewayConnectorConfig
}

func (c *gatewayConnectorConfig) NodeAddress() string {
return *c.c.NodeAddress
}

func (c *gatewayConnectorConfig) DonId() string {
return *c.c.DonId
}

func (c *gatewayConnectorConfig) Gateways() []config.ConnectorGatewayConfig {
t := []config.ConnectorGatewayConfig{}
for index, element := range c.c.Gateways {
t[index] = &connectorGatewayConfig{element}
}
return t
}

func (c *gatewayConnectorConfig) WsClientConfig() network.WebSocketClientConfig {
return *c.c.WsClientConfig
}

func (c *gatewayConnectorConfig) AuthMinChallengeLen() int {
return *c.c.AuthMinChallengeLen
}

func (c *gatewayConnectorConfig) AuthTimestampToleranceSec() uint32 {
return *c.c.AuthTimestampToleranceSec
}

type connectorGatewayConfig struct {
c toml.ConnectorGatewayConfig
}

func (c *connectorGatewayConfig) Id() string {
return *c.c.Id
}

func (c *connectorGatewayConfig) URL() string {
return *c.c.URL
}

0 comments on commit fc3bc6b

Please sign in to comment.