Skip to content

Commit

Permalink
[KS-196] Use Aggregator factory for OCR capability (#13199)
Browse files Browse the repository at this point in the history
Bump common to latest.
  • Loading branch information
bolekk authored May 14, 2024
1 parent e778a32 commit 4f502c9
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/sweet-avocados-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

#internal Use Aggregator factory for OCR capability
21 changes: 21 additions & 0 deletions core/capabilities/aggregator_factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package capabilities

import (
"fmt"

"github.com/smartcontractkit/chainlink-common/pkg/capabilities/consensus/ocr3/datafeeds"
"github.com/smartcontractkit/chainlink-common/pkg/capabilities/consensus/ocr3/types"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/values"
"github.com/smartcontractkit/chainlink/v2/core/capabilities/streams"
)

func NewAggregator(name string, config values.Map, lggr logger.Logger) (types.Aggregator, error) {
switch name {
case "data_feeds":
mc := streams.NewCodec()
return datafeeds.NewDataFeedsAggregator(config, mc, lggr)
default:
return nil, fmt.Errorf("aggregator %s not supported", name)
}
}
24 changes: 24 additions & 0 deletions core/capabilities/streams/codec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package streams

import (
"github.com/smartcontractkit/chainlink-common/pkg/capabilities/mercury"
"github.com/smartcontractkit/chainlink-common/pkg/values"
)

type Codec struct {
}

func (c Codec) Unwrap(raw values.Value) ([]mercury.FeedReport, error) {
dest := []mercury.FeedReport{}
err := raw.UnwrapTo(&dest)
// TODO (KS-196): validate reports
return dest, err
}

func (c Codec) Wrap(reports []mercury.FeedReport) (values.Value, error) {
return values.Wrap(reports)
}

func NewCodec() Codec {
return Codec{}
}
20 changes: 11 additions & 9 deletions core/capabilities/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package capabilities

import (
"context"
"math/big"
"slices"
"sync"
"time"

"github.com/smartcontractkit/chainlink-common/pkg/capabilities"
commoncap "github.com/smartcontractkit/chainlink-common/pkg/capabilities"
"github.com/smartcontractkit/chainlink-common/pkg/capabilities/mercury"
"github.com/smartcontractkit/chainlink-common/pkg/capabilities/triggers"
"github.com/smartcontractkit/chainlink-common/pkg/services"
Expand All @@ -18,6 +18,7 @@ import (

"github.com/smartcontractkit/chainlink/v2/core/capabilities/remote"
remotetypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/remote/types"
"github.com/smartcontractkit/chainlink/v2/core/capabilities/streams"
"github.com/smartcontractkit/chainlink/v2/core/logger"
p2ptypes "github.com/smartcontractkit/chainlink/v2/core/services/p2p/types"
)
Expand Down Expand Up @@ -97,9 +98,9 @@ func (s *registrySyncer) Start(ctx context.Context) error {
}
// NOTE: temporary hard-coded capabilities
capId := "mercury-trigger"
triggerInfo := commoncap.CapabilityInfo{
triggerInfo := capabilities.CapabilityInfo{
ID: capId,
CapabilityType: commoncap.CapabilityTypeTrigger,
CapabilityType: capabilities.CapabilityTypeTrigger,
Description: "Remote Trigger",
Version: "0.0.1",
DON: &triggerCapabilityDonInfo,
Expand All @@ -111,7 +112,8 @@ func (s *registrySyncer) Start(ctx context.Context) error {
}
if slices.Contains(workflowDONPeers, myId) {
s.lggr.Info("member of a workflow DON - starting remote subscribers")
aggregator := triggers.NewMercuryRemoteAggregator(s.lggr)
codec := streams.NewCodec()
aggregator := triggers.NewMercuryRemoteAggregator(codec, s.lggr)
triggerCap := remote.NewTriggerSubscriber(config, triggerInfo, triggerCapabilityDonInfo, workflowDonInfo, s.dispatcher, aggregator, s.lggr)
err = s.registry.Add(ctx, triggerCap)
if err != nil {
Expand Down Expand Up @@ -224,30 +226,30 @@ func (m *mockMercuryDataProducer) loop() {
ticker := time.NewTicker(time.Duration(sleepSec) * time.Second)
defer ticker.Stop()

prices := []int64{300000, 40000, 5000000}
prices := []*big.Int{big.NewInt(300000), big.NewInt(40000), big.NewInt(5000000)}

for range ticker.C {
for i := range prices {
prices[i] = prices[i] + 1
prices[i].Add(prices[i], big.NewInt(1))
}

reports := []mercury.FeedReport{
{
FeedID: "0x1111111111111111111100000000000000000000000000000000000000000000",
FullReport: []byte{0x11, 0xaa, 0xbb, 0xcc},
BenchmarkPrice: prices[0],
BenchmarkPrice: prices[0].Bytes(),
ObservationTimestamp: time.Now().Unix(),
},
{
FeedID: "0x2222222222222222222200000000000000000000000000000000000000000000",
FullReport: []byte{0x22, 0xaa, 0xbb, 0xcc},
BenchmarkPrice: prices[1],
BenchmarkPrice: prices[1].Bytes(),
ObservationTimestamp: time.Now().Unix(),
},
{
FeedID: "0x3333333333333333333300000000000000000000000000000000000000000000",
FullReport: []byte{0x33, 0xaa, 0xbb, 0xcc},
BenchmarkPrice: prices[2],
BenchmarkPrice: prices[2].Bytes(),
ObservationTimestamp: time.Now().Unix(),
},
}
Expand Down
2 changes: 1 addition & 1 deletion core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/prometheus/client_golang v1.17.0
github.com/shopspring/decimal v1.3.1
github.com/smartcontractkit/chainlink-automation v1.0.3
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240509130051-b54aae6a8b65
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240514153505-0ddba5aa4d2c
github.com/smartcontractkit/chainlink-vrf v0.0.0-20240222010609-cd67d123c772
github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000
github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1185,8 +1185,8 @@ github.com/smartcontractkit/chain-selectors v1.0.10 h1:t9kJeE6B6G+hKD0GYR4kGJSCq
github.com/smartcontractkit/chain-selectors v1.0.10/go.mod h1:d4Hi+E1zqjy9HqMkjBE5q1vcG9VGgxf5VxiRHfzi2kE=
github.com/smartcontractkit/chainlink-automation v1.0.3 h1:h/ijT0NiyV06VxYVgcNfsE3+8OEzT3Q0Z9au0z1BPWs=
github.com/smartcontractkit/chainlink-automation v1.0.3/go.mod h1:RjboV0Qd7YP+To+OrzHGXaxUxoSONveCoAK2TQ1INLU=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240509130051-b54aae6a8b65 h1:e/qJZHPDVcgv/bnydjyYBk3JYbDnxPaZ2LvTlfDZeXA=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240509130051-b54aae6a8b65/go.mod h1:sj0pjL+METqeYL9ibp0T8SXquymlaQsofa6bdfLgXX8=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240514153505-0ddba5aa4d2c h1:KiG8PAwUrdYn/AGBQ+B4p6erEUbEB+g6LJKhAaDjJ2s=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240514153505-0ddba5aa4d2c/go.mod h1:sj0pjL+METqeYL9ibp0T8SXquymlaQsofa6bdfLgXX8=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240508101745-af1ed7bc8a69 h1:Sec/GpBpUVaTEax1kSHlTvkzF/+d3w5roAQXaj5+SLA=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240508101745-af1ed7bc8a69/go.mod h1:ZQKf+0OLzCLYIisH/OdOIQuFRI6bDuw+jPBTATyHfFM=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240220203239-09be0ea34540 h1:xFSv8561jsLtF6gYZr/zW2z5qUUAkcFkApin2mnbYTo=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ require (
github.com/shopspring/decimal v1.3.1
github.com/smartcontractkit/chain-selectors v1.0.10
github.com/smartcontractkit/chainlink-automation v1.0.3
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240509130051-b54aae6a8b65
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240514153505-0ddba5aa4d2c
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240508101745-af1ed7bc8a69
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240220203239-09be0ea34540
github.com/smartcontractkit/chainlink-feeds v0.0.0-20240422130241-13c17a91b2ab
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1171,8 +1171,8 @@ github.com/smartcontractkit/chain-selectors v1.0.10 h1:t9kJeE6B6G+hKD0GYR4kGJSCq
github.com/smartcontractkit/chain-selectors v1.0.10/go.mod h1:d4Hi+E1zqjy9HqMkjBE5q1vcG9VGgxf5VxiRHfzi2kE=
github.com/smartcontractkit/chainlink-automation v1.0.3 h1:h/ijT0NiyV06VxYVgcNfsE3+8OEzT3Q0Z9au0z1BPWs=
github.com/smartcontractkit/chainlink-automation v1.0.3/go.mod h1:RjboV0Qd7YP+To+OrzHGXaxUxoSONveCoAK2TQ1INLU=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240509130051-b54aae6a8b65 h1:e/qJZHPDVcgv/bnydjyYBk3JYbDnxPaZ2LvTlfDZeXA=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240509130051-b54aae6a8b65/go.mod h1:sj0pjL+METqeYL9ibp0T8SXquymlaQsofa6bdfLgXX8=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240514153505-0ddba5aa4d2c h1:KiG8PAwUrdYn/AGBQ+B4p6erEUbEB+g6LJKhAaDjJ2s=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240514153505-0ddba5aa4d2c/go.mod h1:sj0pjL+METqeYL9ibp0T8SXquymlaQsofa6bdfLgXX8=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240508101745-af1ed7bc8a69 h1:Sec/GpBpUVaTEax1kSHlTvkzF/+d3w5roAQXaj5+SLA=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240508101745-af1ed7bc8a69/go.mod h1:ZQKf+0OLzCLYIisH/OdOIQuFRI6bDuw+jPBTATyHfFM=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240220203239-09be0ea34540 h1:xFSv8561jsLtF6gYZr/zW2z5qUUAkcFkApin2mnbYTo=
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/shopspring/decimal v1.3.1
github.com/slack-go/slack v0.12.2
github.com/smartcontractkit/chainlink-automation v1.0.3
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240509130051-b54aae6a8b65
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240514153505-0ddba5aa4d2c
github.com/smartcontractkit/chainlink-testing-framework v1.28.11
github.com/smartcontractkit/chainlink-vrf v0.0.0-20231120191722-fef03814f868
github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1512,8 +1512,8 @@ github.com/smartcontractkit/chain-selectors v1.0.10 h1:t9kJeE6B6G+hKD0GYR4kGJSCq
github.com/smartcontractkit/chain-selectors v1.0.10/go.mod h1:d4Hi+E1zqjy9HqMkjBE5q1vcG9VGgxf5VxiRHfzi2kE=
github.com/smartcontractkit/chainlink-automation v1.0.3 h1:h/ijT0NiyV06VxYVgcNfsE3+8OEzT3Q0Z9au0z1BPWs=
github.com/smartcontractkit/chainlink-automation v1.0.3/go.mod h1:RjboV0Qd7YP+To+OrzHGXaxUxoSONveCoAK2TQ1INLU=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240509130051-b54aae6a8b65 h1:e/qJZHPDVcgv/bnydjyYBk3JYbDnxPaZ2LvTlfDZeXA=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240509130051-b54aae6a8b65/go.mod h1:sj0pjL+METqeYL9ibp0T8SXquymlaQsofa6bdfLgXX8=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240514153505-0ddba5aa4d2c h1:KiG8PAwUrdYn/AGBQ+B4p6erEUbEB+g6LJKhAaDjJ2s=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240514153505-0ddba5aa4d2c/go.mod h1:sj0pjL+METqeYL9ibp0T8SXquymlaQsofa6bdfLgXX8=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240508101745-af1ed7bc8a69 h1:Sec/GpBpUVaTEax1kSHlTvkzF/+d3w5roAQXaj5+SLA=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240508101745-af1ed7bc8a69/go.mod h1:ZQKf+0OLzCLYIisH/OdOIQuFRI6bDuw+jPBTATyHfFM=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240220203239-09be0ea34540 h1:xFSv8561jsLtF6gYZr/zW2z5qUUAkcFkApin2mnbYTo=
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/load/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/rs/zerolog v1.30.0
github.com/slack-go/slack v0.12.2
github.com/smartcontractkit/chainlink-automation v1.0.3
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240509130051-b54aae6a8b65
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240514153505-0ddba5aa4d2c
github.com/smartcontractkit/chainlink-testing-framework v1.28.11
github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20240214231432-4ad5eb95178c
github.com/smartcontractkit/chainlink/v2 v2.9.0-beta0.0.20240216210048-da02459ddad8
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/load/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1502,8 +1502,8 @@ github.com/smartcontractkit/chain-selectors v1.0.10 h1:t9kJeE6B6G+hKD0GYR4kGJSCq
github.com/smartcontractkit/chain-selectors v1.0.10/go.mod h1:d4Hi+E1zqjy9HqMkjBE5q1vcG9VGgxf5VxiRHfzi2kE=
github.com/smartcontractkit/chainlink-automation v1.0.3 h1:h/ijT0NiyV06VxYVgcNfsE3+8OEzT3Q0Z9au0z1BPWs=
github.com/smartcontractkit/chainlink-automation v1.0.3/go.mod h1:RjboV0Qd7YP+To+OrzHGXaxUxoSONveCoAK2TQ1INLU=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240509130051-b54aae6a8b65 h1:e/qJZHPDVcgv/bnydjyYBk3JYbDnxPaZ2LvTlfDZeXA=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240509130051-b54aae6a8b65/go.mod h1:sj0pjL+METqeYL9ibp0T8SXquymlaQsofa6bdfLgXX8=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240514153505-0ddba5aa4d2c h1:KiG8PAwUrdYn/AGBQ+B4p6erEUbEB+g6LJKhAaDjJ2s=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240514153505-0ddba5aa4d2c/go.mod h1:sj0pjL+METqeYL9ibp0T8SXquymlaQsofa6bdfLgXX8=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240508101745-af1ed7bc8a69 h1:Sec/GpBpUVaTEax1kSHlTvkzF/+d3w5roAQXaj5+SLA=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240508101745-af1ed7bc8a69/go.mod h1:ZQKf+0OLzCLYIisH/OdOIQuFRI6bDuw+jPBTATyHfFM=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240220203239-09be0ea34540 h1:xFSv8561jsLtF6gYZr/zW2z5qUUAkcFkApin2mnbYTo=
Expand Down
6 changes: 4 additions & 2 deletions plugins/cmd/chainlink-ocr3-capability/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/loop/reportingplugins"
ocr3rp "github.com/smartcontractkit/chainlink-common/pkg/loop/reportingplugins/ocr3"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink/v2/core/capabilities"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm"
)

Expand All @@ -22,8 +23,9 @@ func main() {
defer s.Stop()

c := ocr3.Config{
Logger: s.Logger,
EncoderFactory: evm.NewEVMEncoder,
Logger: s.Logger,
EncoderFactory: evm.NewEVMEncoder,
AggregatorFactory: capabilities.NewAggregator,
}
p := ocr3.NewOCR3(c)
if err := p.Start(context.Background()); err != nil {
Expand Down

0 comments on commit 4f502c9

Please sign in to comment.