Skip to content

Commit 5d2fa87

Browse files
committed
addressed feedback
1 parent 56c681b commit 5d2fa87

File tree

10 files changed

+135
-178
lines changed

10 files changed

+135
-178
lines changed

capabilities/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.24.0
44

55
require (
66
github.com/ethereum/go-ethereum v1.14.11
7-
github.com/smartcontractkit/chainlink-common v0.6.1-0.20250407190234-6aa49242696f
7+
github.com/smartcontractkit/chainlink-common v0.6.1-0.20250407221007-b26aef17d389
88
github.com/stretchr/testify v1.10.0
99
go.opentelemetry.io/otel v1.35.0
1010
go.opentelemetry.io/otel/metric v1.35.0

capabilities/go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,10 @@ github.com/santhosh-tekuri/jsonschema/v5 v5.2.0 h1:WCcC4vZDS1tYNxjWlwRJZQy28r8CM
126126
github.com/santhosh-tekuri/jsonschema/v5 v5.2.0/go.mod h1:FKdcjfQW6rpZSnxxUvEA5H/cDPdvJ/SZJQLWWXWGrZ0=
127127
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
128128
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
129-
github.com/smartcontractkit/chainlink-common v0.6.1-0.20250407190234-6aa49242696f h1:00quRDFuSBYcoDJONuV4C9DJTQQos5YAxN3TSLfqqcg=
130-
github.com/smartcontractkit/chainlink-common v0.6.1-0.20250407190234-6aa49242696f/go.mod h1:pptbsF6z90IGCewkCgDMBxNYjfSOyW9X9l2jzYyQgmk=
129+
github.com/smartcontractkit/chainlink-common v0.6.1-0.20250407215533-f0e300efcd71 h1:iZlVMDR0uTLbpg+1ozVAc5NJAEIgRBy9S06lksLntxE=
130+
github.com/smartcontractkit/chainlink-common v0.6.1-0.20250407215533-f0e300efcd71/go.mod h1:pptbsF6z90IGCewkCgDMBxNYjfSOyW9X9l2jzYyQgmk=
131+
github.com/smartcontractkit/chainlink-common v0.6.1-0.20250407221007-b26aef17d389 h1:XUGOj26ZAFjrBRa8iqItbgYav3oGCQDzDkObGDCGic0=
132+
github.com/smartcontractkit/chainlink-common v0.6.1-0.20250407221007-b26aef17d389/go.mod h1:pptbsF6z90IGCewkCgDMBxNYjfSOyW9X9l2jzYyQgmk=
131133
github.com/smartcontractkit/libocr v0.0.0-20250220133800-f3b940c4f298 h1:PKiqnVOTChlH4a4ljJKL3OKGRgYfIpJS4YD1daAIKks=
132134
github.com/smartcontractkit/libocr v0.0.0-20250220133800-f3b940c4f298/go.mod h1:Mb7+/LC4edz7HyHxX4QkE42pSuov4AV68+AxBXAap0o=
133135
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

capabilities/writetarget/beholder/monitor/metrics.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"go.opentelemetry.io/otel/metric"
99

1010
"github.com/smartcontractkit/chainlink-common/pkg/beholder"
11-
12-
"github.com/smartcontractkit/chainlink-common/pkg/beholder/utils"
1311
)
1412

1513
// TODO: move to another directory / repo
@@ -39,11 +37,11 @@ func (g *GaugeAccBalance) GetAttributes(account string, chainInfo ChainInfo) att
3937
attribute.String("account", account),
4038

4139
// Execution Context - Source
42-
attribute.String("source_id", utils.ValOrUnknown(account)), // reusing account as source_id
40+
attribute.String("source_id", beholder.ValOrUnknown(account)), // reusing account as source_id
4341
// Execution Context - Chain
44-
attribute.String("chain_family_name", utils.ValOrUnknown(chainInfo.ChainFamilyName)),
45-
attribute.String("chain_id", utils.ValOrUnknown(chainInfo.ChainID)),
46-
attribute.String("network_name", utils.ValOrUnknown(chainInfo.NetworkName)),
47-
attribute.String("network_name_full", utils.ValOrUnknown(chainInfo.NetworkNameFull)),
42+
attribute.String("chain_family_name", beholder.ValOrUnknown(chainInfo.ChainFamilyName)),
43+
attribute.String("chain_id", beholder.ValOrUnknown(chainInfo.ChainID)),
44+
attribute.String("network_name", beholder.ValOrUnknown(chainInfo.NetworkName)),
45+
attribute.String("network_name_full", beholder.ValOrUnknown(chainInfo.NetworkNameFull)),
4846
)
4947
}

