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

chore!: remove BlobsByNamespace #1025

Merged
merged 3 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion test/e2e/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# We need to build in a Linux environment to support C libraries, e.g. RocksDB.
# We use Debian instead of Alpine, so that we can use binary database packages
# instead of spending time compiling them.
FROM golang:1.19
FROM golang:1.20-bullseye

RUN apt-get -qq update -y && apt-get -qq upgrade -y >/dev/null
RUN apt-get -qq install -y libleveldb-dev librocksdb-dev >/dev/null
Expand Down
20 changes: 0 additions & 20 deletions types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -1036,26 +1036,6 @@ func (data *Data) Hash() cmtbytes.HexBytes {
return data.hash
}

// BlobsByNamespace implements sort.Interface for Blob
type BlobsByNamespace []Blob

func (b BlobsByNamespace) Len() int {
return len(b)
}

func (b BlobsByNamespace) Swap(i, j int) {
b[i], b[j] = b[j], b[i]
}

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,
// then the elements at index i and j are considered equal.
// See https://pkg.go.dev/sort#Interface
return bytes.Compare(b[i].NamespaceID, b[j].NamespaceID) < 0
}

type Blob struct {
// NamespaceVersion is the version of the namespace. Used in conjunction
// with NamespaceID to determine the namespace of this blob.
Expand Down
53 changes: 0 additions & 53 deletions types/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"math"
"os"
"reflect"
"sort"
"testing"
"time"

Expand Down Expand Up @@ -857,55 +856,3 @@ func TestBlockIDEquals(t *testing.T) {
assert.True(t, blockIDEmpty.Equals(blockIDEmpty))
assert.False(t, blockIDEmpty.Equals(blockIDDifferent))
}

func TestBlobsByNamespaceIsSorted(t *testing.T) {
sortedBlobs := []Blob{
{
NamespaceID: []byte{1, 2, 3, 4, 5, 6, 7, 8},
Data: stdbytes.Repeat([]byte{1}, 100),
},
{
NamespaceID: []byte{8, 7, 6, 5, 4, 3, 2, 1},
Data: stdbytes.Repeat([]byte{2}, 100),
},
}
sameNamespacedBlobs := []Blob{
{
NamespaceID: []byte{1, 2, 3, 4, 5, 6, 7, 8},
Data: stdbytes.Repeat([]byte{1}, 100),
},
{
NamespaceID: []byte{1, 2, 3, 4, 5, 6, 7, 8},
Data: stdbytes.Repeat([]byte{2}, 100),
},
}
unsortedBlobs := []Blob{
{
NamespaceID: []byte{8, 7, 6, 5, 4, 3, 2, 1},
Data: stdbytes.Repeat([]byte{1}, 100),
},
{
NamespaceID: []byte{1, 2, 3, 4, 5, 6, 7, 8},
Data: stdbytes.Repeat([]byte{2}, 100),
},
}

type testCase struct {
description string
blobs []Blob
want bool
}

tests := []testCase{
{"sorted blobs", sortedBlobs, true},
{"same namespace blobs", sameNamespacedBlobs, true},
{"unsorted blobs", unsortedBlobs, false},
}

for _, tc := range tests {
t.Run(tc.description, func(t *testing.T) {
bs := tc.blobs
assert.Equal(t, tc.want, sort.IsSorted(BlobsByNamespace(bs)))
})
}
}
Loading