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: add missing utilities used by celestia-node #109

Merged
merged 15 commits into from
Oct 17, 2024
28 changes: 12 additions & 16 deletions share/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,17 @@ func (n Namespace) ValidateForData() error {
if !n.IsUsableNamespace() {
return fmt.Errorf("invalid data namespace(%s): parity and tail padding namespace are forbidden", n)
}
if n.IsReserved() {
return fmt.Errorf("invalid data namespace(%s): reserved namespace is forbidden", n)
return nil
}

// // ValidateForBlob checks if the Namespace is valid blob namespace.
vgonkivs marked this conversation as resolved.
Show resolved Hide resolved
func (n Namespace) ValidateForBlob() error {
if err := n.ValidateForData(); err != nil {
return err
}

if !slices.Contains(SupportedBlobNamespaceVersions, n.Version()) {
return fmt.Errorf("blob version %d is not supported", n.Version())
}
return nil
}
Expand Down Expand Up @@ -219,19 +228,6 @@ func (n Namespace) Repeat(times int) []Namespace {
return ns
}

// IsBlobNamespace returns true if this namespace is a valid user-specifiable
// blob namespace.
func (n Namespace) IsBlobNamespace() bool {
if err := n.ValidateForData(); err != nil {
return false
}

if !slices.Contains(SupportedBlobNamespaceVersions, n.Version()) {
return false
}
return true
}

func (n Namespace) Equals(n2 Namespace) bool {
return bytes.Equal(n.data, n2.data)
}
Expand All @@ -257,7 +253,7 @@ func (n Namespace) Compare(n2 Namespace) int {
}

// AddInt adds arbitrary int value to namespace, treating namespace as big-endian
// implementation of int. It could be helpful for users to create an adjacent namespaces.
// implementation of int. It could be helpful for users to create adjacent namespaces.
func (n Namespace) AddInt(val int) (Namespace, error) {
if val == 0 {
return n, nil
Expand Down
2 changes: 1 addition & 1 deletion share/random_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func RandomBlobNamespace() Namespace {
for {
id := RandomBlobNamespaceID()
namespace := MustNewV0Namespace(id)
if namespace.IsBlobNamespace() {
if err := namespace.ValidateForBlob(); err == nil {
return namespace
}
}
Expand Down
Loading