Skip to content

Commit

Permalink
refactor: use blob.Namespace() from celestia-core (#2104)
Browse files Browse the repository at this point in the history
Closes #2071
  • Loading branch information
rootulp authored Jul 14, 2023
1 parent e06116c commit 03ed667
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,5 @@ replace (
github.com/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v1.16.0-sdk-v0.46.13
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/tendermint/tendermint => github.com/celestiaorg/celestia-core v1.24.0-tm-v0.34.28
github.com/tendermint/tendermint => github.com/celestiaorg/celestia-core v1.25.0-tm-v0.34.28
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ github.com/bufbuild/protocompile v0.1.0 h1:HjgJBI85hY/qmW5tw/66sNDZ7z0UDdVSi/5r4
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
github.com/c-bata/go-prompt v0.2.2/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOCSiVIqS34=
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
github.com/celestiaorg/celestia-core v1.24.0-tm-v0.34.28 h1:eXS3v26nob8Xs2+flKHVxcTzhzQW44KgTcooR3OxnK4=
github.com/celestiaorg/celestia-core v1.24.0-tm-v0.34.28/go.mod h1:J/GsBjoTZaFz71VeyrLZbG8rV+Rzi6oFEUZUipQ97hQ=
github.com/celestiaorg/celestia-core v1.25.0-tm-v0.34.28 h1:2/b6288LWPPJqb8vxdiafXvBwy/42Edp5rJIVxbBRvg=
github.com/celestiaorg/celestia-core v1.25.0-tm-v0.34.28/go.mod h1:J/GsBjoTZaFz71VeyrLZbG8rV+Rzi6oFEUZUipQ97hQ=
github.com/celestiaorg/cosmos-sdk v1.16.0-sdk-v0.46.13 h1:N1PrCWcYkaODeIQyyVBmDKDTwiQWZ31bgtTEYIGeby8=
github.com/celestiaorg/cosmos-sdk v1.16.0-sdk-v0.46.13/go.mod h1:xpBZc/OYZ736hp0IZlBGNUhEgCD9C+bKs8yNLZibyv0=
github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4 h1:CJdIpo8n5MFP2MwK0gSRcOVlDlFdQJO1p+FqdxYzmvc=
Expand Down
7 changes: 1 addition & 6 deletions pkg/square/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (b *Builder) Export() (Square, error) {
// sort the blobs in order of namespace. We use slice stable here to respect the
// order of multiple blobs within a namespace as per the priority of the PFB
sort.SliceStable(b.Blobs, func(i, j int) bool {
return bytes.Compare(FullNamespace(b.Blobs[i].Blob), FullNamespace(b.Blobs[j].Blob)) < 0
return bytes.Compare(b.Blobs[i].Blob.Namespace(), b.Blobs[j].Blob.Namespace()) < 0
})

// write all the regular transactions into compact shares
Expand Down Expand Up @@ -366,11 +366,6 @@ func (b *Builder) IsEmpty() bool {
return b.TxCounter.Size() == 0 && b.PfbCounter.Size() == 0
}

// TODO: celestia-core should provide this method for `Blob`s
func FullNamespace(blob core.Blob) []byte {
return append([]byte{byte(blob.NamespaceVersion)}, blob.NamespaceID...)
}

type Element struct {
Blob core.Blob
PfbIndex int
Expand Down
4 changes: 2 additions & 2 deletions test/util/malicious/out_of_order_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ func OutOfOrderExport(b *square.Builder) (square.Square, error) {
// sort the blobs in order of namespace. We use slice stable here to respect the
// order of multiple blobs within a namespace as per the priority of the PFB
sort.SliceStable(b.Blobs, func(i, j int) bool {
return bytes.Compare(square.FullNamespace(b.Blobs[i].Blob), square.FullNamespace(b.Blobs[j].Blob)) < 0
return bytes.Compare(b.Blobs[i].Blob.Namespace(), b.Blobs[j].Blob.Namespace()) < 0
})

if len(b.Blobs) > 1 {
// iterate through each blob and find the first two that have different
// namespaces and swap them.
for i := 0; i < len(b.Blobs)-1; i++ {
if !bytes.Equal(square.FullNamespace(b.Blobs[i].Blob), square.FullNamespace(b.Blobs[i+1].Blob)) {
if !bytes.Equal(b.Blobs[i].Blob.Namespace(), b.Blobs[i+1].Blob.Namespace()) {
b.Blobs[i], b.Blobs[i+1] = b.Blobs[i+1], b.Blobs[i]
break
}
Expand Down

0 comments on commit 03ed667

Please sign in to comment.