From 84e1dfa6d1f19b1903cfc563bba4f12d01298147 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Tue, 29 Apr 2025 08:12:37 -0500 Subject: [PATCH] relayer: config enhancements --- .github/workflows/gotron-sdk.yml | 2 +- flake.lock | 6 +- integration-tests/go.mod | 1 + integration-tests/ocr2_local_test.go | 7 +- relayer/CONFIG.md | 109 ++++++++++++++++++ relayer/cmd/chainlink-tron/default.nix | 2 +- relayer/cmd/chainlink-tron/main.go | 9 +- relayer/cmd/config-docs/main.go | 24 ++++ relayer/config/config.go | 55 +++++++++ relayer/config/config_test.go | 47 ++++++++ relayer/config/docs.go | 18 +++ relayer/config/docs.toml | 26 +++++ relayer/config/example.toml | 6 + relayer/config/testdata/config-full.toml | 14 +++ .../{plugin/toml_config.go => config/toml.go} | 25 ++-- relayer/config_test.go | 22 ++++ relayer/mocks/CombinedClient.go | 2 +- relayer/mocks/FullNodeClient.go | 2 +- relayer/mocks/OCR2Reader.go | 2 +- relayer/mocks/Reader.go | 2 +- relayer/plugin/chain_config.go | 93 --------------- relayer/plugin/relayer.go | 7 +- shell.nix | 2 +- 23 files changed, 357 insertions(+), 126 deletions(-) create mode 100644 relayer/CONFIG.md create mode 100644 relayer/cmd/config-docs/main.go create mode 100644 relayer/config/config.go create mode 100644 relayer/config/config_test.go create mode 100644 relayer/config/docs.go create mode 100644 relayer/config/docs.toml create mode 100644 relayer/config/example.toml create mode 100644 relayer/config/testdata/config-full.toml rename relayer/{plugin/toml_config.go => config/toml.go} (93%) create mode 100644 relayer/config_test.go delete mode 100644 relayer/plugin/chain_config.go diff --git a/.github/workflows/gotron-sdk.yml b/.github/workflows/gotron-sdk.yml index dbd88f1..4c91b90 100644 --- a/.github/workflows/gotron-sdk.yml +++ b/.github/workflows/gotron-sdk.yml @@ -18,7 +18,7 @@ jobs: - uses: ./.github/actions/changes id: c with: - folder: tron/gotron-sdk + folder: relayer/gotron-sdk test: name: Unit Tests diff --git a/flake.lock b/flake.lock index da3f19b..84bf4df 100644 --- a/flake.lock +++ b/flake.lock @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1747179050, - "narHash": "sha256-qhFMmDkeJX9KJwr5H32f1r7Prs7XbQWtO0h3V0a0rFY=", + "lastModified": 1756542300, + "narHash": "sha256-tlOn88coG5fzdyqz6R93SQL5Gpq+m/DsWpekNFhqPQk=", "owner": "nixos", "repo": "nixpkgs", - "rev": "adaa24fbf46737f3f1b5497bf64bae750f82942e", + "rev": "d7600c775f877cd87b4f5a831c28aa94137377aa", "type": "github" }, "original": { diff --git a/integration-tests/go.mod b/integration-tests/go.mod index 0a7f803..87c5f14 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -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 diff --git a/integration-tests/ocr2_local_test.go b/integration-tests/ocr2_local_test.go index ea03f4d..8a54fc0 100644 --- a/integration-tests/ocr2_local_test.go +++ b/integration-tests/ocr2_local_test.go @@ -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" @@ -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") diff --git a/relayer/CONFIG.md b/relayer/CONFIG.md new file mode 100644 index 0000000..427ed1c --- /dev/null +++ b/relayer/CONFIG.md @@ -0,0 +1,109 @@ +[//]: # (Documentation generated from docs.toml - DO NOT EDIT.) +This document describes the TOML format for configuration. +## Example + +```toml +ChainID = '' + +[[Tron.Nodes]] +Name = 'primary' +URL = '' +SolidityURL = '' + +``` + +## 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. + diff --git a/relayer/cmd/chainlink-tron/default.nix b/relayer/cmd/chainlink-tron/default.nix index d1415e8..25dd134 100644 --- a/relayer/cmd/chainlink-tron/default.nix +++ b/relayer/cmd/chainlink-tron/default.nix @@ -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 = '' diff --git a/relayer/cmd/chainlink-tron/main.go b/relayer/cmd/chainlink-tron/main.go index 2b03bb3..1339a95 100644 --- a/relayer/cmd/chainlink-tron/main.go +++ b/relayer/cmd/chainlink-tron/main.go @@ -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" ) @@ -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 { diff --git a/relayer/cmd/config-docs/main.go b/relayer/cmd/config-docs/main.go new file mode 100644 index 0000000..dc74c6e --- /dev/null +++ b/relayer/cmd/config-docs/main.go @@ -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) + } +} diff --git a/relayer/config/config.go b/relayer/config/config.go new file mode 100644 index 0000000..58783a3 --- /dev/null +++ b/relayer/config/config.go @@ -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 +} diff --git a/relayer/config/config_test.go b/relayer/config/config_test.go new file mode 100644 index 0000000..8b16c88 --- /dev/null +++ b/relayer/config/config_test.go @@ -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 } diff --git a/relayer/config/docs.go b/relayer/config/docs.go new file mode 100644 index 0000000..051a41f --- /dev/null +++ b/relayer/config/docs.go @@ -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) +} diff --git a/relayer/config/docs.toml b/relayer/config/docs.toml new file mode 100644 index 0000000..512991c --- /dev/null +++ b/relayer/config/docs.toml @@ -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 diff --git a/relayer/config/example.toml b/relayer/config/example.toml new file mode 100644 index 0000000..6f39413 --- /dev/null +++ b/relayer/config/example.toml @@ -0,0 +1,6 @@ +ChainID = '' + +[[Tron.Nodes]] +Name = 'primary' +URL = '' +SolidityURL = '' diff --git a/relayer/config/testdata/config-full.toml b/relayer/config/testdata/config-full.toml new file mode 100644 index 0000000..6a5e8e6 --- /dev/null +++ b/relayer/config/testdata/config-full.toml @@ -0,0 +1,14 @@ +ChainID = 'fake' +Enabled = false +BalancePollPeriod = '1h0m0s' +BroadcastChanSize = 99 +ConfirmPollPeriod = '42ms' +OCR2CachePollPeriod = '1m40s' +OCR2CacheTTL = '15m0s' +RetentionPeriod = '0s' +ReapInterval = '1m0s' + +[[Nodes]] +Name = 'node' +URL = 'https://example.com/tron' +SolidityURL = 'http://example.com/solidity' diff --git a/relayer/plugin/toml_config.go b/relayer/config/toml.go similarity index 93% rename from relayer/plugin/toml_config.go rename to relayer/config/toml.go index a0f1a69..f8b0b7d 100644 --- a/relayer/plugin/toml_config.go +++ b/relayer/config/toml.go @@ -1,4 +1,4 @@ -package plugin +package config import ( "errors" @@ -11,7 +11,6 @@ import ( "golang.org/x/exp/slices" "github.com/smartcontractkit/chainlink-common/pkg/config" - "github.com/smartcontractkit/chainlink-tron/relayer/ocr2" ) type TOMLConfigs []*TOMLConfig @@ -118,12 +117,16 @@ type TOMLConfig struct { Nodes NodeConfigs } -var _ ocr2.Config = (*TOMLConfig)(nil) - func (c *TOMLConfig) IsEnabled() bool { return c.Enabled == nil || *c.Enabled } +func (c *TOMLConfig) SetDefaults() { + def := Defaults() + def.SetFrom(c) + *c = def +} + func (c *TOMLConfig) SetFrom(f *TOMLConfig) { if f.ChainID != nil { c.ChainID = f.ChainID @@ -187,7 +190,7 @@ func (c *TOMLConfig) TOMLString() (string, error) { } func (c *TOMLConfig) BalancePollPeriod() time.Duration { - return *c.ChainConfig.BalancePollPeriod + return c.ChainConfig.BalancePollPeriod.Duration() } func (c *TOMLConfig) BroadcastChanSize() uint64 { @@ -203,23 +206,19 @@ func (c *TOMLConfig) ListNodes() NodeConfigs { } func (c *TOMLConfig) OCR2CachePollPeriod() time.Duration { - return *c.ChainConfig.OCR2CachePollPeriod + return c.ChainConfig.OCR2CachePollPeriod.Duration() } func (c *TOMLConfig) OCR2CacheTTL() time.Duration { - return *c.ChainConfig.OCR2CacheTTL + return c.ChainConfig.OCR2CacheTTL.Duration() } func (c *TOMLConfig) RetentionPeriod() time.Duration { - return *c.ChainConfig.RetentionPeriod + return c.ChainConfig.RetentionPeriod.Duration() } func (c *TOMLConfig) ReapInterval() time.Duration { - return *c.ChainConfig.ReapInterval -} - -func (c *TOMLConfig) SetDefaults() { - c.ChainConfig.SetDefaults() + return c.ChainConfig.ReapInterval.Duration() } func NewDefault() *TOMLConfig { diff --git a/relayer/config_test.go b/relayer/config_test.go new file mode 100644 index 0000000..f9d3fb8 --- /dev/null +++ b/relayer/config_test.go @@ -0,0 +1,22 @@ +package relayer + +import ( + _ "embed" + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/smartcontractkit/chainlink-tron/relayer/config" +) + +var ( + //go:embed CONFIG.md + configMD string +) + +//go:generate go run ./cmd/config-docs +func TestConfigDocs(t *testing.T) { + cfg, err := config.GenerateDocs() + assert.NoError(t, err, "invalid config docs") + assert.Equal(t, configMD, cfg, "CONFIG.md is out of date. Run 'go generate .' to regenerate.") +} diff --git a/relayer/mocks/CombinedClient.go b/relayer/mocks/CombinedClient.go index 98e4384..33b6195 100644 --- a/relayer/mocks/CombinedClient.go +++ b/relayer/mocks/CombinedClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.53.3. DO NOT EDIT. +// Code generated by mockery v2.53.5. DO NOT EDIT. package mocks diff --git a/relayer/mocks/FullNodeClient.go b/relayer/mocks/FullNodeClient.go index d9ba567..0c615c2 100644 --- a/relayer/mocks/FullNodeClient.go +++ b/relayer/mocks/FullNodeClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.53.3. DO NOT EDIT. +// Code generated by mockery v2.53.5. DO NOT EDIT. package mocks diff --git a/relayer/mocks/OCR2Reader.go b/relayer/mocks/OCR2Reader.go index 217256f..24d35ef 100644 --- a/relayer/mocks/OCR2Reader.go +++ b/relayer/mocks/OCR2Reader.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.53.3. DO NOT EDIT. +// Code generated by mockery v2.53.5. DO NOT EDIT. package mocks diff --git a/relayer/mocks/Reader.go b/relayer/mocks/Reader.go index faf3b4f..265414f 100644 --- a/relayer/mocks/Reader.go +++ b/relayer/mocks/Reader.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.53.3. DO NOT EDIT. +// Code generated by mockery v2.53.5. DO NOT EDIT. package mocks diff --git a/relayer/plugin/chain_config.go b/relayer/plugin/chain_config.go deleted file mode 100644 index f23fcba..0000000 --- a/relayer/plugin/chain_config.go +++ /dev/null @@ -1,93 +0,0 @@ -package plugin - -import ( - "errors" - "time" - - "github.com/smartcontractkit/chainlink-common/pkg/config" -) - -// Global tron defaults. -var defaultConfigSet = chainConfigSet{ - // poll period for balance monitoring - BalancePollPeriod: 5 * time.Second, - // transaction broadcast channel size - BroadcastChanSize: 4096, - // polling period for transaction confirmation - ConfirmPollPeriod: 500 * time.Millisecond, // polling for tx confirmation - // polling period for OCR2 contract cache - OCR2CachePollPeriod: 5 * time.Second, - // time to live for OCR2 contract cache - OCR2CacheTTL: time.Minute, - // retention period for transaction manager - RetentionPeriod: 0, - // reap interval for transaction manager - ReapInterval: 1 * time.Minute, -} - -// opt: remove -type chainConfigSet struct { - BroadcastChanSize uint64 - ConfirmPollPeriod time.Duration - OCR2CachePollPeriod time.Duration - OCR2CacheTTL time.Duration - BalancePollPeriod time.Duration - RetentionPeriod time.Duration - ReapInterval time.Duration -} - -type ChainConfig struct { - BroadcastChanSize *uint64 - ConfirmPollPeriod *config.Duration - OCR2CachePollPeriod *time.Duration - OCR2CacheTTL *time.Duration - BalancePollPeriod *time.Duration - RetentionPeriod *time.Duration - ReapInterval *time.Duration -} - -func (c *ChainConfig) SetDefaults() { - if c.BroadcastChanSize == nil { - c.BroadcastChanSize = &defaultConfigSet.BroadcastChanSize - } - if c.ConfirmPollPeriod == nil { - c.ConfirmPollPeriod = config.MustNewDuration(defaultConfigSet.ConfirmPollPeriod) - } - if c.OCR2CachePollPeriod == nil { - c.OCR2CachePollPeriod = &defaultConfigSet.OCR2CachePollPeriod - } - if c.OCR2CacheTTL == nil { - c.OCR2CacheTTL = &defaultConfigSet.OCR2CacheTTL - } - if c.BalancePollPeriod == nil { - c.BalancePollPeriod = &defaultConfigSet.BalancePollPeriod - } - if c.RetentionPeriod == nil { - c.RetentionPeriod = &defaultConfigSet.RetentionPeriod - } - if c.ReapInterval == nil { - c.ReapInterval = &defaultConfigSet.ReapInterval - } -} - -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 -} diff --git a/relayer/plugin/relayer.go b/relayer/plugin/relayer.go index d47c5f4..146b04a 100644 --- a/relayer/plugin/relayer.go +++ b/relayer/plugin/relayer.go @@ -18,6 +18,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/types" "github.com/smartcontractkit/chainlink-common/pkg/types/core" + "github.com/smartcontractkit/chainlink-tron/relayer/config" "github.com/smartcontractkit/chainlink-tron/relayer/monitor" "github.com/smartcontractkit/chainlink-tron/relayer/ocr2" "github.com/smartcontractkit/chainlink-tron/relayer/reader" @@ -31,7 +32,7 @@ type TronRelayer struct { chainId string chainIdNum *big.Int - cfg *TOMLConfig + cfg *config.TOMLConfig lggr logger.Logger client sdk.CombinedClient @@ -41,7 +42,7 @@ type TronRelayer struct { var _ types.Relayer = &TronRelayer{} -func NewRelayer(cfg *TOMLConfig, lggr logger.Logger, keystore core.Keystore) (*TronRelayer, error) { +func NewRelayer(cfg *config.TOMLConfig, lggr logger.Logger, keystore core.Keystore) (*TronRelayer, error) { id := *cfg.ChainID var idNum *big.Int @@ -185,7 +186,7 @@ func (t *TronRelayer) listNodeStatuses(start, end int) ([]types.NodeStatus, int, return stats, total, nil } -func nodeStatus(n *NodeConfig, id string) (types.NodeStatus, error) { +func nodeStatus(n *config.NodeConfig, id string) (types.NodeStatus, error) { // TODO: why does marshalling the config tell us the node status? var s types.NodeStatus s.ChainID = id diff --git a/shell.nix b/shell.nix index 98e4151..a0f352b 100644 --- a/shell.nix +++ b/shell.nix @@ -15,7 +15,7 @@ pkgs.mkShell { delve golangci-lint gotools - go-mockery + go-mockery_2 # Extra tools git