capabilities/writetarget/beholder/pb/data-feeds/on-chain/registry/decode.go

Lines changed: 63 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import (
1515
mercury_v4 "github.com/smartcontractkit/chainlink-framework/capabilities/writetarget/beholder/report/mercury/v4"
1616
)
1717

18-
// DecodeAsFeedUpdated decodes a 'platform.write-target.WriteConfirmed' message
19-
// as a 'data-feeds.registry.ReportProcessed' message
2018
func DecodeAsFeedUpdated(m *wt_msg.WriteConfirmed) ([]*FeedUpdated, error) {
2119
// Decode the confirmed report (WT -> DF contract event)
2220
r, err := platform.Decode(m.Report)
@@ -35,20 +33,14 @@ func DecodeAsFeedUpdated(m *wt_msg.WriteConfirmed) ([]*FeedUpdated, error) {
3533

3634
// Iterate over the underlying Mercury reports
3735
for _, rf := range *reports {
38-
// Notice: we assume that Mercury will be the only source of reports used for Data Feeds,
39-
// at least for the foreseeable future. If this assumption changes, we should check the
40-
// the report type here (potentially encoded in the feed ID) and decode accordingly.
41-
42-
// Decode the common Mercury report
43-
rm, err := mercury_vX.Decode(rf.Data)
36+
// Decode the common Mercury report and get report type
37+
rmCommon, err := mercury_vX.Decode(rf.Data)
4438
if err != nil {
4539
return nil, fmt.Errorf("failed to decode Mercury report: %w", err)
4640
}
4741

48-
// Parse the report type
49-
t := mercury_vX.GetReportType(rm.FeedID)
50-
51-
// Notice: we publish the DataFeed FeedID, not the unrelying DataStream FeedID
42+
// Parse the report type from the common header
43+
t := mercury_vX.GetReportType(rmCommon.FeedID)
5244
feedID := datafeeds.FeedID(rf.FeedID)
5345

5446
switch t {
@@ -57,99 +49,15 @@ func DecodeAsFeedUpdated(m *wt_msg.WriteConfirmed) ([]*FeedUpdated, error) {
5749
if err != nil {
5850
return nil, fmt.Errorf("failed to decode Mercury v%d report: %w", t, err)
5951
}
60-
61-
msgs = append(msgs, &FeedUpdated{
62-
// Event data
63-
FeedId: feedID.String(),
64-
ObservationsTimestamp: rm.ObservationsTimestamp,
65-
Benchmark: rm.BenchmarkPrice.Bytes(), // Map big.Int as []byte
66-
Report: rf.Data,
67-
68-
// Notice: i192 will not fit if scaled number bigger than f64
69-
BenchmarkVal: toBenchmarkVal(feedID, rm.BenchmarkPrice),
70-
71-
// Head data - when was the event produced on-chain
72-
BlockHash: m.BlockHash,
73-
BlockHeight: m.BlockHeight,
74-
BlockTimestamp: m.BlockTimestamp,
75-
76-
// Transaction data - info about the tx that mained the event (optional)
77-
// Notice: we skip SOME head/tx data here (unknown), as we map from 'platform.write-target.WriteConfirmed'
78-
// and not from tx/event data (e.g., 'platform.write-target.WriteTxConfirmed')
79-
TxSender: m.Transmitter,
80-
TxReceiver: m.Forwarder,
81-
82-
// Execution Context - Source
83-
MetaSourceId: m.MetaSourceId,
84-
85-
// Execution Context - Chain
86-
MetaChainFamilyName: m.MetaChainFamilyName,
87-
MetaChainId: m.MetaChainId,
88-
MetaNetworkName: m.MetaNetworkName,
89-
MetaNetworkNameFull: m.MetaNetworkNameFull,
90-
91-
// Execution Context - Workflow (capabilities.RequestMetadata)
92-
MetaWorkflowId: m.MetaWorkflowId,
93-
MetaWorkflowOwner: m.MetaWorkflowOwner,
94-
MetaWorkflowExecutionId: m.MetaWorkflowExecutionId,
95-
MetaWorkflowName: m.MetaWorkflowName,
96-
MetaWorkflowDonId: m.MetaWorkflowDonId,
97-
MetaWorkflowDonConfigVersion: m.MetaWorkflowDonConfigVersion,
98-
MetaReferenceId: m.MetaReferenceId,
99-
100-
// Execution Context - Capability
101-
MetaCapabilityType: m.MetaCapabilityType,
102-
MetaCapabilityId: m.MetaCapabilityId,
103-
MetaCapabilityTimestampStart: m.MetaCapabilityTimestampStart,
104-
MetaCapabilityTimestampEmit: m.MetaCapabilityTimestampEmit,
105-
})
52+
// For Mercury v3, include TxSender and TxReceiver
53+
msgs = append(msgs, newFeedUpdated(m, feedID, rm.ObservationsTimestamp, rm.BenchmarkPrice, rf.Data, true))
10654
case uint16(4):
10755
rm, err := mercury_v4.Decode(rf.Data)
10856
if err != nil {
10957
return nil, fmt.Errorf("failed to decode Mercury v%d report: %w", t, err)
11058
}
111-
112-
msgs = append(msgs, &FeedUpdated{
113-
// Event data
114-
FeedId: feedID.String(),
115-
ObservationsTimestamp: rm.ObservationsTimestamp,
116-
Benchmark: rm.BenchmarkPrice.Bytes(), // Map big.Int as []byte
117-
Report: rf.Data,
118-
119-
// Notice: i192 will not fit if scaled number bigger than f64
120-
BenchmarkVal: toBenchmarkVal(feedID, rm.BenchmarkPrice),
121-
122-
// Notice: we skip head/tx data here (unknown), as we map from 'platform.write-target.WriteConfirmed'
123-
// and not from tx/event data (e.g., 'platform.write-target.WriteTxConfirmed')
124-
125-
BlockHash: m.BlockHash,
126-
BlockHeight: m.BlockHeight,
127-
BlockTimestamp: m.BlockTimestamp,
128-
129-
// Execution Context - Source
130-
MetaSourceId: m.MetaSourceId,
131-
132-
// Execution Context - Chain
133-
MetaChainFamilyName: m.MetaChainFamilyName,
134-
MetaChainId: m.MetaChainId,
135-
MetaNetworkName: m.MetaNetworkName,
136-
MetaNetworkNameFull: m.MetaNetworkNameFull,
137-
138-
// Execution Context - Workflow (capabilities.RequestMetadata)
139-
MetaWorkflowId: m.MetaWorkflowId,
140-
MetaWorkflowOwner: m.MetaWorkflowOwner,
141-
MetaWorkflowExecutionId: m.MetaWorkflowExecutionId,
142-
MetaWorkflowName: m.MetaWorkflowName,
143-
MetaWorkflowDonId: m.MetaWorkflowDonId,
144-
MetaWorkflowDonConfigVersion: m.MetaWorkflowDonConfigVersion,
145-
MetaReferenceId: m.MetaReferenceId,
146-
147-
// Execution Context - Capability
148-
MetaCapabilityType: m.MetaCapabilityType,
149-
MetaCapabilityId: m.MetaCapabilityId,
150-
MetaCapabilityTimestampStart: m.MetaCapabilityTimestampStart,
151-
MetaCapabilityTimestampEmit: m.MetaCapabilityTimestampEmit,
152-
})
59+
// For Mercury v4, skip TxSender and TxReceiver (if not applicable)
60+
msgs = append(msgs, newFeedUpdated(m, feedID, rm.ObservationsTimestamp, rm.BenchmarkPrice, rf.Data, false))
15361
default:
15462
return nil, fmt.Errorf("unsupported Mercury report type: %d", t)
15563
}
@@ -158,6 +66,61 @@ func DecodeAsFeedUpdated(m *wt_msg.WriteConfirmed) ([]*FeedUpdated, error) {
15866
return msgs, nil
15967
}
16068

69+
// newFeedUpdated creates a FeedUpdated from the given common parameters.
70+
// If includeTxInfo is true, TxSender and TxReceiver are set.
71+
func newFeedUpdated(
72+
m *wt_msg.WriteConfirmed,
73+
feedID datafeeds.FeedID,
74+
observationsTimestamp uint32,
75+
benchmarkPrice *big.Int,
76+
report []byte,
77+
includeTxInfo bool,
78+
) *FeedUpdated {
79+
fu := &FeedUpdated{
80+
FeedId: feedID.String(),
81+
ObservationsTimestamp: observationsTimestamp,
82+
Benchmark: benchmarkPrice.Bytes(),
83+
Report: report,
84+
BenchmarkVal: toBenchmarkVal(feedID, benchmarkPrice),
85+
86+
// Head data - when was the event produced on-chain
87+
BlockHash: m.BlockHash,
88+
BlockHeight: m.BlockHeight,
89+
BlockTimestamp: m.BlockTimestamp,
90+
91+
// Execution Context - Source
92+
MetaSourceId: m.MetaSourceId,
93+
94+
// Execution Context - Chain
95+
MetaChainFamilyName: m.MetaChainFamilyName,
96+
MetaChainId: m.MetaChainId,
97+
MetaNetworkName: m.MetaNetworkName,
98+
MetaNetworkNameFull: m.MetaNetworkNameFull,
99+
100+
// Execution Context - Workflow (capabilities.RequestMetadata)
101+
MetaWorkflowId: m.MetaWorkflowId,
102+
MetaWorkflowOwner: m.MetaWorkflowOwner,
103+
MetaWorkflowExecutionId: m.MetaWorkflowExecutionId,
104+
MetaWorkflowName: m.MetaWorkflowName,
105+
MetaWorkflowDonId: m.MetaWorkflowDonId,
106+
MetaWorkflowDonConfigVersion: m.MetaWorkflowDonConfigVersion,
107+
MetaReferenceId: m.MetaReferenceId,
108+
109+
// Execution Context - Capability
110+
MetaCapabilityType: m.MetaCapabilityType,
111+
MetaCapabilityId: m.MetaCapabilityId,
112+
MetaCapabilityTimestampStart: m.MetaCapabilityTimestampStart,
113+
MetaCapabilityTimestampEmit: m.MetaCapabilityTimestampEmit,
114+
}
115+
116+
if includeTxInfo {
117+
fu.TxSender = m.Transmitter
118+
fu.TxReceiver = m.Forwarder
119+
}
120+
121+
return fu
122+
}
123+
161124
// toBenchmarkVal returns the benchmark i192 on-chain value decoded as an double (float64), scaled by number of decimals (e.g., 1e-18)
162125
// Where the number of decimals is extracted from the feed ID.
163126
//

capabilities/writetarget/beholder/pb/data-feeds/on-chain/registry/metrics.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"go.opentelemetry.io/otel/metric"
1111

1212
"github.com/smartcontractkit/chainlink-common/pkg/beholder"
13-
14-
"github.com/smartcontractkit/chainlink-common/pkg/beholder/utils"
1513
)
1614

1715
// ns returns a namespaced metric name
@@ -22,36 +20,36 @@ func ns(name string) string {
2220
// Define metrics configuration
2321
var (
2422
feedUpdated = struct {
25-
basic utils.MetricsInfoCapBasic
23+
basic beholder.MetricsInfoCapBasic
2624
// specific to FeedUpdated
27-
observationsTimestamp utils.MetricInfo
28-
duration utils.MetricInfo // ts.emit - ts.observation
29-
benchmark utils.MetricInfo
30-
blockTimestamp utils.MetricInfo
31-
blockNumber utils.MetricInfo
25+
observationsTimestamp beholder.MetricInfo
26+
duration beholder.MetricInfo // ts.emit - ts.observation
27+
benchmark beholder.MetricInfo
28+
blockTimestamp beholder.MetricInfo
29+
blockNumber beholder.MetricInfo
3230
}{
33-
basic: utils.NewMetricsInfoCapBasic(ns("feed_updated"), "data-feeds.on-chain.registry.FeedUpdated"),
34-
observationsTimestamp: utils.MetricInfo{
31+
basic: beholder.NewMetricsInfoCapBasic(ns("feed_updated"), "data-feeds.on-chain.registry.FeedUpdated"),
32+
observationsTimestamp: beholder.MetricInfo{
3533
Name: ns("feed_updated_observations_timestamp"),
3634
Unit: "ms",
3735
Description: "The observations timestamp for the latest confirmed update (as reported)",
3836
},
39-
duration: utils.MetricInfo{
37+
duration: beholder.MetricInfo{
4038
Name: ns("feed_updated_duration"),
4139
Unit: "ms",
4240
Description: "The duration (local) since observation to message: 'data-feeds.on-chain.registry.FeedUpdated' emit",
4341
},
44-
benchmark: utils.MetricInfo{
42+
benchmark: beholder.MetricInfo{
4543
Name: ns("feed_updated_benchmark"),
4644
Unit: "",
4745
Description: "The benchmark value for the latest confirmed update (as reported)",
4846
},
49-
blockTimestamp: utils.MetricInfo{
47+
blockTimestamp: beholder.MetricInfo{
5048
Name: ns("feed_updated_block_timestamp"),
5149
Unit: "ms",
5250
Description: "The block timestamp at the latest confirmed update (as observed)",
5351
},
54-
blockNumber: utils.MetricInfo{
52+
blockNumber: beholder.MetricInfo{
5553
Name: ns("feed_updated_block_number"),
5654
Unit: "",
5755
Description: "The block number at the latest confirmed update (as observed)",
@@ -63,7 +61,7 @@ var (
6361
type Metrics struct {
6462
// Define on FeedUpdated metrics
6563
feedUpdated struct {
66-
basic utils.MetricsCapBasic
64+
basic beholder.MetricsCapBasic
6765
// specific to FeedUpdated
6866
observationsTimestamp metric.Int64Gauge
6967
duration metric.Int64Gauge // ts.emit - ts.observation
@@ -82,7 +80,7 @@ func NewMetrics() (*Metrics, error) {
8280
// Create new metrics
8381
var err error
8482

85-
m.feedUpdated.basic, err = utils.NewMetricsCapBasic(feedUpdated.basic)
83+
m.feedUpdated.basic, err = beholder.NewMetricsCapBasic(feedUpdated.basic)
8684
if err != nil {
8785
return nil, fmt.Errorf("failed to create new basic metrics: %w", err)
8886
}
@@ -146,7 +144,7 @@ func (m *Metrics) OnFeedUpdated(ctx context.Context, msg *FeedUpdated, attrKVs .
146144

147145
// Attributes returns the attributes for the FeedUpdated message to be used in metrics
148146
func (m *FeedUpdated) Attributes() []attribute.KeyValue {
149-
context := utils.ExecutionMetadata{
147+
context := beholder.ExecutionMetadata{
150148
// Execution Context - Source
151149
SourceId: m.MetaSourceId,
152150
// Execution Context - Chain

capabilities/writetarget/beholder/pb/platform/error.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
// AsError returns the WriteError message as an (Go) error
10-
func (e *WriteError) AsError() error {
10+
func (e *WriteError) Error() string {
1111
protoName := protoimpl.X.MessageTypeOf(e).Descriptor().FullName()
12-
return fmt.Errorf("%s [ERR-%v] - %s: %s", protoName, e.Code, e.Summary, e.Cause)
12+
return fmt.Sprintf("%s [ERR-%v] - %s: %s", protoName, e.Code, e.Summary, e.Cause)
1313
}

0 commit comments

Comments
 (0)