From 7c80c686dfb8dc140838a2500b5e0649ba3c0a07 Mon Sep 17 00:00:00 2001 From: Chris <104409744+vreff@users.noreply.github.com> Date: Thu, 9 Jan 2025 11:24:43 -0500 Subject: [PATCH] Add AggregationConfig --- .../consensus/ocr3/aggregators/identical.go | 10 +++++----- .../ocr3/ocr3cap/identical_consensus.go | 11 +++++++---- .../ocr3/ocr3cap/identical_consensus_test.go | 17 +++++++++++++---- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/pkg/capabilities/consensus/ocr3/aggregators/identical.go b/pkg/capabilities/consensus/ocr3/aggregators/identical.go index aa05e7cf4..163fa550c 100644 --- a/pkg/capabilities/consensus/ocr3/aggregators/identical.go +++ b/pkg/capabilities/consensus/ocr3/aggregators/identical.go @@ -15,10 +15,10 @@ import ( // Aggregates by the most frequent observation for each index of a data set type identicalAggregator struct { - config identicalAggConfig + config IdenticalAggConfig } -type identicalAggConfig struct { +type IdenticalAggConfig struct { // Length of the list of observations that each node is expected to provide. // Aggregator's output (i.e. EncodableOutcome) will be a values.Map with the same // number of elements and keyed by indices 0,1,2,... (unless KeyOverrides are provided). @@ -112,10 +112,10 @@ func NewIdenticalAggregator(config values.Map) (*identicalAggregator, error) { }, nil } -func ParseConfigIdenticalAggregator(config values.Map) (identicalAggConfig, error) { - parsedConfig := identicalAggConfig{} +func ParseConfigIdenticalAggregator(config values.Map) (IdenticalAggConfig, error) { + parsedConfig := IdenticalAggConfig{} if err := config.UnwrapTo(&parsedConfig); err != nil { - return identicalAggConfig{}, err + return IdenticalAggConfig{}, err } if parsedConfig.ExpectedObservationsLen == 0 { parsedConfig.ExpectedObservationsLen = 1 diff --git a/pkg/capabilities/consensus/ocr3/ocr3cap/identical_consensus.go b/pkg/capabilities/consensus/ocr3/ocr3cap/identical_consensus.go index 9fb49935e..904adf4d4 100644 --- a/pkg/capabilities/consensus/ocr3/ocr3cap/identical_consensus.go +++ b/pkg/capabilities/consensus/ocr3/ocr3cap/identical_consensus.go @@ -2,16 +2,18 @@ package ocr3cap import ( "github.com/smartcontractkit/chainlink-common/pkg/capabilities" + "github.com/smartcontractkit/chainlink-common/pkg/capabilities/consensus/ocr3/aggregators" "github.com/smartcontractkit/chainlink-common/pkg/workflows/sdk" ) // Note this isn't generated because generics isn't supported in json schema type IdenticalConsensusConfig[T any] struct { - Encoder Encoder - EncoderConfig EncoderConfig - ReportID ReportId - KeyID KeyId + Encoder Encoder + EncoderConfig EncoderConfig + AggregationConfig aggregators.IdenticalAggConfig + ReportID ReportId + KeyID KeyId } func (c IdenticalConsensusConfig[T]) New(w *sdk.WorkflowSpecFactory, ref string, input IdenticalConsensusInput[T]) SignedReportCap { @@ -22,6 +24,7 @@ func (c IdenticalConsensusConfig[T]) New(w *sdk.WorkflowSpecFactory, ref string, Config: map[string]any{ "encoder": c.Encoder, "encoder_config": c.EncoderConfig, + "aggregation_config": c.AggregationConfig, "aggregation_method": "identical", "report_id": c.ReportID, "key_id": c.KeyID, diff --git a/pkg/capabilities/consensus/ocr3/ocr3cap/identical_consensus_test.go b/pkg/capabilities/consensus/ocr3/ocr3cap/identical_consensus_test.go index 0b3d02146..c9300fa2a 100644 --- a/pkg/capabilities/consensus/ocr3/ocr3cap/identical_consensus_test.go +++ b/pkg/capabilities/consensus/ocr3/ocr3cap/identical_consensus_test.go @@ -7,6 +7,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/capabilities" "github.com/smartcontractkit/chainlink-common/pkg/capabilities/cli/cmd/testdata/fixtures/capabilities/basictrigger" + "github.com/smartcontractkit/chainlink-common/pkg/capabilities/consensus/ocr3/aggregators" ocr3 "github.com/smartcontractkit/chainlink-common/pkg/capabilities/consensus/ocr3/ocr3cap" "github.com/smartcontractkit/chainlink-common/pkg/capabilities/targets/chainwriter" "github.com/smartcontractkit/chainlink-common/pkg/workflows/sdk" @@ -22,8 +23,12 @@ func TestIdenticalConsensus(t *testing.T) { consensus := ocr3.IdenticalConsensusConfig[basictrigger.TriggerOutputs]{ Encoder: ocr3.EncoderEVM, EncoderConfig: ocr3.EncoderConfig{}, - ReportID: "0001", - KeyID: "evm", + AggregationConfig: aggregators.IdenticalAggConfig{ + KeyOverrides: []string{"evm"}, + ExpectedObservationsLen: 1, + }, + ReportID: "0001", + KeyID: "evm", }.New(workflow, "consensus", ocr3.IdenticalConsensusInput[basictrigger.TriggerOutputs]{ Observation: trigger, Encoder: "evm", @@ -66,8 +71,12 @@ func TestIdenticalConsensus(t *testing.T) { "encoder": "EVM", "encoder_config": map[string]any{}, "aggregation_method": "identical", - "report_id": "0001", - "key_id": "evm", + "aggregation_config": map[string]any{ + "KeyOverrides": []string{"evm"}, + "ExpectedObservationsLen": 1, + }, + "report_id": "0001", + "key_id": "evm", }, CapabilityType: capabilities.CapabilityTypeConsensus, },