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

chore(share): Ensure consistent naming for root/dah and datahash/hashNaming #3177

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 2 additions & 2 deletions core/eds.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ func extendShares(s [][]byte, options ...nmt.Option) (*rsmt2d.ExtendedDataSquare
}

// storeEDS will only store extended block if it is not empty and doesn't already exist.
func storeEDS(ctx context.Context, hash share.DataHash, eds *rsmt2d.ExtendedDataSquare, store *eds.Store) error {
func storeEDS(ctx context.Context, datahash share.DataHash, eds *rsmt2d.ExtendedDataSquare, store *eds.Store) error {
if eds == nil {
return nil
}
err := store.Put(ctx, hash, eds)
err := store.Put(ctx, datahash, eds)
if errors.Is(err, dagstore.ErrShardExists) {
// block with given root already exists, return nil
return nil
Expand Down
2 changes: 1 addition & 1 deletion core/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (ce *Exchange) getRangeByHeight(ctx context.Context, from, amount uint64) (
}

func (ce *Exchange) Get(ctx context.Context, hash libhead.Hash) (*header.ExtendedHeader, error) {
log.Debugw("requesting header", "hash", hash.String())
log.Debugw("requesting header", "datahash", hash.String())
block, err := ce.fetcher.GetBlockByHash(ctx, hash)
if err != nil {
return nil, fmt.Errorf("fetching block by hash %s: %w", hash.String(), err)
Expand Down
2 changes: 1 addition & 1 deletion das/coordinator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ func (m *mockSampler) discover(ctx context.Context, newHeight uint64, emit liste
emit(ctx, &header.ExtendedHeader{
Commit: &types.Commit{},
RawHeader: header.RawHeader{Height: int64(newHeight)},
DAH: &share.Root{RowRoots: make([][]byte, 0)},
DAH: &share.Dah{RowRoots: make([][]byte, 0)},
})
}

Expand Down
4 changes: 2 additions & 2 deletions das/daser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ type benchGetterStub struct {

func newBenchGetter() benchGetterStub {
return benchGetterStub{header: &header.ExtendedHeader{
DAH: &share.Root{RowRoots: make([][]byte, 0)}}}
DAH: &share.Dah{RowRoots: make([][]byte, 0)}}}
}

func (m benchGetterStub) GetByHeight(context.Context, uint64) (*header.ExtendedHeader, error) {
Expand All @@ -419,7 +419,7 @@ func (m getterStub) GetByHeight(_ context.Context, height uint64) (*header.Exten
return &header.ExtendedHeader{
Commit: &types.Commit{},
RawHeader: header.RawHeader{Height: int64(height)},
DAH: &share.Root{RowRoots: make([][]byte, 0)}}, nil
DAH: &share.Dah{RowRoots: make([][]byte, 0)}}, nil
}

func (m getterStub) GetRangeByHeight(
Expand Down
2 changes: 1 addition & 1 deletion das/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (w *worker) sample(ctx context.Context, timeout time.Duration, height uint6
"failed to sample header",
"type", w.state.jobType,
"height", h.Height(),
"hash", h.Hash(),
"datahash", h.Hash(),
"square width", len(h.DAH.RowRoots),
"data root", h.DAH.String(),
"err", err,
Expand Down
2 changes: 1 addition & 1 deletion docs/adr/adr-009-public-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ NetworkHead(ctx context.Context) (*header.ExtendedHeader, error)
// coordinates.
GetShare(ctx context.Context, root *Root, row, col int) (Share, error)
// GetEDS gets the full EDS identified by the given root.
GetEDS(ctx context.Context, root *share.Root) (*rsmt2d.ExtendedDataSquare, error)
GetEDS(ctx context.Context, root *share.Dah) (*rsmt2d.ExtendedDataSquare, error)
// GetSharesByNamespace gets all shares from an EDS within the given namespace.
// Shares are returned in a row-by-row order if the namespace spans multiple rows.
GetSharesByNamespace(
Expand Down
2 changes: 1 addition & 1 deletion docs/adr/adr-011-blocksync-overhaul-part-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ The `GetDAH` method returns the DAH (`share.Root`) of the EDS identified by `Dat

```go
// GetDAH returns the DataAvailabilityHeader for the EDS identified by DataHash.
func (s *Store) GetDAH(context.Context, share.DataHash) (*share.Root, error)
func (s *Store) GetDAH(context.Context, share.DataHash) (*share.Dah, error)
```

##### `eds.Store.Get`
Expand Down
4 changes: 2 additions & 2 deletions nodebuilder/share/cmd/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ var sharesAvailableCmd = &cobra.Command{
}
return struct {
Available bool `json:"available"`
Hash []byte `json:"dah_hash"`
DataHash []byte `json:"dah_hash"`
Reason error `json:"reason,omitempty"`
}{
Available: available,
Hash: []byte(args[0]),
DataHash: []byte(args[0]),
Reason: err,
}
}
Expand Down
4 changes: 2 additions & 2 deletions share/availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ var ErrNotAvailable = errors.New("share: data not available")

// Root represents root commitment to multiple Shares.
// In practice, it is a commitment to all the Data in a square.
type Root = da.DataAvailabilityHeader
type Dah = da.DataAvailabilityHeader

// NewRoot generates Root(DataAvailabilityHeader) using the
// provided extended data square.
func NewRoot(eds *rsmt2d.ExtendedDataSquare) (*Root, error) {
func NewRoot(eds *rsmt2d.ExtendedDataSquare) (*Dah, error) {
dah, err := da.NewDataAvailabilityHeader(eds)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions share/availability/full/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import (

// GetterWithRandSquare provides a share.Getter filled with 'n' NMT
// trees of 'n' random shares, essentially storing a whole square.
func GetterWithRandSquare(t *testing.T, n int) (share.Getter, *share.Root) {
func GetterWithRandSquare(t *testing.T, n int) (share.Getter, *share.Dah) {
bServ := ipld.NewMemBlockservice()
getter := getters.NewIPLDGetter(bServ)
return getter, availability_test.RandFillBS(t, n, bServ)
}

// RandNode creates a Full Node filled with a random block of the given size.
func RandNode(dn *availability_test.TestDagNet, squareSize int) (*availability_test.TestNode, *share.Root) {
func RandNode(dn *availability_test.TestDagNet, squareSize int) (*availability_test.TestNode, *share.Dah) {
nd := Node(dn)
return nd, availability_test.RandFillBS(dn.T, squareSize, nd.BlockService)
}
Expand Down
2 changes: 1 addition & 1 deletion share/availability/light/availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (la *ShareAvailability) SharesAvailable(ctx context.Context, header *header
return nil
}

func rootKey(root *share.Root) datastore.Key {
func rootKey(root *share.Dah) datastore.Key {
return datastore.NewKey(root.String())
}

Expand Down
2 changes: 1 addition & 1 deletion share/availability/light/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func EmptyGetter() (share.Getter, blockservice.BlockService) {
}

// RandNode creates a Light Node filled with a random block of the given size.
func RandNode(dn *availability_test.TestDagNet, squareSize int) (*availability_test.TestNode, *share.Root) {
func RandNode(dn *availability_test.TestDagNet, squareSize int) (*availability_test.TestNode, *share.Dah) {
nd := Node(dn)
return nd, availability_test.RandFillBS(dn.T, squareSize, nd.BlockService)
}
Expand Down
4 changes: 2 additions & 2 deletions share/availability/test/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import (
)

// RandFillBS fills the given BlockService with a random block of a given size.
func RandFillBS(t *testing.T, n int, bServ blockservice.BlockService) *share.Root {
func RandFillBS(t *testing.T, n int, bServ blockservice.BlockService) *share.Dah {
shares := sharetest.RandShares(t, n*n)
return FillBS(t, bServ, shares)
}

// FillBS fills the given BlockService with the given shares.
func FillBS(t *testing.T, bServ blockservice.BlockService, shares []share.Share) *share.Root {
func FillBS(t *testing.T, bServ blockservice.BlockService, shares []share.Share) *share.Dah {
eds, err := ipld.AddShares(context.TODO(), shares, bServ)
require.NoError(t, err)
dah, err := share.NewRoot(eds)
Expand Down
2 changes: 1 addition & 1 deletion share/eds/edstest/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func RandEDSWithNamespace(
t require.TestingT,
namespace share.Namespace,
size int,
) (*rsmt2d.ExtendedDataSquare, *share.Root) {
) (*rsmt2d.ExtendedDataSquare, *share.Dah) {
shares := sharetest.RandSharesWithNamespace(t, namespace, size*size)
eds, err := rsmt2d.ComputeExtendedDataSquare(shares, share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(size)))
require.NoError(t, err, "failure to recompute the extended data square")
Expand Down
8 changes: 4 additions & 4 deletions share/eds/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func (s *Store) carBlockstore(
}

// GetDAH returns the DataAvailabilityHeader for the EDS identified by DataHash.
func (s *Store) GetDAH(ctx context.Context, root share.DataHash) (*share.Root, error) {
func (s *Store) GetDAH(ctx context.Context, root share.DataHash) (*share.Dah, error) {
ctx, span := tracer.Start(ctx, "store/car-dah")
tnow := time.Now()
r, err := s.getDAH(ctx, root)
Expand All @@ -414,7 +414,7 @@ func (s *Store) GetDAH(ctx context.Context, root share.DataHash) (*share.Root, e
return r, err
}

func (s *Store) getDAH(ctx context.Context, root share.DataHash) (*share.Root, error) {
func (s *Store) getDAH(ctx context.Context, root share.DataHash) (*share.Dah, error) {
r, err := s.getCAR(ctx, root)
if err != nil {
return nil, fmt.Errorf("eds/store: failed to get CAR file: %w", err)
Expand All @@ -434,13 +434,13 @@ func (s *Store) getDAH(ctx context.Context, root share.DataHash) (*share.Root, e
}

// dahFromCARHeader returns the DataAvailabilityHeader stored in the CIDs of a CARv1 header.
func dahFromCARHeader(carHeader *carv1.CarHeader) *share.Root {
func dahFromCARHeader(carHeader *carv1.CarHeader) *share.Dah {
rootCount := len(carHeader.Roots)
rootBytes := make([][]byte, 0, rootCount)
for _, root := range carHeader.Roots {
rootBytes = append(rootBytes, ipld.NamespacedSha256FromCID(root))
}
return &share.Root{
return &share.Dah{
RowRoots: rootBytes[:rootCount/2],
ColumnRoots: rootBytes[rootCount/2:],
}
Expand Down
2 changes: 1 addition & 1 deletion share/eds/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ func newStore(t *testing.T) (*Store, error) {
return NewStore(DefaultParameters(), t.TempDir(), ds)
}

func randomEDS(t *testing.T) (*rsmt2d.ExtendedDataSquare, *share.Root) {
func randomEDS(t *testing.T) (*rsmt2d.ExtendedDataSquare, *share.Dah) {
eds := edstest.RandEDS(t, 4)
dah, err := share.NewRoot(eds)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions share/eds/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func closeAndLog(name string, closer io.Closer) {
func RetrieveNamespaceFromStore(
ctx context.Context,
store *Store,
dah *share.Root,
dah *share.Dah,
namespace share.Namespace,
) (shares share.NamespacedShares, err error) {
if err = namespace.ValidateForData(); err != nil {
Expand Down Expand Up @@ -111,7 +111,7 @@ func RetrieveNamespaceFromStore(
func CollectSharesByNamespace(
ctx context.Context,
bg blockservice.BlockGetter,
root *share.Root,
root *share.Dah,
namespace share.Namespace,
) (shares share.NamespacedShares, err error) {
ctx, span := tracer.Start(ctx, "collect-shares-by-namespace", trace.WithAttributes(
Expand Down
4 changes: 2 additions & 2 deletions share/empty.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

// EmptyRoot returns Root of the empty block EDS.
func EmptyRoot() *Root {
func EmptyRoot() *Dah {
initEmpty()
return emptyBlockRoot
}
Expand All @@ -31,7 +31,7 @@ func EmptyBlockShares() []Share {

var (
emptyMu sync.Mutex
emptyBlockRoot *Root
emptyBlockRoot *Dah
emptyBlockEDS *rsmt2d.ExtendedDataSquare
emptyBlockShares []Share
)
Expand Down
2 changes: 1 addition & 1 deletion share/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type NamespacedRow struct {
}

// Verify validates NamespacedShares by checking every row with nmt inclusion proof.
func (ns NamespacedShares) Verify(root *Root, namespace Namespace) error {
func (ns NamespacedShares) Verify(root *Dah, namespace Namespace) error {
var originalRoots [][]byte
for _, row := range root.RowRoots {
if !namespace.IsOutsideRange(row, row) {
Expand Down
12 changes: 6 additions & 6 deletions share/getters/getter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ func TestStoreGetter(t *testing.T) {
assert.True(t, randEds.Equals(retrievedEDS))

// root not found
emptyRoot := da.MinDataAvailabilityHeader()
eh.DAH = &emptyRoot
emptyDah := da.MinDataAvailabilityHeader()
eh.DAH = &emptyDah
_, err = sg.GetEDS(ctx, eh)
require.ErrorIs(t, err, share.ErrNotFound)
})
Expand All @@ -99,8 +99,8 @@ func TestStoreGetter(t *testing.T) {
require.Empty(t, emptyShares.Flatten())

// root not found
emptyRoot := da.MinDataAvailabilityHeader()
eh.DAH = &emptyRoot
emptyDah := da.MinDataAvailabilityHeader()
eh.DAH = &emptyDah
_, err = sg.GetSharesByNamespace(ctx, eh, namespace)
require.ErrorIs(t, err, share.ErrNotFound)
})
Expand Down Expand Up @@ -232,8 +232,8 @@ func TestIPLDGetter(t *testing.T) {
require.Empty(t, emptyShares.Flatten())

// nid doesn't exist in root
emptyRoot := da.MinDataAvailabilityHeader()
eh.DAH = &emptyRoot
emptyDah := da.MinDataAvailabilityHeader()
eh.DAH = &emptyDah
emptyShares, err = sg.GetSharesByNamespace(ctx, eh, namespace)
require.NoError(t, err)
require.Empty(t, emptyShares.Flatten())
Expand Down
2 changes: 1 addition & 1 deletion share/getters/shrex.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (sg *ShrexGetter) GetEDS(ctx context.Context, header *header.ExtendedHeader
peer, setStatus, getErr := sg.peerManager.Peer(ctx, header.DAH.Hash(), header.Height())
if getErr != nil {
log.Debugw("eds: couldn't find peer",
"hash", header.DAH.String(),
"datahash", header.DAH.String(),
"err", getErr,
"finished (s)", time.Since(start))
sg.metrics.recordEDSAttempt(ctx, attempt, false)
Expand Down
2 changes: 1 addition & 1 deletion share/getters/shrex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func newStore(t *testing.T) (*eds.Store, error) {
return eds.NewStore(eds.DefaultParameters(), t.TempDir(), ds)
}

func generateTestEDS(t *testing.T) (*rsmt2d.ExtendedDataSquare, *share.Root, share.Namespace) {
func generateTestEDS(t *testing.T) (*rsmt2d.ExtendedDataSquare, *share.Dah, share.Namespace) {
eds := edstest.RandEDS(t, 4)
dah, err := share.NewRoot(eds)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion share/getters/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (seg *SingleEDSGetter) GetSharesByNamespace(context.Context, *header.Extend
panic("SingleEDSGetter: GetSharesByNamespace is not implemented")
}

func (seg *SingleEDSGetter) checkRoot(root *share.Root) error {
func (seg *SingleEDSGetter) checkRoot(root *share.Dah) error {
dah, err := da.NewDataAvailabilityHeader(seg.EDS)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion share/ipld/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// FilterRootByNamespace returns the row roots from the given share.Root that contain the namespace.
func FilterRootByNamespace(root *share.Root, namespace share.Namespace) []cid.Cid {
func FilterRootByNamespace(root *share.Dah, namespace share.Namespace) []cid.Cid {
rowRootCIDs := make([]cid.Cid, 0, len(root.RowRoots))
for _, row := range root.RowRoots {
if !namespace.IsOutsideRange(row, row) {
Expand Down
4 changes: 2 additions & 2 deletions share/p2p/shrexeds/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (c *Client) RequestEDS(
if err != p2p.ErrNotFound {
log.Warnw("client: eds request to peer failed",
"peer", peer.String(),
"hash", dataHash.String(),
"datahash", dataHash.String(),
"err", err)
}

Expand All @@ -93,7 +93,7 @@ func (c *Client) doRequest(

c.setStreamDeadlines(ctx, stream)

req := &pb.EDSRequest{Hash: dataHash}
req := &pb.EDSRequest{Datahash: dataHash}

// request ODS
log.Debugw("client: requesting ods", "hash", dataHash.String(), "peer", to.String())
Expand Down
Loading
Loading