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

Sort signers in decided message #484

Merged
merged 5 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
27 changes: 27 additions & 0 deletions qbft/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package qbft

import (
"bytes"
"sort"

"github.com/pkg/errors"
"github.com/ssvlabs/ssv-spec/types"
Expand Down Expand Up @@ -58,6 +59,32 @@ func aggregateCommitMsgs(msgs []*ProcessingMessage, fullData []byte) (*types.Sig
}
}
ret.FullData = fullData

// Sort the OperatorIDs and Signatures in the SignedSSVMessage

pairs := make([]struct {
OpID types.OperatorID
Sig types.Signature
}, len(ret.OperatorIDs))

for i, id := range ret.OperatorIDs {
pairs[i] = struct {
OpID types.OperatorID
Sig types.Signature
}{OpID: id, Sig: ret.Signatures[i]}
}

// Sort the slice of pairs
sort.Slice(pairs, func(i, j int) bool {
return pairs[i].OpID < pairs[j].OpID
})

// Extract the sorted IDs and Signatures back into separate slices
for i, pair := range pairs {
ret.OperatorIDs[i] = pair.OpID
ret.Signatures[i] = pair.Sig
}

return ret, nil
}

Expand Down
1 change: 1 addition & 0 deletions qbft/spectest/all_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ var AllTests = []tests.TestF{
commit.NoCommitQuorum,
commit.ForceStop,
commit.PostCutoff,
commit.SortedDecided,

roundchange.HappyFlow,
roundchange.WrongHeight,
Expand Down
Loading