Skip to content

Commit

Permalink
Merge branch 'main' into feat/fee-components-pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
nickcorin authored Jun 18, 2024
2 parents 245edf2 + 86cc58c commit 408afd8
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 209 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ linters:
- whitespace
- depguard
- containedctx
- gomodguard
linters-settings:
exhaustive:
default-signifies-exhaustive: true
Expand Down Expand Up @@ -113,6 +114,9 @@ linters-settings:
desc: Use gopkg.in/guregu/null.v4 instead
- pkg: "gopkg.in/guregu/null.v3"
desc: Use gopkg.in/guregu/null.v4 instead
gomodguard:
blocked:
local_replace_directives: true
issues:
exclude-rules:
- path: test
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# chainlink-common

SDK for implementing Chainlink Services, like Chain Relayers or Product Plugins.

Internal references

- [loop](pkg/loop/README.md)
- [loop/internal](./pkg/loop/internal/README.md)
- Reporting plugins
- Protobuf definitions


2 changes: 1 addition & 1 deletion observability-lib/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var DeployCmd = &cobra.Command{
case "core-node":
builder, err = corenode.BuildDashboard(name, dataSourcesType.Metrics, platform)
case "core-node-components":
builder, err = corenodecomponents.BuildDashboard(name, dataSourcesType.Metrics)
builder, err = corenodecomponents.BuildDashboard(name, dataSourcesType.Metrics, dataSourcesType.Logs)
case "core-node-resources":
builder, err = k8sresources.BuildDashboard(name, dataSourcesType.Metrics, dataSourcesType.Logs)
case "ocr":
Expand Down
2 changes: 1 addition & 1 deletion observability-lib/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var GenerateCmd = &cobra.Command{
case "core-node":
builder, err = corenode.BuildDashboard(name, dataSourcesType.Metrics, platform)
case "core-node-components":
builder, err = corenodecomponents.BuildDashboard(name, dataSourcesType.Metrics)
builder, err = corenodecomponents.BuildDashboard(name, dataSourcesType.Metrics, dataSourcesType.Logs)
case "core-node-resources":
builder, err = k8sresources.BuildDashboard(name, dataSourcesType.Metrics, dataSourcesType.Logs)
case "ocr":
Expand Down
15 changes: 14 additions & 1 deletion observability-lib/core-node-components/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"github.com/smartcontractkit/chainlink-common/observability-lib/utils"
)

func BuildDashboard(name string, dataSourceMetric string) (dashboard.Dashboard, error) {
func BuildDashboard(name string, dataSourceMetric string, dataSourceLog string) (dashboard.Dashboard, error) {
props := Props{
MetricsDataSource: dataSourceMetric,
LogsDataSource: dataSourceLog,
PlatformOpts: PlatformPanelOpts(),
}

Expand Down Expand Up @@ -140,5 +141,17 @@ func panelsGeneralInfo(p Props) []cog.Builder[dashboard.Panel] {
},
).Min(0).Max(100))

panelsArray = append(panelsArray, utils.LogPanel(
p.LogsDataSource,
"Logs with severity >= error",
"",
6,
24,
utils.PrometheusQuery{
Query: `{env="${env}", cluster="${cluster}", product="${product}", network_type="${network_type}", instance=~"${service}"} | json | level=~"(error|panic|fatal|crit)"`,
Legend: "",
},
))

return panelsArray
}
1 change: 1 addition & 0 deletions observability-lib/core-node-components/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type PlatformOpts struct {

type Props struct {
MetricsDataSource string
LogsDataSource string
PlatformOpts PlatformOpts
}

Expand Down
23 changes: 23 additions & 0 deletions observability-lib/utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/grafana/grafana-foundation-sdk/go/common"
"github.com/grafana/grafana-foundation-sdk/go/dashboard"
"github.com/grafana/grafana-foundation-sdk/go/gauge"
"github.com/grafana/grafana-foundation-sdk/go/logs"
"github.com/grafana/grafana-foundation-sdk/go/prometheus"
"github.com/grafana/grafana-foundation-sdk/go/stat"
"github.com/grafana/grafana-foundation-sdk/go/table"
Expand Down Expand Up @@ -189,3 +190,25 @@ func TablePanel(

return panel
}

func LogPanel(
datasource string,
title string,
description string,
height uint32,
span uint32,
query ...PrometheusQuery,
) *logs.PanelBuilder {
panel := logs.NewPanelBuilder().
Datasource(datasourceRef(datasource)).
Height(height).
Span(span).
Title(title).
Description(description)

for _, q := range query {
panel.WithTarget(prometheusQuery(q.Query, q.Legend))
}

return panel
}
3 changes: 3 additions & 0 deletions pkg/loop/internal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ Product specific development is the most nuanced kind of development. There are

## Protobuf best practices


It's extremely important to be mindful of compatibility when changing protobuf definition. See the [official best practices](https://protobuf.dev/programming-guides/dos-donts/) for details.

To update protobuf, update the corresponding `.proto` file in the `pb` package. Then run `make generate` to regenerate the code.

## FAQ
350 changes: 165 additions & 185 deletions pkg/loop/internal/pb/ccip/offramp.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/loop/internal/pb/ccip/offramp.proto
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,5 @@ message OffRampStaticConfig {
message OffRampTokens {
repeated string destination_tokens = 1; // []Address
repeated string source_tokens = 2; // []Address
map<string,string> destination_pool = 3; // map[Address]Address
reserved 3;
}
10 changes: 0 additions & 10 deletions pkg/loop/internal/relayer/pluginprovider/ext/ccip/offramp.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,15 +632,10 @@ func offRampTokens(in *ccippb.OffRampTokens) cciptypes.OffRampTokens {
for i, t := range in.DestinationTokens {
dest[i] = cciptypes.Address(t)
}
destPool := make(map[cciptypes.Address]cciptypes.Address)
for k, v := range in.DestinationPool {
destPool[cciptypes.Address(k)] = cciptypes.Address(v)
}

return cciptypes.OffRampTokens{
SourceTokens: source,
DestinationTokens: dest,
DestinationPool: destPool,
}
}

Expand All @@ -653,15 +648,10 @@ func offRampTokensToPB(in cciptypes.OffRampTokens) *ccippb.OffRampTokens {
for i, t := range in.DestinationTokens {
dest[i] = string(t)
}
destPool := make(map[string]string)
for k, v := range in.DestinationPool {
destPool[string(k)] = string(v)
}

return &ccippb.OffRampTokens{
SourceTokens: source,
DestinationTokens: dest,
DestinationPool: destPool,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ var OffRampReader = staticOffRamp{
ccip.Address("sourceToken1"),
ccip.Address("sourceToken2"),
},
DestinationPool: map[ccip.Address]ccip.Address{
ccip.Address("key1"): ccip.Address("value1"),
},
},

// GetRouter test data
Expand Down Expand Up @@ -245,7 +242,7 @@ func (s staticOffRamp) DecodeExecutionReport(ctx context.Context, report []byte)
// EncodeExecutionReport implements OffRampEvaluator.
func (s staticOffRamp) EncodeExecutionReport(ctx context.Context, report ccip.ExecReport) ([]byte, error) {
// struggling to get full report equality via reflect.DeepEqual or assert.ObjectsAreEqual
// take a short cut and compare the fields we care about
// take a shortcut and compare the fields we care about
if len(report.Messages) != len(s.encodeExecutionReportRequest.Messages) {
return nil, fmt.Errorf(" encodeExecutionReport message len %v but got %v", len(s.encodeExecutionReportRequest.Messages), len(report.Messages))
}
Expand Down Expand Up @@ -378,12 +375,12 @@ func (s staticOffRamp) Evaluate(ctx context.Context, other ccip.OffRampReader) e
return fmt.Errorf("expected gasPrice %v but got %v", GasPriceEstimatorExec.getGasPriceResponse, price)
}
// DenoteInUSD test case
gotusd, err := gasPriceEstimator.DenoteInUSD(GasPriceEstimatorExec.denoteInUSDRequest.p, GasPriceEstimatorExec.denoteInUSDRequest.wrappedNativePrice)
gotUsd, err := gasPriceEstimator.DenoteInUSD(GasPriceEstimatorExec.denoteInUSDRequest.p, GasPriceEstimatorExec.denoteInUSDRequest.wrappedNativePrice)
if err != nil {
return fmt.Errorf("failed to get other usd: %w", err)
}
if gotusd.Cmp(GasPriceEstimatorExec.denoteInUSDResponse.result) != 0 {
return fmt.Errorf("expected usd %v but got %v", GasPriceEstimatorExec.denoteInUSDResponse.result, gotusd)
if gotUsd.Cmp(GasPriceEstimatorExec.denoteInUSDResponse.result) != 0 {
return fmt.Errorf("expected usd %v but got %v", GasPriceEstimatorExec.denoteInUSDResponse.result, gotUsd)
}
// EstimateMsgCostUSD test case
cost, err := gasPriceEstimator.EstimateMsgCostUSD(
Expand Down
1 change: 0 additions & 1 deletion pkg/types/ccip/offramp.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ type OffRampStaticConfig struct {
type OffRampTokens struct {
DestinationTokens []Address
SourceTokens []Address
DestinationPool map[Address]Address
}

// MessageExecutionState defines the execution states of CCIP messages.
Expand Down
5 changes: 3 additions & 2 deletions pkg/types/interfacetests/chain_reader_interface_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,14 @@ func runQueryKeyInterfaceTests[T TestingT[T]](t T, tester ChainReaderInterfaceTe
ctx := tests.Context(t)
cr := tester.GetChainReader(t)
require.NoError(t, cr.Bind(ctx, tester.GetBindings(t)))
ts1 := CreateTestStruct[T](0, tester)
ts1 := CreateTestStruct[T](1, tester)
tester.TriggerEvent(t, &ts1)
ts2 := CreateTestStruct[T](1, tester)
ts2 := CreateTestStruct[T](0, tester)
tester.TriggerEvent(t, &ts2)

ts := &TestStruct{}
assert.Eventually(t, func() bool {
// sequences from queryKey without limit and sort should be in descending order
sequences, err := cr.QueryKey(ctx, AnyContractName, query.KeyFilter{Key: EventName}, query.LimitAndSort{}, ts)
return err == nil && len(sequences) == 2 && reflect.DeepEqual(&ts1, sequences[0].Data) && reflect.DeepEqual(&ts2, sequences[1].Data)
}, tester.MaxWaitTimeForEvents(), time.Millisecond*10)
Expand Down

0 comments on commit 408afd8

Please sign in to comment.