Skip to content

Commit

Permalink
chore: fix nits
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed Feb 28, 2024
1 parent 522e65c commit 6a35738
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 42 deletions.
1 change: 1 addition & 0 deletions blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func (b *Blob) Namespace() share.Namespace {
}

// Index returns the blob's first share index in the EDS.
// Only retrieved, on-chain blobs will have the index set. Default is -1.
func (b *Blob) Index() int {
return b.index
}
Expand Down
3 changes: 2 additions & 1 deletion blob/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ func TestBlob(t *testing.T) {
require.NoError(t, err)
shares, err := toAppShares(sh...)
require.NoError(t, err)
b, err := parseShares(shares, 0)
p := &parser{length: len(shares), shares: shares}
b, err := p.transform()
require.NoError(t, err)
assert.Equal(t, blob[0].Commitment, b.Commitment)
},
Expand Down
37 changes: 0 additions & 37 deletions blob/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package blob

import (
"bytes"
"errors"
"sort"

"github.com/tendermint/tendermint/types"
Expand All @@ -12,42 +11,6 @@ import (
"github.com/celestiaorg/celestia-node/share"
)

// parseShares takes shares and converts them to the *Blob.
func parseShares(appShrs []shares.Share, index int) (*Blob, error) {
sequence, err := shares.ParseShares(appShrs, true)
if err != nil {
return nil, err
}

// ensure that sequence length is not 0
if len(sequence) == 0 {
return nil, ErrBlobNotFound
}
if len(sequence) > 1 {
return nil, errors.New("unexpected amount of sequences")
}

data, err := sequence[0].RawData()
if err != nil {
return nil, err
}
if len(data) == 0 {
return nil, ErrBlobNotFound
}

shareVersion, err := sequence[0].Shares[0].Version()
if err != nil {
return nil, err
}

blob, err := NewBlob(shareVersion, sequence[0].Namespace.Bytes(), data)
if err != nil {
return nil, err
}
blob.index = index
return blob, nil
}

// BlobsToShares accepts blobs and convert them to the Shares.
func BlobsToShares(blobs ...*Blob) ([]share.Share, error) {
b := make([]types.Blob, len(blobs))
Expand Down
34 changes: 31 additions & 3 deletions blob/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package blob

import (
"errors"
"fmt"

"github.com/celestiaorg/celestia-app/pkg/shares"
)

// parser is a helper struct that allows collecting shares and transforming it into the blob.
// parser is a helper struct that allows collecting shares and transforming them into the blob.
// it contains all necessary information that is needed to build the blob:
// * position of the blob inside the EDS;
// * blob's length;
Expand Down Expand Up @@ -95,13 +96,40 @@ func (p *parser) addShares(shares []shares.Share) (shrs []shares.Share, isComple
// transform parses shares and creates the Blob.
func (p *parser) transform() (*Blob, error) {
if p.length != len(p.shares) {
return nil, errors.New("insufficient shares amount")
return nil, fmt.Errorf("invalid shares amount. want:%d, have:%d", p.length, len(p.shares))
}

blob, err := parseShares(p.shares, p.index)
sequence, err := shares.ParseShares(p.shares, true)
if err != nil {
return nil, err
}

// ensure that sequence length is not 0
if len(sequence) == 0 {
return nil, ErrBlobNotFound
}
if len(sequence) > 1 {
return nil, errors.New("unexpected amount of sequences")
}

data, err := sequence[0].RawData()
if err != nil {
return nil, err
}
if len(data) == 0 {
return nil, ErrBlobNotFound
}

shareVersion, err := sequence[0].Shares[0].Version()
if err != nil {
return nil, err
}

blob, err := NewBlob(shareVersion, sequence[0].Namespace.Bytes(), data)
if err != nil {
return nil, err
}
blob.index = p.index
return blob, nil
}

Expand Down
2 changes: 1 addition & 1 deletion blob/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
)

func TestBlobService_Get(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
t.Cleanup(cancel)
var (
blobSize0 = 18
Expand Down

0 comments on commit 6a35738

Please sign in to comment.