Skip to content

Commit bce49d5

Browse files
authored
Merge pull request #655 from smartcontractkit/feature/add-v2-txm-metrics
Feature/add v2 txm metrics
2 parents ea9a798 + d9b07d9 commit bce49d5

File tree

19 files changed

+2255
-57
lines changed

19 files changed

+2255
-57
lines changed

relayer/CONFIG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ OCR2CacheTTL = '1m' # Default
2121
RequestTimeout = '10s' # Default
2222
TxTimeout = '10s' # Default
2323
ConfirmationPoll = '5s' # Default
24+
FeeEstimationMaxAttempts = 5 # Default
2425
```
2526

2627

@@ -72,6 +73,12 @@ ConfirmationPoll = '5s' # Default
7273
```
7374
ConfirmationPoll is how often to confirmer checks for tx inclusion on chain.
7475

76+
### FeeEstimationMaxAttempts
77+
```toml
78+
FeeEstimationMaxAttempts = 5 # Default
79+
```
80+
FeeEstimationMaxAttempts is the maximum number of retry attempts for fee estimation.
81+
7582
## Nodes
7683
```toml
7784
[[Nodes]]

relayer/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ require (
88
github.com/ethereum/go-ethereum v1.15.0
99
github.com/hashicorp/go-plugin v1.6.2
1010
github.com/pelletier/go-toml/v2 v2.2.3
11+
github.com/prometheus/client_golang v1.21.1
1112
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250602141924-3c15a42d8266
1213
github.com/smartcontractkit/freeport v0.1.0
1314
github.com/smartcontractkit/libocr v0.0.0-20250220133800-f3b940c4f298
1415
github.com/stretchr/testify v1.10.0
16+
go.opentelemetry.io/otel v1.35.0
17+
go.opentelemetry.io/otel/metric v1.35.0
1518
go.uber.org/zap v1.27.0
1619
golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa
1720
)
@@ -98,7 +101,6 @@ require (
98101
github.com/oklog/run v1.1.0 // indirect
99102
github.com/pkg/errors v0.9.1 // indirect
100103
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
101-
github.com/prometheus/client_golang v1.21.1 // indirect
102104
github.com/prometheus/client_model v0.6.1 // indirect
103105
github.com/prometheus/common v0.63.0 // indirect
104106
github.com/prometheus/procfs v0.16.0 // indirect
@@ -120,7 +122,6 @@ require (
120122
github.com/yusufpapurcu/wmi v1.2.4 // indirect
121123
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
122124
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0 // indirect
123-
go.opentelemetry.io/otel v1.35.0 // indirect
124125
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.0.0-20240823153156-2a54df7bffb9 // indirect
125126
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.6.0 // indirect
126127
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.35.0 // indirect
@@ -132,7 +133,6 @@ require (
132133
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.28.0 // indirect
133134
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.28.0 // indirect
134135
go.opentelemetry.io/otel/log v0.6.0 // indirect
135-
go.opentelemetry.io/otel/metric v1.35.0 // indirect
136136
go.opentelemetry.io/otel/sdk v1.35.0 // indirect
137137
go.opentelemetry.io/otel/sdk/log v0.6.0 // indirect
138138
go.opentelemetry.io/otel/sdk/metric v1.35.0 // indirect

relayer/pkg/chainlink/chain/chain.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strconv"
1010

1111
"github.com/pelletier/go-toml/v2"
12+
"go.opentelemetry.io/otel/metric"
1213

1314
"github.com/smartcontractkit/chainlink-common/pkg/chains"
1415
"github.com/smartcontractkit/chainlink-common/pkg/logger"
@@ -33,9 +34,9 @@ type Chain interface {
3334
}
3435

3536
type ChainOpts struct {
36-
Logger logger.Logger
37-
// the implementation used here needs to be co-ordinated with the starknet transaction manager keystore adapter
38-
KeyStore loop.Keystore
37+
Logger logger.Logger
38+
KeyStore loop.Keystore // the implementation used here needs to be co-ordinated with the starknet transaction manager keystore adapter
39+
Meter metric.Meter // OpenTelemetry meter for beholder metrics
3940
}
4041

4142
func (o *ChainOpts) Name() string {
@@ -69,14 +70,14 @@ func NewChain(cfg *config.TOMLConfig, opts ChainOpts) (Chain, error) {
6970
if !cfg.IsEnabled() {
7071
return nil, fmt.Errorf("cannot create new chain with ID %s: chain is disabled", *cfg.ChainID)
7172
}
72-
c, err := newChain(*cfg.ChainID, cfg, opts.KeyStore, opts.Logger)
73+
c, err := newChain(*cfg.ChainID, cfg, opts.KeyStore, opts.Logger, opts.Meter)
7374
if err != nil {
7475
return nil, err
7576
}
7677
return c, nil
7778
}
7879

79-
func newChain(id string, cfg *config.TOMLConfig, loopKs loop.Keystore, lggr logger.Logger) (*chain, error) {
80+
func newChain(id string, cfg *config.TOMLConfig, loopKs loop.Keystore, lggr logger.Logger, meter metric.Meter) (*chain, error) {
8081
lggr = logger.Named(lggr, "Chain")
8182
lggr = logger.With(lggr, "starknetChainID", id)
8283
ch := &chain{
@@ -86,7 +87,7 @@ func newChain(id string, cfg *config.TOMLConfig, loopKs loop.Keystore, lggr logg
8687
}
8788

8889
var err error
89-
ch.txm, err = txm.New(lggr, loopKs, cfg, ch.getClient, ch.getFeederClient)
90+
ch.txm, err = txm.New(lggr, loopKs, cfg, ch.ChainID(), meter, ch.getClient, ch.getFeederClient)
9091
if err != nil {
9192
return nil, err
9293
}

relayer/pkg/chainlink/cmd/chainlink-starknet/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/hashicorp/go-plugin"
99
"github.com/pelletier/go-toml/v2"
1010

11+
"github.com/smartcontractkit/chainlink-common/pkg/beholder"
1112
"github.com/smartcontractkit/chainlink-common/pkg/loop"
1213
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
1314

@@ -75,9 +76,13 @@ func (c *pluginRelayer) NewRelayer(ctx context.Context, config string, loopKs lo
7576
}
7677
c.Logger.Infow("Creating relayer", "config", cfgStr)
7778

79+
// Get beholder meter for injection into chain/txm
80+
meter := beholder.GetMeter()
81+
7882
chain, err := starkchain.NewChain(&cfg, starkchain.ChainOpts{
7983
Logger: c.Logger,
8084
KeyStore: loopKs,
85+
Meter: meter,
8186
})
8287
if err != nil {
8388
return nil, fmt.Errorf("failed to create chain: %w", err)

relayer/pkg/chainlink/config/config.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ type ConfigSet struct { //nolint:revive
4040
RequestTimeout time.Duration
4141

4242
// txm config
43-
TxTimeout time.Duration
44-
ConfirmationPoll time.Duration
43+
TxTimeout time.Duration
44+
ConfirmationPoll time.Duration
45+
FeeEstimationMaxAttempts int
4546
}
4647

4748
type Config interface {
@@ -55,11 +56,12 @@ type Config interface {
5556
}
5657

5758
type Chain struct {
58-
OCR2CachePollPeriod *config.Duration
59-
OCR2CacheTTL *config.Duration
60-
RequestTimeout *config.Duration
61-
TxTimeout *config.Duration
62-
ConfirmationPoll *config.Duration
59+
OCR2CachePollPeriod *config.Duration
60+
OCR2CacheTTL *config.Duration
61+
RequestTimeout *config.Duration
62+
TxTimeout *config.Duration
63+
ConfirmationPoll *config.Duration
64+
FeeEstimationMaxAttempts *int
6365
}
6466

6567
type Node struct {
@@ -174,6 +176,9 @@ func setFromChain(c, f *Chain) {
174176
if f.ConfirmationPoll != nil {
175177
c.ConfirmationPoll = f.ConfirmationPoll
176178
}
179+
if f.FeeEstimationMaxAttempts != nil {
180+
c.FeeEstimationMaxAttempts = f.FeeEstimationMaxAttempts
181+
}
177182
}
178183

179184
func (c *TOMLConfig) ValidateConfig() (err error) {
@@ -248,6 +253,13 @@ func (c *TOMLConfig) ConfirmationPoll() time.Duration {
248253
return c.Chain.ConfirmationPoll.Duration()
249254
}
250255

256+
func (c *TOMLConfig) FeeEstimationMaxAttempts() int {
257+
if c.Chain.FeeEstimationMaxAttempts == nil {
258+
return 5 // Default value for fee estimation
259+
}
260+
return *c.Chain.FeeEstimationMaxAttempts
261+
}
262+
251263
func (c *TOMLConfig) OCR2CachePollPeriod() time.Duration {
252264
return c.Chain.OCR2CachePollPeriod.Duration()
253265
}

relayer/pkg/chainlink/config/config_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ func TestTOMLConfig_FullMarshal(t *testing.T) {
3030
Enabled: ptr(true),
3131
FeederURL: config.MustParseURL("http://feeder.url"),
3232
Chain: Chain{
33-
OCR2CachePollPeriod: config.MustNewDuration(6 * time.Hour),
34-
OCR2CacheTTL: config.MustNewDuration(3 * time.Minute),
35-
RequestTimeout: config.MustNewDuration(1*time.Minute + 3*time.Second),
36-
TxTimeout: config.MustNewDuration(13 * time.Second),
37-
ConfirmationPoll: config.MustNewDuration(42 * time.Second),
33+
OCR2CachePollPeriod: config.MustNewDuration(6 * time.Hour),
34+
OCR2CacheTTL: config.MustNewDuration(3 * time.Minute),
35+
RequestTimeout: config.MustNewDuration(1*time.Minute + 3*time.Second),
36+
TxTimeout: config.MustNewDuration(13 * time.Second),
37+
ConfirmationPoll: config.MustNewDuration(42 * time.Second),
38+
FeeEstimationMaxAttempts: ptr(8),
3839
},
3940
Nodes: []*Node{
4041
{

relayer/pkg/chainlink/config/docs.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ RequestTimeout = '10s' # Default
1414
TxTimeout = '10s' # Default
1515
# ConfirmationPoll is how often to confirmer checks for tx inclusion on chain.
1616
ConfirmationPoll = '5s' # Default
17+
# FeeEstimationMaxAttempts is the maximum number of retry attempts for fee estimation.
18+
FeeEstimationMaxAttempts = 5 # Default
1719

1820
[[Nodes]]
1921
# Name is a unique (per-chain) identifier for this node.

relayer/pkg/chainlink/config/testdata/config-full.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ OCR2CacheTTL = '3m0s'
66
RequestTimeout = '1m3s'
77
TxTimeout = '13s'
88
ConfirmationPoll = '42s'
9+
FeeEstimationMaxAttempts = 8
910

1011
[[Nodes]]
1112
Name = 'primary'

relayer/pkg/chainlink/txm/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ import "time"
88
type Config interface {
99
ConfirmationPoll() time.Duration
1010
TxTimeout() time.Duration
11+
FeeEstimationMaxAttempts() int
1112
}

0 commit comments

Comments
 (0)