Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed Oct 7, 2024
1 parent aad5872 commit 3c01d85
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 85 deletions.
6 changes: 5 additions & 1 deletion api/gateway/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ func (h *Handler) handleDataByNamespaceRequest(w http.ResponseWriter, r *http.Re
}
}

func (h *Handler) getShares(ctx context.Context, height uint64, namespace gosquare.Namespace) ([]gosquare.Share, error) {
func (h *Handler) getShares(
ctx context.Context,
height uint64,
namespace gosquare.Namespace,
) ([]gosquare.Share, error) {
header, err := h.header.GetByHeight(ctx, height)
if err != nil {
return nil, err
Expand Down
1 change: 0 additions & 1 deletion blob/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func BlobsToShares(nodeBlobs ...*Blob) ([]gosquare.Share, error) {
if err != nil {
return nil, fmt.Errorf("failed to split blob at index: %d: %w", i, err)
}

}
return splitter.Export(), nil
}
Expand Down
3 changes: 2 additions & 1 deletion blob/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ func TestService_GetAllWithoutPadding(t *testing.T) {
rawShares = append(rawShares, append(sh, padding, padding, padding)...)

sh, err = BlobsToShares(blobs[4])
require.NoError(t, err)
rawShares = append(rawShares, sh...)
service := createService(ctx, t, rawShares)

Expand Down Expand Up @@ -953,7 +954,7 @@ func proveAndVerifyShareCommitments(t *testing.T, blobSize int) {
msgs, blobs, nss, eds, _, _, dataRoot := edstest.GenerateTestBlock(t, blobSize, 10)
for msgIndex, msg := range msgs {
t.Run(fmt.Sprintf("msgIndex=%d", msgIndex), func(t *testing.T) {
blb, err := NewBlob(uint8(blobs[msgIndex].ShareVersion()), nss[msgIndex], blobs[msgIndex].Data(), nil)
blb, err := NewBlob(blobs[msgIndex].ShareVersion(), nss[msgIndex], blobs[msgIndex].Data(), nil)
require.NoError(t, err)
blobShares, err := BlobsToShares(blb)
require.NoError(t, err)
Expand Down
11 changes: 5 additions & 6 deletions share/availability/full/testing.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package full

//
//import (
// import (
// "context"
//
// "testing"
Expand All @@ -20,27 +19,27 @@ package full
//
//// GetterWithRandSquare provides a gosquare.Getter filled with 'n' NMT
//// trees of 'n' random shares, essentially storing a whole share.
//func GetterWithRandSquare(t *testing.T, n int) (share.Getter, *share.AxisRoots) {
// func GetterWithRandSquare(t *testing.T, n int) (share.Getter, *share.AxisRoots) {
// bServ := ipld.NewMemBlockservice()
// getter := shwap.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.AxisRoots) {
// func RandNode(dn *availability_test.TestDagNet, squareSize int) (*availability_test.TestNode, *share.AxisRoots) {
// nd := Node(dn)
// return nd, availability_test.RandFillBS(dn.T, squareSize, nd.BlockService)
//}
//
//// Node creates a new empty Full Node.
//func Node(dn *availability_test.TestDagNet) *availability_test.TestNode {
// func Node(dn *availability_test.TestDagNet) *availability_test.TestNode {
// nd := dn.NewTestNode()
// nd.Getter = getters.NewIPLDGetter(nd.BlockService)
// nd.Availability = TestAvailability(dn.T, nd.Getter)
// return nd
//}
//
//func TestAvailability(t *testing.T, getter share.Getter) *ShareAvailability {
// func TestAvailability(t *testing.T, getter share.Getter) *ShareAvailability {
// params := discovery.DefaultParameters()
// params.AdvertiseInterval = time.Second
// params.PeersLimit = 10
Expand Down
48 changes: 0 additions & 48 deletions share/shwap/p2p/shrex/shrex_getter/shrex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package shrex_getter //nolint:stylecheck // underscore in pkg name will be fixed

import (
"context"
"encoding/binary"
"errors"
"sync/atomic"
"testing"
"time"
Expand Down Expand Up @@ -348,49 +346,3 @@ func newEDSClientServer(
require.NoError(t, err)
return client, server
}

// addToNamespace adds arbitrary int value to namespace, treating namespace as big-endian
// implementation of int
func addToNamespace(namespace gosquare.Namespace, val int) (gosquare.Namespace, error) {
if val == 0 {
return namespace, nil
}
// Convert the input integer to a byte slice and add it to result slice
result := make([]byte, gosquare.NamespaceSize)
if val > 0 {
binary.BigEndian.PutUint64(result[gosquare.NamespaceSize-8:], uint64(val))
} else {
binary.BigEndian.PutUint64(result[gosquare.NamespaceSize-8:], uint64(-val))
}

// Perform addition byte by byte
var carry int
for i := gosquare.NamespaceSize - 1; i >= 0; i-- {
var sum int
if val > 0 {
sum = int(namespace.Bytes()[i]) + int(result[i]) + carry
} else {
sum = int(namespace.Bytes()[i]) - int(result[i]) + carry
}

switch {
case sum > 255:
carry = 1
sum -= 256
case sum < 0:
carry = -1
sum += 256
default:
carry = 0
}

result[i] = uint8(sum)
}

// Handle any remaining carry
if carry != 0 {
return gosquare.Namespace{}, errors.New("namespace overflow")
}

return gosquare.NewNamespaceFromBytes(result)
}
8 changes: 6 additions & 2 deletions share/shwap/row_namespace_data_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ const RowNamespaceDataIDSize = RowIDSize + gosquare.NamespaceSize
// RowNamespaceDataID uniquely identifies a piece of namespaced data within a row of an Extended
// Data Square (EDS).
type RowNamespaceDataID struct {
RowID // Embedded RowID representing the specific row in the EDS.
DataNamespace gosquare.Namespace // DataNamespace is a string representation of the namespace to facilitate comparisons.
RowID // Embedded RowID representing the specific row in the EDS.
// DataNamespace is a string representation of the namespace to facilitate comparisons.
DataNamespace gosquare.Namespace
}

// NewRowNamespaceDataID creates a new RowNamespaceDataID with the specified parameters. It
Expand Down Expand Up @@ -56,6 +57,9 @@ func RowNamespaceDataIDFromBinary(data []byte) (RowNamespaceDataID, error) {
}

ns, err := gosquare.NewNamespaceFromBytes(data[RowIDSize:])
if err != nil {
return RowNamespaceDataID{}, fmt.Errorf("invalid namespace format: %w", err)
}
rndid := RowNamespaceDataID{
RowID: rid,
DataNamespace: ns,
Expand Down
52 changes: 26 additions & 26 deletions share/shwap/row_namespace_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ func TestNamespacedRowFromShares(t *testing.T) {
}
}

//func TestNamespacedRowFromSharesNonIncluded(t *testing.T) {
// // TODO: this will fail until absence proof support is added
// func TestNamespacedRowFromSharesNonIncluded(t *testing.T) {
// //TODO: this will fail until absence proof support is added
// t.Skip()
//
// const odsSize = 8
// // Test absent namespace
// //Test absent namespace
// shares := gosquare.RandShares( odsSize)
// absentNs, err := share.GetNamespace(shares[0]).AddInt(1)
// require.NoError(t, err)
Expand All @@ -63,29 +63,29 @@ func TestNamespacedRowFromShares(t *testing.T) {
// require.True(t, nr.Proof.IsOfAbsence())
//}

//func TestValidateNamespacedRow(t *testing.T) {
// ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
// t.Cleanup(cancel)
//
// const odsSize = 8
// sharesAmount := odsSize * odsSize
// namespace := sharetest.RandV0Namespace()
// for amount := 1; amount < sharesAmount; amount++ {
// randEDS, root := edstest.RandEDSWithNamespace(t, namespace, amount, odsSize)
// rsmt2d := &eds.Rsmt2D{ExtendedDataSquare: randEDS}
// nd, err := eds.NamespaceData(ctx, rsmt2d, namespace)
// require.NoError(t, err)
// require.True(t, len(nd) > 0)
//
// rowIdxs := share.RowsWithNamespace(root, namespace)
// require.Len(t, nd, len(rowIdxs))
//
// for i, rowIdx := range rowIdxs {
// err = nd[i].Verify(root, namespace, rowIdx)
// require.NoError(t, err)
// }
// }
//}
func TestValidateNamespacedRow(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
t.Cleanup(cancel)

const odsSize = 8
sharesAmount := odsSize * odsSize
namespace := gosquare.RandomNamespace()
for amount := 1; amount < sharesAmount; amount++ {
randEDS, root := edstest.RandEDSWithNamespace(t, namespace, amount, odsSize)
rsmt2d := &eds.Rsmt2D{ExtendedDataSquare: randEDS}
nd, err := eds.NamespaceData(ctx, rsmt2d, namespace)
require.NoError(t, err)
require.True(t, len(nd) > 0)

rowIdxs := share.RowsWithNamespace(root, namespace)
require.Len(t, nd, len(rowIdxs))

for i, rowIdx := range rowIdxs {
err = nd[i].Verify(root, namespace, rowIdx)
require.NoError(t, err)
}
}
}

func TestNamespacedRowProtoEncoding(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
Expand Down

0 comments on commit 3c01d85

Please sign in to comment.