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

misc(blob/service)!: return empty values in case blobs were not found #3223

Merged
merged 10 commits into from
Jul 4, 2024
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)
vgonkivs marked this conversation as resolved.
Show resolved Hide resolved
resultErr[i] = err
vgonkivs marked this conversation as resolved.
Show resolved Hide resolved
}
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)
vgonkivs marked this conversation as resolved.
Show resolved Hide resolved
},
},
{
Expand All @@ -328,6 +330,24 @@ func TestBlobService_Get(t *testing.T) {
require.NoError(t, proof.equal(*newProof))
},
},
{
name: "internal error",
vgonkivs marked this conversation as resolved.
Show resolved Hide resolved
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