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!: refactor Namespace type #68

Merged
merged 11 commits into from
Jun 14, 2024
Merged

feat!: refactor Namespace type #68

merged 11 commits into from
Jun 14, 2024

Conversation

cmwaters
Copy link
Collaborator

Addresses: #66

@cmwaters cmwaters requested review from a team as code owners June 11, 2024 14:35
@cmwaters cmwaters requested review from evan-forbes, ninabarbakadze, ramin and renaynay and removed request for a team June 11, 2024 14:35
@celestia-bot celestia-bot requested review from a team June 11, 2024 14:35
rootulp
rootulp previously approved these changes Jun 11, 2024
blob/blob.go Show resolved Hide resolved
namespace/consts.go Outdated Show resolved Hide resolved
blob/blob.go Outdated
return bytes.Compare(blobs[i].Namespace().Bytes(), blobs[j].Namespace().Bytes()) < 0
ns1 := append([]byte{byte(blobs[i].NamespaceVersion)}, blobs[i].NamespaceId...)
ns2 := append([]byte{byte(blobs[j].NamespaceVersion)}, blobs[j].NamespaceId...)
return bytes.Compare(ns1, ns2) < 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not add method Compare(other *Blob) to Blob type instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I can do that

cristaloleg
cristaloleg previously approved these changes Jun 12, 2024
Copy link
Contributor

@cristaloleg cristaloleg left a comment

Choose a reason for hiding this comment

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

SGTM

blob/blob.go Outdated Show resolved Hide resolved
namespace/namespace.go Outdated Show resolved Hide resolved
@@ -7,8 +7,7 @@ import (
)

type Namespace struct {
Version uint8
ID []byte
data []byte
Copy link
Member

Choose a reason for hiding this comment

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

One option we haven't discussed yet is making Namespace map friendly by keeping this byte slice as a string(basically string(data)). I haven't seen this being needed that often, but intuitively one would wanna map namespaces to Blobs or else sometimes.

No actionable here, but a discussion point we haven't touched previously.

namespace/namespace.go Outdated Show resolved Hide resolved
blob/blob.go Show resolved Hide resolved
@celestia-bot celestia-bot requested a review from a team June 12, 2024 17:21
walldiss
walldiss previously approved these changes Jun 13, 2024
namespace/namespace.go Show resolved Hide resolved
blob/blob.go Outdated Show resolved Hide resolved
@cmwaters cmwaters dismissed stale reviews from walldiss and rootulp via 7e5737b June 13, 2024 09:23
@celestia-bot celestia-bot requested a review from a team June 13, 2024 09:23
return &Blob{
NamespaceId: ns.ID,
NamespaceId: ns.ID(),
Copy link
Member

Choose a reason for hiding this comment

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

This is a nit but I think it should be NamespaceID

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the proto generated struct and I don't intend to break that but I will keep your suggestion for when we create a go-native Blob implementation

Version: NamespaceVersionZero,
ID: append(bytes.Repeat([]byte{0x00}, NamespaceIDSize-1), lastByte),
}
return newNamespace(NamespaceVersionZero, append(bytes.Repeat([]byte{0x00}, NamespaceIDSize-1), lastByte))
Copy link
Member

Choose a reason for hiding this comment

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

nit but NamespaceVersionZero vs NamespaceVersionMax ? Can we make NamespaceVersionZero --> NamespaceVersionMin?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we were to go back we would probably start user namespaces at v1 and have NamespaceVersionMin as 0 for the primary reserved namespaces. For now v0 is both used by external users and by us. I think it would be more confusing to call it version min

Copy link
Member

Choose a reason for hiding this comment

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

Unfortunate but ok

}

func newNamespace(version uint8, id []byte) Namespace {
data := make([]byte, 1+len(id))
Copy link
Member

Choose a reason for hiding this comment

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

nit but do you want to point at NamespaceVersionSize + len(id)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I missed these parts when going through it again

func newNamespace(version uint8, id []byte) Namespace {
data := make([]byte, 1+len(id))
data[0] = version
copy(data[1:], id)
Copy link
Member

Choose a reason for hiding this comment

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

nit: NamespaceVersionIndex? for readability


// Version return this namespace's version
func (n Namespace) Version() uint8 {
return n.data[NamespaceVersionSize-1]
Copy link
Member

Choose a reason for hiding this comment

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

why not NamespaceVersionIndex

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was updated in two steps. I just missed this. Thanks for pointing it out

@celestia-bot celestia-bot requested a review from a team June 13, 2024 12:40
Wondertan
Wondertan previously approved these changes Jun 13, 2024
Comment on lines +1 to +2
go.work
go.work.sum
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need this, considering #67 was merged?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think so, else it's going to see this as a diff between the users branch and main and will want to check it in

Comment on lines +73 to +75
func (b *Blob) Compare(other *Blob) int {
return bytes.Compare(b.RawNamespace(), other.RawNamespace())
}
Copy link
Member

Choose a reason for hiding this comment

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

Usually, such methods are called Equals with the bool return value, but as long as this is not PR targeting Blob we can omit that and this method altogether

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Thats improvement over that comment

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I actually thinking comparing is more important because it's more common to want to order these things then see if the namespaces are equal

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Of course nothing wrong with having both

rootulp
rootulp previously approved these changes Jun 13, 2024
namespace/consts.go Outdated Show resolved Hide resolved
@cmwaters cmwaters dismissed stale reviews from rootulp and Wondertan via 56ed7ec June 13, 2024 14:42
@celestia-bot celestia-bot requested review from a team June 13, 2024 14:42
@celestia-bot celestia-bot requested review from a team June 14, 2024 09:04
@cmwaters cmwaters merged commit 72ff6e0 into main Jun 14, 2024
11 checks passed
@cmwaters cmwaters deleted the cal/namespace-type branch June 14, 2024 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants