Skip to content

Commit

Permalink
Spec - Sort signers in decided message (#484)
Browse files Browse the repository at this point in the history
* Sort signers in decided message

* Add test for sorted signers in decided msg

* Generate JSON tests

* Fix lint issue
  • Loading branch information
MatheusFranco99 authored and GalRogozinski committed Sep 12, 2024
1 parent 980da78 commit c9a618c
Show file tree
Hide file tree
Showing 6 changed files with 1,162 additions and 1 deletion.
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

0 comments on commit c9a618c

Please sign in to comment.