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 ##2138
This PR also addresses the concerns raised in the
[comment](#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 9ea27d4 commit b3b8611
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 37 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
27 changes: 15 additions & 12 deletions specs/src/specs/namespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,28 @@ The ID is encoded as a byte slice of length 28.
## Reserved Namespaces

Celestia reserves certain namespaces with specific meanings.
Celestia makes use of the reserved namespaces to properly organize and order transactions and blobs inside the [data square](./data_square_layout.md).
Reserved namespaces are used to properly organize and order transactions and blobs inside the [data square](./data_square_layout.md).
Applications MUST NOT use these reserved namespaces for their blob data.

Below is a list of reserved namespaces, along with a brief description of each.
In addition to the items listed in this table, it should be noted that namespaces with values less than `0x00000000000000000000000000000000000000000000000000000000FF` are exclusively reserved for use within the Celestia protocols.
Reserved namespaces fall into two categories, _Primary Reserved Namespaces_ and _Secondary Reserved Namespaces_.
- Primary Reserved Namespaces: Namespaces with values less than or equal to `0x00000000000000000000000000000000000000000000000000000000FF` are referred to as Primary Reserved Namespaces and are exclusively reserved for use within the Celestia protocols.
- Secondary Reserved Namespaces: Currently, there are two secondary reserved namespaces, namely, `PARITY_SHARE_NAMESPACE` and `TAIL_PADDING_NAMESPACE` which fall out of the range of primary reserved namespaces.
In the table, you will notice that the `PARITY_SHARE_NAMESPACE` and `TAIL_PADDING_NAMESPACE` utilize the namespace version `255`, which differs from the supported user-specified versions.
The reason for employing version `255` for the `PARITY_SHARE_NAMESPACE` is to enable more efficient proof generation within the context of [nmt](https://github.com/celestiaorg/nmt), where it is used in conjunction with the `IgnoreMaxNamespace` feature.
Similarly, the `TAIL_PADDING_NAMESPACE` utilizes the namespace version `255` to ensure that padding shares are always properly ordered and placed at the end of the Celestia data square even if a new namespace version is introduced.

Below is a list of currently used primary and secondary reserved namespaces, along with a brief description of each.
For additional information on the significance and application of the reserved namespaces, please refer to the [Data Square Layout](./data_square_layout.md) specifications.

| name | type | value | description |
|-------------------------------------|-------------|----------------------------------------------------------------|------------------------------------------------------------------------------------------------------|
| `TRANSACTION_NAMESPACE` | `Namespace` | `0x0000000000000000000000000000000000000000000000000000000001` | Transactions: requests that modify the state. |
| `INTERMEDIATE_STATE_ROOT_NAMESPACE` | `Namespace` | `0x0000000000000000000000000000000000000000000000000000000002` | Intermediate state roots, committed after every transaction. |
| `PAY_FOR_BLOB_NAMESPACE` | `Namespace` | `0x0000000000000000000000000000000000000000000000000000000004` | Namespace reserved for transactions that contain a PayForBlob. |
| `RESERVED_PADDING_NAMESPACE` | `Namespace` | `0x00000000000000000000000000000000000000000000000000000000FF` | Padding after all reserved namespaces but before blobs. |
| `MAX_RESERVED_NAMESPACE` | `Namespace` | `0x00000000000000000000000000000000000000000000000000000000FF` | Max reserved namespace is lexicographically the largest namespace that is reserved for protocol use. |
| `TAIL_PADDING_NAMESPACE` | `Namespace` | `0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE` | Tail padding for blobs: padding after all blobs to fill up the original data square. |
| `PARITY_SHARE_NAMESPACE` | `Namespace` | `0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF` | Parity shares: extended shares in the available data matrix. |
| name | type | value | description |
|-------------------------------------|-------------|----------------------------------------------------------------|-------------------------------------------------------------------------------------------------------|
| `TRANSACTION_NAMESPACE` | `Namespace` | `0x0000000000000000000000000000000000000000000000000000000001` | Transactions: requests that modify the state. |
| `INTERMEDIATE_STATE_ROOT_NAMESPACE` | `Namespace` | `0x0000000000000000000000000000000000000000000000000000000002` | Intermediate state roots, committed after every transaction. |
| `PAY_FOR_BLOB_NAMESPACE` | `Namespace` | `0x0000000000000000000000000000000000000000000000000000000004` | Namespace reserved for transactions that contain a PayForBlob. |
| `RESERVED_PADDING_NAMESPACE` | `Namespace` | `0x00000000000000000000000000000000000000000000000000000000FF` | Padding after all reserved namespaces but before blobs. |
| `MAX_PRIMARY_RESERVED_NAMESPACE` | `Namespace` | `0x00000000000000000000000000000000000000000000000000000000FF` | Max primary reserved namespace is the largest primary reserved namespace designated for protocol use. |
| `TAIL_PADDING_NAMESPACE` | `Namespace` | `0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE` | Tail padding for blobs: padding after all blobs to fill up the original data square. |
| `PARITY_SHARE_NAMESPACE` | `Namespace` | `0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF` | Parity shares: extended shares in the available data matrix. |

## Assumptions and Considerations

Expand Down
10 changes: 1 addition & 9 deletions x/blob/types/payforblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,7 @@ func DefaultEstimateGas(blobSizes []uint32) uint64 {
// tail padding).
func ValidateBlobNamespace(ns appns.Namespace) error {
if ns.IsReserved() {
return ErrReservedNamespace.Wrapf("got namespace: %x, want: > %x", ns, appns.MaxReservedNamespace)
}

if ns.IsParityShares() {
return ErrParitySharesNamespace
}

if ns.IsTailPadding() {
return ErrTailPaddingNamespace
return ErrReservedNamespace
}

if !slices.Contains(appns.SupportedBlobNamespaceVersions, ns.Version) {
Expand Down
8 changes: 4 additions & 4 deletions x/blob/types/payforblob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ func TestValidateBasic(t *testing.T) {
intermediateStateRootsNamespaceMsg := validMsgPayForBlobs(t)
intermediateStateRootsNamespaceMsg.Namespaces[0] = appns.IntermediateStateRootsNamespace.Bytes()

// MsgPayForBlobs that uses the max reserved namespace
// MsgPayForBlobs that uses the max primary reserved namespace
maxReservedNamespaceMsg := validMsgPayForBlobs(t)
maxReservedNamespaceMsg.Namespaces[0] = appns.MaxReservedNamespace.Bytes()
maxReservedNamespaceMsg.Namespaces[0] = appns.MaxPrimaryReservedNamespace.Bytes()

// MsgPayForBlobs that has an empty share commitment
emptyShareCommitment := validMsgPayForBlobs(t)
Expand Down Expand Up @@ -176,12 +176,12 @@ func TestValidateBasic(t *testing.T) {
{
name: "parity shares namespace",
msg: paritySharesMsg,
wantErr: ErrParitySharesNamespace,
wantErr: ErrReservedNamespace,
},
{
name: "tail padding namespace",
msg: tailPaddingMsg,
wantErr: ErrTailPaddingNamespace,
wantErr: ErrReservedNamespace,
},
{
name: "tx namespace",
Expand Down

0 comments on commit b3b8611

Please sign in to comment.