Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: incorporates ParitySharesNamespace and TailPaddingNamespace into IsReserved function #2194

Merged
merged 15 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these errors used anywhere else? Do we want to remove them if they aren't used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After integrating this PR, there will be no active usage for ErrParitySharesNamespace in the app. I also initially thought of deleting it, however, there are other unused errors among the existing registered errors e.g., ErrInvalidShareCommitments, so I decided to keep it as is. @rootulp Do you think there will be future usage for this error?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't expect future usages of ErrParitySharesNamespace so it seems feasible to remove but we can def do in a follow-up issue / PR.

One question I have is: when we delete errors that are no longer used, do we need to reserve the error code indefinitely or can it be repurposed?

Copy link
Member

@rach-id rach-id Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a related note, sometimes some errors are not used but kept so that their code number is not replaced by some other error which might break downstream for people depending on it

Edit: Rootul front ran me :D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too sure who uses the error code since the message is always accompanied with it in the response but I'd tend to agree that safest thing to do would be to reserve it (just by leaving a comment probably)

}

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
Loading