Skip to content

Commit

Permalink
rename validate functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Wondertan committed Jun 27, 2023
1 parent f16fc78 commit fc0363b
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion api/gateway/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,5 @@ func parseGetByNamespaceArgs(r *http.Request) (height uint64, namespace share.Na
if err != nil {
return 0, nil, err
}
return height, namespace, namespace.ValidateDataNamespace()
return height, namespace, namespace.ValidateForData()
}
2 changes: 1 addition & 1 deletion blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func NewBlob(shareVersion uint8, namespace share.Namespace, data []byte) (*Blob,
if len(data) == 0 || len(data) > appconsts.DefaultMaxBytes {
return nil, fmt.Errorf("blob data must be > 0 && <= %d, but it was %d bytes", appconsts.DefaultMaxBytes, len(data))
}
if err := namespace.ValidateBlobNamespace(); err != nil {
if err := namespace.ValidateForBlob(); err != nil {
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion share/getters/ipld.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (ig *IPLDGetter) GetSharesByNamespace(
utils.SetStatusAndEnd(span, err)
}()

if err = namespace.ValidateDataNamespace(); err != nil {
if err = namespace.ValidateForData(); err != nil {
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion share/getters/shrex.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (sg *ShrexGetter) GetSharesByNamespace(
root *share.Root,
namespace share.Namespace,
) (share.NamespacedShares, error) {
if err := namespace.ValidateDataNamespace(); err != nil {
if err := namespace.ValidateForData(); err != nil {
return nil, err
}
var (
Expand Down
2 changes: 1 addition & 1 deletion share/getters/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (sg *StoreGetter) GetSharesByNamespace(
utils.SetStatusAndEnd(span, err)
}()

if err = namespace.ValidateDataNamespace(); err != nil {
if err = namespace.ValidateForData(); err != nil {
return nil, err
}

Expand Down
13 changes: 7 additions & 6 deletions share/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var (
ReservedPaddingNamespace = Namespace(appns.ReservedPaddingNamespace.Bytes())
TxNamespace = Namespace(appns.TxNamespace.Bytes())
PayForBlobNamespace = Namespace(appns.PayForBlobNamespace.Bytes())
ISRNamespace = Namespace(appns.IntermediateStateRootsNamespace.Bytes())
)

// Namespace represents namespace of a Share.
Expand All @@ -40,7 +41,7 @@ func NewBlobNamespaceV0(id []byte) (Namespace, error) {
// version and zero padding are already set as zero,
// so simply copying subNID to the end is enough to comply the V0 spec
copy(n[len(n)-len(id):], id)
return n, n.ValidateBlobNamespace()
return n, n.ValidateForBlob()
}

// NamespaceFromBytes converts bytes into Namespace and validates it.
Expand Down Expand Up @@ -104,8 +105,8 @@ func (n Namespace) Validate() error {
return nil
}

// ValidateDataNamespace checks if the Namespace contains real/useful data.
func (n Namespace) ValidateDataNamespace() error {
// ValidateForData checks if the Namespace is of real/useful data.
func (n Namespace) ValidateForData() error {
if err := n.Validate(); err != nil {
return err
}
Expand All @@ -115,9 +116,9 @@ func (n Namespace) ValidateDataNamespace() error {
return nil
}

// ValidateBlobNamespace checks if the Namespace is valid blob namespace.
func (n Namespace) ValidateBlobNamespace() error {
if err := n.ValidateDataNamespace(); err != nil {
// ValidateForBlob checks if the Namespace is valid blob namespace.
func (n Namespace) ValidateForBlob() error {
if err := n.ValidateForData(); err != nil {
return err
}
if bytes.Compare(n, MaxReservedNamespace) < 1 {
Expand Down
2 changes: 1 addition & 1 deletion share/p2p/shrexnd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (c *Client) RequestND(
namespace share.Namespace,
peer peer.ID,
) (share.NamespacedShares, error) {
if err := namespace.ValidateDataNamespace(); err != nil {
if err := namespace.ValidateForData(); err != nil {
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion share/p2p/shrexnd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (srv *Server) handleNamespacedData(ctx context.Context, stream network.Stre

// validateRequest checks correctness of the request
func validateRequest(req pb.GetSharesByNamespaceRequest) error {
if err := share.Namespace(req.Namespace).ValidateDataNamespace(); err != nil {
if err := share.Namespace(req.Namespace).ValidateForData(); err != nil {
return err
}
if len(req.RootHash) != sha256.Size {
Expand Down
2 changes: 1 addition & 1 deletion share/sharetest/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func RandV0Namespace() share.Namespace {
rndMu.Unlock()
for {
namespace, _ := share.NewBlobNamespaceV0(rb)
if err := namespace.ValidateDataNamespace(); err != nil {
if err := namespace.ValidateForData(); err != nil {
continue
}
return namespace
Expand Down
2 changes: 1 addition & 1 deletion state/core_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (ca *CoreAccessor) SubmitPayForBlob(

appblobs := make([]*apptypes.Blob, len(blobs))
for i, b := range blobs {
if err := b.Namespace().ValidateBlobNamespace(); err != nil {
if err := b.Namespace().ValidateForBlob(); err != nil {
return nil, err
}
appblobs[i] = &b.Blob
Expand Down

0 comments on commit fc0363b

Please sign in to comment.