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

add gateway connector capability config #14325

Merged
merged 8 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions .changeset/four-eggs-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

configuration updates
16 changes: 16 additions & 0 deletions core/config/capabilities_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,24 @@ type CapabilitiesExternalRegistry interface {
RelayID() types.RelayID
}

type GatewayConnector interface {
ChainIDForNodeKey() string
NodeAddress() string
DonID() string
Gateways() []ConnectorGateway
WsHandshakeTimeoutMillis() uint32
AuthMinChallengeLen() int
AuthTimestampToleranceSec() uint32
}

type ConnectorGateway interface {
ID() string
URL() string
}

type Capabilities interface {
Peering() P2P
Dispatcher() Dispatcher
ExternalRegistry() CapabilitiesExternalRegistry
GatewayConnector() GatewayConnector
}
20 changes: 20 additions & 0 deletions core/config/docs/core.toml
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,26 @@ DeltaReconcile = '1m' # Default
# but the host and port must be fully specified and cannot be empty. You can specify `0.0.0.0` (IPv4) or `::` (IPv6) to listen on all interfaces, but that is not recommended.
ListenAddresses = ['1.2.3.4:9999', '[a52d:0:a88:1274::abcd]:1337'] # Example

[Capabilities.GatewayConnector]
# ChainIDForNodeKey is the ChainID of the network associated with a private key to be used for authentication with Gateway nodes
ChainIDForNodeKey = '11155111' # Example
# NodeAddress is the address of the desired private key to be used for authentication with Gateway nodes
NodeAddress = '0x68902d681c28119f9b2531473a417088bf008e59' # Example
# DonID is the Id of the Don
DonID = 'example_don' # Example
# WsHandshakeTimeoutMillis is Websocket handshake timeout
WsHandshakeTimeoutMillis = 1000 # Example
# AuthMinChallengeLen is the minimum number of bytes in authentication challenge payload
AuthMinChallengeLen = 10 # Example
# AuthTimestampToleranceSec is Authentication timestamp tolerance
AuthTimestampToleranceSec = 10 # Example

[[Capabilities.GatewayConnector.Gateways]]
# ID of the Gateway
ID = 'example_gateway' # Example
# URL of the Gateway
URL = 'wss://localhost:8081/node' # Example

[Keeper]
# **ADVANCED**
# DefaultTransactionQueueDepth controls the queue size for `DropOldestStrategy` in Keeper. Set to 0 to use `SendEvery` strategy instead.
Expand Down
49 changes: 49 additions & 0 deletions core/config/toml/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net"
"net/url"
"reflect"
"regexp"
"strings"

Expand All @@ -25,6 +26,7 @@ import (
"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 +1480,63 @@ func (drl *DispatcherRateLimit) setFrom(f *DispatcherRateLimit) {
}
}

type GatewayConnector struct {
ChainIDForNodeKey *string
NodeAddress *string
DonID *string
Gateways []ConnectorGateway
WsHandshakeTimeoutMillis *uint32
Copy link
Contributor

Choose a reason for hiding this comment

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

I think WS should be upper case according to Go naming rules:

Suggested change
WsHandshakeTimeoutMillis *uint32
WSHandshakeTimeoutMillis *uint32

AuthMinChallengeLen *int
AuthTimestampToleranceSec *uint32
}

