diff --git a/lib/grandpa/tracker_votes.go b/lib/grandpa/tracker_votes.go index a3e1653979e..6d9f33ff5d8 100644 --- a/lib/grandpa/tracker_votes.go +++ b/lib/grandpa/tracker_votes.go @@ -146,7 +146,7 @@ func (vt *votesTracker) delete(blockHash common.Hash) { // getMessagesForBlockHash returns all the vote messages // for a particular block hash from the tracker as a slice -// of networkVoteMessage. +// of networkVoteMessage. There is no order in the slice. // It returns nil if the block hash does not exist. func (vt *votesTracker) getMessagesForBlockHash( blockHash common.Hash) (messages []networkVoteMessage) { diff --git a/lib/grandpa/tracker_votes_test.go b/lib/grandpa/tracker_votes_test.go index b00320547d8..1987cc2c973 100644 --- a/lib/grandpa/tracker_votes_test.go +++ b/lib/grandpa/tracker_votes_test.go @@ -308,6 +308,13 @@ func Test_votesTracker_getMessagesForBlockHash(t *testing.T) { vt := testCase.votesTracker messages := vt.getMessagesForBlockHash(testCase.blockHash) + sort.Slice(messages, func(i, j int) bool { + if messages[i].from == messages[j].from { + return messages[i].msg.Round < messages[j].msg.Round + } + return messages[i].from < messages[j].from + }) + assert.Equal(t, testCase.messages, messages) }) }