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 8 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 according to the specs.
staheri14 marked this conversation as resolved.
Show resolved Hide resolved
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
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
6 changes: 3 additions & 3 deletions x/blob/types/payforblob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestValidateBasic(t *testing.T) {

// MsgPayForBlobs that uses the max reserved namespace
maxReservedNamespaceMsg := validMsgPayForBlobs(t)
maxReservedNamespaceMsg.Namespaces[0] = appns.MaxReservedNamespace.Bytes()
maxReservedNamespaceMsg.Namespaces[0] = appns.MaxPrimaryReservedNamespace.Bytes()
staheri14 marked this conversation as resolved.
Show resolved Hide resolved

// 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