Skip to content

Commit

Permalink
fix(share/availability): update availability ErrNotAvailable handling…
Browse files Browse the repository at this point in the history
… logic (#2445)

## Overview

`ipldFormat.IsNotFound` could no longer reach Availability layer. It
will get converted on getter layer to `share.ErrNotFound`. Update
outdated error handling.

---------

Co-authored-by: rene <[email protected]>
  • Loading branch information
walldiss and renaynay authored Jul 26, 2023
1 parent 7d981d5 commit e354bb5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
3 changes: 1 addition & 2 deletions share/availability/full/availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"

ipldFormat "github.com/ipfs/go-ipld-format"
logging "github.com/ipfs/go-log/v2"

"github.com/celestiaorg/celestia-node/share"
Expand Down Expand Up @@ -77,7 +76,7 @@ func (fa *ShareAvailability) SharesAvailable(ctx context.Context, root *share.Ro
}
log.Errorw("availability validation failed", "root", root.String(), "err", err.Error())
var byzantineErr *byzantine.ErrByzantine
if ipldFormat.IsNotFound(err) || errors.Is(err, context.DeadlineExceeded) && !errors.As(err, &byzantineErr) {
if errors.Is(err, share.ErrNotFound) || errors.Is(err, context.DeadlineExceeded) && !errors.As(err, &byzantineErr) {
return share.ErrNotAvailable
}
}
Expand Down
26 changes: 26 additions & 0 deletions share/availability/full/availability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ import (
"context"
"testing"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/celestiaorg/celestia-app/pkg/da"

"github.com/celestiaorg/celestia-node/share"
availability_test "github.com/celestiaorg/celestia-node/share/availability/test"
"github.com/celestiaorg/celestia-node/share/eds/edstest"
"github.com/celestiaorg/celestia-node/share/mocks"
)

func TestShareAvailableOverMocknet_Full(t *testing.T) {
Expand All @@ -32,3 +39,22 @@ func TestSharesAvailable_Full(t *testing.T) {
err := avail.SharesAvailable(ctx, dah)
assert.NoError(t, err)
}

func TestSharesAvailable_Full_ErrNotAvailable(t *testing.T) {
ctrl := gomock.NewController(t)
getter := mocks.NewMockGetter(ctrl)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

eds := edstest.RandEDS(t, 4)
dah, err := da.NewDataAvailabilityHeader(eds)
require.NoError(t, err)
avail := TestAvailability(getter)

errors := []error{share.ErrNotFound, context.DeadlineExceeded}
for _, getterErr := range errors {
getter.EXPECT().GetEDS(gomock.Any(), gomock.Any()).Return(nil, getterErr)
err := avail.SharesAvailable(ctx, &dah)
require.ErrorIs(t, err, share.ErrNotAvailable)
}
}

0 comments on commit e354bb5

Please sign in to comment.