Skip to content

Commit f931d12

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

File tree

15 files changed

+238
-42
lines changed

15 files changed

+238
-42
lines changed

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/plugin/chain_config.go renamed to relayer/config/config.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
1-
package plugin
1+
package config
22

33
import (
44
"errors"
5+
"log"
6+
"strings"
57
"time"
68

79
"github.com/smartcontractkit/chainlink-common/pkg/config"
10+
"github.com/smartcontractkit/chainlink-common/pkg/config/configtest"
811
)
912

13+
var defaults TOMLConfig
14+
15+
func init() {
16+
if err := configtest.DocDefaultsOnly(strings.NewReader(docsTOML), &defaults, config.DecodeTOML); err != nil {
17+
log.Fatalf("Failed to initialize defaults from docs: %v", err)
18+
}
19+
}
20+
21+
// TODO use this
22+
func Defaults() (c TOMLConfig) {
23+
c.SetFrom(&defaults)
24+
return
25+
}
26+
27+
//TODO remove
1028
// Global tron defaults.
1129
var defaultConfigSet = chainConfigSet{
1230
// poll period for balance monitoring
@@ -33,27 +51,9 @@ type chainConfigSet struct {
3351
type ChainConfig struct {
3452
BroadcastChanSize *uint64
3553
ConfirmPollPeriod *config.Duration
36-
OCR2CachePollPeriod *time.Duration
37-
OCR2CacheTTL *time.Duration
38-
BalancePollPeriod *time.Duration
39-
}
40-
41-
func (c *ChainConfig) SetDefaults() {
42-
if c.BroadcastChanSize == nil {
43-
c.BroadcastChanSize = &defaultConfigSet.BroadcastChanSize
44-
}
45-
if c.ConfirmPollPeriod == nil {
46-
c.ConfirmPollPeriod = config.MustNewDuration(defaultConfigSet.ConfirmPollPeriod)
47-
}
48-
if c.OCR2CachePollPeriod == nil {
49-
c.OCR2CachePollPeriod = &defaultConfigSet.OCR2CachePollPeriod
50-
}
51-
if c.OCR2CacheTTL == nil {
52-
c.OCR2CacheTTL = &defaultConfigSet.OCR2CacheTTL
53-
}
54-
if c.BalancePollPeriod == nil {
55-
c.BalancePollPeriod = &defaultConfigSet.BalancePollPeriod
56-
}
54+
OCR2CachePollPeriod *config.Duration
55+
OCR2CacheTTL *config.Duration
56+
BalancePollPeriod *config.Duration
5757
}
5858

5959
type NodeConfig struct {

relayer/config/config_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package config
2+
3+
//TODO

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>'

relayer/plugin/toml_config.go renamed to relayer/config/toml.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package plugin
1+
package config
22

33
import (
44
"errors"
@@ -11,7 +11,6 @@ import (
1111
"golang.org/x/exp/slices"
1212

1313
"github.com/smartcontractkit/chainlink-common/pkg/config"
14-
"github.com/smartcontractkit/chainlink-tron/relayer/ocr2"
1514
)
1615

1716
type TOMLConfigs []*TOMLConfig
@@ -118,12 +117,16 @@ type TOMLConfig struct {
118117
Nodes NodeConfigs
119118
}
120119

121-
var _ ocr2.Config = (*TOMLConfig)(nil)
122-
123120
func (c *TOMLConfig) IsEnabled() bool {
124121
return c.Enabled == nil || *c.Enabled
125122
}
126123

124+
func (c *TOMLConfig) SetDefaults() {
125+
def := Defaults()
126+
def.SetFrom(c)
127+
*c = def
128+
}
129+
127130
func (c *TOMLConfig) SetFrom(f *TOMLConfig) {
128131
if f.ChainID != nil {
129132
c.ChainID = f.ChainID
@@ -181,7 +184,7 @@ func (c *TOMLConfig) TOMLString() (string, error) {
181184
}
182185

183186
func (c *TOMLConfig) BalancePollPeriod() time.Duration {
184-
return *c.ChainConfig.BalancePollPeriod
187+
return c.ChainConfig.BalancePollPeriod.Duration()
185188
}
186189

187190
func (c *TOMLConfig) BroadcastChanSize() uint64 {
@@ -197,11 +200,11 @@ func (c *TOMLConfig) ListNodes() NodeConfigs {
197200
}
198201

199202
func (c *TOMLConfig) OCR2CachePollPeriod() time.Duration {
200-
return *c.ChainConfig.OCR2CachePollPeriod
203+
return c.ChainConfig.OCR2CachePollPeriod.Duration()
201204
}
202205

203206
func (c *TOMLConfig) OCR2CacheTTL() time.Duration {
204-
return *c.ChainConfig.OCR2CacheTTL
207+
return c.ChainConfig.OCR2CacheTTL.Duration()
205208
}
206209

207210
func NewDefault() *TOMLConfig {

relayer/config_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package relayer
2+
3+
import (
4+
_ "embed"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
9+
"github.com/smartcontractkit/chainlink-tron/relayer/config"
10+
)
11+
12+
var (
13+
//go:embed CONFIG.md
14+
configMD string
15+
)
16+
17+
//go:generate go run ./cmd/config-docs
18+
func TestConfigDocs(t *testing.T) {
19+
cfg, err := config.GenerateDocs()
20+
assert.NoError(t, err, "invalid config docs")
21+
assert.Equal(t, configMD, cfg, "CONFIG.md is out of date. Run 'go generate .' to regenerate.")
22+
}

relayer/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/pelletier/go-toml/v2 v2.2.3
1313
github.com/pkg/errors v0.9.1
1414
github.com/prometheus/client_golang v1.22.0
15-
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250425195105-d9eabb4a4519
15+
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250430133340-d04a3b64e331
1616
github.com/smartcontractkit/chainlink-evm v0.0.0-20250418155716-b70a99cec060
1717
github.com/smartcontractkit/libocr v0.0.0-20250328171017-609ec10a5510
1818
github.com/stretchr/testify v1.10.0

relayer/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp
379379
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
380380
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
381381
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
382-
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250425195105-d9eabb4a4519 h1:FMQVnelIaY4MZwYjKJDnTfoKJ1d6y4xZY6SpORGFlDo=
383-
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250425195105-d9eabb4a4519/go.mod h1:vHs/mPpAztdKJtzRKLnmLinmpS78fBh9sAuyKqQrQ+I=
382+
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250430133340-d04a3b64e331 h1:+bN5yuawZeQeVw7vG+Me7kXLFK1vcesVeku3mdgRwqI=
383+
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250430133340-d04a3b64e331/go.mod h1:UGZVg18zzyJ1KimGM5SSmxG5jb7aCSq3OwQQKfhHGyE=
384384
github.com/smartcontractkit/chainlink-evm v0.0.0-20250418155716-b70a99cec060 h1:5dnr4CLdbzGBXgWhWdzGzaEdJ3Ky70lY0oRCDsoDTu8=
385385
github.com/smartcontractkit/chainlink-evm v0.0.0-20250418155716-b70a99cec060/go.mod h1:fAS8SDyCxiCIRujq7v3D1ISGCrDyuXxd9zOEjQllJL8=
386386
github.com/smartcontractkit/grpc-proxy v0.0.0-20240830132753-a7e17fec5ab7 h1:12ijqMM9tvYVEm+nR826WsrNi6zCKpwBhuApq127wHs=

0 commit comments

Comments
 (0)