Skip to content
Merged
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
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ require (
github.com/klauspost/cpuid/v2 v2.2.10 // 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
7 changes: 4 additions & 3 deletions integration-tests/ocr2_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ import (
"github.com/stretchr/testify/require"

relaylogger "github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-tron/relayer/config"

"github.com/smartcontractkit/libocr/offchainreporting2plus/types"

"github.com/smartcontractkit/chainlink-tron/integration-tests/common"
"github.com/smartcontractkit/chainlink-tron/integration-tests/contract"
"github.com/smartcontractkit/chainlink-tron/integration-tests/utils"
"github.com/smartcontractkit/chainlink-tron/relayer/ocr2"
"github.com/smartcontractkit/chainlink-tron/relayer/plugin"
"github.com/smartcontractkit/chainlink-tron/relayer/reader"
"github.com/smartcontractkit/chainlink-tron/relayer/sdk"
"github.com/smartcontractkit/chainlink-tron/relayer/testutils"
Expand Down Expand Up @@ -305,8 +306,8 @@ func validateRounds(t *testing.T, combinedClient sdk.CombinedClient, ocrAddress
readerClient := reader.NewReader(combinedClient, ocrLogger)
ocrReader := ocr2.NewOCR2Reader(readerClient, ocrLogger)
contractReader := ocr2.NewContractReader(ocrAddress, ocrReader, ocrLogger)
ocr2Config := plugin.NewDefault()
transmissionsCache := ocr2.NewTransmissionsCache(ocr2Config, contractReader, ocrLogger)
ocr2Config := config.Defaults()
transmissionsCache := ocr2.NewTransmissionsCache(&ocr2Config, contractReader, ocrLogger)
err = transmissionsCache.Start()
require.NoError(t, err, "Failed to start transmissions cache")

Expand Down
109 changes: 109 additions & 0 deletions relayer/CONFIG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
[//]: # (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
RetentionPeriod = 0 # Default
ReapInterval = '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

### RetentionPeriod
```toml
RetentionPeriod = 0 # Default
```
RetentionPeriod is the time for the tx manager to retain txes.

### ReapInterval
```toml
ReapInterval = '1m' # Default
```
ReapInterval is how often the tx manager cleans up old txes.

## 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.

2 changes: 1 addition & 1 deletion relayer/cmd/chainlink-tron/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ in
];

# pin the vendor hash (update using 'pkgs.lib.fakeHash')
vendorHash = "sha256-jOXWgQNKCI8HRdyT3YXXCpAKXvIXzqcYbvREWNAf2ao=";
vendorHash = "sha256-d7uPn6jiFjgpK7foLEXObdfFO6l2M3R5AU6anRKvqsw=";

# postInstall script to write version and rev to share folder
postInstall = ''
Expand Down
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, csaKeystore core.Keystore, capabilityRegistry core.CapabilitiesRegistry) (loop.Relayer, error) {
d := toml.NewDecoder(strings.NewReader(config))
func (c *pluginRelayer) NewRelayer(ctx context.Context, configTOML string, keystore, csaKeystore core.Keystore, capabilityRegistry 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)
}
}
55 changes: 55 additions & 0 deletions relayer/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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
RetentionPeriod *config.Duration
ReapInterval *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
}
47 changes: 47 additions & 0 deletions relayer/config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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),
RetentionPeriod: config.MustNewDuration(0),
ReapInterval: config.MustNewDuration(time.Minute),
},
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)
}
26 changes: 26 additions & 0 deletions relayer/config/docs.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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
# RetentionPeriod is the time for the tx manager to retain txes.
RetentionPeriod = 0 # Default
# ReapInterval is how often the tx manager cleans up old txes.
ReapInterval = '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>'
Loading
Loading