Skip to content

Commit d33e956

Browse files
authored
Fix mode aggregator non-determinism (#106)
1 parent 809e4b8 commit d33e956

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

llo/aggregators.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package llo
22

33
import (
44
"fmt"
5+
"slices"
56
"sort"
67

78
"github.com/shopspring/decimal"
9+
"golang.org/x/exp/maps"
810

911
llotypes "github.com/smartcontractkit/chainlink-common/pkg/types/llo"
1012
)
@@ -93,7 +95,11 @@ func ModeAggregator(values []StreamValue, f int) (StreamValue, error) {
9395
}
9496
var modeSerialized []byte
9597
var modeCount int
96-
for value, count := range counts {
98+
// tie-break selecting lowest "key"
99+
keys := maps.Keys(counts)
100+
slices.Sort(keys)
101+
for _, value := range keys {
102+
count := counts[value]
97103
if count > modeCount {
98104
modeSerialized = []byte(value)
99105
modeCount = count

0 commit comments

Comments
 (0)