Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing aggregaion config to identical consensus #988

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pkg/capabilities/consensus/ocr3/aggregators/identical.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions pkg/capabilities/consensus/ocr3/ocr3cap/identical_consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down Expand Up @@ -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,
},
Expand Down
Loading