Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -306,24 +306,33 @@ func (a *reduceAggregator) extractValues(lggr logger.Logger, observations map[oc
// values are then re-wrapped here to handle aggregating against Value types
// which is used for mode aggregation
switch val := val.(type) {
case map[string]interface{}:
case map[string]any:
_, ok := val[aggregationKey]
if !ok {
continue
}
if val[aggregationKey] == nil {
lggr.Warnf("node %d contributed with a nil value under key %s", nodeID, aggregationKey)
continue
}

rewrapped, err := values.Wrap(val[aggregationKey])
if err != nil {
lggr.Warnf("unable to wrap value %s", val[aggregationKey])
continue
}
vals = append(vals, rewrapped)
case []interface{}:
case []any:
i, err := strconv.Atoi(aggregationKey)
if err != nil {
lggr.Warnf("aggregation key %s could not be used to index a list type", aggregationKey)
continue
}
if i >= len(val) {
lggr.Warnf("node %d contributed with an array shorter than index %s", nodeID, aggregationKey)
continue
}

rewrapped, err := values.Wrap(val[i])
if err != nil {
lggr.Warnf("unable to wrap value %s", val[i])
Expand Down
55 changes: 55 additions & 0 deletions pkg/capabilities/consensus/ocr3/aggregators/reduce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,61 @@ func TestReduceAggregator_Aggregate(t *testing.T) {
},
expectedState: map[string]any{"Price": int64(1)},
},
{
name: "handle nils gracefully",
fields: []aggregators.AggregationField{
{
InputKey: "FeedID",
OutputKey: "FeedID",
Method: "mode",
},
{
InputKey: "BenchmarkPrice",
OutputKey: "Price",
Method: "median",
DeviationString: "10",
DeviationType: "percent",
},
{
InputKey: "Timestamp",
OutputKey: "Timestamp",
Method: "median",
DeviationString: "100",
DeviationType: "absolute",
},
},
extraConfig: map[string]any{},
observationsFactory: func() map[commontypes.OracleID][]values.Value {
mockValue, err := values.WrapMap(map[string]any{
"FeedID": idABytes[:],
"BenchmarkPrice": uint64(100),
"Timestamp": 12341414929,
})
require.NoError(t, err)
mockValueWithNil, err := values.WrapMap(map[string]any{
"FeedID": idABytes[:],
"BenchmarkPrice": uint64(100),
"Timestamp": 12341414929,
})
mockValueWithNil.Underlying["BenchmarkPrice"] = nil // simulate failed wraping of uint64
return map[commontypes.OracleID][]values.Value{1: {mockValue}, 2: {mockValue}, 3: {mockValue}, 4: {mockValueWithNil}}
},
shouldReport: true,
expectedOutcome: map[string]any{
"Reports": []any{
map[string]any{
"FeedID": idABytes[:],
"Timestamp": int64(12341414929),
"Price": uint64(100),
},
},
},
expectedState: map[string]any{
"FeedID": idABytes[:],
"Timestamp": int64(12341414929),
"Price": uint64(100),
},
},
}
for _, tt := range cases {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading