Skip to content

relayer: config enhancements #11

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/gotron-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: ./.github/actions/changes
id: c
with:
folder: tron/gotron-sdk
folder: relayer/gotron-sdk

test:
name: Unit Tests
Expand Down
3 changes: 2 additions & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/google/uuid v1.6.0
github.com/lib/pq v1.10.9
github.com/rs/zerolog v1.33.0
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250425195105-d9eabb4a4519
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250430133340-d04a3b64e331
github.com/smartcontractkit/chainlink-testing-framework/lib v1.54.1
github.com/smartcontractkit/chainlink-tron/relayer v0.0.11-0.20250422175525-b7575d96bd4d
github.com/smartcontractkit/chainlink/deployment v0.0.0-20250428183335-14ac746cbe81
Expand Down Expand Up @@ -194,6 +194,7 @@ require (
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/linxGnu/grocksdb v1.9.3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -910,8 +910,8 @@ github.com/smartcontractkit/chainlink-ccip v0.0.0-20250425101833-7b7e760694ed h1
github.com/smartcontractkit/chainlink-ccip v0.0.0-20250425101833-7b7e760694ed/go.mod h1:Jb05WL6lj5H89XGcaaOinxTf4Gdj+vXO4TcUhqTgqIM=
github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250425163923-16aa375957b7 h1:j6Vo/NX2ABsPdGxETC5pfQLcz/h6iLJu/Yx+8AhPa34=
github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250425163923-16aa375957b7/go.mod h1:k3/Z6AvwurPUlfuDFEonRbkkiTSgNSrtVNhJEWNlUZA=
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250425195105-d9eabb4a4519 h1:FMQVnelIaY4MZwYjKJDnTfoKJ1d6y4xZY6SpORGFlDo=
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250425195105-d9eabb4a4519/go.mod h1:vHs/mPpAztdKJtzRKLnmLinmpS78fBh9sAuyKqQrQ+I=
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250430133340-d04a3b64e331 h1:+bN5yuawZeQeVw7vG+Me7kXLFK1vcesVeku3mdgRwqI=
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250430133340-d04a3b64e331/go.mod h1:UGZVg18zzyJ1KimGM5SSmxG5jb7aCSq3OwQQKfhHGyE=
github.com/smartcontractkit/chainlink-data-streams v0.1.1-0.20250417193446-eeb0a7d1e049 h1:7HwYt8rDz1ehTcB28oNipdTZUtV17F2sfkLTLtMJC4c=
github.com/smartcontractkit/chainlink-data-streams v0.1.1-0.20250417193446-eeb0a7d1e049/go.mod h1:2MggrMtbhqr0u4U2pcYa21lvAtvaeSawjxdIy1ytHWE=
github.com/smartcontractkit/chainlink-evm v0.0.0-20250424162751-35c5921b8597 h1:VJE7FviGR6lmXNSBZdplm8F5t4Yq2Hl6JC7FbWc+FdM=
Expand Down
95 changes: 95 additions & 0 deletions relayer/CONFIG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
[//]: # (Documentation generated from docs.toml - DO NOT EDIT.)
This document describes the TOML format for configuration.
## Example

```toml
ChainID = '<id>'

[[Tron.Nodes]]
Name = 'primary'
URL = '<full node http url>'
SolidityURL = '<solidity http url>'

```

## Global
```toml
ChainID = 'foobar' # Example
Enabled = true # Default
BalancePollPeriod = '5s' # Default
BroadcastChanSize = 4096 # Default
ConfirmPollPeriod = '500ms' # Default
OCR2CachePollPeriod = '5s' # Default
OCR2CacheTTL = '1m' # Default
```


### ChainID
```toml
ChainID = 'foobar' # Example
```
ChainID is the Tron chain ID.

### Enabled
```toml
Enabled = true # Default
```
Enabled enables this chain.

### BalancePollPeriod
```toml
BalancePollPeriod = '5s' # Default
```
BalancePollPeriod is the poll period for balance monitoring

### BroadcastChanSize
```toml
BroadcastChanSize = 4096 # Default
```
BroadcastChanSize is the transaction broadcast channel size

### ConfirmPollPeriod
```toml
ConfirmPollPeriod = '500ms' # Default
```
ConfirmPollPeriod is the polling period for transaction confirmation

### OCR2CachePollPeriod
```toml
OCR2CachePollPeriod = '5s' # Default
```
OCR2CachePollPeriod is the polling period for OCR2 contract cache

### OCR2CacheTTL
```toml
OCR2CacheTTL = '1m' # Default
```
OCR2CacheTTL is the time to live for OCR2 contract cache

## Nodes
```toml
[[Nodes]]
Name = 'primary' # Example
URL = 'https://api.trongrid.io/wallet' # Example
SolidityURL = 'http://api.trongrid.io/wallet' # Example
```


### Name
```toml
Name = 'primary' # Example
```
Name is a unique (per-chain) identifier for this node.

### URL
```toml
URL = 'https://api.trongrid.io/wallet' # Example
```
URL is the full node HTTP endpoint for this node.

### SolidityURL
```toml
SolidityURL = 'http://api.trongrid.io/wallet' # Example
```
SolidityURL is the solidity node HTTP endpoint for this node.

9 changes: 5 additions & 4 deletions relayer/cmd/chainlink-tron/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/smartcontractkit/chainlink-common/pkg/loop"
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
"github.com/smartcontractkit/chainlink-tron/relayer/config"

tronplugin "github.com/smartcontractkit/chainlink-tron/relayer/plugin"
)
Expand Down Expand Up @@ -52,14 +53,14 @@ type pluginRelayer struct {

var _ loop.PluginRelayer = &pluginRelayer{}

func (c *pluginRelayer) NewRelayer(ctx context.Context, config string, keystore loop.Keystore, capRegistry core.CapabilitiesRegistry) (loop.Relayer, error) {
d := toml.NewDecoder(strings.NewReader(config))
func (c *pluginRelayer) NewRelayer(ctx context.Context, configTOML string, keystore loop.Keystore, capRegistry core.CapabilitiesRegistry) (loop.Relayer, error) {
d := toml.NewDecoder(strings.NewReader(configTOML))
d.DisallowUnknownFields()

var cfg tronplugin.TOMLConfig
var cfg config.TOMLConfig

if err := d.Decode(&cfg); err != nil {
return nil, fmt.Errorf("failed to decode config toml: %w:\n\t%s", err, config)
return nil, fmt.Errorf("failed to decode config toml: %w:\n\t%s", err, configTOML)
}

if err := cfg.ValidateConfig(); err != nil {
Expand Down
24 changes: 24 additions & 0 deletions relayer/cmd/config-docs/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"flag"
"fmt"
"log"
"os"
"path/filepath"

"github.com/smartcontractkit/chainlink-tron/relayer/config"
)

var outDir = flag.String("o", "", "output directory")

func main() {
s, err := config.GenerateDocs()
if err != nil {
log.Fatalln("Failed to generate docs:", err)
}
if err = os.WriteFile(filepath.Join(*outDir, "CONFIG.md"), []byte(s), 0600); err != nil {
fmt.Fprintf(os.Stderr, "failed to write config docs: %v\n", err)
os.Exit(1)
}
}
53 changes: 53 additions & 0 deletions relayer/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package config

import (
"errors"
"log"
"strings"

"github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-common/pkg/config/configtest"
)

var defaults TOMLConfig

func init() {
if err := configtest.DocDefaultsOnly(strings.NewReader(docsTOML), &defaults, config.DecodeTOML); err != nil {
log.Fatalf("Failed to initialize defaults from docs: %v", err)
}
}

func Defaults() (c TOMLConfig) {
c.SetFrom(&defaults)
return
}

type ChainConfig struct {
BalancePollPeriod *config.Duration
BroadcastChanSize *uint64
ConfirmPollPeriod *config.Duration
OCR2CachePollPeriod *config.Duration
OCR2CacheTTL *config.Duration
}

type NodeConfig struct {
Name *string
URL *config.URL
SolidityURL *config.URL
}

func (n *NodeConfig) ValidateConfig() error {
var err error
if n.Name == nil {
err = errors.Join(err, config.ErrMissing{Name: "Name", Msg: "required for all nodes"})
} else if *n.Name == "" {
err = errors.Join(err, config.ErrEmpty{Name: "Name", Msg: "required for all nodes"})
}
if n.URL == nil {
err = errors.Join(err, config.ErrMissing{Name: "URL", Msg: "required for all nodes"})
}
if n.SolidityURL == nil {
err = errors.Join(err, config.ErrMissing{Name: "SolidityURL", Msg: "required for all nodes"})
}
return err
}
45 changes: 45 additions & 0 deletions relayer/config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package config

import (
_ "embed"
"testing"
"time"

"github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-common/pkg/config/configtest"
)

func TestDefaults_fieldsNotNil(t *testing.T) {
configtest.AssertFieldsNotNil(t, Defaults())
}

func TestDocsTOMLComplete(t *testing.T) {
configtest.AssertDocsTOMLComplete[TOMLConfig](t, docsTOML)
}

//go:embed testdata/config-full.toml
var fullTOML string

func TestTOMLConfig_FullMarshal(t *testing.T) {
full := TOMLConfig{
ChainID: ptr("fake"),
Enabled: ptr(false),
ChainConfig: ChainConfig{
BroadcastChanSize: ptr[uint64](99),
ConfirmPollPeriod: config.MustNewDuration(42 * time.Millisecond),
OCR2CachePollPeriod: config.MustNewDuration(100 * time.Second),
OCR2CacheTTL: config.MustNewDuration(15 * time.Minute),
BalancePollPeriod: config.MustNewDuration(time.Hour),
},
Nodes: NodeConfigs{
{
Name: ptr("node"),
URL: config.MustParseURL("https://example.com/tron"),
SolidityURL: config.MustParseURL("http://example.com/solidity"),
},
},
}
configtest.AssertFullMarshal(t, full, fullTOML)
}

func ptr[T any](v T) *T { return &v }
18 changes: 18 additions & 0 deletions relayer/config/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package config

import (
_ "embed"

"github.com/smartcontractkit/chainlink-common/pkg/config/configdoc"
)

//go:embed docs.toml
var docsTOML string

//go:embed example.toml
var exampleConfig string

func GenerateDocs() (string, error) {
return configdoc.Generate(docsTOML, `[//]: # (Documentation generated from docs.toml - DO NOT EDIT.)
This document describes the TOML format for configuration.`, exampleConfig, nil)
}
22 changes: 22 additions & 0 deletions relayer/config/docs.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# ChainID is the Tron chain ID.
ChainID = 'foobar' # Example
# Enabled enables this chain.
Enabled = true # Default
# BalancePollPeriod is the poll period for balance monitoring
BalancePollPeriod = '5s' # Default
# BroadcastChanSize is the transaction broadcast channel size
BroadcastChanSize = 4096 # Default
# ConfirmPollPeriod is the polling period for transaction confirmation
ConfirmPollPeriod = '500ms' # Default
# OCR2CachePollPeriod is the polling period for OCR2 contract cache
OCR2CachePollPeriod = '5s' # Default
# OCR2CacheTTL is the time to live for OCR2 contract cache
OCR2CacheTTL = '1m' # Default

[[Nodes]]
# Name is a unique (per-chain) identifier for this node.
Name = 'primary' # Example
# URL is the full node HTTP endpoint for this node.
URL = 'https://api.trongrid.io/wallet' # Example
# SolidityURL is the solidity node HTTP endpoint for this node.
SolidityURL = 'http://api.trongrid.io/wallet' # Example
6 changes: 6 additions & 0 deletions relayer/config/example.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ChainID = '<id>'

[[Tron.Nodes]]
Name = 'primary'
URL = '<full node http url>'
SolidityURL = '<solidity http url>'
12 changes: 12 additions & 0 deletions relayer/config/testdata/config-full.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ChainID = 'fake'
Enabled = false
BalancePollPeriod = '1h0m0s'
BroadcastChanSize = 99
ConfirmPollPeriod = '42ms'
OCR2CachePollPeriod = '1m40s'
OCR2CacheTTL = '15m0s'

[[Nodes]]
Name = 'node'
URL = 'https://example.com/tron'
SolidityURL = 'http://example.com/solidity'
Loading
Loading