Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed Jul 3, 2024
1 parent 734d185 commit a9398b7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
16 changes: 6 additions & 10 deletions blob/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,14 @@ func (s *Service) GetAll(ctx context.Context, height uint64, namespaces []share.
defer wg.Done()

blobs, err := s.getBlobs(ctx, namespace, header)
switch {
case err == nil:
log.Infow("retrieved blobs", "height", height, "total", len(blobs))
resultBlobs[i] = blobs
case errors.Is(err, ErrBlobNotFound):
default:
if err != nil && !errors.Is(err, ErrBlobNotFound) {
log.Debugf("getting blobs for namespace(%s): %v", namespace.String(), err)
resultErr[i] = err
}
if len(blobs) > 0 {
log.Infow("retrieved blobs", "height", height, "total", len(blobs))
resultBlobs[i] = blobs
}
}(i, namespace)
}
wg.Wait()
Expand Down Expand Up @@ -412,8 +411,5 @@ func (s *Service) getBlobs(
sharesParser := &parser{verifyFn: verifyFn}

_, _, err = s.retrieve(ctx, header.Height(), namespace, sharesParser)
if len(blobs) == 0 {
return nil, ErrBlobNotFound
}
return blobs, nil
return blobs, err
}
24 changes: 22 additions & 2 deletions blob/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"sort"
"testing"
"time"

"github.com/golang/mock/gomock"
ds "github.com/ipfs/go-datastore"
ds_sync "github.com/ipfs/go-datastore/sync"
"github.com/stretchr/testify/assert"
Expand All @@ -20,10 +22,10 @@ import (
"github.com/celestiaorg/celestia-app/pkg/shares"
"github.com/celestiaorg/go-header/store"


"github.com/celestiaorg/celestia-node/blob/blobtest"
"github.com/celestiaorg/celestia-node/header"
"github.com/celestiaorg/celestia-node/header/headertest"
shareMock "github.com/celestiaorg/celestia-node/nodebuilder/share/mocks"
"github.com/celestiaorg/celestia-node/share"
"github.com/celestiaorg/celestia-node/share/getters"
"github.com/celestiaorg/celestia-node/share/ipld"
Expand Down Expand Up @@ -306,7 +308,7 @@ func TestBlobService_Get(t *testing.T) {
blobs, ok := i.([]*Blob)
require.True(t, ok)
assert.Empty(t, blobs)
assert.Empty(t, err)
assert.Nil(t, err)
},
},
{
Expand All @@ -328,6 +330,24 @@ func TestBlobService_Get(t *testing.T) {
require.NoError(t, proof.equal(*newProof))
},
},
{
name: "internal error",
doFn: func() (interface{}, error) {
ctrl := gomock.NewController(t)
shareGetterMock := shareMock.NewMockModule(ctrl)
service.shareGetter = shareGetterMock
shareGetterMock.EXPECT().
GetSharesByNamespace(gomock.Any(), gomock.Any(), gomock.Any()).
Return(nil, errors.New("internal error"))
return service.GetAll(ctx, 1, []share.Namespace{blobs0[0].Namespace()})
},
expectedResult: func(res interface{}, err error) {
blobs, ok := res.([]*Blob)
require.True(t, ok)
assert.Empty(t, blobs)
require.Error(t, err)
},
},
}

for _, tt := range test {
Expand Down

0 comments on commit a9398b7

Please sign in to comment.