diff --git a/.changeset/sweet-avocados-do.md b/.changeset/sweet-avocados-do.md new file mode 100644 index 00000000000..4b8bb33a7e1 --- /dev/null +++ b/.changeset/sweet-avocados-do.md @@ -0,0 +1,5 @@ +--- +"chainlink": patch +--- + +#internal Use Aggregator factory for OCR capability diff --git a/core/capabilities/aggregator_factory.go b/core/capabilities/aggregator_factory.go new file mode 100644 index 00000000000..bd0f0ceb237 --- /dev/null +++ b/core/capabilities/aggregator_factory.go @@ -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) + } +} diff --git a/core/capabilities/streams/codec.go b/core/capabilities/streams/codec.go new file mode 100644 index 00000000000..c04d7ee6a0c --- /dev/null +++ b/core/capabilities/streams/codec.go @@ -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{} +} diff --git a/core/capabilities/syncer.go b/core/capabilities/syncer.go index 455582c4598..67e069c831d 100644 --- a/core/capabilities/syncer.go +++ b/core/capabilities/syncer.go @@ -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" @@ -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" ) @@ -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, @@ -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 { @@ -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(), }, } diff --git a/core/scripts/go.mod b/core/scripts/go.mod index 2135c6833c9..542bdece430 100644 --- a/core/scripts/go.mod +++ b/core/scripts/go.mod @@ -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 diff --git a/core/scripts/go.sum b/core/scripts/go.sum index 47254fb049d..a20ad0cce4f 100644 --- a/core/scripts/go.sum +++ b/core/scripts/go.sum @@ -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= diff --git a/go.mod b/go.mod index 1c44fac9da9..4250c0fef43 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 7cc88d7c0f4..5fa3897fc21 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/integration-tests/go.mod b/integration-tests/go.mod index 17b62c4d844..50296d09764 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -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 diff --git a/integration-tests/go.sum b/integration-tests/go.sum index 893dff72823..04f7899c2d7 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -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= diff --git a/integration-tests/load/go.mod b/integration-tests/load/go.mod index 83ef49e1682..8840e1264f9 100644 --- a/integration-tests/load/go.mod +++ b/integration-tests/load/go.mod @@ -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 diff --git a/integration-tests/load/go.sum b/integration-tests/load/go.sum index 34d954a1604..05159b26ef5 100644 --- a/integration-tests/load/go.sum +++ b/integration-tests/load/go.sum @@ -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= diff --git a/plugins/cmd/chainlink-ocr3-capability/main.go b/plugins/cmd/chainlink-ocr3-capability/main.go index 85767554a1c..c70a5a6f2ad 100644 --- a/plugins/cmd/chainlink-ocr3-capability/main.go +++ b/plugins/cmd/chainlink-ocr3-capability/main.go @@ -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" ) @@ -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 {