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

refactor: address namespace follow-ups from celestia-app v1.0.0-rc12 bump #2597

Merged
merged 3 commits into from
Aug 24, 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
14 changes: 7 additions & 7 deletions share/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ var (
// MinSecondaryReservedNamespace is the lowest secondary reserved namespace
// reserved for protocol use. Namespaces higher than this are reserved for
// protocol use.
MinSecondaryReservedNamespace = Namespace(appns.MinSecondaryReservedNamespace.Bytes())
ParitySharesNamespace = Namespace(appns.ParitySharesNamespace.Bytes())
TailPaddingNamespace = Namespace(appns.TailPaddingNamespace.Bytes())
ReservedPaddingNamespace = Namespace(appns.PrimaryReservedPaddingNamespace.Bytes())
TxNamespace = Namespace(appns.TxNamespace.Bytes())
PayForBlobNamespace = Namespace(appns.PayForBlobNamespace.Bytes())
ISRNamespace = Namespace(appns.IntermediateStateRootsNamespace.Bytes())
MinSecondaryReservedNamespace = Namespace(appns.MinSecondaryReservedNamespace.Bytes())
ParitySharesNamespace = Namespace(appns.ParitySharesNamespace.Bytes())
TailPaddingNamespace = Namespace(appns.TailPaddingNamespace.Bytes())
PrimaryReservedPaddingNamespace = Namespace(appns.PrimaryReservedPaddingNamespace.Bytes())
TxNamespace = Namespace(appns.TxNamespace.Bytes())
PayForBlobNamespace = Namespace(appns.PayForBlobNamespace.Bytes())
ISRNamespace = Namespace(appns.IntermediateStateRootsNamespace.Bytes())
)

// Namespace represents namespace of a Share.
Expand Down
26 changes: 26 additions & 0 deletions share/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ func TestValidateForBlob(t *testing.T) {
ns: append([]byte{appns.NamespaceVersionMax}, bytes.Repeat([]byte{0x0}, appns.NamespaceIDSize)...),
wantErr: true,
},
{
name: "invalid blob namespace: primary reserved namespace",
ns: primaryReservedNamespace(0x10),
wantErr: true,
},
{
name: "invalid blob namespace: secondary reserved namespace",
ns: secondaryReservedNamespace(0x10),
wantErr: true,
},
}

for _, tc := range testCases {
Expand All @@ -186,5 +196,21 @@ func TestValidateForBlob(t *testing.T) {
assert.NoError(t, err)
})
}
}

func primaryReservedNamespace(lastByte byte) Namespace {
result := make([]byte, NamespaceSize)
result = append(result, appns.NamespaceVersionZero)
result = append(result, appns.NamespaceVersionZeroPrefix...)
result = append(result, bytes.Repeat([]byte{0x0}, appns.NamespaceVersionZeroIDSize-1)...)
result = append(result, lastByte)
return result
}

func secondaryReservedNamespace(lastByte byte) Namespace {
result := make([]byte, NamespaceSize)
result = append(result, appns.NamespaceVersionMax)
result = append(result, bytes.Repeat([]byte{0xFF}, appns.NamespaceIDSize-1)...)
result = append(result, lastByte)
return result
}
Loading