Skip to content

Commit f932182

Browse files
committed
relayer: config enhancements
1 parent c0bdd36 commit f932182

16 files changed

Lines changed: 348 additions & 117 deletions

File tree

.github/workflows/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/gotron-sdk
21+
folder: relayer/gotron-sdk
2222

2323
test:
2424
name: Unit Tests

integration-tests/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ require (
192192
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
193193
github.com/kr/pretty v0.3.1 // indirect
194194
github.com/kr/text v0.2.0 // indirect
195+
github.com/kylelemons/godebug v1.1.0 // indirect
195196
github.com/leodido/go-urn v1.4.0 // indirect
196197
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
197198
github.com/linxGnu/grocksdb v1.9.3 // indirect

integration-tests/ocr2_local_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ import (
1717
"github.com/stretchr/testify/require"
1818

1919
relaylogger "github.com/smartcontractkit/chainlink-common/pkg/logger"
20+
"github.com/smartcontractkit/chainlink-tron/relayer/config"
21+
2022
"github.com/smartcontractkit/libocr/offchainreporting2plus/types"
2123

2224
"github.com/smartcontractkit/chainlink-tron/integration-tests/common"
2325
"github.com/smartcontractkit/chainlink-tron/integration-tests/contract"
2426
"github.com/smartcontractkit/chainlink-tron/integration-tests/utils"
2527
"github.com/smartcontractkit/chainlink-tron/relayer/ocr2"
26-
"github.com/smartcontractkit/chainlink-tron/relayer/plugin"
2728
"github.com/smartcontractkit/chainlink-tron/relayer/reader"
2829
"github.com/smartcontractkit/chainlink-tron/relayer/sdk"
2930
"github.com/smartcontractkit/chainlink-tron/relayer/testutils"
@@ -305,8 +306,8 @@ func validateRounds(t *testing.T, combinedClient sdk.CombinedClient, ocrAddress
305306
readerClient := reader.NewReader(combinedClient, ocrLogger)
306307
ocrReader := ocr2.NewOCR2Reader(readerClient, ocrLogger)
307308
contractReader := ocr2.NewContractReader(ocrAddress, ocrReader, ocrLogger)
308-
ocr2Config := plugin.NewDefault()
309-
transmissionsCache := ocr2.NewTransmissionsCache(ocr2Config, contractReader, ocrLogger)
309+
ocr2Config := config.Defaults()
310+
transmissionsCache := ocr2.NewTransmissionsCache(&ocr2Config, contractReader, ocrLogger)
310311
err = transmissionsCache.Start()
311312
require.NoError(t, err, "Failed to start transmissions cache")
312313

relayer/CONFIG.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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+
RetentionPeriod = 0 # Default
25+
ReapInterval = '1m' # Default
26+
```
27+
28+
29+
### ChainID
30+
```toml
31+
ChainID = 'foobar' # Example
32+
```
33+
ChainID is the Tron chain ID.
34+
35+
### Enabled
36+
```toml
37+
Enabled = true # Default
38+
```
39+
Enabled enables this chain.
40+
41+
### BalancePollPeriod
42+
```toml
43+
BalancePollPeriod = '5s' # Default
44+
```
45+
BalancePollPeriod is the poll period for balance monitoring
46+
47+
### BroadcastChanSize
48+
```toml
49+
BroadcastChanSize = 4096 # Default
50+
```
51+
BroadcastChanSize is the transaction broadcast channel size
52+
53+
### ConfirmPollPeriod
54+
```toml
55+
ConfirmPollPeriod = '500ms' # Default
56+
```
57+
ConfirmPollPeriod is the polling period for transaction confirmation
58+
59+
### OCR2CachePollPeriod
60+
```toml
61+
OCR2CachePollPeriod = '5s' # Default
62+
```
63+
OCR2CachePollPeriod is the polling period for OCR2 contract cache
64+
65+
### OCR2CacheTTL
66+
```toml
67+
OCR2CacheTTL = '1m' # Default
68+
```
69+
OCR2CacheTTL is the time to live for OCR2 contract cache
70+
71+
### RetentionPeriod
72+
```toml
73+
RetentionPeriod = 0 # Default
74+
```
75+
RetentionPeriod is the time for the tx manager to retain txes.
76+
77+
### ReapInterval
78+
```toml
79+
ReapInterval = '1m' # Default
80+
```
81+
ReapInterval is how often the tx manager cleans up old txes.
82+
83+
## Nodes
84+
```toml
85+
[[Nodes]]
86+
Name = 'primary' # Example
87+
URL = 'https://api.trongrid.io/wallet' # Example
88+
SolidityURL = 'http://api.trongrid.io/wallet' # Example
89+
```
90+
91+
92+
### Name
93+
```toml
94+
Name = 'primary' # Example
95+
```
96+
Name is a unique (per-chain) identifier for this node.
97+
98+
### URL
99+
```toml
100+
URL = 'https://api.trongrid.io/wallet' # Example
101+
```
102+
URL is the full node HTTP endpoint for this node.
103+
104+
### SolidityURL
105+
```toml
106+
SolidityURL = 'http://api.trongrid.io/wallet' # Example
107+
```
108+
SolidityURL is the solidity node HTTP endpoint for this node.
109+

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, csaKeystore core.Keystore, capabilityRegistry core.CapabilitiesRegistry) (loop.Relayer, error) {
56-
d := toml.NewDecoder(strings.NewReader(config))
56+
func (c *pluginRelayer) NewRelayer(ctx context.Context, configTOML string, keystore, csaKeystore core.Keystore, capabilityRegistry 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: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
RetentionPeriod *config.Duration
32+
ReapInterval *config.Duration
33+
}
34+
35+
type NodeConfig struct {
36+
Name *string
37+
URL *config.URL
38+
SolidityURL *config.URL
39+
}
40+
41+
func (n *NodeConfig) ValidateConfig() error {
42+
var err error
43+
if n.Name == nil {
44+
err = errors.Join(err, config.ErrMissing{Name: "Name", Msg: "required for all nodes"})
45+
} else if *n.Name == "" {
46+
err = errors.Join(err, config.ErrEmpty{Name: "Name", Msg: "required for all nodes"})
47+
}
48+
if n.URL == nil {
49+
err = errors.Join(err, config.ErrMissing{Name: "URL", Msg: "required for all nodes"})
50+
}
51+
if n.SolidityURL == nil {
52+
err = errors.Join(err, config.ErrMissing{Name: "SolidityURL", Msg: "required for all nodes"})
53+
}
54+
return err
55+
}

relayer/config/config_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
RetentionPeriod: config.MustNewDuration(0),
34+
ReapInterval: config.MustNewDuration(time.Minute),
35+
},
36+
Nodes: NodeConfigs{
37+
{
38+
Name: ptr("node"),
39+
URL: config.MustParseURL("https://example.com/tron"),
40+
SolidityURL: config.MustParseURL("http://example.com/solidity"),
41+
},
42+
},
43+
}
44+
configtest.AssertFullMarshal(t, full, fullTOML)
45+
}
46+
47+
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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
# RetentionPeriod is the time for the tx manager to retain txes.
16+
RetentionPeriod = 0 # Default
17+
# ReapInterval is how often the tx manager cleans up old txes.
18+
ReapInterval = '1m' # Default
19+
20+
[[Nodes]]
21+
# Name is a unique (per-chain) identifier for this node.
22+
Name = 'primary' # Example
23+
# URL is the full node HTTP endpoint for this node.
24+
URL = 'https://api.trongrid.io/wallet' # Example
25+
# SolidityURL is the solidity node HTTP endpoint for this node.
26+
SolidityURL = 'http://api.trongrid.io/wallet' # Example

0 commit comments

Comments
 (0)