diff --git a/share/availability/light/availability_test.go b/share/availability/light/availability_test.go index a0586c12bc..146cb8554a 100644 --- a/share/availability/light/availability_test.go +++ b/share/availability/light/availability_test.go @@ -134,7 +134,7 @@ func TestService_GetSharesByNamespaceNotFound(t *testing.T) { root.RowsRoots = nil _, err := getter.GetSharesByNamespace(context.Background(), root, []byte{1, 1, 1, 1, 1, 1, 1, 1}) - assert.ErrorIs(t, err, share.ErrNotFound) + assert.ErrorIs(t, err, share.ErrNamespaceNotFound) } func BenchmarkService_GetSharesByNamespace(b *testing.B) { diff --git a/share/getter.go b/share/getter.go index 325253e974..163741f925 100644 --- a/share/getter.go +++ b/share/getter.go @@ -12,8 +12,13 @@ import ( "github.com/celestiaorg/rsmt2d" ) -// ErrNotFound is used to indicated that requested data could not be found. -var ErrNotFound = errors.New("data not found") +var ( + // ErrNotFound is used to indicate that requested data could not be found. + ErrNotFound = errors.New("share: data not found") + // ErrNamespaceNotFound is returned by GetSharesByNamespace when data for requested root does + // not include any shares from the given namespace + ErrNamespaceNotFound = errors.New("share: namespace not found in data") +) // Getter interface provides a set of accessors for shares by the Root. // Automatically verifies integrity of shares(exceptions possible depending on the implementation). diff --git a/share/getters/cascade.go b/share/getters/cascade.go index cca1eab944..3dcb2a472b 100644 --- a/share/getters/cascade.go +++ b/share/getters/cascade.go @@ -124,6 +124,9 @@ func cascadeGetters[V any]( if getErr == nil { return val, nil } + if errors.Is(share.ErrNamespaceNotFound, getErr) { + return zero, getErr + } if !errors.Is(getErr, errOperationNotSupported) { err = errors.Join(err, getErr) diff --git a/share/getters/getter_test.go b/share/getters/getter_test.go index 6075f6678e..8751f49da0 100644 --- a/share/getters/getter_test.go +++ b/share/getters/getter_test.go @@ -138,7 +138,7 @@ func TestStoreGetter(t *testing.T) { // nid not found nID = make([]byte, 8) _, err = sg.GetSharesByNamespace(ctx, &dah, nID) - require.ErrorIs(t, err, share.ErrNotFound) + require.ErrorIs(t, err, share.ErrNamespaceNotFound) // root not found root := share.Root{} @@ -206,6 +206,7 @@ func TestIPLDGetter(t *testing.T) { err = edsStore.Put(ctx, dah.Hash(), eds) require.NoError(t, err) + // first check that shares are returned correctly if they exist shares, err := sg.GetSharesByNamespace(ctx, &dah, nID) require.NoError(t, err) require.NoError(t, shares.Verify(&dah, nID)) @@ -213,13 +214,14 @@ func TestIPLDGetter(t *testing.T) { // nid not found nID = make([]byte, 8) - _, err = sg.GetSharesByNamespace(ctx, &dah, nID) - require.ErrorIs(t, err, share.ErrNotFound) + emptyShares, err := sg.GetSharesByNamespace(ctx, &dah, nID) + require.ErrorIs(t, err, share.ErrNamespaceNotFound) + require.Nil(t, emptyShares) - // root not found + // nid doesnt exist in root root := share.Root{} _, err = sg.GetSharesByNamespace(ctx, &root, nID) - require.ErrorIs(t, err, share.ErrNotFound) + require.ErrorIs(t, err, share.ErrNamespaceNotFound) }) } diff --git a/share/getters/shrex.go b/share/getters/shrex.go index dc26d6ed7a..c860e01532 100644 --- a/share/getters/shrex.go +++ b/share/getters/shrex.go @@ -187,6 +187,13 @@ func (sg *ShrexGetter) GetSharesByNamespace( attempt int err error ) + + // verify that the namespace could exist inside the roots before starting network requests + roots := filterRootsByNamespace(root, id) + if len(roots) == 0 { + return nil, share.ErrNamespaceNotFound + } + for { if ctx.Err() != nil { sg.metrics.recordNDAttempt(ctx, attempt, false) @@ -210,10 +217,10 @@ func (sg *ShrexGetter) GetSharesByNamespace( nd, getErr := sg.ndClient.RequestND(reqCtx, root, id, peer) cancel() switch { - case getErr == nil: + case getErr == nil, errors.Is(getErr, share.ErrNamespaceNotFound): setStatus(peers.ResultNoop) sg.metrics.recordNDAttempt(ctx, attempt, true) - return nd, nil + return nd, getErr case errors.Is(getErr, context.DeadlineExceeded), errors.Is(getErr, context.Canceled): setStatus(peers.ResultCooldownPeer) diff --git a/share/getters/shrex_test.go b/share/getters/shrex_test.go index 01322b014c..1e86d8255e 100644 --- a/share/getters/shrex_test.go +++ b/share/getters/shrex_test.go @@ -87,6 +87,25 @@ func TestShrexGetter(t *testing.T) { require.ErrorIs(t, err, share.ErrNotFound) }) + t.Run("ND_namespace_not_found", func(t *testing.T) { + ctx, cancel := context.WithTimeout(ctx, time.Second) + t.Cleanup(cancel) + + // generate test data + eds, dah, nID := generateTestEDS(t) + require.NoError(t, edsStore.Put(ctx, dah.Hash(), eds)) + peerManager.Validate(ctx, srvHost.ID(), shrexsub.Notification{ + DataHash: dah.Hash(), + Height: 1, + }) + + // corrupt NID + nID[4]++ + + _, err := getter.GetSharesByNamespace(ctx, &dah, nID) + require.ErrorIs(t, err, share.ErrNamespaceNotFound) + }) + t.Run("EDS_Available", func(t *testing.T) { ctx, cancel := context.WithTimeout(ctx, time.Second) t.Cleanup(cancel) @@ -150,7 +169,8 @@ func generateTestEDS(t *testing.T) (*rsmt2d.ExtendedDataSquare, da.DataAvailabil return eds, dah, randNID } -func testManager(ctx context.Context, host host.Host, headerSub libhead.Subscriber[*header.ExtendedHeader], +func testManager( + ctx context.Context, host host.Host, headerSub libhead.Subscriber[*header.ExtendedHeader], ) (*peers.Manager, error) { shrexSub, err := shrexsub.NewPubSub(ctx, host, "test") if err != nil { @@ -177,7 +197,8 @@ func testManager(ctx context.Context, host host.Host, headerSub libhead.Subscrib return manager, err } -func newNDClientServer(ctx context.Context, t *testing.T, edsStore *eds.Store, srvHost, clHost host.Host, +func newNDClientServer( + ctx context.Context, t *testing.T, edsStore *eds.Store, srvHost, clHost host.Host, ) (*shrexnd.Client, *shrexnd.Server) { params := shrexnd.DefaultParameters() @@ -196,7 +217,8 @@ func newNDClientServer(ctx context.Context, t *testing.T, edsStore *eds.Store, s return client, server } -func newEDSClientServer(ctx context.Context, t *testing.T, edsStore *eds.Store, srvHost, clHost host.Host, +func newEDSClientServer( + ctx context.Context, t *testing.T, edsStore *eds.Store, srvHost, clHost host.Host, ) (*shrexeds.Client, *shrexeds.Server) { params := shrexeds.DefaultParameters() diff --git a/share/getters/store.go b/share/getters/store.go index 1c88206577..156c9cf2ee 100644 --- a/share/getters/store.go +++ b/share/getters/store.go @@ -128,5 +128,6 @@ func (sg *StoreGetter) GetSharesByNamespace( if err != nil { return nil, fmt.Errorf("getter/store: failed to retrieve shares by namespace: %w", err) } + return shares, nil } diff --git a/share/getters/utils.go b/share/getters/utils.go index 6c7c2ba7e6..a6fd4a7beb 100644 --- a/share/getters/utils.go +++ b/share/getters/utils.go @@ -59,7 +59,7 @@ func collectSharesByNamespace( rootCIDs := filterRootsByNamespace(root, nID) if len(rootCIDs) == 0 { - return nil, share.ErrNotFound + return nil, share.ErrNamespaceNotFound } errGroup, ctx := errgroup.WithContext(ctx) @@ -84,9 +84,9 @@ func collectSharesByNamespace( return nil, err } - // return ErrNotFound if no shares are found for namespaceID + // return ErrNamespaceNotFound if no shares are found for the namespace.ID if len(rootCIDs) == 1 && len(shares[0].Shares) == 0 { - return nil, share.ErrNotFound + return nil, share.ErrNamespaceNotFound } return shares, nil diff --git a/share/p2p/shrexnd/client.go b/share/p2p/shrexnd/client.go index b5ae66f51f..ff51ef1fe0 100644 --- a/share/p2p/shrexnd/client.go +++ b/share/p2p/shrexnd/client.go @@ -71,7 +71,7 @@ func (c *Client) RequestND( return nil, context.DeadlineExceeded } } - if err != p2p.ErrNotFound { + if err != p2p.ErrNotFound && err != share.ErrNamespaceNotFound { log.Warnw("client-nd: peer returned err", "err", err) } return nil, err @@ -195,6 +195,8 @@ func (c *Client) statusToErr(ctx context.Context, code pb.StatusCode) error { case pb.StatusCode_NOT_FOUND: c.metrics.ObserveRequests(ctx, 1, p2p.StatusNotFound) return p2p.ErrNotFound + case pb.StatusCode_NAMESPACE_NOT_FOUND: + return share.ErrNamespaceNotFound case pb.StatusCode_INVALID: log.Debug("client-nd: invalid request") fallthrough diff --git a/share/p2p/shrexnd/exchange_test.go b/share/p2p/shrexnd/exchange_test.go index 05bca67237..944b763229 100644 --- a/share/p2p/shrexnd/exchange_test.go +++ b/share/p2p/shrexnd/exchange_test.go @@ -39,7 +39,7 @@ func TestExchange_RequestND_NotFound(t *testing.T) { require.ErrorIs(t, err, p2p.ErrNotFound) }) - t.Run("Getter_err_not_found", func(t *testing.T) { + t.Run("ErrNamespaceNotFound", func(t *testing.T) { ctx, cancel := context.WithTimeout(ctx, time.Second) t.Cleanup(cancel) @@ -49,7 +49,7 @@ func TestExchange_RequestND_NotFound(t *testing.T) { randNID := dah.RowsRoots[(len(dah.RowsRoots)-1)/2][:8] _, err := client.RequestND(ctx, &dah, randNID, server.host.ID()) - require.ErrorIs(t, err, p2p.ErrNotFound) + require.ErrorIs(t, err, share.ErrNamespaceNotFound) }) } @@ -118,7 +118,7 @@ func (m notFoundGetter) GetEDS( func (m notFoundGetter) GetSharesByNamespace( _ context.Context, _ *share.Root, _ namespace.ID, ) (share.NamespacedShares, error) { - return nil, share.ErrNotFound + return nil, share.ErrNamespaceNotFound } func newStore(t *testing.T) *eds.Store { diff --git a/share/p2p/shrexnd/params.go b/share/p2p/shrexnd/params.go index 1acf65ba96..a645267962 100644 --- a/share/p2p/shrexnd/params.go +++ b/share/p2p/shrexnd/params.go @@ -8,7 +8,7 @@ import ( "github.com/celestiaorg/celestia-node/share/p2p" ) -const protocolString = "/shrex/nd/0.0.1" +const protocolString = "/shrex/nd/v0.0.2" var log = logging.Logger("shrex/nd") diff --git a/share/p2p/shrexnd/pb/share.pb.go b/share/p2p/shrexnd/pb/share.pb.go index bb9d1e4d40..d902570410 100644 --- a/share/p2p/shrexnd/pb/share.pb.go +++ b/share/p2p/shrexnd/pb/share.pb.go @@ -25,10 +25,11 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type StatusCode int32 const ( - StatusCode_INVALID StatusCode = 0 - StatusCode_OK StatusCode = 1 - StatusCode_NOT_FOUND StatusCode = 2 - StatusCode_INTERNAL StatusCode = 3 + StatusCode_INVALID StatusCode = 0 + StatusCode_OK StatusCode = 1 + StatusCode_NOT_FOUND StatusCode = 2 + StatusCode_INTERNAL StatusCode = 3 + StatusCode_NAMESPACE_NOT_FOUND StatusCode = 4 ) var StatusCode_name = map[int32]string{ @@ -36,13 +37,15 @@ var StatusCode_name = map[int32]string{ 1: "OK", 2: "NOT_FOUND", 3: "INTERNAL", + 4: "NAMESPACE_NOT_FOUND", } var StatusCode_value = map[string]int32{ - "INVALID": 0, - "OK": 1, - "NOT_FOUND": 2, - "INTERNAL": 3, + "INVALID": 0, + "OK": 1, + "NOT_FOUND": 2, + "INTERNAL": 3, + "NAMESPACE_NOT_FOUND": 4, } func (x StatusCode) String() string { @@ -280,31 +283,32 @@ func init() { func init() { proto.RegisterFile("share/p2p/shrexnd/pb/share.proto", fileDescriptor_ed9f13149b0de397) } var fileDescriptor_ed9f13149b0de397 = []byte{ - // 374 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0xc1, 0x6a, 0xdb, 0x40, - 0x10, 0x86, 0x25, 0x6d, 0xad, 0xda, 0x23, 0xb5, 0x88, 0xa5, 0xb4, 0x2a, 0x2e, 0xc2, 0xd5, 0xc9, - 0xb4, 0x20, 0x81, 0x0a, 0x3d, 0x16, 0xec, 0xda, 0x6d, 0x45, 0xcd, 0xba, 0xac, 0xdd, 0xdc, 0x82, - 0x91, 0xa3, 0x0d, 0xca, 0x21, 0xda, 0x8d, 0x76, 0x8d, 0x93, 0x73, 0x5e, 0x20, 0x8f, 0x95, 0xa3, - 0x8f, 0x39, 0x06, 0xfb, 0x45, 0x82, 0x56, 0x4e, 0x72, 0x88, 0x6f, 0xfa, 0xff, 0xf9, 0xe6, 0x9f, - 0x19, 0x2d, 0xf4, 0x64, 0x91, 0x55, 0x2c, 0x16, 0x89, 0x88, 0x65, 0x51, 0xb1, 0xcb, 0x32, 0x8f, - 0xc5, 0x32, 0xd6, 0x66, 0x24, 0x2a, 0xae, 0x38, 0xc6, 0x7b, 0x91, 0x88, 0x48, 0x13, 0x51, 0x99, - 0x87, 0xc7, 0xd0, 0xfd, 0xcd, 0xd4, 0xac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0x68, 0x30, 0x49, 0x47, 0x9e, - 0x81, 0x6d, 0xb0, 0xa6, 0x7f, 0x3d, 0x13, 0xbf, 0x81, 0x0e, 0x99, 0xce, 0x17, 0xbf, 0xa6, 0xff, - 0xc9, 0xc8, 0xb3, 0xb0, 0x0b, 0xed, 0x94, 0xcc, 0xc7, 0x94, 0x0c, 0x26, 0x1e, 0x1a, 0xfa, 0xb7, - 0xdb, 0xc0, 0xdc, 0x6c, 0x03, 0xf3, 0x7e, 0x1b, 0x98, 0x37, 0xbb, 0xc0, 0xd8, 0xec, 0x02, 0xe3, - 0x6e, 0x17, 0x18, 0x4b, 0x5b, 0x3f, 0xf8, 0xb7, 0x87, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x23, - 0xba, 0xf9, 0x14, 0x02, 0x00, 0x00, + // 386 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x92, 0xc1, 0xae, 0x93, 0x40, + 0x14, 0x86, 0x81, 0xb9, 0xc5, 0x7b, 0x0f, 0x68, 0xc8, 0x68, 0xbc, 0x98, 0x6b, 0x48, 0x65, 0xd5, + 0x68, 0x02, 0x09, 0x26, 0xee, 0x69, 0x8b, 0x4a, 0xac, 0xd3, 0x66, 0x5a, 0x75, 0x65, 0x08, 0x95, + 0x31, 0xb8, 0x90, 0x19, 0x99, 0x69, 0xaa, 0x6b, 0x5f, 0xc0, 0xc7, 0x72, 0xd9, 0xa5, 0x4b, 0xd3, + 0xbe, 0x88, 0x61, 0xa8, 0x76, 0x61, 0x77, 0xfc, 0xff, 0xf9, 0xce, 0x7f, 0xce, 0x21, 0x03, 0x43, + 0x59, 0x97, 0x2d, 0x8b, 0x45, 0x22, 0x62, 0x59, 0xb7, 0xec, 0x6b, 0x53, 0xc5, 0x62, 0x1d, 0x6b, + 0x33, 0x12, 0x2d, 0x57, 0x1c, 0xe3, 0xa3, 0x48, 0x44, 0xa4, 0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, + 0x0e, 0xe0, 0x74, 0x19, 0x76, 0xe0, 0x56, 0x4e, 0xde, 0xa6, 0xb3, 0x7c, 0xea, 0x19, 0xd8, 0x06, + 0x6b, 0xfe, 0xca, 0x33, 0xf1, 0x6d, 0xb8, 0x22, 0xf3, 0x55, 0xf1, 0x7c, 0xfe, 0x86, 0x4c, 0x3d, + 0x0b, 0xbb, 0x70, 0x99, 0x93, 0x55, 0x46, 0x49, 0x3a, 0xf3, 0x10, 0xbe, 0x86, 0xbb, 0x24, 0x7d, + 0x9d, 0x2d, 0x17, 0xe9, 0x24, 0x2b, 0x4e, 0xd8, 0xc5, 0xd8, 0xff, 0xb9, 0x0f, 0xcc, 0xdd, 0x3e, + 0x30, 0x7f, 0xef, 0x03, 0xf3, 0xc7, 0x21, 0x30, 0x76, 0x87, 0xc0, 0xf8, 0x75, 0x08, 0x8c, 0xb5, + 0xad, 0x5f, 0xc2, 0xd3, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xba, 0xc1, 0x4e, 0xec, 0x2d, 0x02, + 0x00, 0x00, } func (m *GetSharesByNamespaceRequest) Marshal() (dAtA []byte, err error) { diff --git a/share/p2p/shrexnd/pb/share.proto b/share/p2p/shrexnd/pb/share.proto index d181dd7010..3d6a896641 100644 --- a/share/p2p/shrexnd/pb/share.proto +++ b/share/p2p/shrexnd/pb/share.proto @@ -17,6 +17,7 @@ enum StatusCode { OK = 1; NOT_FOUND = 2; INTERNAL = 3; + NAMESPACE_NOT_FOUND = 4; }; message Row { diff --git a/share/p2p/shrexnd/server.go b/share/p2p/shrexnd/server.go index 5c1fe80f52..748d9fbd10 100644 --- a/share/p2p/shrexnd/server.go +++ b/share/p2p/shrexnd/server.go @@ -130,12 +130,15 @@ func (srv *Server) handleNamespacedData(ctx context.Context, stream network.Stre } shares, err := srv.getter.GetSharesByNamespace(ctx, dah, req.NamespaceId) - if errors.Is(err, share.ErrNotFound) { + switch { + case errors.Is(err, share.ErrNotFound): logger.Warn("server: nd not found") srv.respondNotFoundError(ctx, logger, stream) return - } - if err != nil { + case errors.Is(err, share.ErrNamespaceNotFound): + srv.respondNamespaceNotFoundError(ctx, logger, stream) + return + case err != nil: logger.Errorw("server: retrieving shares", "err", err) srv.respondInternalError(ctx, logger, stream) return @@ -157,7 +160,7 @@ func validateRequest(req pb.GetSharesByNamespaceRequest) error { return nil } -// respondNotFoundError sends internal error response to client +// respondNotFoundError sends a not found response to client func (srv *Server) respondNotFoundError(ctx context.Context, logger *zap.SugaredLogger, stream network.Stream) { resp := &pb.GetSharesByNamespaceResponse{ @@ -166,6 +169,15 @@ func (srv *Server) respondNotFoundError(ctx context.Context, srv.respond(ctx, logger, stream, resp) } +// respondNamespaceNotFoundError sends a namespace not found response to client +func (srv *Server) respondNamespaceNotFoundError(ctx context.Context, + logger *zap.SugaredLogger, stream network.Stream) { + resp := &pb.GetSharesByNamespaceResponse{ + Status: pb.StatusCode_NAMESPACE_NOT_FOUND, + } + srv.respond(ctx, logger, stream, resp) +} + // respondInternalError sends internal error response to client func (srv *Server) respondInternalError(ctx context.Context, logger *zap.SugaredLogger, stream network.Stream) {