Skip to content

Commit

Permalink
feat!: incorporates ParitySharesNamespace and TailPaddingNamespace in…
Browse files Browse the repository at this point in the history
…to IsReserved function (#2194)

## Overview
Closes #celestiaorg/celestia-app#2138
This PR also addresses the concerns raised in the
[comment](celestiaorg/celestia-app#2138 (comment))
by introducing a distinction between two types of reserved namespaces.
Namespaces within the range [0-255] are now identified as "Primary
Reserved Namespaces," while any other reserved namespaces beyond this
range are categorized as "Non-Primary Reserved Namespaces." Hopefully,
this differentiation provides better clarity and organization regarding
namespace allocation and usage within the code.

## Checklist

- [x] New and updated code has appropriate documentation
- [x] New and updated code has new and/or updated testing
- [x] Required CI checks are passing
- [x] Visual proof for any user facing features like CLI or
documentation updates
- [x] Linked issues closed with keywords
  • Loading branch information
staheri14 authored Aug 3, 2023
1 parent ee1579e commit 025b132
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
7 changes: 4 additions & 3 deletions pkg/namespace/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ var (
// (ordinary and PFBs) but before blobs.
ReservedPaddingNamespace = MustNewV0([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 255})

// MaxReservedNamespace is lexicographically the largest namespace that is
// reserved for protocol use.
MaxReservedNamespace = MustNewV0([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 255})
// MaxPrimaryReservedNamespace represents the largest primary reserved
// namespace reserved for protocol use. Note that there may be other
// non-primary reserved namespaces beyond this upper limit.
MaxPrimaryReservedNamespace = MustNewV0([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 255})

// TailPaddingNamespace is the namespace reserved for tail padding. All data
// with this namespace will be ignored.
Expand Down
6 changes: 5 additions & 1 deletion pkg/namespace/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ func validateID(version uint8, id []byte) error {
return nil
}

// IsReserved returns true if the namespace is reserved for protocol-use.
func (n Namespace) IsReserved() bool {
return bytes.Compare(n.Bytes(), MaxReservedNamespace.Bytes()) < 1
isLessThanOrEqualToMaxPrimaryReservedNamespace := bytes.Compare(n.Bytes(), MaxPrimaryReservedNamespace.Bytes()) < 1
isParityNamespace := n.IsParityShares()
isTailPadding := n.IsTailPadding()
return isLessThanOrEqualToMaxPrimaryReservedNamespace || isParityNamespace || isTailPadding
}

func (n Namespace) IsParityShares() bool {
Expand Down
8 changes: 0 additions & 8 deletions pkg/namespace/random_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ func isBlobNamespace(ns Namespace) bool {
return false
}

if ns.IsParityShares() {
return false
}

if ns.IsTailPadding() {
return false
}

if !slices.Contains(SupportedBlobNamespaceVersions, ns.Version) {
return false
}
Expand Down

0 comments on commit 025b132

Please sign in to comment.