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

fix non-deterministic map iteration #12693

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
use generic functions to sort map
  • Loading branch information
bruce-wayne2 committed Jul 26, 2022
commit 0ae4cc8be208d75e747bb6daf3de1a9ce655df23
14 changes: 4 additions & 10 deletions types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package types
import (
"encoding/json"
"fmt"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
"reflect"
"sort"
"strings"
Expand Down Expand Up @@ -88,7 +90,8 @@ func TypedEventToEvent(tev proto.Message) (Event, error) {
}

// sort the keys to ensure the order is always the same
keys := orderedKeys(attrMap)
keys := maps.Keys(attrMap)
slices.Sort(keys)

attrs := make([]abci.EventAttribute, 0, len(attrMap))
for _, k := range keys {
Expand All @@ -105,15 +108,6 @@ func TypedEventToEvent(tev proto.Message) (Event, error) {
}, nil
}

func orderedKeys(m map[string]json.RawMessage) []string {
keys := make([]string, 0, len(m))
for k := range m {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}

// ParseTypedEvent converts abci.Event back to typed event
func ParseTypedEvent(event abci.Event) (proto.Message, error) {
concreteGoType := proto.MessageType(event.Type)
Expand Down