Skip to content

Commit

Permalink
refactor: address namespace follow-ups from celestia-app v1.0.0-rc12 …
Browse files Browse the repository at this point in the history
…bump (#2597)

Addresses two follow-ups from
#2581
Closes #2561
  • Loading branch information
rootulp authored Aug 24, 2023
1 parent 440e232 commit 1205437
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
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
}

0 comments on commit 1205437

Please sign in to comment.