celestiaorg / go-square

A library for encoding blobs into a 2D square of evenly sized chunks designed for sampling and reconstruction
Apache License 2.0
13 stars 16 forks source link

Canonicalise Namespace and Share types #66

Closed cmwaters closed 1 month ago

cmwaters commented 2 months ago

Summary

We have different constructions of the Share and Namespace types across celestia repos. We should converge on types and have them standardised across repos.

https://github.com/celestiaorg/celestia-node/blob/762bd93b1b6242bdd5660172d1b32fcade144a8c/share/namespace.go#L34

https://github.com/celestiaorg/go-square/blob/fd78256df076539ef5e13cd271276f058a167d8c/namespace/namespace.go#L8-L11

https://github.com/celestiaorg/celestia-node/blob/762bd93b1b6242bdd5660172d1b32fcade144a8c/share/share.go#L29

https://github.com/celestiaorg/go-square/blob/fd78256df076539ef5e13cd271276f058a167d8c/shares/shares.go#L12-L14

Proposal

Agreed upon types:

type Namespace struct {
    data []byte
}

type Share struct {
    data []byte
}

We have decided to encapsulate the types as this completely prevents users from misusing them (i.e. incorrect length).

Encapsulation also allows us to make changes in the future that don't break users such as caching certain bytes in the struct i.e. namespace in the share struct.

The other option considered was to use type Namespace []byte

For Admin Use

cmwaters commented 1 month ago

This has now been resolved (in v2)