func (r *GatewayConnector) setFrom(f *GatewayConnector) {
if f.ChainIDForNodeKey != nil {
r.ChainIDForNodeKey = f.ChainIDForNodeKey
}

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

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

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

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

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

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

type ConnectorGateway struct {
ID *string
URL *string
}

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

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

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

import (
"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-common/pkg/types"
)

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

func (c *capabilitiesConfig) GatewayConnector() config.GatewayConnector {
return &gatewayConnector{
c: c.c.GatewayConnector,
}
}

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

type gatewayConnector struct {
c toml.GatewayConnector
}

func (c *gatewayConnector) ChainIDForNodeKey() string {
return *c.c.ChainIDForNodeKey
}
func (c *gatewayConnector) NodeAddress() string {
return *c.c.NodeAddress
}

func (c *gatewayConnector) DonID() string {
return *c.c.DonID
}

func (c *gatewayConnector) Gateways() []config.ConnectorGateway {
t := []config.ConnectorGateway{}
for index, element := range c.c.Gateways {
t[index] = &connectorGateway{element}
}
return t
}

func (c *gatewayConnector) WsHandshakeTimeoutMillis() uint32 {
return *c.c.WsHandshakeTimeoutMillis
}

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

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

type connectorGateway struct {
c toml.ConnectorGateway
}

func (c *connectorGateway) ID() string {
return *c.c.ID
}

func (c *connectorGateway) URL() string {
return *c.c.URL
}
11 changes: 11 additions & 0 deletions core/services/chainlink/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,17 @@ func TestConfig_Marshal(t *testing.T) {
PerSenderBurst: ptr(50),
},
},
GatewayConnector: toml.GatewayConnector{
ChainIDForNodeKey: ptr("11155111"),
NodeAddress: ptr("0x68902d681c28119f9b2531473a417088bf008e59"),
DonID: ptr("example_don"),
WsHandshakeTimeoutMillis: ptr[uint32](100),
AuthMinChallengeLen: ptr[int](10),
AuthTimestampToleranceSec: ptr[uint32](10),
Gateways: []toml.ConnectorGateway{
{ID: ptr("example_gateway"), URL: ptr("wss://localhost:8081/node")},
},
},
}
full.Keeper = toml.Keeper{
DefaultTransactionQueueDepth: ptr[uint32](17),
Expand Down
12 changes: 12 additions & 0 deletions core/services/chainlink/testdata/config-empty-effective.toml
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,15 @@ PerSenderBurst = 50
Address = ''
NetworkID = 'evm'
ChainID = '1'

[Capabilities.GatewayConnector]
ChainIDForNodeKey = ''
NodeAddress = ''
DonID = ''
WsHandshakeTimeoutMillis = 0
AuthMinChallengeLen = 0
AuthTimestampToleranceSec = 0

[[Capabilities.GatewayConnector.Gateways]]
ID = ''
URL = ''
12 changes: 12 additions & 0 deletions core/services/chainlink/testdata/config-full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,18 @@ Address = ''
NetworkID = 'evm'
ChainID = '1'

[Capabilities.GatewayConnector]
ChainIDForNodeKey = '11155111'
NodeAddress = '0x68902d681c28119f9b2531473a417088bf008e59'
DonID = 'example_don'
WsHandshakeTimeoutMillis = 100
AuthMinChallengeLen = 10
AuthTimestampToleranceSec = 10

[[Capabilities.GatewayConnector.Gateways]]
ID = 'example_gateway'
URL = 'wss://localhost:8081/node'

[[EVM]]
ChainID = '1'
Enabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,18 @@ Address = ''
NetworkID = 'evm'
ChainID = '1'

[Capabilities.GatewayConnector]
ChainIDForNodeKey = ''
NodeAddress = ''
DonID = ''
WsHandshakeTimeoutMillis = 0
AuthMinChallengeLen = 0
AuthTimestampToleranceSec = 0

[[Capabilities.GatewayConnector.Gateways]]
ID = ''
URL = ''

[[EVM]]
ChainID = '1'
AutoCreateKey = true
Expand Down
12 changes: 12 additions & 0 deletions core/web/resolver/testdata/config-empty-effective.toml
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,15 @@ PerSenderBurst = 50
Address = ''
NetworkID = 'evm'
ChainID = '1'

[Capabilities.GatewayConnector]
ChainIDForNodeKey = ''
NodeAddress = ''
DonID = ''
WsHandshakeTimeoutMillis = 0
AuthMinChallengeLen = 0
AuthTimestampToleranceSec = 0

[[Capabilities.GatewayConnector.Gateways]]
ID = ''
URL = ''
12 changes: 12 additions & 0 deletions core/web/resolver/testdata/config-full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,18 @@ Address = ''
NetworkID = 'evm'
ChainID = '1'

[Capabilities.GatewayConnector]
ChainIDForNodeKey = '11155111'
NodeAddress = '0x68902d681c28119f9b2531473a417088bf008e59'
DonID = 'example_don'
WsHandshakeTimeoutMillis = 100
AuthMinChallengeLen = 10
AuthTimestampToleranceSec = 10

[[Capabilities.GatewayConnector.Gateways]]
ID = 'example_gateway'
URL = 'wss://localhost:8081/node'

[[EVM]]
ChainID = '1'
Enabled = false
Expand Down
12 changes: 12 additions & 0 deletions core/web/resolver/testdata/config-multi-chain-effective.toml
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,18 @@ Address = ''
NetworkID = 'evm'
ChainID = '1'

[Capabilities.GatewayConnector]
ChainIDForNodeKey = ''
NodeAddress = ''
DonID = ''
WsHandshakeTimeoutMillis = 0
AuthMinChallengeLen = 0
AuthTimestampToleranceSec = 0

[[Capabilities.GatewayConnector.Gateways]]
ID = ''
URL = ''

[[EVM]]
ChainID = '1'
AutoCreateKey = true
Expand Down
Loading
Loading