Skip to content

Commit b3862c0

Browse files
committed
relay/config: config enhancements
1 parent 56cd77f commit b3862c0

File tree

15 files changed

+449
-28
lines changed

15 files changed

+449
-28
lines changed

CONFIG.md

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
TODO header
2+
## Example
3+
4+
```toml
5+
TODO example
6+
```
7+
8+
## Global
9+
```toml
10+
Enabled = true # Default
11+
ChainID = 'TODO' # Example
12+
NetworkName = 'TODO' # Example
13+
NetworkNameFull = 'TODO' # Example
14+
```
15+
16+
17+
### Enabled
18+
```toml
19+
Enabled = true # Default
20+
```
21+
Enabled TODO
22+
23+
### ChainID
24+
```toml
25+
ChainID = 'TODO' # Example
26+
```
27+
ChainID TODO
28+
29+
### NetworkName
30+
```toml
31+
NetworkName = 'TODO' # Example
32+
```
33+
NetworkName TODO
34+
35+
### NetworkNameFull
36+
```toml
37+
NetworkNameFull = 'TODO' # Example
38+
```
39+
NetworkNameFull TODO
40+
41+
## TransactionManager
42+
```toml
43+
[TransactionManager]
44+
BroadcastChanSize = 100 # Default
45+
ConfirmPoll = '2s' # Default
46+
DefaultMaxGasAmount = 200000 # Default
47+
MaxSimulateAttempts = 5 # Default
48+
MaxSubmitRetryAttempts = 10 # Default
49+
SubmitDelayDuration = '3s' # Default
50+
TxExpiration = '10s' # Default
51+
MaxTxRetryAttempts = 5 # Default
52+
PruneInterval = '4h' # Default
53+
PruneTxExpiration = '2h' # Default
54+
```
55+
56+
57+
### BroadcastChanSize
58+
```toml
59+
BroadcastChanSize = 100 # Default
60+
```
61+
BroadcastChanSize TODO
62+
63+
### ConfirmPoll
64+
```toml
65+
ConfirmPoll = '2s' # Default
66+
```
67+
ConfirmPoll TODO
68+
69+
### DefaultMaxGasAmount
70+
```toml
71+
DefaultMaxGasAmount = 200000 # Default
72+
```
73+
DefaultMaxGasAmount TODO
74+
https://github.com/aptos-labs/aptos-ts-sdk/blob/32d4360740392782c1368647f89ba62e1b6a2cb3/src/utils/const.ts#L21
75+
76+
### MaxSimulateAttempts
77+
```toml
78+
MaxSimulateAttempts = 5 # Default
79+
```
80+
MaxSimulateAttempts TODO
81+
82+
### MaxSubmitRetryAttempts
83+
```toml
84+
MaxSubmitRetryAttempts = 10 # Default
85+
```
86+
MaxSubmitRetryAttempts TODO
87+
88+
### SubmitDelayDuration
89+
```toml
90+
SubmitDelayDuration = '3s' # Default
91+
```
92+
SubmitDelayDuration TODO
93+
94+
### TxExpiration
95+
```toml
96+
TxExpiration = '10s' # Default
97+
```
98+
TxExpiration TODO
99+
100+
### MaxTxRetryAttempts
101+
```toml
102+
MaxTxRetryAttempts = 5 # Default
103+
```
104+
MaxTxRetryAttempts TODO
105+
106+
### PruneInterval
107+
```toml
108+
PruneInterval = '4h' # Default
109+
```
110+
PruneInterval TODO
111+
112+
### PruneTxExpiration
113+
```toml
114+
PruneTxExpiration = '2h' # Default
115+
```
116+
PruneTxExpiration TODO
117+
118+
## BalanceMonitor
119+
```toml
120+
[BalanceMonitor]
121+
BalancePollPeriod = '10s' # Default
122+
```
123+
124+
125+
### BalancePollPeriod
126+
```toml
127+
BalancePollPeriod = '10s' # Default
128+
```
129+
BalancePollPeriod TODO
130+
131+
## WriteTargetCap
132+
```toml
133+
[WriteTargetCap]
134+
ConfirmerPollPeriod = '1s' # Default
135+
ConfirmerTimeout = '10s' # Default
136+
```
137+
138+
139+
### ConfirmerPollPeriod
140+
```toml
141+
ConfirmerPollPeriod = '1s' # Default
142+
```
143+
ConfirmerPollPeriod TODO
144+
145+
### ConfirmerTimeout
146+
```toml
147+
ConfirmerTimeout = '10s' # Default
148+
```
149+
ConfirmerTimeout TODO
150+
151+
## Workflow
152+
```toml
153+
[Workflow]
154+
ForwarderAddress = 'TODO' # Example
155+
PublicKey = 'TODO' # Example
156+
```
157+
158+
159+
### ForwarderAddress
160+
```toml
161+
ForwarderAddress = 'TODO' # Example
162+
```
163+
ForwarderAddress TODO
164+
165+
### PublicKey
166+
```toml
167+
PublicKey = 'TODO' # Example
168+
```
169+
PublicKey TODO
170+
171+
## Nodes
172+
```toml
173+
[[Nodes]]
174+
Name = 'TODO' # Example
175+
URL = '' # Example
176+
```
177+
178+
179+
### Name
180+
```toml
181+
Name = 'TODO' # Example
182+
```
183+
Name TODO
184+
185+
### URL
186+
```toml
187+
URL = '' # Example
188+
```
189+
URL TODO
190+

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"
9+
10+
"github.com/smartcontractkit/chainlink-aptos/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(path.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+
}

