diff --git a/proto/tendermint/types/types.pb.go b/proto/tendermint/types/types.pb.go index 6c6b8a3b88..912b98b5c0 100644 --- a/proto/tendermint/types/types.pb.go +++ b/proto/tendermint/types/types.pb.go @@ -780,7 +780,8 @@ func (m *EvidenceList) GetEvidence() []Evidence { return nil } -// Blob defines an indivisible chunk of data that is posted on chain. +// Blob defines a chunk of data that is attributed to a namespace and under +// usual circumstances, ends up published on-chain. type Blob struct { NamespaceId []byte `protobuf:"bytes,1,opt,name=namespace_id,json=namespaceId,proto3" json:"namespace_id,omitempty"` Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` diff --git a/types/block.go b/types/block.go index edd18e7046..5ccc1f21f8 100644 --- a/types/block.go +++ b/types/block.go @@ -4,7 +4,6 @@ import ( "bytes" "errors" "fmt" - "sort" "strings" "time" @@ -1047,18 +1046,18 @@ func (data *Data) Hash() tmbytes.HexBytes { return data.hash } -// ByNamespace implements sort.Interface for Blob -type Blobs []Blob +// BlobsByNamespace implements sort.Interface for Blob +type BlobsByNamespace []Blob -func (b Blobs) Len() int { +func (b BlobsByNamespace) Len() int { return len(b) } -func (b Blobs) Swap(i, j int) { +func (b BlobsByNamespace) Swap(i, j int) { b[i], b[j] = b[j], b[i] } -func (b Blobs) Less(i, j int) bool { +func (b BlobsByNamespace) Less(i, j int) bool { // The following comparison is `<` and not `<=` because bytes.Compare returns 0 for if a == b. // We want this comparison to return `false` if a == b because: // If both Less(i, j) and Less(j, i) are false, @@ -1067,16 +1066,6 @@ func (b Blobs) Less(i, j int) bool { return bytes.Compare(b[i].NamespaceID, b[j].NamespaceID) < 0 } -// SortMessages sorts messages by ascending namespace id -func (b *Blobs) SortMessages() { - sort.Sort(b) -} - -// IsSorted returns whether the messages are sorted by namespace id -func (b *Blobs) IsSorted() bool { - return sort.IsSorted(b) -} - type Blob struct { // NamespaceID defines the namespace of this message, i.e. the // namespace it will use in the namespaced Merkle tree. diff --git a/types/block_test.go b/types/block_test.go index 45ec0a5c46..02e07713a3 100644 --- a/types/block_test.go +++ b/types/block_test.go @@ -9,6 +9,7 @@ import ( "math" "os" "reflect" + "sort" "testing" "time" @@ -900,8 +901,8 @@ func TestMessagesIsSorted(t *testing.T) { for _, tc := range tests { t.Run(tc.descripton, func(t *testing.T) { - bs := Blobs(tc.blobs) - assert.Equal(t, tc.want, bs.IsSorted()) + bs := tc.blobs + assert.Equal(t, tc.want, sort.IsSorted(BlobsByNamespace(bs))) }) } }