Skip to content

Commit bcdb923

Browse files
committed
relayer: config enhancements
1 parent 743a278 commit bcdb923

File tree

19 files changed

+326
-102
lines changed

19 files changed

+326
-102
lines changed

.github/workflows/tron-gotron-sdk.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- uses: ./.github/actions/changes
1919
id: c
2020
with:
21-
folder: tron
21+
folder: relayer/gotron-sdk
2222

2323
test:
2424
name: Unit Tests

.github/workflows/tron-integration-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- uses: ./.github/actions/changes
2424
id: c
2525
with:
26-
folder: tron
26+
folder: .
2727
integration_tests_docker:
2828
name: Run Docker Integration Tests
2929
runs-on: ubuntu-latest-32cores-128GB

integration-tests/go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/google/uuid v1.6.0
1111
github.com/lib/pq v1.10.9
1212
github.com/rs/zerolog v1.33.0
13-
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250425195105-d9eabb4a4519
13+
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250430133340-d04a3b64e331
1414
github.com/smartcontractkit/chainlink-testing-framework/lib v1.54.1
1515
github.com/smartcontractkit/chainlink-tron/relayer v0.0.11-0.20250422175525-b7575d96bd4d
1616
github.com/smartcontractkit/chainlink/deployment v0.0.0-20250428183335-14ac746cbe81
@@ -194,6 +194,7 @@ require (
194194
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
195195
github.com/kr/pretty v0.3.1 // indirect
196196
github.com/kr/text v0.2.0 // indirect
197+
github.com/kylelemons/godebug v1.1.0 // indirect
197198
github.com/leodido/go-urn v1.4.0 // indirect
198199
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
199200
github.com/linxGnu/grocksdb v1.9.3 // indirect

integration-tests/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -910,8 +910,8 @@ github.com/smartcontractkit/chainlink-ccip v0.0.0-20250425101833-7b7e760694ed h1
910910
github.com/smartcontractkit/chainlink-ccip v0.0.0-20250425101833-7b7e760694ed/go.mod h1:Jb05WL6lj5H89XGcaaOinxTf4Gdj+vXO4TcUhqTgqIM=
911911
github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250425163923-16aa375957b7 h1:j6Vo/NX2ABsPdGxETC5pfQLcz/h6iLJu/Yx+8AhPa34=
912912
github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250425163923-16aa375957b7/go.mod h1:k3/Z6AvwurPUlfuDFEonRbkkiTSgNSrtVNhJEWNlUZA=
913-
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250425195105-d9eabb4a4519 h1:FMQVnelIaY4MZwYjKJDnTfoKJ1d6y4xZY6SpORGFlDo=
914-
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250425195105-d9eabb4a4519/go.mod h1:vHs/mPpAztdKJtzRKLnmLinmpS78fBh9sAuyKqQrQ+I=
913+
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250430133340-d04a3b64e331 h1:+bN5yuawZeQeVw7vG+Me7kXLFK1vcesVeku3mdgRwqI=
914+
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250430133340-d04a3b64e331/go.mod h1:UGZVg18zzyJ1KimGM5SSmxG5jb7aCSq3OwQQKfhHGyE=
915915
github.com/smartcontractkit/chainlink-data-streams v0.1.1-0.20250417193446-eeb0a7d1e049 h1:7HwYt8rDz1ehTcB28oNipdTZUtV17F2sfkLTLtMJC4c=
916916
github.com/smartcontractkit/chainlink-data-streams v0.1.1-0.20250417193446-eeb0a7d1e049/go.mod h1:2MggrMtbhqr0u4U2pcYa21lvAtvaeSawjxdIy1ytHWE=
917917
github.com/smartcontractkit/chainlink-evm v0.0.0-20250424162751-35c5921b8597 h1:VJE7FviGR6lmXNSBZdplm8F5t4Yq2Hl6JC7FbWc+FdM=

relayer/CONFIG.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
[//]: # (Documentation generated from docs.toml - DO NOT EDIT.)
2+
This document describes the TOML format for configuration.
3+
## Example
4+
5+
```toml
6+
ChainID = '<id>'
7+
8+
[[Tron.Nodes]]
9+
Name = 'primary'
10+
URL = '<full node http url>'
11+
SolidityURL = '<solidity http url>'
12+
13+
```
14+
15+
## Global
16+
```toml
17+
ChainID = 'foobar' # Example
18+
Enabled = true # Default
19+
BalancePollPeriod = '5s' # Default
20+
BroadcastChanSize = 4096 # Default
21+
ConfirmPollPeriod = '500ms' # Default
22+
OCR2CachePollPeriod = '5s' # Default
23+
OCR2CacheTTL = '1m' # Default
24+
```
25+
26+
27+
### ChainID
28+
```toml
29+
ChainID = 'foobar' # Example
30+
```
31+
ChainID is the Tron chain ID.
32+
33+
### Enabled
34+
```toml
35+
Enabled = true # Default
36+
```
37+
Enabled enables this chain.
38+
39+
### BalancePollPeriod
40+
```toml
41+
BalancePollPeriod = '5s' # Default
42+
```
43+
BalancePollPeriod is the poll period for balance monitoring
44+
45+
### BroadcastChanSize
46+
```toml
47+
BroadcastChanSize = 4096 # Default
48+
```
49+
BroadcastChanSize is the transaction broadcast channel size
50+
51+
### ConfirmPollPeriod
52+
```toml
53+
ConfirmPollPeriod = '500ms' # Default
54+
```
55+
ConfirmPollPeriod is the polling period for transaction confirmation
56+
57+
### OCR2CachePollPeriod
58+
```toml
59+
OCR2CachePollPeriod = '5s' # Default
60+
```
61+
OCR2CachePollPeriod is the polling period for OCR2 contract cache
62+
63+
### OCR2CacheTTL
64+
```toml
65+
OCR2CacheTTL = '1m' # Default
66+
```
67+
OCR2CacheTTL is the time to live for OCR2 contract cache
68+
69+
## Nodes
70+
```toml
71+
[[Nodes]]
72+
Name = 'primary' # Example
73+
URL = 'https://api.trongrid.io/wallet' # Example
74+
SolidityURL = 'http://api.trongrid.io/wallet' # Example
75+
```
76+
77+
78+
### Name
79+
```toml
80+
Name = 'primary' # Example
81+
```
82+
Name is a unique (per-chain) identifier for this node.
83+
84+
### URL
85+
```toml
86+
URL = 'https://api.trongrid.io/wallet' # Example
87+
```
88+
URL is the full node HTTP endpoint for this node.
89+
90+
### SolidityURL
91+
```toml
92+
SolidityURL = 'http://api.trongrid.io/wallet' # Example
93+
```
94+
SolidityURL is the solidity node HTTP endpoint for this node.
95+

relayer/cmd/chainlink-tron/main.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/smartcontractkit/chainlink-common/pkg/loop"
1212
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
13+
"github.com/smartcontractkit/chainlink-tron/relayer/config"
1314

1415
tronplugin "github.com/smartcontractkit/chainlink-tron/relayer/plugin"
1516
)
@@ -52,14 +53,14 @@ type pluginRelayer struct {
5253

5354
var _ loop.PluginRelayer = &pluginRelayer{}
5455

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

59-
var cfg tronplugin.TOMLConfig
60+
var cfg config.TOMLConfig
6061

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

6566
if err := cfg.ValidateConfig(); err != nil {

relayer/cmd/config-docs/main.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"log"
7+
"os"
8+
"path/filepath"
9+
10+
"github.com/smartcontractkit/chainlink-tron/relayer/config"
11+
)
12+
13+
var outDir = flag.String("o", "", "output directory")
14+
15+
func main() {
16+
s, err := config.GenerateDocs()
17+
if err != nil {
18+
log.Fatalln("Failed to generate docs:", err)
19+
}
20+
if err = os.WriteFile(filepath.Join(*outDir, "CONFIG.md"), []byte(s), 0600); err != nil {
21+
fmt.Fprintf(os.Stderr, "failed to write config docs: %v\n", err)
22+
os.Exit(1)
23+
}
24+
}

relayer/config/config.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package config
2+
3+
import (
4+
"errors"
5+
"log"
6+
"strings"
7+
8+
"github.com/smartcontractkit/chainlink-common/pkg/config"
9+
"github.com/smartcontractkit/chainlink-common/pkg/config/configtest"
10+
)
11+
12+
var defaults TOMLConfig
13+
14+
func init() {
15+
if err := configtest.DocDefaultsOnly(strings.NewReader(docsTOML), &defaults, config.DecodeTOML); err != nil {
16+
log.Fatalf("Failed to initialize defaults from docs: %v", err)
17+
}
18+
}
19+
20+
func Defaults() (c TOMLConfig) {
21+
c.SetFrom(&defaults)
22+
return
23+
}
24+
25+
type ChainConfig struct {
26+
BalancePollPeriod *config.Duration
27+
BroadcastChanSize *uint64
28+
ConfirmPollPeriod *config.Duration
29+
OCR2CachePollPeriod *config.Duration
30+
OCR2CacheTTL *config.Duration
31+
}
32+
33+
type NodeConfig struct {
34+
Name *string
35+
URL *config.URL
36+
SolidityURL *config.URL
37+
}
38+
39+
func (n *NodeConfig) ValidateConfig() error {
40+
var err error
41+
if n.Name == nil {
42+
err = errors.Join(err, config.ErrMissing{Name: "Name", Msg: "required for all nodes"})
43+
} else if *n.Name == "" {
44+
err = errors.Join(err, config.ErrEmpty{Name: "Name", Msg: "required for all nodes"})
45+
}
46+
if n.URL == nil {
47+
err = errors.Join(err, config.ErrMissing{Name: "URL", Msg: "required for all nodes"})
48+
}
49+
if n.SolidityURL == nil {
50+
err = errors.Join(err, config.ErrMissing{Name: "SolidityURL", Msg: "required for all nodes"})
51+
}
52+
return err
53+
}

relayer/config/config_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package config
2+
3+
import (
4+
_ "embed"
5+
"testing"
6+
"time"
7+
8+
"github.com/smartcontractkit/chainlink-common/pkg/config"
9+
"github.com/smartcontractkit/chainlink-common/pkg/config/configtest"
10+
)
11+
12+
func TestDefaults_fieldsNotNil(t *testing.T) {
13+
configtest.AssertFieldsNotNil(t, Defaults())
14+
}
15+
16+
func TestDocsTOMLComplete(t *testing.T) {
17+
configtest.AssertDocsTOMLComplete[TOMLConfig](t, docsTOML)
18+
}
19+
20+
//go:embed testdata/config-full.toml
21+
var fullTOML string
22+
23+
func TestTOMLConfig_FullMarshal(t *testing.T) {
24+
full := TOMLConfig{
25+
ChainID: ptr("fake"),
26+
Enabled: ptr(false),
27+
ChainConfig: ChainConfig{
28+
BroadcastChanSize: ptr[uint64](99),
29+
ConfirmPollPeriod: config.MustNewDuration(42 * time.Millisecond),
30+
OCR2CachePollPeriod: config.MustNewDuration(100 * time.Second),
31+
OCR2CacheTTL: config.MustNewDuration(15 * time.Minute),
32+
BalancePollPeriod: config.MustNewDuration(time.Hour),
33+
},
34+
Nodes: NodeConfigs{
35+
{
36+
Name: ptr("node"),
37+
URL: config.MustParseURL("https://example.com/tron"),
38+
SolidityURL: config.MustParseURL("http://example.com/solidity"),
39+
},
40+
},
41+
}
42+
configtest.AssertFullMarshal(t, full, fullTOML)
43+
}
44+
45+
func ptr[T any](v T) *T { return &v }

relayer/config/docs.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package config
2+
3+
import (
4+
_ "embed"
5+
6+
"github.com/smartcontractkit/chainlink-common/pkg/config/configdoc"
7+
)
8+
9+
//go:embed docs.toml
10+
var docsTOML string
11+
12+
//go:embed example.toml
13+
var exampleConfig string
14+
15+
func GenerateDocs() (string, error) {
16+
return configdoc.Generate(docsTOML, `[//]: # (Documentation generated from docs.toml - DO NOT EDIT.)
17+
This document describes the TOML format for configuration.`, exampleConfig, nil)
18+
}

relayer/config/docs.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# ChainID is the Tron chain ID.
2+
ChainID = 'foobar' # Example
3+
# Enabled enables this chain.
4+
Enabled = true # Default
5+
# BalancePollPeriod is the poll period for balance monitoring
6+
BalancePollPeriod = '5s' # Default
7+
# BroadcastChanSize is the transaction broadcast channel size
8+
BroadcastChanSize = 4096 # Default
9+
# ConfirmPollPeriod is the polling period for transaction confirmation
10+
ConfirmPollPeriod = '500ms' # Default
11+
# OCR2CachePollPeriod is the polling period for OCR2 contract cache
12+
OCR2CachePollPeriod = '5s' # Default
13+
# OCR2CacheTTL is the time to live for OCR2 contract cache
14+
OCR2CacheTTL = '1m' # Default
15+
16+
[[Nodes]]
17+
# Name is a unique (per-chain) identifier for this node.
18+
Name = 'primary' # Example
19+
# URL is the full node HTTP endpoint for this node.
20+
URL = 'https://api.trongrid.io/wallet' # Example
21+
# SolidityURL is the solidity node HTTP endpoint for this node.
22+
SolidityURL = 'http://api.trongrid.io/wallet' # Example

relayer/config/example.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ChainID = '<id>'
2+
3+
[[Tron.Nodes]]
4+
Name = 'primary'
5+
URL = '<full node http url>'
6+
SolidityURL = '<solidity http url>'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
ChainID = 'fake'
2+
Enabled = false
3+
BalancePollPeriod = '1h0m0s'
4+
BroadcastChanSize = 99
5+
ConfirmPollPeriod = '42ms'
6+
OCR2CachePollPeriod = '1m40s'
7+
OCR2CacheTTL = '15m0s'
8+
9+
[[Nodes]]
10+
Name = 'node'
11+
URL = 'https://example.com/tron'
12+
SolidityURL = 'http://example.com/solidity'

0 commit comments

Comments
 (0)