config_test.go

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

gen.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ package aptos
1919
//go:generate go run ./cmd/bindgen --uppercase CCIP,MCMS --input ./contracts/mcms/mcms/sources/mcms_registry.move --output ./bindings/mcms/mcms_registry
2020

2121
//go:generate go run ./cmd/bindgen --uppercase CCIP,MCMS --input ./contracts/mcms/mcms_test/sources/mcms_user.move --output ./bindings/mcms_test/mcms_user
22+
23+
//go:generate go run ./cmd/config-docs -o CONFIG.md

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/jpillora/backoff v1.0.0
1515
github.com/pelletier/go-toml/v2 v2.2.3
1616
github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82
17-
github.com/smartcontractkit/chainlink-common v0.5.1-0.20250314131019-e227d4e2dc2f
17+
github.com/smartcontractkit/chainlink-common v0.6.1-0.20250407120709-04fce0e6d2b7
1818
github.com/stretchr/testify v1.10.0
1919
github.com/valyala/fastjson v1.6.4
2020
go.opentelemetry.io/otel v1.35.0
@@ -73,6 +73,7 @@ require (
7373
github.com/jmoiron/sqlx v1.4.0 // indirect
7474
github.com/klauspost/compress v1.18.0 // indirect
7575
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
76+
github.com/kylelemons/godebug v1.1.0 // indirect
7677
github.com/leodido/go-urn v1.4.0 // indirect
7778
github.com/lib/pq v1.10.9 // indirect
7879
github.com/mailru/easyjson v0.9.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB
295295
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
296296
github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82 h1:6C8qej6f1bStuePVkLSFxoU22XBS165D3klxlzRg8F4=
297297
github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82/go.mod h1:xe4pgH49k4SsmkQq5OT8abwhWmnzkhpgnXeekbx2efw=
298-
github.com/smartcontractkit/chainlink-common v0.5.1-0.20250314131019-e227d4e2dc2f h1:5j1pQ2jWIRo8IWHDv02TcjPoLSaTO6Hc2NcRH+3cmWU=
299-
github.com/smartcontractkit/chainlink-common v0.5.1-0.20250314131019-e227d4e2dc2f/go.mod h1:YQuXIqQpmpAqstWV0LHaDTJ5nsSWuip5ivEM+Fisb+4=
298+
github.com/smartcontractkit/chainlink-common v0.6.1-0.20250407120709-04fce0e6d2b7 h1:hiDBbLY6y81ejFlwiPHEo9dupsBlpXAWKCd7gszG5hI=
299+
github.com/smartcontractkit/chainlink-common v0.6.1-0.20250407120709-04fce0e6d2b7/go.mod h1:FAY6l9UaRzjL9yxvKoNUETQrbCOALDZTgbhoFldOytM=
300300
github.com/smartcontractkit/grpc-proxy v0.0.0-20240830132753-a7e17fec5ab7 h1:12ijqMM9tvYVEm+nR826WsrNi6zCKpwBhuApq127wHs=
301301
github.com/smartcontractkit/grpc-proxy v0.0.0-20240830132753-a7e17fec5ab7/go.mod h1:FX7/bVdoep147QQhsOPkYsPEXhGZjeYx6lBSaSXtZOA=
302302
github.com/smartcontractkit/libocr v0.0.0-20250220133800-f3b940c4f298 h1:PKiqnVOTChlH4a4ljJKL3OKGRgYfIpJS4YD1daAIKks=

relayer/config/config.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package config
33
import (
44
"errors"
55
"fmt"
6+
"log"
67
"net/url"
78
"slices"
89
"strings"
@@ -12,6 +13,7 @@ import (
1213
"github.com/pelletier/go-toml/v2"
1314

1415
"github.com/smartcontractkit/chainlink-common/pkg/config"
16+
"github.com/smartcontractkit/chainlink-common/pkg/config/configtest"
1517

1618
"github.com/smartcontractkit/chainlink-aptos/relayer/monitor"
1719
"github.com/smartcontractkit/chainlink-aptos/relayer/txm"
@@ -21,14 +23,30 @@ import (
2123
// Name of the chain family (e.g., "ethereum", "solana", "aptos")
2224
const ChainFamilyName = "aptos"
2325

26+
var defaults TOMLConfig
27+
28+
func init() {
29+
if err := configtest.DocDefaultsOnly(strings.NewReader(docsTOML), &defaults, config.DecodeTOML); err != nil {
30+
log.Fatalf("Failed to initialize defaults from docs: %v", err)
31+
}
32+
}
33+
34+
//TODO use this
35+
func Defaults() (c TOMLConfig) {
36+
c.SetFrom(&defaults)
37+
return
38+
}
39+
40+
//TODO remove?
2441
var DefaultConfigSet = ConfigSet{
2542
TransactionManager: txm.DefaultConfigSet,
2643
BalanceMonitor: monitor.GenericBalanceConfig{
27-
BalancePollPeriod: *config.MustNewDuration(10 * time.Second),
44+
BalancePollPeriod: config.MustNewDuration(10 * time.Second),
2845
},
2946
WriteTargetCap: write_target.DefaultConfigSet,
3047
}
3148

49+
//TODO remove?
3250
type ConfigSet struct { //nolint:revive
3351
TransactionManager txm.Config
3452
BalanceMonitor monitor.GenericBalanceConfig
@@ -126,7 +144,7 @@ func (cs TOMLConfigs) validateKeys() (err error) {
126144
type TOMLConfig struct {
127145
// Do not access directly. Use [IsEnabled]
128146
Enabled *bool
129-
147+
//TODO pointer fields
130148
// Chain configuration
131149
ChainID string
132150
NetworkName string
@@ -156,7 +174,7 @@ func NewDecodedTOMLConfig(rawConfig string) (*TOMLConfig, error) {
156174
return &TOMLConfig{}, fmt.Errorf("cannot create new chain with ID %s: config is disabled", cfg.ChainID)
157175
}
158176

159-
cfg.SetDefaults()
177+
cfg.SetDefaults() //TODO validate after?
160178
return &cfg, nil
161179
}
162180

0 commit comments

Comments
 (0)