Skip to content

Commit

Permalink
use helpers from share everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
Wondertan committed Jun 26, 2023
1 parent c9370c7 commit 2282bd2
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions share/availability/light/availability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ func TestService_GetSharesByNamespace(t *testing.T) {
totalShares := squareSize * squareSize
getter, bServ := EmptyGetter()
randShares := sharetest.RandShares(t, totalShares)
lastNID := randShares[totalShares-1][:share.NamespaceSize]
lastNID := share.GetNamespace(randShares[totalShares-1])
for i := totalShares / 2; i < totalShares; i++ {
copy(randShares[i][:share.NamespaceSize], lastNID)
copy(share.GetNamespace(randShares[i]), lastNID)
}
root := availability_test.FillBS(t, bServ, randShares)

Expand Down
2 changes: 1 addition & 1 deletion share/eds/byzantine/bad_encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (p *BadEncodingProof) Validate(hdr libhead.Header) error {
}
// NMTree commits the additional namespace while rsmt2d does not know about, so we trim it
// this is ugliness from NMTWrapper that we have to embrace ¯\_(ツ)_/¯
shares[index] = shr.Share[share.NamespaceSize:]
shares[index] = share.GetData(shr.Share)
}

odsWidth := uint64(len(merkleRowRoots) / 2)
Expand Down
4 changes: 2 additions & 2 deletions share/eds/eds.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func prependNamespace(quadrant int, shr []byte) []byte {
namespacedShare := make([]byte, 0, share.NamespaceSize+share.Size)
switch quadrant {
case 0:
return append(append(namespacedShare, shr[:share.NamespaceSize]...), shr...)
return append(append(namespacedShare, share.GetNamespace(shr)...), shr...)
case 1, 2, 3:
return append(append(namespacedShare, share.ParitySharesNamespace...), shr...)
default:
Expand Down Expand Up @@ -271,7 +271,7 @@ func ReadEDS(ctx context.Context, r io.Reader, root share.DataHash) (eds *rsmt2d
}
// the stored first quadrant shares are wrapped with the namespace twice.
// we cut it off here, because it is added again while importing to the tree below
shares[i] = block.RawData()[share.NamespaceSize:]
shares[i] = share.GetData(block.RawData())
}

eds, err = rsmt2d.ComputeExtendedDataSquare(
Expand Down
2 changes: 1 addition & 1 deletion share/eds/eds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestWriteEDSStartsWithLeaves(t *testing.T) {
block, err := reader.Next()
require.NoError(t, err, "error getting first block")

require.Equal(t, block.RawData()[share.NamespaceSize:], eds.GetCell(0, 0))
require.Equal(t, share.GetData(block.RawData()), eds.GetCell(0, 0))
}

func TestWriteEDSIncludesRoots(t *testing.T) {
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 @@ -15,7 +15,7 @@ import (
func RandByzantineEDS(t *testing.T, size int) *rsmt2d.ExtendedDataSquare {
eds := RandEDS(t, size)
shares := share.ExtractEDS(eds)
copy(shares[0][share.NamespaceSize:], shares[1][share.NamespaceSize:])
copy(share.GetData(shares[0]), share.GetData(shares[1])) // corrupting eds
eds, err := rsmt2d.ImportExtendedDataSquare(shares, share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(size)))
require.NoError(t, err, "failure to recompute the extended data square")
return eds
Expand Down
2 changes: 1 addition & 1 deletion share/eds/ods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestODSReader(t *testing.T) {
assert.NoError(t, err)

// check that original data from eds is same as data from reader
assert.Equal(t, original, block.RawData()[share.NamespaceSize:])
assert.Equal(t, original, share.GetData(block.RawData()))
}
}

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 @@ -78,7 +78,7 @@ func TestEDSStore(t *testing.T) {
original := eds.GetCell(uint(i), uint(j))
block, err := carReader.Next()
assert.NoError(t, err)
assert.Equal(t, original, block.RawData()[share.NamespaceSize:])
assert.Equal(t, original, share.GetData(block.RawData()))
}
}
})
Expand Down
4 changes: 2 additions & 2 deletions share/getters/getter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func randomEDSWithDoubledNamespace(t *testing.T, size int) (*rsmt2d.ExtendedData
// D _ _ _
// _ _ _ _
// where the D shares have a common namespace.
copy(randShares[idx2][:share.NamespaceSize], randShares[idx1][:share.NamespaceSize])
copy(share.GetNamespace(randShares[idx2]), share.GetNamespace(randShares[idx1]))

eds, err := rsmt2d.ComputeExtendedDataSquare(
randShares,
Expand All @@ -262,5 +262,5 @@ func randomEDSWithDoubledNamespace(t *testing.T, size int) (*rsmt2d.ExtendedData
require.NoError(t, err, "failure to recompute the extended data square")
dah := da.NewDataAvailabilityHeader(eds)

return eds, randShares[idx1][:share.NamespaceSize], dah
return eds, share.GetNamespace(randShares[idx1]), dah
}
2 changes: 1 addition & 1 deletion share/ipld/get_shares.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ func GetSharesByNamespace(
func leafToShare(nd format.Node) share.Share {
// * Additional namespace is prepended so that parity data can be identified with a parity
// namespace, which we cut off
return nd.RawData()[share.NamespaceSize:]
return share.GetData(nd.RawData())
}
8 changes: 4 additions & 4 deletions share/ipld/get_shares_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func TestCollectLeavesByNamespace_IncompleteData(t *testing.T) {
// set all shares to the same namespace id
namespace := share.GetNamespace(shares[0])
for _, shr := range shares {
copy(shr[:share.NamespaceSize], namespace)
copy(share.GetNamespace(shr), namespace)
}

eds, err := AddShares(ctx, shares, bServ)
Expand Down Expand Up @@ -288,7 +288,7 @@ func TestCollectLeavesByNamespace_MultipleRowsContainingSameNamespaceId(t *testi
shares := sharetest.RandShares(t, 16)

// set all shares to the same namespace and data but the last one
nid := shares[0][:share.NamespaceSize]
namespace := share.GetNamespace(shares[0])
commonNamespaceData := shares[0]

for i, nspace := range shares {
Expand All @@ -304,7 +304,7 @@ func TestCollectLeavesByNamespace_MultipleRowsContainingSameNamespaceId(t *testi

for _, row := range eds.RowRoots() {
rcid := MustCidFromNamespacedSha256(row)
data := NewNamespaceData(len(shares), nid, WithLeaves())
data := NewNamespaceData(len(shares), namespace, WithLeaves())
err := data.CollectLeavesByNamespace(ctx, bServ, rcid)
if errors.Is(err, ErrNamespaceOutsideRange) {
continue
Expand All @@ -314,7 +314,7 @@ func TestCollectLeavesByNamespace_MultipleRowsContainingSameNamespaceId(t *testi
for _, node := range leaves {
// test that the data returned by collectLeavesByNamespace for nid
// matches the commonNamespaceData that was copied across almost all data
assert.Equal(t, commonNamespaceData, node.RawData()[share.NamespaceSize:])
assert.Equal(t, commonNamespaceData, share.GetData(node.RawData()))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions share/sharetest/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ func RandShares(t require.TestingT, total int) []share.Share {
shares := make([]share.Share, total)
for i := range shares {
shr := make([]byte, share.Size)
copy(shr[:share.NamespaceSize], RandV0Namespace())
copy(share.GetNamespace(shr), RandV0Namespace())
rndMu.Lock()
_, err := rnd.Read(shr[share.NamespaceSize:])
_, err := rnd.Read(share.GetData(shr))
rndMu.Unlock()
require.NoError(t, err)
shares[i] = shr
Expand Down

0 comments on commit 2282bd2

Please sign in to comment.