diff --git a/api/docgen/examples.go b/api/docgen/examples.go index 9b12994be9..acb5fdb08a 100644 --- a/api/docgen/examples.go +++ b/api/docgen/examples.go @@ -22,14 +22,15 @@ import ( "github.com/celestiaorg/go-fraud" libhead "github.com/celestiaorg/go-header" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/blob" "github.com/celestiaorg/celestia-node/das" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/nodebuilder/node" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" "github.com/celestiaorg/celestia-node/state" ) @@ -79,7 +80,7 @@ var ExampleValues = map[reflect.Type]interface{}{ } func init() { - addToExampleValues(share.EmptyEDS()) + addToExampleValues(square.EmptyEDS()) addr, err := sdk.AccAddressFromBech32("celestia1377k5an3f94v6wyaceu0cf4nq6gk2jtpc46g7h") if err != nil { panic(err) @@ -165,7 +166,7 @@ func init() { // randomly generated namespace that's used in the blob example above // (AAAAAAAAAAAAAAAAAAAAAAAAAAAAAMJ/xGlNMdE=) - namespace, err := share.NewBlobNamespaceV0([]byte{0xc2, 0x7f, 0xc4, 0x69, 0x4d, 0x31, 0xd1}) + namespace, err := share.NewV0Namespace([]byte{0xc2, 0x7f, 0xc4, 0x69, 0x4d, 0x31, 0xd1}) if err != nil { panic(err) } diff --git a/api/gateway/availability.go b/api/gateway/availability.go index e8e96083d5..f9372018af 100644 --- a/api/gateway/availability.go +++ b/api/gateway/availability.go @@ -8,7 +8,7 @@ import ( "github.com/gorilla/mux" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" ) const heightAvailabilityEndpoint = "/data_available" @@ -45,7 +45,7 @@ func (h *Handler) handleHeightAvailabilityRequest(w http.ResponseWriter, r *http if werr != nil { log.Errorw("serving request", "endpoint", heightAvailabilityEndpoint, "err", err) } - case errors.Is(err, share.ErrNotAvailable): + case errors.Is(err, square.ErrNotAvailable): resp, err := json.Marshal(&AvailabilityResponse{Available: false}) if err != nil { writeError(w, http.StatusInternalServerError, heightAvailabilityEndpoint, err) diff --git a/api/gateway/share.go b/api/gateway/share.go index cdd40e1d2b..f6b5156ab4 100644 --- a/api/gateway/share.go +++ b/api/gateway/share.go @@ -9,9 +9,7 @@ import ( "github.com/gorilla/mux" - "github.com/celestiaorg/go-square/shares" - - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/go-square/v2/share" ) const ( @@ -105,11 +103,7 @@ func (h *Handler) getShares(ctx context.Context, height uint64, namespace share. } func dataFromShares(input []share.Share) (data [][]byte, err error) { - appShares, err := shares.FromBytes(input) - if err != nil { - return nil, err - } - sequences, err := shares.ParseShares(appShares, false) + sequences, err := share.ParseShares(input, false) if err != nil { return nil, err } @@ -129,13 +123,18 @@ func parseGetByNamespaceArgs(r *http.Request) (height uint64, namespace share.Na if strHeight, ok := vars[heightKey]; ok { height, err = strconv.ParseUint(strHeight, 10, 64) if err != nil { - return 0, nil, err + return 0, share.Namespace{}, err } } hexNamespace := vars[namespaceKey] - namespace, err = hex.DecodeString(hexNamespace) + nsString, err := hex.DecodeString(hexNamespace) + if err != nil { + return 0, share.Namespace{}, err + } + ns, err := share.NewNamespaceFromBytes(nsString) if err != nil { - return 0, nil, err + return 0, share.Namespace{}, err } - return height, namespace, namespace.ValidateForData() + namespace = ns + return height, namespace, share.ValidateForData(namespace) } diff --git a/api/gateway/share_test.go b/api/gateway/share_test.go index 1928c721ec..b51d043f73 100644 --- a/api/gateway/share_test.go +++ b/api/gateway/share_test.go @@ -6,11 +6,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - "github.com/celestiaorg/go-square/blob" - "github.com/celestiaorg/go-square/shares" - - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/go-square/v2/share" ) func Test_dataFromShares(t *testing.T) { @@ -20,17 +16,12 @@ func Test_dataFromShares(t *testing.T) { []byte("BEEEEAHP"), } - ns := sharetest.RandV0Namespace() - sss := shares.NewSparseShareSplitter() + ns := share.RandomNamespace() + sss := share.NewSparseShareSplitter() for _, data := range testData { - b := blob.Blob{ - Data: data, - NamespaceId: ns.ID(), - NamespaceVersion: uint32(ns.Version()), - ShareVersion: uint32(appconsts.ShareVersionZero), - } - err := sss.Write(&b) + b, err := share.NewBlob(ns, data, share.ShareVersionZero, nil) require.NoError(t, err) + require.NoError(t, sss.Write(b)) } sssShares := sss.Export() @@ -41,7 +32,9 @@ func Test_dataFromShares(t *testing.T) { rawSSSShares[i] = d } - parsedSSSShares, err := dataFromShares(rawSSSShares) + shrs, err := share.FromBytes(rawSSSShares) + require.NoError(t, err) + parsedSSSShares, err := dataFromShares(shrs) require.NoError(t, err) require.Equal(t, testData, parsedSSSShares) diff --git a/blob/blob.go b/blob/blob.go index 3b26e5f198..6f4029c0b4 100644 --- a/blob/blob.go +++ b/blob/blob.go @@ -6,23 +6,21 @@ import ( "errors" "fmt" - "github.com/tendermint/tendermint/crypto/merkle" - - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - v2 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v2" - "github.com/celestiaorg/go-square/blob" - "github.com/celestiaorg/go-square/inclusion" - "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + app "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v2" + "github.com/celestiaorg/go-square/merkle" + "github.com/celestiaorg/go-square/v2/inclusion" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" - - "github.com/celestiaorg/celestia-node/share" ) // appVersion is the current application version of celestia-app. -const appVersion = v2.Version +const appVersion = app.Version var errEmptyShares = errors.New("empty shares") +var subtreeRootThreshold = appconsts.SubtreeRootThreshold(appVersion) + // The Proof is a set of nmt proofs that can be verified only through // the included method (due to limitation of the nmt https://github.com/celestiaorg/nmt/issues/218). // Proof proves the WHOLE namespaced data to the row roots. @@ -61,14 +59,10 @@ func (p Proof) equal(input Proof) error { // Blob represents any application-specific binary data that anyone can submit to Celestia. type Blob struct { - *blob.Blob `json:"blob"` + *share.Blob `json:"blob"` Commitment Commitment `json:"commitment"` - // the celestia-node's namespace type - // this is to avoid converting to and from app's type - namespace share.Namespace - // index represents the index of the blob's first share in the EDS. // Only retrieved, on-chain blobs will have the index set. Default is -1. index int @@ -77,35 +71,43 @@ type Blob struct { // NewBlobV0 constructs a new blob from the provided Namespace and data. // The blob will be formatted as v0 shares. func NewBlobV0(namespace share.Namespace, data []byte) (*Blob, error) { - return NewBlob(appconsts.ShareVersionZero, namespace, data) + return NewBlob(share.ShareVersionZero, namespace, data, nil) +} + +// NewBlobV1 constructs a new blob from the provided Namespace and data. +// The blob will be formatted as v0 shares. +func NewBlobV1(namespace share.Namespace, data, signer []byte) (*Blob, error) { + return NewBlob(share.ShareVersionOne, namespace, data, signer) } // NewBlob constructs a new blob from the provided Namespace, data and share version. -func NewBlob(shareVersion uint8, namespace share.Namespace, data []byte) (*Blob, error) { +func NewBlob(shareVersion uint8, namespace share.Namespace, data, signer []byte) (*Blob, error) { if len(data) == 0 || len(data) > appconsts.DefaultMaxBytes { return nil, fmt.Errorf("blob data must be > 0 && <= %d, but it was %d bytes", appconsts.DefaultMaxBytes, len(data)) } - if err := namespace.ValidateForBlob(); err != nil { - return nil, err + + if err := share.ValidateUserNamespace(namespace.Version(), namespace.ID()); err != nil { + return nil, fmt.Errorf("invalid user namespace: %w", err) + } + if !namespace.IsUsableNamespace() { + return nil, fmt.Errorf("namespace %s is not usable", namespace.ID()) // rename } - blob := blob.Blob{ - NamespaceId: namespace.ID(), - Data: data, - ShareVersion: uint32(shareVersion), - NamespaceVersion: uint32(namespace.Version()), + squareBlob, err := share.NewBlob(namespace, data, shareVersion, signer) + if err != nil { + return nil, err } - com, err := inclusion.CreateCommitment(&blob, merkle.HashFromByteSlices, appconsts.SubtreeRootThreshold(appVersion)) + com, err := inclusion.CreateCommitment(squareBlob, merkle.HashFromByteSlices, subtreeRootThreshold) if err != nil { return nil, err } - return &Blob{Blob: &blob, Commitment: com, namespace: namespace, index: -1}, nil + return &Blob{Blob: squareBlob, Commitment: com, index: -1}, nil } // Namespace returns blob's namespace. func (b *Blob) Namespace() share.Namespace { - return b.namespace + return b.Blob.Namespace() } // Index returns the blob's first share index in the EDS. @@ -124,18 +126,12 @@ func (b *Blob) Length() (int, error) { if len(s) == 0 { return 0, errors.New("blob with zero shares received") } + return share.SparseSharesNeeded(s[0].SequenceLen()), nil +} - appShare, err := shares.NewShare(s[0]) - if err != nil { - return 0, err - } - - seqLength, err := appShare.SequenceLen() - if err != nil { - return 0, err - } - - return shares.SparseSharesNeeded(seqLength), nil +// Signer returns blob's author. +func (b *Blob) Signer() []byte { + return b.Blob.Signer() } func (b *Blob) compareCommitments(com Commitment) bool { @@ -143,19 +139,21 @@ func (b *Blob) compareCommitments(com Commitment) bool { } type jsonBlob struct { - Namespace share.Namespace `json:"namespace"` - Data []byte `json:"data"` - ShareVersion uint32 `json:"share_version"` - Commitment Commitment `json:"commitment"` - Index int `json:"index"` + Namespace []byte `json:"namespace"` + Data []byte `json:"data"` + ShareVersion uint32 `json:"share_version"` + Commitment Commitment `json:"commitment"` + Signer []byte `json:"signer,omitempty"` + Index int `json:"index"` } func (b *Blob) MarshalJSON() ([]byte, error) { blob := &jsonBlob{ - Namespace: b.Namespace(), - Data: b.Data, - ShareVersion: b.ShareVersion, + Namespace: b.Namespace().Bytes(), + Data: b.Data(), + ShareVersion: uint32(b.ShareVersion()), Commitment: b.Commitment, + Signer: b.Signer(), Index: b.index, } return json.Marshal(blob) @@ -168,17 +166,18 @@ func (b *Blob) UnmarshalJSON(data []byte) error { return err } - if len(jsonBlob.Namespace) == 0 { - return errors.New("expected a non-empty namespace") + ns, err := share.NewNamespaceFromBytes(jsonBlob.Namespace) + if err != nil { + return err + } + + blob, err := NewBlob(uint8(jsonBlob.ShareVersion), ns, jsonBlob.Data, jsonBlob.Signer) + if err != nil { + return err } - b.Blob = &blob.Blob{} - b.Blob.NamespaceVersion = uint32(jsonBlob.Namespace.Version()) - b.Blob.NamespaceId = jsonBlob.Namespace.ID() - b.Blob.Data = jsonBlob.Data - b.Blob.ShareVersion = jsonBlob.ShareVersion - b.Commitment = jsonBlob.Commitment - b.namespace = jsonBlob.Namespace - b.index = jsonBlob.Index + blob.Commitment = jsonBlob.Commitment + blob.index = jsonBlob.Index + *b = *blob return nil } diff --git a/blob/blob_test.go b/blob/blob_test.go index d747090758..20871706d5 100644 --- a/blob/blob_test.go +++ b/blob/blob_test.go @@ -7,11 +7,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - apptypes "github.com/celestiaorg/celestia-app/v2/x/blob/types" - "github.com/celestiaorg/go-square/blob" - "github.com/celestiaorg/go-square/inclusion" "github.com/celestiaorg/go-square/merkle" + "github.com/celestiaorg/go-square/v2/inclusion" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob/blobtest" ) @@ -42,7 +40,7 @@ func TestBlob(t *testing.T) { comm, err := inclusion.CreateCommitment( blob[0].Blob, merkle.HashFromByteSlices, - appconsts.SubtreeRootThreshold(appVersion), + subtreeRootThreshold, ) require.NoError(t, err) assert.Equal(t, blob[0].Commitment, Commitment(comm)) @@ -51,9 +49,8 @@ func TestBlob(t *testing.T) { { name: "verify namespace", expectedRes: func(t *testing.T) { - ns := blob[0].Namespace().ToAppNamespace() - require.NoError(t, err) - require.NoError(t, apptypes.ValidateBlobNamespace(ns)) + ns := blob[0].Namespace() + require.NoError(t, share.ValidateUserNamespace(ns.Version(), ns.ID())) }, }, { @@ -67,9 +64,7 @@ func TestBlob(t *testing.T) { { name: "shares to blobs", expectedRes: func(t *testing.T) { - sh, err := BlobsToShares(blob...) - require.NoError(t, err) - shares, err := toAppShares(sh...) + shares, err := BlobsToShares(blob...) require.NoError(t, err) p := &parser{length: len(shares), shares: shares} b, err := p.parse() @@ -85,7 +80,7 @@ func TestBlob(t *testing.T) { newBlob := &Blob{} require.NoError(t, newBlob.UnmarshalJSON(data)) - require.True(t, bytes.Equal(blob[0].Blob.GetData(), newBlob.Data)) + require.True(t, bytes.Equal(blob[0].Blob.Data(), newBlob.Data())) require.True(t, bytes.Equal(blob[0].Commitment, newBlob.Commitment)) }, }, @@ -96,10 +91,10 @@ func TestBlob(t *testing.T) { } } -func convertBlobs(appBlobs ...*blob.Blob) ([]*Blob, error) { +func convertBlobs(appBlobs ...*share.Blob) ([]*Blob, error) { blobs := make([]*Blob, 0, len(appBlobs)) for _, appBlob := range appBlobs { - blob, err := NewBlob(uint8(appBlob.GetShareVersion()), appBlob.Namespace().Bytes(), appBlob.GetData()) + blob, err := NewBlob(appBlob.ShareVersion(), appBlob.Namespace(), appBlob.Data(), appBlob.Signer()) if err != nil { return nil, err } diff --git a/blob/blobtest/testing.go b/blob/blobtest/testing.go index eb85bead27..e509e36af3 100644 --- a/blob/blobtest/testing.go +++ b/blob/blobtest/testing.go @@ -1,31 +1,34 @@ package blobtest import ( + "fmt" + tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - "github.com/celestiaorg/celestia-app/v2/test/util/testfactory" - "github.com/celestiaorg/go-square/blob" + "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" "github.com/celestiaorg/go-square/shares" - - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/go-square/v2/share" ) // GenerateV0Blobs is a test utility producing v0 share formatted blobs with the // requested size and random namespaces. -func GenerateV0Blobs(sizes []int, sameNamespace bool) ([]*blob.Blob, error) { - blobs := make([]*blob.Blob, 0, len(sizes)) - +func GenerateV0Blobs(sizes []int, sameNamespace bool) ([]*share.Blob, error) { + blobs := make([]*share.Blob, 0, len(sizes)) for _, size := range sizes { - size := rawBlobSize(appconsts.FirstSparseShareContentSize * size) + size := RawBlobSize(share.FirstSparseShareContentSize * size) appBlob := testfactory.GenerateRandomBlob(size) if !sameNamespace { - namespace, err := share.NewBlobNamespaceV0(tmrand.Bytes(7)) + namespace, err := share.NewV0Namespace(tmrand.Bytes(7)) + if err != nil { + return nil, err + } + if namespace.IsReserved() { + return nil, fmt.Errorf("reserved namespace") + } + appBlob, err = share.NewV0Blob(namespace, appBlob.Data()) if err != nil { return nil, err } - appBlob.NamespaceVersion = uint32(namespace[0]) - appBlob.NamespaceId = namespace[1:] } blobs = append(blobs, appBlob) @@ -33,6 +36,6 @@ func GenerateV0Blobs(sizes []int, sameNamespace bool) ([]*blob.Blob, error) { return blobs, nil } -func rawBlobSize(totalSize int) int { +func RawBlobSize(totalSize int) int { return totalSize - shares.DelimLen(uint64(totalSize)) } diff --git a/blob/commitment_proof.go b/blob/commitment_proof.go index 82fed368dc..d59614a693 100644 --- a/blob/commitment_proof.go +++ b/blob/commitment_proof.go @@ -5,13 +5,12 @@ import ( "errors" "fmt" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - "github.com/celestiaorg/celestia-app/v2/pkg/proof" - "github.com/celestiaorg/go-square/inclusion" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + "github.com/celestiaorg/celestia-app/v3/pkg/proof" + "github.com/celestiaorg/go-square/v2/inclusion" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/nmt/namespace" - - "github.com/celestiaorg/celestia-node/share" ) // Commitment is a Merkle Root of the subtree built from shares of the Blob. diff --git a/blob/helper.go b/blob/helper.go index 17f0068c9e..3b81fce5be 100644 --- a/blob/helper.go +++ b/blob/helper.go @@ -1,60 +1,38 @@ package blob import ( + "fmt" "sort" - squareblob "github.com/celestiaorg/go-square/blob" - "github.com/celestiaorg/go-square/shares" - - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/go-square/v2/share" ) // BlobsToShares accepts blobs and convert them to the Shares. func BlobsToShares(nodeBlobs ...*Blob) ([]share.Share, error) { - b := make([]*squareblob.Blob, len(nodeBlobs)) + sort.Slice(nodeBlobs, func(i, j int) bool { + return nodeBlobs[i].Blob.Namespace().Compare(nodeBlobs[j].Blob.Namespace()) < 0 + }) + + splitter := share.NewSparseShareSplitter() for i, nodeBlob := range nodeBlobs { - namespace := nodeBlob.Namespace() - b[i] = &squareblob.Blob{ - NamespaceVersion: uint32(namespace[0]), - NamespaceId: namespace[1:], - Data: nodeBlob.Data, - ShareVersion: nodeBlob.ShareVersion, + err := splitter.Write(nodeBlob.Blob) + if err != nil { + return nil, fmt.Errorf("failed to split blob at index: %d: %w", i, err) } - } - - sort.Slice(b, func(i, j int) bool { - return b[i].Namespace().Compare(b[j].Namespace()) < 0 - }) - rawShares, err := shares.SplitBlobs(b...) - if err != nil { - return nil, err } - return shares.ToBytes(rawShares), nil + return splitter.Export(), nil } // ToAppBlobs converts node's blob type to the blob type from go-square. -func ToAppBlobs(blobs ...*Blob) []*squareblob.Blob { - appBlobs := make([]*squareblob.Blob, len(blobs)) +func ToAppBlobs(blobs ...*Blob) []*share.Blob { + appBlobs := make([]*share.Blob, len(blobs)) for i := range blobs { appBlobs[i] = blobs[i].Blob } return appBlobs } -// toAppShares converts node's raw shares to the app shares, skipping padding -func toAppShares(shrs ...share.Share) ([]shares.Share, error) { - appShrs := make([]shares.Share, 0, len(shrs)) - for _, shr := range shrs { - bShare, err := shares.NewShare(shr) - if err != nil { - return nil, err - } - appShrs = append(appShrs, *bShare) - } - return appShrs, nil -} - func calculateIndex(rowLength, blobIndex int) (row, col int) { row = blobIndex / rowLength col = blobIndex - (row * rowLength) diff --git a/blob/helper_test.go b/blob/helper_test.go index 39f0ba7c3f..f4ac403b97 100644 --- a/blob/helper_test.go +++ b/blob/helper_test.go @@ -7,52 +7,37 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - squareblob "github.com/celestiaorg/go-square/blob" - "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/go-square/v2/share" ) func TestBlobsToShares(t *testing.T) { t.Run("should sort blobs by namespace in ascending order", func(t *testing.T) { - namespaceA := namespace.MustNewV0(bytes.Repeat([]byte{0xa}, 10)).Bytes() - namespaceB := namespace.MustNewV0(bytes.Repeat([]byte{0xb}, 10)).Bytes() + namespaceA := share.MustNewV0Namespace(bytes.Repeat([]byte{0xa}, 10)) + namespaceB := share.MustNewV0Namespace(bytes.Repeat([]byte{0xb}, 10)) - blobA, err := NewBlob(appconsts.ShareVersionZero, namespaceA, []byte("dataA")) + blobA, err := NewBlob(share.ShareVersionZero, namespaceA, []byte("dataA"), nil) require.NoError(t, err) - blobB, err := NewBlob(appconsts.ShareVersionZero, namespaceB, []byte("dataB")) + blobB, err := NewBlob(share.ShareVersionZero, namespaceB, []byte("dataB"), nil) require.NoError(t, err) got, err := BlobsToShares(blobB, blobA) require.NoError(t, err) - assert.Equal(t, got[0][:appconsts.NamespaceSize], namespaceA) - assert.Equal(t, got[1][:appconsts.NamespaceSize], namespaceB) - assert.IsIncreasing(t, got) + assert.Equal(t, got[0].Namespace(), namespaceA) + assert.Equal(t, got[1].Namespace(), namespaceB) + assert.True(t, got[0].Namespace().IsLessThan(got[1].Namespace())) }) } func TestToAppBlobs(t *testing.T) { - namespaceA := namespace.MustNewV0(bytes.Repeat([]byte{0xa}, 10)) - namespaceB := namespace.MustNewV0(bytes.Repeat([]byte{0xb}, 10)) + namespaceA := share.MustNewV0Namespace(bytes.Repeat([]byte{0xa}, 10)) + namespaceB := share.MustNewV0Namespace(bytes.Repeat([]byte{0xb}, 10)) - blobA, err := NewBlob(appconsts.ShareVersionZero, namespaceA.Bytes(), []byte("dataA")) + blobA, err := NewBlob(share.ShareVersionZero, namespaceA, []byte("dataA"), nil) require.NoError(t, err) - blobB, err := NewBlob(appconsts.ShareVersionZero, namespaceB.Bytes(), []byte("dataB")) + blobB, err := NewBlob(share.ShareVersionZero, namespaceB, []byte("dataB"), nil) require.NoError(t, err) got := ToAppBlobs(blobA, blobB) - want := []*squareblob.Blob{ - { - NamespaceId: blobA.NamespaceId, - NamespaceVersion: blobA.NamespaceVersion, - Data: blobA.Data, - ShareVersion: blobA.ShareVersion, - }, - { - NamespaceId: blobB.NamespaceId, - NamespaceVersion: blobB.NamespaceVersion, - Data: blobB.Data, - ShareVersion: blobB.ShareVersion, - }, - } - assert.Equal(t, want, got) + + assert.Equal(t, []*share.Blob{blobA.Blob, blobB.Blob}, got) } diff --git a/blob/parser.go b/blob/parser.go index 0033d29ebf..d693b3a8c3 100644 --- a/blob/parser.go +++ b/blob/parser.go @@ -4,7 +4,9 @@ import ( "errors" "fmt" - "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/go-square/merkle" + "github.com/celestiaorg/go-square/v2/inclusion" + "github.com/celestiaorg/go-square/v2/share" ) // parser helps to collect shares and transform them into a blob. @@ -15,13 +17,13 @@ type parser struct { // length is an amount of the shares needed to build the blob. length int // shares is a set of shares to build the blob. - shares []shares.Share + shares []share.Share verifyFn func(blob *Blob) bool } // set tries to find the first blob's share by skipping padding shares and // sets the metadata of the blob(index and length) -func (p *parser) set(index int, shrs []shares.Share) ([]shares.Share, error) { +func (p *parser) set(index int, shrs []share.Share) ([]share.Share, error) { if len(shrs) == 0 { return nil, errEmptyShares } @@ -37,19 +39,15 @@ func (p *parser) set(index int, shrs []shares.Share) ([]shares.Share, error) { // `+=` as index could be updated in `skipPadding` p.index += index - length, err := shrs[0].SequenceLen() - if err != nil { - return nil, err - } - - p.length = shares.SparseSharesNeeded(length) + length := shrs[0].SequenceLen() + p.length = share.SparseSharesNeeded(length) return shrs, nil } // addShares sets shares until the blob is completed and extra remaining shares back. // It assumes that the remaining shares required for blob completeness are correct and // do not include padding shares. -func (p *parser) addShares(shares []shares.Share) (shrs []shares.Share, isComplete bool) { +func (p *parser) addShares(shares []share.Share) (shrs []share.Share, isComplete bool) { index := -1 for i, sh := range shares { p.shares = append(p.shares, sh) @@ -77,54 +75,37 @@ func (p *parser) parse() (*Blob, error) { return nil, fmt.Errorf("invalid shares amount. want:%d, have:%d", p.length, len(p.shares)) } - sequence, err := shares.ParseShares(p.shares, true) + blobs, err := share.ParseBlobs(p.shares) if err != nil { return nil, err } - // ensure that sequence length is not 0 - if len(sequence) == 0 { + if len(blobs) == 0 { return nil, ErrBlobNotFound } - if len(sequence) > 1 { - return nil, errors.New("unexpected amount of sequences") - } - - data, err := sequence[0].RawData() - if err != nil { - return nil, err - } - if len(data) == 0 { - return nil, ErrBlobNotFound + if len(blobs) > 1 { + return nil, errors.New("unexpected amount of blobs") } - shareVersion, err := sequence[0].Shares[0].Version() + com, err := inclusion.CreateCommitment(blobs[0], merkle.HashFromByteSlices, subtreeRootThreshold) if err != nil { return nil, err } - blob, err := NewBlob(shareVersion, sequence[0].Namespace.Bytes(), data) - if err != nil { - return nil, err - } - blob.index = p.index + blob := &Blob{Blob: blobs[0], Commitment: com, index: p.index} return blob, nil } // skipPadding iterates through the shares until non-padding share will be found. It guarantees that // the returned set of shares will start with non-padding share(or empty set of shares). -func (p *parser) skipPadding(shares []shares.Share) ([]shares.Share, error) { +func (p *parser) skipPadding(shares []share.Share) ([]share.Share, error) { if len(shares) == 0 { return nil, errEmptyShares } offset := 0 for _, sh := range shares { - isPadding, err := sh.IsPadding() - if err != nil { - return nil, err - } - if !isPadding { + if !sh.IsPadding() { break } offset++ diff --git a/blob/repro_test.go b/blob/repro_test.go index 27070d1f28..6cb39948ac 100644 --- a/blob/repro_test.go +++ b/blob/repro_test.go @@ -3,7 +3,7 @@ package blob import ( "testing" - "github.com/celestiaorg/celestia-app/v2/pkg/proof" + "github.com/celestiaorg/celestia-app/v3/pkg/proof" "github.com/celestiaorg/nmt" "github.com/celestiaorg/nmt/pb" ) diff --git a/blob/service.go b/blob/service.go index 22a238ec97..f40114b8c8 100644 --- a/blob/service.go +++ b/blob/service.go @@ -1,7 +1,7 @@ package blob import ( - bytes2 "bytes" + "bytes" "context" "encoding/hex" "errors" @@ -16,18 +16,16 @@ import ( "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - pkgproof "github.com/celestiaorg/celestia-app/v2/pkg/proof" - "github.com/celestiaorg/go-square/inclusion" - appns "github.com/celestiaorg/go-square/namespace" - "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + pkgproof "github.com/celestiaorg/celestia-app/v3/pkg/proof" + "github.com/celestiaorg/go-square/v2/inclusion" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square/shwap" "github.com/celestiaorg/celestia-node/state" ) @@ -171,9 +169,9 @@ func (s *Service) Subscribe(ctx context.Context, ns share.Namespace) (<-chan *Su func (s *Service) Submit(ctx context.Context, blobs []*Blob, txConfig *SubmitOptions) (uint64, error) { log.Debugw("submitting blobs", "amount", len(blobs)) - squareBlobs := make([]*state.Blob, len(blobs)) + squareBlobs := make([]*share.Blob, len(blobs)) for i := range blobs { - if err := blobs[i].Namespace().ValidateForBlob(); err != nil { + if err := share.ValidateForData(blobs[i].Namespace()); err != nil { return 0, err } squareBlobs[i] = blobs[i].Blob @@ -276,7 +274,7 @@ func (s *Service) getAll( blobs, err := s.getBlobs(ctx, namespace, header) if err != nil && !errors.Is(err, ErrBlobNotFound) { - log.Errorf("getting blobs for namespaceID(%s): %v", namespace.ID().String(), err) + log.Errorf("getting blobs for namespaceID(%s): %v", hex.EncodeToString(namespace.ID()), err) resultErr[i] = err } if len(blobs) > 0 { @@ -378,7 +376,7 @@ func (s *Service) retrieve( attribute.Int64("eds-size", int64(len(header.DAH.RowRoots))))) var ( - appShares = make([]shares.Share, 0) + appShares = make([]share.Share, 0) proofs = make(Proof, 0) ) @@ -390,18 +388,14 @@ func (s *Service) retrieve( return nil, nil, ErrBlobNotFound } - appShares, err = toAppShares(row.Shares...) - if err != nil { - return nil, nil, err - } - + appShares = row.Shares proofs = append(proofs, row.Proof) index := row.Proof.Start() for { var ( isComplete bool - shrs []shares.Share + shrs []share.Share wasEmpty = sharesParser.isEmpty() ) @@ -459,11 +453,7 @@ func (s *Service) retrieve( err = ErrBlobNotFound for _, sh := range appShares { - ok, err := sh.IsPadding() - if err != nil { - return nil, nil, err - } - if !ok { + if !sh.IsPadding() { err = fmt.Errorf("incomplete blob with the "+ "namespace: %s detected at %d: %w", namespace.String(), height, err) log.Error(err) @@ -570,7 +560,7 @@ func ProveCommitment( // find the blob shares in the EDS blobSharesStartIndex := -1 for index, share := range eds.FlattenedODS() { - if bytes2.Equal(share, blobShares[0]) { + if bytes.Equal(share, blobShares[0].ToBytes()) { blobSharesStartIndex = index } } @@ -578,11 +568,6 @@ func ProveCommitment( return nil, fmt.Errorf("couldn't find the blob shares in the ODS") } - nID, err := appns.From(namespace) - if err != nil { - return nil, err - } - log.Debugw( "generating the blob share proof for commitment", "start_share", @@ -592,8 +577,8 @@ func ProveCommitment( ) sharesProof, err := pkgproof.NewShareInclusionProofFromEDS( eds, - nID, - shares.NewRange(blobSharesStartIndex, blobSharesStartIndex+len(blobShares)), + namespace, + share.NewRange(blobSharesStartIndex, blobSharesStartIndex+len(blobShares)), ) if err != nil { return nil, err @@ -624,7 +609,7 @@ func ProveCommitment( ranges, err := nmt.ToLeafRanges( proof.Start(), proof.End(), - inclusion.SubTreeWidth(len(blobShares), appconsts.DefaultSubtreeRootThreshold), + inclusion.SubTreeWidth(len(blobShares), subtreeRootThreshold), ) if err != nil { return nil, err @@ -673,7 +658,7 @@ func computeSubtreeRoots(shares []share.Share, ranges []nmt.LeafRange, offset in ) for _, sh := range shares { leafData := make([]byte, 0) - leafData = append(append(leafData, share.GetNamespace(sh)...), sh...) + leafData = append(append(leafData, sh.Namespace().Bytes()...), sh.ToBytes()...) err := tree.Push(leafData) if err != nil { return nil, err diff --git a/blob/service_test.go b/blob/service_test.go index 621419dbd9..1114b84a97 100644 --- a/blob/service_test.go +++ b/blob/service_test.go @@ -16,17 +16,17 @@ import ( ds_sync "github.com/ipfs/go-datastore/sync" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/tendermint/tendermint/crypto/merkle" tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - pkgproof "github.com/celestiaorg/celestia-app/v2/pkg/proof" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + pkgproof "github.com/celestiaorg/celestia-app/v3/pkg/proof" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" "github.com/celestiaorg/go-header/store" - "github.com/celestiaorg/go-square/blob" - "github.com/celestiaorg/go-square/inclusion" + "github.com/celestiaorg/go-square/merkle" squarens "github.com/celestiaorg/go-square/namespace" appshares "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/go-square/v2/inclusion" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" @@ -34,12 +34,12 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/ipld" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/getters/mock" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/ipld" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/getters/mock" ) func TestBlobService_Get(t *testing.T) { @@ -135,7 +135,7 @@ func TestBlobService_Get(t *testing.T) { assert.Len(t, blobs, 4) sort.Slice(blobs, func(i, j int) bool { - val := bytes.Compare(blobs[i].NamespaceId, blobs[j].NamespaceId) + val := bytes.Compare(blobs[i].Namespace().ID(), blobs[j].Namespace().ID()) return val < 0 }) @@ -149,17 +149,17 @@ func TestBlobService_Get(t *testing.T) { row, col := calculateIndex(len(h.DAH.RowRoots), blobs[i].index) sh, err := service.shareGetter.GetShare(ctx, h, row, col) require.NoError(t, err) - require.True(t, bytes.Equal(sh, resultShares[shareOffset]), + require.True(t, bytes.Equal(sh.ToBytes(), resultShares[shareOffset].ToBytes()), fmt.Sprintf("issue on %d attempt. ROW:%d, COL: %d, blobIndex:%d", i, row, col, blobs[i].index), ) - shareOffset += appshares.SparseSharesNeeded(uint32(len(blobs[i].Data))) + shareOffset += appshares.SparseSharesNeeded(uint32(len(blobs[i].Data()))) } }, }, { name: "get all with different namespaces", doFn: func() (interface{}, error) { - nid, err := share.NewBlobNamespaceV0(tmrand.Bytes(7)) + nid, err := share.NewV0Namespace(tmrand.Bytes(7)) require.NoError(t, err) b, err := service.GetAll(ctx, 1, []share.Namespace{ @@ -177,8 +177,9 @@ func TestBlobService_Get(t *testing.T) { assert.NotEmpty(t, blobs) assert.Len(t, blobs, 2) // check the order - require.True(t, bytes.Equal(blobs[0].Namespace(), blobsWithDiffNamespaces[0].Namespace())) - require.True(t, bytes.Equal(blobs[1].Namespace(), blobsWithDiffNamespaces[1].Namespace())) + + require.True(t, blobs[0].Namespace().Equals(blobsWithDiffNamespaces[0].Namespace())) + require.True(t, blobs[1].Namespace().Equals(blobsWithDiffNamespaces[1].Namespace())) }, }, { @@ -241,7 +242,7 @@ func TestBlobService_Get(t *testing.T) { for _, p := range *proof { from := to to = p.End() - p.Start() + from - eq := p.VerifyInclusion(share.NewSHA256Hasher(), namespace.ToNMT(), rawShares[from:to], row) + eq := p.VerifyInclusion(square.NewSHA256Hasher(), namespace.Bytes(), rawShares[from:to], row) if eq == true { return } @@ -252,7 +253,7 @@ func TestBlobService_Get(t *testing.T) { rawShares, err := BlobsToShares(blobsWithDiffNamespaces[1]) require.NoError(t, err) - verifyFn(t, rawShares, proof, blobsWithDiffNamespaces[1].Namespace()) + verifyFn(t, share.ToBytes(rawShares), proof, blobsWithDiffNamespaces[1].Namespace()) }, }, { @@ -357,7 +358,7 @@ func TestBlobService_Get(t *testing.T) { { name: "empty result and err when blobs were not found ", doFn: func() (interface{}, error) { - nid, err := share.NewBlobNamespaceV0(tmrand.Bytes(squarens.NamespaceVersionZeroIDSize)) + nid, err := share.NewV0Namespace(tmrand.Bytes(squarens.NamespaceVersionZeroIDSize)) require.NoError(t, err) return service.GetAll(ctx, 1, []share.Namespace{nid}) }, @@ -456,7 +457,7 @@ func TestBlobService_Get(t *testing.T) { // But to satisfy the rule of eds creating, padding namespace share is placed between // blobs. Test ensures that blob service will skip padding share and return the correct blob. func TestService_GetSingleBlobWithoutPadding(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5) + ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) t.Cleanup(cancel) appBlob, err := blobtest.GenerateV0Blobs([]int{9, 5}, true) @@ -464,20 +465,18 @@ func TestService_GetSingleBlobWithoutPadding(t *testing.T) { blobs, err := convertBlobs(appBlob...) require.NoError(t, err) - ns1, ns2 := blobs[0].Namespace().ToAppNamespace(), blobs[1].Namespace().ToAppNamespace() - - padding0, err := appshares.NamespacePaddingShare(ns1, appconsts.ShareVersionZero) + padding0, err := share.NamespacePaddingShare(blobs[0].Namespace(), share.ShareVersionZero) require.NoError(t, err) - padding1, err := appshares.NamespacePaddingShare(ns2, appconsts.ShareVersionZero) + padding1, err := share.NamespacePaddingShare(blobs[1].Namespace(), share.ShareVersionZero) require.NoError(t, err) rawShares0, err := BlobsToShares(blobs[0]) require.NoError(t, err) rawShares1, err := BlobsToShares(blobs[1]) require.NoError(t, err) - rawShares := make([][]byte, 0) - rawShares = append(rawShares, append(rawShares0, padding0.ToBytes())...) - rawShares = append(rawShares, append(rawShares1, padding1.ToBytes())...) + rawShares := make([]share.Share, 0) + rawShares = append(rawShares, append(rawShares0, padding0)...) + rawShares = append(rawShares, append(rawShares1, padding1)...) service := createService(ctx, t, rawShares) newBlob, err := service.Get(ctx, 1, blobs[1].Namespace(), blobs[1].Commitment) @@ -528,7 +527,7 @@ func TestService_Get(t *testing.T) { require.NoError(t, err) assert.Equal(t, sh, resultShares[shareOffset], fmt.Sprintf("issue on %d attempt", i)) - shareOffset += appshares.SparseSharesNeeded(uint32(len(blob.Data))) + shareOffset += appshares.SparseSharesNeeded(uint32(len(blob.Data()))) } } @@ -544,30 +543,27 @@ func TestService_GetAllWithoutPadding(t *testing.T) { blobs, err := convertBlobs(appBlob...) require.NoError(t, err) - var ( - ns = blobs[0].Namespace().ToAppNamespace() - rawShares = make([][]byte, 0) - ) + rawShares := make([]share.Share, 0) - padding, err := appshares.NamespacePaddingShare(ns, appconsts.ShareVersionZero) + require.NoError(t, err) + padding, err := share.NamespacePaddingShare(blobs[0].Namespace(), share.ShareVersionZero) require.NoError(t, err) for i := 0; i < 2; i++ { sh, err := BlobsToShares(blobs[i]) require.NoError(t, err) - rawShares = append(rawShares, append(sh, padding.ToBytes())...) + rawShares = append(rawShares, append(sh, padding)...) } sh, err := BlobsToShares(blobs[2]) require.NoError(t, err) - rawShares = append(rawShares, append(sh, padding.ToBytes(), padding.ToBytes())...) + rawShares = append(rawShares, append(sh, padding, padding)...) sh, err = BlobsToShares(blobs[3]) require.NoError(t, err) - rawShares = append(rawShares, append(sh, padding.ToBytes(), padding.ToBytes(), padding.ToBytes())...) + 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) @@ -589,19 +585,20 @@ func TestService_GetAllWithoutPadding(t *testing.T) { require.NoError(t, err) assert.Equal(t, sh, resultShares[shareOffset]) - shareOffset += appshares.SparseSharesNeeded(uint32(len(blob.Data))) + shareOffset += appshares.SparseSharesNeeded(uint32(len(blob.Data()))) } } func TestAllPaddingSharesInEDS(t *testing.T) { - nid, err := share.NewBlobNamespaceV0(tmrand.Bytes(7)) + nid, err := share.NewV0Namespace(tmrand.Bytes(7)) require.NoError(t, err) - padding, err := appshares.NamespacePaddingShare(nid.ToAppNamespace(), appconsts.ShareVersionZero) + + padding, err := share.NamespacePaddingShare(nid, share.ShareVersionZero) require.NoError(t, err) rawShares := make([]share.Share, 16) for i := 0; i < 16; i++ { - rawShares[i] = padding.ToBytes() + rawShares[i] = padding } ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) @@ -614,22 +611,23 @@ func TestAllPaddingSharesInEDS(t *testing.T) { } func TestSkipPaddingsAndRetrieveBlob(t *testing.T) { - nid, err := share.NewBlobNamespaceV0(tmrand.Bytes(7)) - require.NoError(t, err) - padding, err := appshares.NamespacePaddingShare(nid.ToAppNamespace(), appconsts.ShareVersionZero) + nid := share.RandomBlobNamespace() + padding, err := share.NamespacePaddingShare(nid, share.ShareVersionZero) require.NoError(t, err) rawShares := make([]share.Share, 0, 64) for i := 0; i < 58; i++ { - rawShares = append(rawShares, padding.ToBytes()) + rawShares = append(rawShares, padding) } - appBlob, err := blobtest.GenerateV0Blobs([]int{6}, true) + size := blobtest.RawBlobSize(share.FirstSparseShareContentSize * 6) + ns, err := share.NewNamespace(nid.Version(), nid.ID()) + require.NoError(t, err) + data := tmrand.Bytes(size) + appBlob, err := share.NewBlob(ns, data, share.ShareVersionZero, nil) require.NoError(t, err) - appBlob[0].NamespaceVersion = uint32(nid[0]) - appBlob[0].NamespaceId = nid[1:] - blobs, err := convertBlobs(appBlob...) + blobs, err := convertBlobs(appBlob) require.NoError(t, err) sh, err := BlobsToShares(blobs[0]) require.NoError(t, err) @@ -668,7 +666,7 @@ func TestService_Subscribe(t *testing.T) { select { case resp := <-subCh: assert.Equal(t, i+1, resp.Height) - assert.Equal(t, blobs[i].Data, resp.Blobs[0].Data) + assert.Equal(t, blobs[i].Data(), resp.Blobs[0].Data()) case <-time.After(time.Second * 2): t.Fatalf("timeout waiting for subscription response %d", i) } @@ -676,7 +674,7 @@ func TestService_Subscribe(t *testing.T) { }) t.Run("subscription with no matching blobs", func(t *testing.T) { - ns, err := share.NewBlobNamespaceV0([]byte("nonexist")) + ns, err := share.NewV0Namespace([]byte("nonexist")) require.NoError(t, err) subCh, err := service.Subscribe(ctx, ns) @@ -760,7 +758,7 @@ func TestService_Subscribe_MultipleNamespaces(t *testing.T) { appBlobs2, err := blobtest.GenerateV0Blobs([]int{100, 100}, true) for i := range appBlobs2 { // if we don't do this, appBlobs1 and appBlobs2 will share a NS - appBlobs2[i].GetNamespaceId()[len(appBlobs2[i].GetNamespaceId())-1] = 0xDE + appBlobs2[i].Namespace().ID()[len(appBlobs2[i].Namespace().ID())-1] = 0xDE } require.NoError(t, err) @@ -892,8 +890,8 @@ func createServiceWithSub(ctx context.Context, t testing.TB, blobs []*Blob) *Ser func createService(ctx context.Context, t testing.TB, shares []share.Share) *Service { odsSize := int(utils.SquareSize(len(shares))) square, err := rsmt2d.ComputeExtendedDataSquare( - shares, - share.DefaultRSMT2DCodec(), + share.ToBytes(shares), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize))) require.NoError(t, err) @@ -955,12 +953,12 @@ 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].GetShareVersion()), nss[msgIndex].Bytes(), blobs[msgIndex].GetData()) + blb, err := NewBlob(uint8(blobs[msgIndex].ShareVersion()), nss[msgIndex], blobs[msgIndex].Data(), nil) require.NoError(t, err) blobShares, err := BlobsToShares(blb) require.NoError(t, err) // compute the commitment - actualCommitmentProof, err := ProveCommitment(eds, nss[msgIndex].Bytes(), blobShares) + actualCommitmentProof, err := ProveCommitment(eds, nss[msgIndex], blobShares) require.NoError(t, err) // make sure the actual commitment attests to the data @@ -973,7 +971,7 @@ func proveAndVerifyShareCommitments(t *testing.T, blobSize int) { require.True(t, valid) // generate an expected proof and verify it's valid - expectedCommitmentProof := generateCommitmentProofFromBlock(t, eds, nss[msgIndex].Bytes(), blobs[msgIndex], dataRoot) + expectedCommitmentProof := generateCommitmentProofFromBlock(t, eds, nss[msgIndex], blobs[msgIndex], dataRoot) require.NoError(t, expectedCommitmentProof.Validate()) valid, err = expectedCommitmentProof.Verify( dataRoot, @@ -998,14 +996,14 @@ func generateCommitmentProofFromBlock( t *testing.T, eds *rsmt2d.ExtendedDataSquare, ns share.Namespace, - blob *blob.Blob, + blob *share.Blob, dataRoot []byte, ) CommitmentProof { // create the blob from the data - blb, err := NewBlob( - uint8(blob.GetShareVersion()), + blb, err := NewBlob(blob.ShareVersion(), ns, - blob.GetData(), + blob.Data(), + nil, ) require.NoError(t, err) @@ -1016,7 +1014,7 @@ func generateCommitmentProofFromBlock( // find the first share of the blob in the ODS startShareIndex := -1 for i, sh := range eds.FlattenedODS() { - if bytes.Equal(sh, blobShares[0]) { + if bytes.Equal(sh, blobShares[0].ToBytes()) { startShareIndex = i break } @@ -1026,8 +1024,8 @@ func generateCommitmentProofFromBlock( // create an inclusion proof of the blob using the share range instead of the commitment sharesProof, err := pkgproof.NewShareInclusionProofFromEDS( eds, - ns.ToAppNamespace(), - appshares.NewRange(startShareIndex, startShareIndex+len(blobShares)), + ns, + share.NewRange(startShareIndex, startShareIndex+len(blobShares)), ) require.NoError(t, err) require.NoError(t, sharesProof.Validate(dataRoot)) @@ -1039,7 +1037,7 @@ func generateCommitmentProofFromBlock( ranges, err := nmt.ToLeafRanges( int(proof.Start), int(proof.End), - inclusion.SubTreeWidth(len(blobShares), appconsts.DefaultSubtreeRootThreshold), + inclusion.SubTreeWidth(len(blobShares), subtreeRootThreshold), ) require.NoError(t, err) roots, err := computeSubtreeRoots( diff --git a/cmd/cel-key/main.go b/cmd/cel-key/main.go index 5db3f4bc7c..33d3f1487a 100644 --- a/cmd/cel-key/main.go +++ b/cmd/cel-key/main.go @@ -12,8 +12,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/spf13/cobra" - "github.com/celestiaorg/celestia-app/v2/app" - "github.com/celestiaorg/celestia-app/v2/app/encoding" + "github.com/celestiaorg/celestia-app/v3/app" + "github.com/celestiaorg/celestia-app/v3/app/encoding" ) var encodingConfig = encoding.MakeConfig(app.ModuleEncodingRegisters...) diff --git a/cmd/cel-shed/shwap.go b/cmd/cel-shed/shwap.go index 2d88e59ca9..60a6d237ac 100644 --- a/cmd/cel-shed/shwap.go +++ b/cmd/cel-shed/shwap.go @@ -7,7 +7,7 @@ import ( "github.com/ipfs/go-cid" "github.com/spf13/cobra" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/bitswap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/bitswap" ) func init() { diff --git a/cmd/start.go b/cmd/start.go index 85970cbd6e..3a71c5a6db 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -10,8 +10,8 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/spf13/cobra" - "github.com/celestiaorg/celestia-app/v2/app" - "github.com/celestiaorg/celestia-app/v2/app/encoding" + "github.com/celestiaorg/celestia-app/v3/app" + "github.com/celestiaorg/celestia-app/v3/app/encoding" "github.com/celestiaorg/celestia-node/nodebuilder" ) diff --git a/cmd/util.go b/cmd/util.go index 750b9d9ae5..16ff39d5d7 100644 --- a/cmd/util.go +++ b/cmd/util.go @@ -11,6 +11,8 @@ import ( "github.com/spf13/cobra" flag "github.com/spf13/pflag" + "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/celestia-node/nodebuilder/core" "github.com/celestiaorg/celestia-node/nodebuilder/gateway" "github.com/celestiaorg/celestia-node/nodebuilder/header" @@ -19,7 +21,6 @@ import ( "github.com/celestiaorg/celestia-node/nodebuilder/pruner" rpc_cfg "github.com/celestiaorg/celestia-node/nodebuilder/rpc" "github.com/celestiaorg/celestia-node/nodebuilder/state" - "github.com/celestiaorg/celestia-node/share" ) func PrintOutput(data interface{}, err error, formatData func(interface{}) interface{}) error { @@ -50,11 +51,11 @@ func PrintOutput(data interface{}, err error, formatData func(interface{}) inter func ParseV0Namespace(param string) (share.Namespace, error) { userBytes, err := DecodeToBytes(param) if err != nil { - return nil, err + return share.Namespace{}, err } // if the namespace ID is <= 10 bytes, left pad it with 0s - return share.NewBlobNamespaceV0(userBytes) + return share.NewV0Namespace(userBytes) } // DecodeToBytes decodes a Base64 or hex input string into a byte slice. diff --git a/cmd/util_test.go b/cmd/util_test.go index b6e245f3e2..97dc7cc83c 100644 --- a/cmd/util_test.go +++ b/cmd/util_test.go @@ -4,22 +4,23 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/go-square/v2/share" ) func Test_parseNamespaceID(t *testing.T) { type testCase struct { name string param string - want share.Namespace + want []byte wantErr bool } testCases := []testCase{ { param: "0x0c204d39600fddd3", name: "8 byte hex encoded namespace ID gets left padded", - want: share.Namespace{ + want: []byte{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc, 0x20, 0x4d, 0x39, 0x60, 0xf, 0xdd, 0xd3, }, @@ -28,7 +29,7 @@ func Test_parseNamespaceID(t *testing.T) { { name: "10 byte hex encoded namespace ID", param: "0x42690c204d39600fddd3", - want: share.Namespace{ + want: []byte{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x42, 0x69, 0xc, 0x20, 0x4d, 0x39, 0x60, 0xf, 0xdd, 0xd3, }, @@ -37,7 +38,7 @@ func Test_parseNamespaceID(t *testing.T) { { name: "29 byte hex encoded namespace ID", param: "0x0000000000000000000000000000000000000001010101010101010101", - want: share.Namespace{ + want: []byte{ 0x0, // namespace version 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // v0 ID prefix 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // namespace ID @@ -47,13 +48,13 @@ func Test_parseNamespaceID(t *testing.T) { { name: "11 byte hex encoded namespace ID returns error", param: "0x42690c204d39600fddd3a3", - want: share.Namespace{}, + want: nil, wantErr: true, }, { name: "10 byte base64 encoded namespace ID", param: "QmkMIE05YA/d0w==", - want: share.Namespace{ + want: []byte{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x42, 0x69, 0xc, 0x20, 0x4d, 0x39, 0x60, 0xf, 0xdd, 0xd3, }, @@ -62,7 +63,7 @@ func Test_parseNamespaceID(t *testing.T) { { name: "not base64 or hex encoded namespace ID returns error", param: "5748493939429", - want: share.Namespace{}, + want: nil, wantErr: true, }, } @@ -74,8 +75,11 @@ func Test_parseNamespaceID(t *testing.T) { assert.Error(t, err) return } + assert.NoError(t, err) - assert.Equal(t, tc.want, got) + ns, err := share.NewNamespaceFromBytes(tc.want) + require.NoError(t, err) + assert.Equal(t, ns, got) }) } } diff --git a/core/eds.go b/core/eds.go index a069ca7cec..b4d4fdfbcb 100644 --- a/core/eds.go +++ b/core/eds.go @@ -6,18 +6,19 @@ import ( "github.com/tendermint/tendermint/types" - "github.com/celestiaorg/celestia-app/v2/app" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/app" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" "github.com/celestiaorg/go-square/shares" - "github.com/celestiaorg/go-square/square" + libSquare "github.com/celestiaorg/go-square/v2" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/pruner" "github.com/celestiaorg/celestia-node/pruner/full" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" "github.com/celestiaorg/celestia-node/store" ) @@ -26,11 +27,11 @@ import ( // nil is returned in place of the eds. func extendBlock(data types.Data, appVersion uint64, options ...nmt.Option) (*rsmt2d.ExtendedDataSquare, error) { if app.IsEmptyBlock(data, appVersion) { - return share.EmptyEDS(), nil + return square.EmptyEDS(), nil } // Construct the data square from the block's transactions - dataSquare, err := square.Construct( + dataSquare, err := libSquare.Construct( data.Txs.ToSliceOfBytes(), appconsts.SquareSizeUpperBound(appVersion), appconsts.SubtreeRootThreshold(appVersion), @@ -38,7 +39,7 @@ func extendBlock(data types.Data, appVersion uint64, options ...nmt.Option) (*rs if err != nil { return nil, err } - return extendShares(shares.ToBytes(dataSquare), options...) + return extendShares(share.ToBytes(dataSquare), options...) } func extendShares(s [][]byte, options ...nmt.Option) (*rsmt2d.ExtendedDataSquare, error) { @@ -48,7 +49,7 @@ func extendShares(s [][]byte, options ...nmt.Option) (*rsmt2d.ExtendedDataSquare } // here we construct a tree // Note: uses the nmt wrapper to construct the tree. - squareSize := square.Size(len(s)) + squareSize := libSquare.Size(len(s)) return rsmt2d.ComputeExtendedDataSquare(s, appconsts.DefaultCodec(), wrapper.NewConstructor(uint64(squareSize), diff --git a/core/eds_test.go b/core/eds_test.go index 462561852a..ff4f6be808 100644 --- a/core/eds_test.go +++ b/core/eds_test.go @@ -7,10 +7,10 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/types" - "github.com/celestiaorg/celestia-app/v2/app" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" + "github.com/celestiaorg/celestia-app/v3/app" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" ) // TestTrulyEmptySquare ensures that a truly empty square (square size 1 and no @@ -24,7 +24,7 @@ func TestTrulyEmptySquare(t *testing.T) { eds, err := extendBlock(data, appconsts.LatestVersion) require.NoError(t, err) - require.True(t, eds.Equals(share.EmptyEDS())) + require.True(t, eds.Equals(square.EmptyEDS())) } // TestEmptySquareWithZeroTxs tests that the datahash of a block with no transactions @@ -40,13 +40,13 @@ func TestEmptySquareWithZeroTxs(t *testing.T) { eds, err := extendBlock(data, appconsts.LatestVersion) require.NoError(t, err) - require.True(t, eds.Equals(share.EmptyEDS())) + require.True(t, eds.Equals(square.EmptyEDS())) // force extend the square using an empty block and compare with the min DAH eds, err = app.ExtendBlock(data, appconsts.LatestVersion) require.NoError(t, err) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) - assert.Equal(t, share.EmptyEDSRoots().Hash(), roots.Hash()) + assert.Equal(t, square.EmptyEDSRoots().Hash(), roots.Hash()) } diff --git a/core/exchange_test.go b/core/exchange_test.go index fb3795d380..c7c1b6e3ab 100644 --- a/core/exchange_test.go +++ b/core/exchange_test.go @@ -10,11 +10,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-app/v2/test/util/testnode" + "github.com/celestiaorg/celestia-app/v3/test/util/testnode" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" "github.com/celestiaorg/celestia-node/store" ) @@ -103,7 +103,7 @@ func TestExchange_DoNotStoreHistoric(t *testing.T) { assert.False(t, has) // empty EDSs are expected to exist in the store, so we skip them - if h.DAH.Equals(share.EmptyEDSRoots()) { + if h.DAH.Equals(square.EmptyEDSRoots()) { continue } has, err = store.HasByHash(ctx, h.DAH.Hash()) @@ -147,7 +147,7 @@ func generateNonEmptyBlocks( fetcher *BlockFetcher, cfg *testnode.Config, cctx testnode.Context, -) []share.DataHash { +) []square.DataHash { // generate several non-empty blocks generateCtx, generateCtxCancel := context.WithCancel(context.Background()) @@ -160,7 +160,7 @@ func generateNonEmptyBlocks( go fillBlocks(t, generateCtx, cfg, cctx) - hashes := make([]share.DataHash, 0, 20) + hashes := make([]square.DataHash, 0, 20) i := 0 for i < 20 { @@ -168,10 +168,10 @@ func generateNonEmptyBlocks( case b, ok := <-sub: require.True(t, ok) - if bytes.Equal(share.EmptyEDSDataHash(), b.Data.Hash()) { + if bytes.Equal(square.EmptyEDSDataHash(), b.Data.Hash()) { continue } - hashes = append(hashes, share.DataHash(b.Data.Hash())) + hashes = append(hashes, square.DataHash(b.Data.Hash())) i++ case <-ctx.Done(): t.Fatal("failed to fill blocks within timeout") diff --git a/core/header_test.go b/core/header_test.go index bcf3f177c9..87c4378bb4 100644 --- a/core/header_test.go +++ b/core/header_test.go @@ -9,11 +9,11 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/rand" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" ) func TestMakeExtendedHeaderForEmptyBlock(t *testing.T) { @@ -40,7 +40,7 @@ func TestMakeExtendedHeaderForEmptyBlock(t *testing.T) { headerExt, err := header.MakeExtendedHeader(&b.Header, comm, val, eds) require.NoError(t, err) - assert.Equal(t, share.EmptyEDSRoots(), headerExt.DAH) + assert.Equal(t, square.EmptyEDSRoots(), headerExt.DAH) } func TestMismatchedDataHash_ComputedRoot(t *testing.T) { diff --git a/core/listener.go b/core/listener.go index 67e532d970..694675d420 100644 --- a/core/listener.go +++ b/core/listener.go @@ -15,7 +15,7 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" "github.com/celestiaorg/celestia-node/store" ) diff --git a/core/listener_no_race_test.go b/core/listener_no_race_test.go index b7d26fba36..3c67932104 100644 --- a/core/listener_no_race_test.go +++ b/core/listener_no_race_test.go @@ -11,7 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" "github.com/celestiaorg/celestia-node/store" ) @@ -43,7 +43,7 @@ func TestListenerWithNonEmptyBlocks(t *testing.T) { require.NoError(t, err) t.Cleanup(sub.Cancel) - empty := share.EmptyEDSRoots() + empty := square.EmptyEDSRoots() // TODO extract 16 for i := 0; i < 16; i++ { accounts := cfg.Genesis.Accounts() diff --git a/core/listener_test.go b/core/listener_test.go index 252c6e88c1..54a52864cf 100644 --- a/core/listener_test.go +++ b/core/listener_test.go @@ -16,7 +16,7 @@ import ( "github.com/celestiaorg/celestia-node/header" nodep2p "github.com/celestiaorg/celestia-node/nodebuilder/p2p" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" "github.com/celestiaorg/celestia-node/store" ) diff --git a/core/testing.go b/core/testing.go index dafeaed756..6d2aa8cc36 100644 --- a/core/testing.go +++ b/core/testing.go @@ -10,8 +10,8 @@ import ( tmconfig "github.com/tendermint/tendermint/config" tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/celestiaorg/celestia-app/v2/test/util/genesis" - "github.com/celestiaorg/celestia-app/v2/test/util/testnode" + "github.com/celestiaorg/celestia-app/v3/test/util/genesis" + "github.com/celestiaorg/celestia-app/v3/test/util/testnode" ) const chainID = "private" diff --git a/das/coordinator.go b/das/coordinator.go index aff41bac8c..c5ad1a668c 100644 --- a/das/coordinator.go +++ b/das/coordinator.go @@ -8,7 +8,7 @@ import ( libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" ) // samplingCoordinator runs and coordinates sampling workers and updates current sampling state diff --git a/das/coordinator_test.go b/das/coordinator_test.go index a94a9a4e6f..3b5b7f793a 100644 --- a/das/coordinator_test.go +++ b/das/coordinator_test.go @@ -13,8 +13,8 @@ import ( "github.com/tendermint/tendermint/types" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" ) func TestCoordinator(t *testing.T) { @@ -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.AxisRoots{RowRoots: make([][]byte, 0)}, + DAH: &square.AxisRoots{RowRoots: make([][]byte, 0)}, }) } diff --git a/das/daser.go b/das/daser.go index 2b0b84ba29..cf8056ff95 100644 --- a/das/daser.go +++ b/das/daser.go @@ -14,9 +14,9 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" ) var log = logging.Logger("das") @@ -30,7 +30,7 @@ var errOutsideSamplingWindow = fmt.Errorf("skipping header outside of sampling w type DASer struct { params Parameters - da share.Availability + da square.Availability bcast fraud.Broadcaster[*header.ExtendedHeader] hsub libhead.Subscriber[*header.ExtendedHeader] // listens for new headers in the network getter libhead.Getter[*header.ExtendedHeader] // retrieves past headers @@ -51,7 +51,7 @@ type ( // NewDASer creates a new DASer. func NewDASer( - da share.Availability, + da square.Availability, hsub libhead.Subscriber[*header.ExtendedHeader], getter libhead.Getter[*header.ExtendedHeader], dstore datastore.Datastore, diff --git a/das/daser_test.go b/das/daser_test.go index c67e5c06e2..bf4516f40f 100644 --- a/das/daser_test.go +++ b/das/daser_test.go @@ -20,9 +20,9 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/availability/mocks" - "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/availability/mocks" + "github.com/celestiaorg/celestia-node/square/eds/edstest" ) var timeout = time.Second * 15 @@ -285,7 +285,7 @@ func TestDASer_SamplingWindow(t *testing.T) { // createDASerSubcomponents takes numGetter (number of headers // to store in mockGetter) and numSub (number of headers to store // in the mock header.Subscriber), returning a newly instantiated -// mockGetter, share.Availability, and mock header.Subscriber. +// mockGetter, square.Availability, and mock header.Subscriber. func createDASerSubcomponents( t *testing.T, numGetter, @@ -399,7 +399,7 @@ type benchGetterStub struct { func newBenchGetter() benchGetterStub { return benchGetterStub{header: &header.ExtendedHeader{ - DAH: &share.AxisRoots{RowRoots: make([][]byte, 0)}, + DAH: &square.AxisRoots{RowRoots: make([][]byte, 0)}, }} } @@ -420,7 +420,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.AxisRoots{RowRoots: make([][]byte, 0)}, + DAH: &square.AxisRoots{RowRoots: make([][]byte, 0)}, }, nil } diff --git a/das/worker.go b/das/worker.go index 88ca387211..4da0acd89e 100644 --- a/das/worker.go +++ b/das/worker.go @@ -10,7 +10,7 @@ import ( libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" ) type jobType string diff --git a/docs/adr/adr-011-blocksync-overhaul-part-1.md b/docs/adr/adr-011-blocksync-overhaul-part-1.md index 0173e78efb..50318efa09 100644 --- a/docs/adr/adr-011-blocksync-overhaul-part-1.md +++ b/docs/adr/adr-011-blocksync-overhaul-part-1.md @@ -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, square.DataHash) (*share.Root, error) ``` ##### `eds.Store.Get` diff --git a/go.mod b/go.mod index 985bfb4c41..a8f2fce0d2 100644 --- a/go.mod +++ b/go.mod @@ -7,14 +7,15 @@ require ( github.com/BurntSushi/toml v1.4.0 github.com/alecthomas/jsonschema v0.0.0-20220216202328-9eeeec9d044b github.com/benbjohnson/clock v1.3.5 - github.com/celestiaorg/celestia-app/v2 v2.2.0-arabica + github.com/celestiaorg/celestia-app/v3 v3.0.0 github.com/celestiaorg/go-fraud v0.2.1 github.com/celestiaorg/go-header v0.6.2 github.com/celestiaorg/go-libp2p-messenger v0.2.0 github.com/celestiaorg/go-square v1.1.0 github.com/celestiaorg/go-square/merkle v0.0.0-20240117232118-fd78256df076 + github.com/celestiaorg/go-square/v2 v2.0.0 github.com/celestiaorg/nmt v0.22.1 - github.com/celestiaorg/rsmt2d v0.13.1 + github.com/celestiaorg/rsmt2d v0.14.0 github.com/cosmos/cosmos-sdk v0.46.16 github.com/cristalhq/jwt/v5 v5.4.0 github.com/dgraph-io/badger/v4 v4.2.1-0.20240106094458-1c417aa3799c @@ -74,13 +75,13 @@ require ( golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa golang.org/x/sync v0.8.0 golang.org/x/text v0.17.0 - google.golang.org/grpc v1.66.2 + google.golang.org/grpc v1.67.0 google.golang.org/protobuf v1.34.2 ) require ( cloud.google.com/go v0.112.1 // indirect - cloud.google.com/go/compute/metadata v0.3.0 // indirect + cloud.google.com/go/compute/metadata v0.5.0 // indirect cloud.google.com/go/iam v1.1.6 // indirect cloud.google.com/go/storage v1.38.0 // indirect cosmossdk.io/errors v1.0.1 // indirect @@ -134,13 +135,14 @@ require ( github.com/dgraph-io/badger/v2 v2.2007.4 // indirect github.com/dgraph-io/ristretto v0.1.1 // indirect github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect + github.com/docker/go-connections v0.4.1-0.20210727194412-58542c764a11 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/dvsekhvalnov/jose2go v1.6.0 // indirect github.com/elastic/gosigar v0.14.3 // indirect github.com/etclabscore/go-jsonschema-walk v0.0.6 // indirect github.com/ethereum/c-kzg-4844 v1.0.0 // indirect - github.com/ethereum/go-ethereum v1.14.5 // indirect + github.com/ethereum/go-ethereum v1.14.7 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/flynn/noise v1.1.0 // indirect github.com/francoispqt/gojay v1.2.13 // indirect @@ -155,12 +157,12 @@ require ( github.com/go-openapi/jsonpointer v0.19.6 // indirect github.com/go-openapi/jsonreference v0.20.2 // indirect github.com/go-openapi/spec v0.19.11 // indirect - github.com/go-openapi/swag v0.22.3 // indirect + github.com/go-openapi/swag v0.22.4 // indirect github.com/go-task/slim-sprig/v3 v3.0.0 // indirect github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/gogo/gateway v1.1.0 // indirect - github.com/golang/glog v1.2.1 // indirect + github.com/golang/glog v1.2.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect @@ -194,7 +196,7 @@ require ( github.com/hashicorp/golang-lru/arc/v2 v2.0.7 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/hdevalence/ed25519consensus v0.0.0-20220222234857-c00d1f31bab3 // indirect - github.com/holiman/uint256 v1.2.4 // indirect + github.com/holiman/uint256 v1.3.0 // indirect github.com/huin/goupnp v1.3.0 // indirect github.com/iancoleman/orderedmap v0.2.0 // indirect github.com/improbable-eng/grpc-web v0.15.0 // indirect @@ -309,7 +311,7 @@ require ( github.com/wlynxg/anet v0.0.4 // indirect github.com/zondax/hid v0.9.2 // indirect github.com/zondax/ledger-go v0.14.3 // indirect - go.etcd.io/bbolt v1.3.6 // indirect + go.etcd.io/bbolt v1.3.10 // indirect go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 // indirect @@ -319,7 +321,7 @@ require ( go.uber.org/multierr v1.11.0 // indirect golang.org/x/mod v0.20.0 // indirect golang.org/x/net v0.28.0 // indirect - golang.org/x/oauth2 v0.21.0 // indirect + golang.org/x/oauth2 v0.22.0 // indirect golang.org/x/sys v0.24.0 // indirect golang.org/x/term v0.23.0 // indirect golang.org/x/time v0.5.0 // indirect @@ -328,8 +330,8 @@ require ( gonum.org/v1/gonum v0.15.0 // indirect google.golang.org/api v0.169.0 // indirect google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240617180043-68d350f18fd4 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240617180043-68d350f18fd4 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect @@ -340,6 +342,8 @@ require ( ) replace ( + github.com/celestiaorg/celestia-app/v3 v3.0.0 => ../celestia-app + github.com/celestiaorg/go-square/v2 v2.0.0 => ../go-square github.com/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v1.24.1-sdk-v0.46.16 github.com/filecoin-project/dagstore => github.com/celestiaorg/dagstore v0.0.0-20230824094345-537c012aa403 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 diff --git a/go.sum b/go.sum index bda10e72d1..571089ea83 100644 --- a/go.sum +++ b/go.sum @@ -73,8 +73,8 @@ cloud.google.com/go/compute v1.6.0/go.mod h1:T29tfhtVbq1wvAPo0E3+7vhgmkOYeXjhFvz cloud.google.com/go/compute v1.6.1/go.mod h1:g85FgpzFvNULZ+S8AYq87axRKuf2Kh7deLqV/jJ3thU= cloud.google.com/go/compute v1.7.0/go.mod h1:435lt8av5oL9P3fv1OEzSbSUe+ybHXGMPQHHZWZxy9U= cloud.google.com/go/compute v1.10.0/go.mod h1:ER5CLbMxl90o2jtNbGSbtfOpQKR0t15FOtRsugnLrlU= -cloud.google.com/go/compute/metadata v0.3.0 h1:Tz+eQXMEqDIKRsmY3cHTL6FVaynIjX2QxYC4trgAKZc= -cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k= +cloud.google.com/go/compute/metadata v0.5.0 h1:Zr0eK8JbFv6+Wi4ilXAR8FJ3wyNdpxHKJNPos6LTZOY= +cloud.google.com/go/compute/metadata v0.5.0/go.mod h1:aHnloV2TPI38yx4s9+wAZhHykWvVCfu7hQbF+9CWoiY= cloud.google.com/go/containeranalysis v0.5.1/go.mod h1:1D92jd8gRR/c0fGMlymRgxWD3Qw9C1ff6/T7mLgVL8I= cloud.google.com/go/containeranalysis v0.6.0/go.mod h1:HEJoiEIu+lEXM+k7+qLCci0h33lX3ZqoYFdmPcoO7s4= cloud.google.com/go/datacatalog v1.3.0/go.mod h1:g9svFY6tuR+j+hrTw3J2dNcmI0dzmSiyOzm8kpLq0a0= @@ -229,6 +229,7 @@ github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go github.com/Masterminds/glide v0.13.2/go.mod h1:STyF5vcenH/rUqTEv+/hBXlSTo7KYwg2oc2f4tzPWic= github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= github.com/Masterminds/vcs v1.13.0/go.mod h1:N09YCmOQr6RLxC6UNHzuVwAdodYbbnycGHSmwVJjcKA= +github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw= @@ -344,8 +345,6 @@ github.com/c-bata/go-prompt v0.2.2/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOC github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= github.com/celestiaorg/blobstream-contracts/v3 v3.1.0 h1:h1Y4V3EMQ2mFmNtWt2sIhZIuyASInj1a9ExI8xOsTOw= github.com/celestiaorg/blobstream-contracts/v3 v3.1.0/go.mod h1:x4DKyfKOSv1ZJM9NwV+Pw01kH2CD7N5zTFclXIVJ6GQ= -github.com/celestiaorg/celestia-app/v2 v2.2.0-arabica h1:EbcV7BVOs8oaN4DFO76B9dKOJtZu1DH8yLSGcwejIKU= -github.com/celestiaorg/celestia-app/v2 v2.2.0-arabica/go.mod h1:+7xlXlBA3Tx9u1LxZF/4QAaAGfBIXv8JPrrFQAbLiWA= github.com/celestiaorg/celestia-core v1.40.0-tm-v0.34.29 h1:J79TAjizxwIvm7/k+WI3PPH1aFj4AjOSjajoq5UzAwI= github.com/celestiaorg/celestia-core v1.40.0-tm-v0.34.29/go.mod h1:5jJ5magtH7gQOwSYfS/m5fliIS7irKunLV7kLNaD8o0= github.com/celestiaorg/cosmos-sdk v1.24.1-sdk-v0.46.16 h1:SeQ7Y/CyOcUMKo7mQiexaj/pZ/xIgyuZFIwYZwpSkWE= @@ -364,8 +363,8 @@ github.com/celestiaorg/merkletree v0.0.0-20230308153949-c33506a7aa26 h1:P2RI1xJ4 github.com/celestiaorg/merkletree v0.0.0-20230308153949-c33506a7aa26/go.mod h1:2m8ukndOegwB0PU0AfJCwDUQHqd7QQRlSXvQL5VToVY= github.com/celestiaorg/nmt v0.22.1 h1:t7fqoP5MJ8mBns5DB2XjfcPxQpS3CKMkY+v+BEkDxYc= github.com/celestiaorg/nmt v0.22.1/go.mod h1:ia/EpCk0enD5yO5frcxoNoFToz2Ghtk2i+blmCRjIY8= -github.com/celestiaorg/rsmt2d v0.13.1 h1:eRhp79DKTkDojwInKVs1lRK6f6zJc1BVlmZfUfI19yQ= -github.com/celestiaorg/rsmt2d v0.13.1/go.mod h1:P7t92OATXbBmc/P5uR+GCOBv+PV8wLb0vU32ucrb148= +github.com/celestiaorg/rsmt2d v0.14.0 h1:L7XJ3tRJDY8sQcvCjzHq0L7JmsmaSD+VItymIYFLqYc= +github.com/celestiaorg/rsmt2d v0.14.0/go.mod h1:4kxqiTdFev49sGiKXTDjohbWYOG5GlcIfftTgaBJnpc= github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= @@ -410,12 +409,14 @@ github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWH github.com/cockroachdb/apd/v2 v2.0.2 h1:weh8u7Cneje73dDh+2tEVLUvyBc89iwepWCD8b8034E= github.com/cockroachdb/apd/v2 v2.0.2/go.mod h1:DDxRlzC2lo3/vSlmSoS7JkqbbrARPuFOGr0B9pvN3Gw= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= -github.com/cockroachdb/errors v1.11.1 h1:xSEW75zKaKCWzR3OfxXUxgrk/NtT4G1MiOv5lWZazG8= -github.com/cockroachdb/errors v1.11.1/go.mod h1:8MUxA3Gi6b25tYlFEBGLf+D8aISL+M4MIpiWMSNRfxw= +github.com/cockroachdb/errors v1.11.3 h1:5bA+k2Y6r+oz/6Z/RFlNeVCesGARKuC6YymtcDrbC/I= +github.com/cockroachdb/errors v1.11.3/go.mod h1:m4UIW4CDjx+R5cybPsNrRbreomiFqt8o1h1wUVazSd8= +github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce h1:giXvy4KSc/6g/esnpM7Geqxka4WSqI1SZc7sMJFd3y4= +github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce/go.mod h1:9/y3cnZ5GKakj/H4y9r9GTjCvAFta7KLgSHPJJYc52M= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= -github.com/cockroachdb/pebble v1.1.0 h1:pcFh8CdCIt2kmEpK0OIatq67Ln9uGDYY3d5XnE0LJG4= -github.com/cockroachdb/pebble v1.1.0/go.mod h1:sEHm5NOXxyiAoKWhoFxT8xMgd/f3RA6qUqQ1BXKrh2E= +github.com/cockroachdb/pebble v1.1.1 h1:XnKU22oiCLy2Xn8vp1re67cXg4SAasg/WDt1NtcRFaw= +github.com/cockroachdb/pebble v1.1.1/go.mod h1:4exszw1r40423ZsmkG/09AFEG83I0uDgfujJdbL6kYU= github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30= github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= @@ -441,8 +442,8 @@ github.com/containerd/cgroups v0.0.0-20201119153540-4cbc285b3327/go.mod h1:ZJeTF github.com/containerd/cgroups v1.0.3/go.mod h1:/ofk34relqNjSGyqPrmEULrO4Sc8LJhvJmWbUCUKqj8= github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM= github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw= -github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg= -github.com/containerd/continuity v0.3.0/go.mod h1:wJEAIwKOm/pBZuBd0JmeTvnLquTB1Ag8espWhkykbPM= +github.com/containerd/continuity v0.4.2 h1:v3y/4Yz5jwnvqPKJJ+7Wf93fyWoCB3F5EclWG023MDM= +github.com/containerd/continuity v0.4.2/go.mod h1:F6PTNCKepoxEaXLQp3wDAjygEnImnZ/7o4JzpodfroQ= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= @@ -579,8 +580,8 @@ github.com/etclabscore/go-openrpc-reflect v0.0.37/go.mod h1:0404Ky3igAasAOpyj1eE github.com/ethereum/c-kzg-4844 v1.0.0 h1:0X1LBXxaEtYD9xsyj9B9ctQEZIpnvVDeoBx8aHEwTNA= github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= github.com/ethereum/go-ethereum v1.10.17/go.mod h1:Lt5WzjM07XlXc95YzrhosmR4J9Ahd6X2wyEV2SvGhk0= -github.com/ethereum/go-ethereum v1.14.5 h1:szuFzO1MhJmweXjoM5nSAeDvjNUH3vIQoMzzQnfvjpw= -github.com/ethereum/go-ethereum v1.14.5/go.mod h1:VEDGGhSxY7IEjn98hJRFXl/uFvpRgbIIf2PpXiyGGgc= +github.com/ethereum/go-ethereum v1.14.7 h1:EHpv3dE8evQmpVEQ/Ne2ahB06n2mQptdwqaMNhAT29g= +github.com/ethereum/go-ethereum v1.14.7/go.mod h1:Mq0biU2jbdmKSZoqOj29017ygFrMnB5/Rifwp980W4o= github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0 h1:KrE8I4reeVvf7C1tm8elRjj4BdscTYzz/WAbYyf/JI4= github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0/go.mod h1:D9AJLVXSyZQXJQVk8oh1EwjISE+sJTn2duYIZC0dy3w= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0= @@ -627,8 +628,8 @@ github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff h1:tY80oXqG github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww= github.com/getkin/kin-openapi v0.53.0/go.mod h1:7Yn5whZr5kJi6t+kShccXS8ae1APpYTW6yheSwk8Yi4= github.com/getkin/kin-openapi v0.61.0/go.mod h1:7Yn5whZr5kJi6t+kShccXS8ae1APpYTW6yheSwk8Yi4= -github.com/getsentry/sentry-go v0.18.0 h1:MtBW5H9QgdcJabtZcuJG80BMOwaBpkRDZkxRkNC1sN0= -github.com/getsentry/sentry-go v0.18.0/go.mod h1:Kgon4Mby+FJ7ZWHFUAZgVaIa8sxHtnRJRLTXZr51aKQ= +github.com/getsentry/sentry-go v0.27.0 h1:Pv98CIbtB3LkMWmXi4Joa5OOcwbmnX88sF5qbK3r3Ps= +github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= @@ -685,8 +686,9 @@ github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.19.8/go.mod h1:ao+8BpOPyKdpQz3AOJfbeEVpLmWAvlT1IfTe5McPyhY= github.com/go-openapi/swag v0.19.11/go.mod h1:Uc0gKkdR+ojzsEpjh39QChyu92vPgIr72POcgHMAgSY= -github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g= github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= +github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU= +github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= @@ -727,8 +729,8 @@ github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/glog v1.2.1 h1:OptwRhECazUx5ix5TTWC3EZhsZEHWcYWY4FQHTIubm4= -github.com/golang/glog v1.2.1/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= +github.com/golang/glog v1.2.2 h1:1+mZ9upx1Dh6FmUTFR1naJ77miKiXgALjWOZ3NVFPmY= +github.com/golang/glog v1.2.2/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -969,8 +971,8 @@ github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4/go.mod h1:5GuXa7vkL8 github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw= -github.com/holiman/uint256 v1.2.4 h1:jUc4Nk8fm9jZabQuqr2JzednajVmBpC+oiTiXZJEApU= -github.com/holiman/uint256 v1.2.4/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E= +github.com/holiman/uint256 v1.3.0 h1:4wdcm/tnd0xXdu7iS3ruNvxkWwrb4aeBQv19ayYn8F4= +github.com/holiman/uint256 v1.3.0/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc= @@ -1512,8 +1514,8 @@ github.com/open-rpc/meta-schema v0.0.0-20201029221707-1b72ef2ea333 h1:CznVS40zms github.com/open-rpc/meta-schema v0.0.0-20201029221707-1b72ef2ea333/go.mod h1:Ag6rSXkHIckQmjFBCweJEEt1mrTPBv8b9W4aU/NQWfI= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= -github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b h1:YWuSjZCQAPM8UUBLkYUk1e+rZcvWHJmFb6i6rM44Xs8= -github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b/go.mod h1:3OVijpioIKYWTqjiG0zfF6wvoJ4fAXGbjdZuI2NgsRQ= +github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug= +github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM= github.com/opencontainers/runc v1.1.3 h1:vIXrkId+0/J2Ymu2m7VjGvbSlAId9XNRPhn2p4b+d8w= github.com/opencontainers/runc v1.1.3/go.mod h1:1J5XiS+vdZ3wCyZybsuxXZWGrgSr8fFJHLXuG2PsnNg= github.com/opencontainers/runtime-spec v1.0.2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= @@ -1737,6 +1739,7 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDaXHZDBsXlPCDqdhQuJkuw4NOtaxYe3xii4= github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= @@ -1910,8 +1913,8 @@ gitlab.com/NebulousLabs/errors v0.0.0-20200929122200-06c536cf6975/go.mod h1:ZkMZ gitlab.com/NebulousLabs/fastrand v0.0.0-20181126182046-603482d69e40 h1:dizWJqTWjwyD8KGcMOwgrkqu1JIkofYgKkmDeNE7oAs= gitlab.com/NebulousLabs/fastrand v0.0.0-20181126182046-603482d69e40/go.mod h1:rOnSnoRyxMI3fe/7KIbVcsHRGxe30OONv8dEgo+vCfA= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= -go.etcd.io/bbolt v1.3.6 h1:/ecaJf0sk1l4l6V4awd65v2C3ILy7MSj+s/x1ADCIMU= -go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4= +go.etcd.io/bbolt v1.3.10 h1:+BqfJTcCzTItrop8mq/lbzL8wSGtj94UO/3U31shqG0= +go.etcd.io/bbolt v1.3.10/go.mod h1:bK3UQLPJZly7IlNmV7uVHJDxfe5aK9Ll93e/74Y9oEQ= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= @@ -2191,8 +2194,8 @@ golang.org/x/oauth2 v0.0.0-20220822191816-0ebed06d0094/go.mod h1:h4gKUeWbJ4rQPri golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg= golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg= golang.org/x/oauth2 v0.1.0/go.mod h1:G9FE4dLTsbXUu90h/Pf85g4w1D+SSAgR+q46nJZ8M4A= -golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= -golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA= +golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/perf v0.0.0-20180704124530-6e6d33e29852/go.mod h1:JLpeXjPJfIyPr5TlbXLkXWLhP8nz10XfvxElABhCtcw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -2275,7 +2278,6 @@ golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -2645,10 +2647,10 @@ google.golang.org/genproto v0.0.0-20221014213838-99cd37c6964a/go.mod h1:1vXfmgAz google.golang.org/genproto v0.0.0-20221025140454-527a21cfbd71/go.mod h1:9qHF0xnpdSfF6knlcsnpzUu5y+rpwgbvsyGAZPBMg4s= google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de h1:F6qOa9AZTYJXOUEr4jDysRDLrm4PHePlge4v4TGAlxY= google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo= -google.golang.org/genproto/googleapis/api v0.0.0-20240617180043-68d350f18fd4 h1:MuYw1wJzT+ZkybKfaOXKp5hJiZDn2iHaXRw0mRYdHSc= -google.golang.org/genproto/googleapis/api v0.0.0-20240617180043-68d350f18fd4/go.mod h1:px9SlOOZBg1wM1zdnr8jEL4CNGUBZ+ZKYtNPApNQc4c= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240617180043-68d350f18fd4 h1:Di6ANFilr+S60a4S61ZM00vLdw0IrQOSMS2/6mrnOU0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240617180043-68d350f18fd4/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= +google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 h1:wKguEg1hsxI2/L3hUYrpo1RVi48K+uTyzKqprwLXsb8= +google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142/go.mod h1:d6be+8HhtEtucleCbxpPW9PA9XwISACu8nvpPqF0BVo= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:e7S5W7MGGLaSu8j3YjdezkZ+m1/Nm0uRVRMEMGk26Xs= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= @@ -2694,8 +2696,8 @@ google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACu google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= google.golang.org/grpc v1.50.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= -google.golang.org/grpc v1.66.2 h1:3QdXkuq3Bkh7w+ywLdLvM56cmGvQHUMZpiCzt6Rqaoo= -google.golang.org/grpc v1.66.2/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= +google.golang.org/grpc v1.67.0 h1:IdH9y6PF5MPSdAntIcpjQ+tXO41pcQsfZV2RxtQgVcw= +google.golang.org/grpc v1.67.0/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= diff --git a/header/header.go b/header/header.go index 669061044e..4db80d0ac3 100644 --- a/header/header.go +++ b/header/header.go @@ -11,8 +11,8 @@ import ( "github.com/tendermint/tendermint/light" core "github.com/tendermint/tendermint/types" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - "github.com/celestiaorg/celestia-app/v2/pkg/da" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + "github.com/celestiaorg/celestia-app/v3/pkg/da" libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/rsmt2d" ) diff --git a/header/headertest/fraud/testing.go b/header/headertest/fraud/testing.go index 5f4bdca084..0f3b8a11b5 100644 --- a/header/headertest/fraud/testing.go +++ b/header/headertest/fraud/testing.go @@ -10,14 +10,14 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" - "github.com/celestiaorg/celestia-app/v2/pkg/da" + "github.com/celestiaorg/celestia-app/v3/pkg/da" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/ipld" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/ipld" "github.com/celestiaorg/celestia-node/store" ) diff --git a/header/headertest/testing.go b/header/headertest/testing.go index ddac1995a6..44d93c9db5 100644 --- a/header/headertest/testing.go +++ b/header/headertest/testing.go @@ -17,13 +17,13 @@ import ( "github.com/tendermint/tendermint/types" tmtime "github.com/tendermint/tendermint/types/time" - "github.com/celestiaorg/celestia-app/v2/pkg/da" + "github.com/celestiaorg/celestia-app/v3/pkg/da" libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/go-header/headertest" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" ) // TestSuite provides everything you need to test chain of Headers. @@ -66,7 +66,7 @@ func NewTestSuite(t *testing.T, numValidators int, blockTime time.Duration) *Tes } func (s *TestSuite) genesis() *header.ExtendedHeader { - dah := share.EmptyEDSRoots() + dah := square.EmptyEDSRoots() gen := RandRawHeader(s.t) @@ -152,7 +152,7 @@ func (s *TestSuite) NextHeader() *header.ExtendedHeader { return s.head } - dah := share.EmptyEDSRoots() + dah := square.EmptyEDSRoots() height := s.Head().Height() + 1 rh := s.GenRawHeader(height, s.Head().Hash(), libhead.Hash(s.Head().Commit.Hash()), dah.Hash()) s.head = &header.ExtendedHeader{ @@ -229,7 +229,7 @@ func RandExtendedHeader(t testing.TB) *header.ExtendedHeader { } func RandExtendedHeaderAtTimestamp(t testing.TB, timestamp time.Time) *header.ExtendedHeader { - dah := share.EmptyEDSRoots() + dah := square.EmptyEDSRoots() rh := RandRawHeader(t) rh.DataHash = dah.Hash() @@ -328,7 +328,7 @@ func ExtendedHeadersFromEdsses(t testing.TB, edsses []*rsmt2d.ExtendedDataSquare for i, eds := range edsses { gen := RandRawHeader(t) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) gen.DataHash = roots.Hash() gen.ValidatorsHash = valSet.Hash() @@ -358,7 +358,7 @@ func ExtendedHeadersFromEdsses(t testing.TB, edsses []*rsmt2d.ExtendedDataSquare func ExtendedHeaderFromEDS(t testing.TB, height uint64, eds *rsmt2d.ExtendedDataSquare) *header.ExtendedHeader { valSet, vals := RandValidatorSet(10, 10) gen := RandRawHeader(t) - dah, err := share.NewAxisRoots(eds) + dah, err := square.NewAxisRoots(eds) require.NoError(t, err) gen.DataHash = dah.Hash() diff --git a/header/headertest/validate_test.go b/header/headertest/validate_test.go index d7c6e4b1cc..f569f0d6e0 100644 --- a/header/headertest/validate_test.go +++ b/header/headertest/validate_test.go @@ -10,7 +10,7 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" - "github.com/celestiaorg/celestia-app/v2/pkg/da" + "github.com/celestiaorg/celestia-app/v3/pkg/da" "github.com/celestiaorg/celestia-node/header" ) @@ -30,7 +30,11 @@ func TestValidate(t *testing.T) { }, { extendedHeader: getExtendedHeader(t, 3), - wantErr: "has version 3, this node supports up to version 2. " + + wantErr: "", + }, + { + extendedHeader: getExtendedHeader(t, 4), + wantErr: "has version 4, this node supports up to version 3. " + "Please upgrade to support new version. Note, 0 is not a valid version", }, } diff --git a/header/pb/extended_header.pb.go b/header/pb/extended_header.pb.go index 03ca6cba06..b1c989532a 100644 --- a/header/pb/extended_header.pb.go +++ b/header/pb/extended_header.pb.go @@ -5,7 +5,7 @@ package header_pb import ( fmt "fmt" - da "github.com/celestiaorg/celestia-app/v2/proto/celestia/core/v1/da" + da "github.com/celestiaorg/celestia-app/v3/proto/celestia/core/v1/da" proto "github.com/gogo/protobuf/proto" types "github.com/tendermint/tendermint/proto/tendermint/types" io "io" diff --git a/header/pb/extended_header.proto b/header/pb/extended_header.proto index aafb575327..e93b64d862 100644 --- a/header/pb/extended_header.proto +++ b/header/pb/extended_header.proto @@ -4,13 +4,13 @@ package header.pb; import "tendermint/types/types.proto"; import "tendermint/types/validator.proto"; -import "celestia/da/data_availability_header.proto"; +import "celestia/core/v1/da/data_availability_header.proto"; message ExtendedHeader { tendermint.types.Header header = 1; tendermint.types.Commit commit = 2; tendermint.types.ValidatorSet validator_set = 3; - celestia.da.DataAvailabilityHeader dah = 4; + celestia.core.v1.da.DataAvailabilityHeader dah = 4; } // Generated with: diff --git a/header/serde.go b/header/serde.go index fae310457b..8c5412ec81 100644 --- a/header/serde.go +++ b/header/serde.go @@ -5,7 +5,7 @@ import ( core "github.com/tendermint/tendermint/types" "golang.org/x/crypto/blake2b" - "github.com/celestiaorg/celestia-app/v2/pkg/da" + "github.com/celestiaorg/celestia-app/v3/pkg/da" header_pb "github.com/celestiaorg/celestia-node/header/pb" ) diff --git a/libs/edssser/edssser.go b/libs/edssser/edssser.go index dfb01e1756..2c0ad624a4 100644 --- a/libs/edssser/edssser.go +++ b/libs/edssser/edssser.go @@ -9,8 +9,8 @@ import ( "testing" "time" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" "github.com/celestiaorg/celestia-node/store" ) @@ -148,13 +148,13 @@ func (ss *EDSsser) put(ctx context.Context, t *testing.T, height int) (time.Dura defer cancel() // divide by 2 to get ODS size as expected by RandEDS - square := edstest.RandEDS(t, ss.config.EDSSize/2) - roots, err := share.NewAxisRoots(square) + dataSquare := edstest.RandEDS(t, ss.config.EDSSize/2) + roots, err := square.NewAxisRoots(dataSquare) if err != nil { return 0, err } now := time.Now() - err = ss.edsstore.PutODSQ4(ctx, roots, uint64(height), square) + err = ss.edsstore.PutODSQ4(ctx, roots, uint64(height), dataSquare) return time.Since(now), err } diff --git a/libs/keystore/map_keystore.go b/libs/keystore/map_keystore.go index 9efd21f88b..b6355ed85c 100644 --- a/libs/keystore/map_keystore.go +++ b/libs/keystore/map_keystore.go @@ -6,8 +6,8 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" - "github.com/celestiaorg/celestia-app/v2/app" - "github.com/celestiaorg/celestia-app/v2/app/encoding" + "github.com/celestiaorg/celestia-app/v3/app" + "github.com/celestiaorg/celestia-app/v3/app/encoding" ) // mapKeystore is a simple in-memory Keystore implementation. diff --git a/nodebuilder/blob/blob.go b/nodebuilder/blob/blob.go index b93257e8d9..3d14a3487d 100644 --- a/nodebuilder/blob/blob.go +++ b/nodebuilder/blob/blob.go @@ -3,8 +3,9 @@ package blob import ( "context" + "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/celestia-node/blob" - "github.com/celestiaorg/celestia-node/share" ) var _ Module = (*API)(nil) diff --git a/nodebuilder/blob/cmd/blob.go b/nodebuilder/blob/cmd/blob.go index 5e57f91e0d..527ac9b2d7 100644 --- a/nodebuilder/blob/cmd/blob.go +++ b/nodebuilder/blob/cmd/blob.go @@ -11,10 +11,11 @@ import ( "github.com/spf13/cobra" + "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/celestia-node/blob" cmdnode "github.com/celestiaorg/celestia-node/cmd" state "github.com/celestiaorg/celestia-node/nodebuilder/state/cmd" - "github.com/celestiaorg/celestia-node/share" ) // flagFileInput allows the user to provide file path to the json file @@ -285,8 +286,8 @@ func formatData(ns string) func(interface{}) interface{} { for i, b := range blobs { result[i] = tempBlob{ Namespace: ns, - Data: string(b.Data), - ShareVersion: b.ShareVersion, + Data: string(b.Data()), + ShareVersion: uint32(b.ShareVersion()), Commitment: "0x" + hex.EncodeToString(b.Commitment), Index: b.Index(), } @@ -297,8 +298,8 @@ func formatData(ns string) func(interface{}) interface{} { b := data.(*blob.Blob) return tempBlob{ Namespace: ns, - Data: string(b.Data), - ShareVersion: b.ShareVersion, + Data: string(b.Data()), + ShareVersion: uint32(b.ShareVersion()), Commitment: "0x" + hex.EncodeToString(b.Commitment), Index: b.Index(), } diff --git a/nodebuilder/blob/mocks/api.go b/nodebuilder/blob/mocks/api.go index 786fe7d7fb..a7c1d7d909 100644 --- a/nodebuilder/blob/mocks/api.go +++ b/nodebuilder/blob/mocks/api.go @@ -9,8 +9,8 @@ import ( reflect "reflect" blob "github.com/celestiaorg/celestia-node/blob" - share "github.com/celestiaorg/celestia-node/share" state "github.com/celestiaorg/celestia-node/state" + share "github.com/celestiaorg/go-square/v2/share" gomock "github.com/golang/mock/gomock" ) diff --git a/nodebuilder/blob/module.go b/nodebuilder/blob/module.go index cf07ed3732..d62624adf8 100644 --- a/nodebuilder/blob/module.go +++ b/nodebuilder/blob/module.go @@ -9,7 +9,7 @@ import ( "github.com/celestiaorg/celestia-node/header" headerService "github.com/celestiaorg/celestia-node/nodebuilder/header" "github.com/celestiaorg/celestia-node/nodebuilder/state" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square/shwap" ) func ConstructModule() fx.Option { diff --git a/nodebuilder/core/module.go b/nodebuilder/core/module.go index 441907ce32..f186d724c2 100644 --- a/nodebuilder/core/module.go +++ b/nodebuilder/core/module.go @@ -12,7 +12,7 @@ import ( "github.com/celestiaorg/celestia-node/libs/fxutil" "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/p2p" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" "github.com/celestiaorg/celestia-node/store" ) diff --git a/nodebuilder/da/service.go b/nodebuilder/da/service.go index b4b8388b17..b9a87a629c 100644 --- a/nodebuilder/da/service.go +++ b/nodebuilder/da/service.go @@ -10,12 +10,12 @@ import ( logging "github.com/ipfs/go-log/v2" "github.com/rollkit/go-da" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" "github.com/celestiaorg/celestia-node/header" nodeblob "github.com/celestiaorg/celestia-node/nodebuilder/blob" - "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/state" ) @@ -68,23 +68,32 @@ func (s *Service) Get(ctx context.Context, ids []da.ID, ns da.Namespace) ([]da.B blobs := make([]da.Blob, 0, len(ids)) for _, id := range ids { height, commitment := SplitID(id) - log.Debugw("getting blob", "height", height, "commitment", commitment, "namespace", share.Namespace(ns)) - currentBlob, err := s.blobServ.Get(ctx, height, ns, commitment) - log.Debugw("got blob", "height", height, "commitment", commitment, "namespace", share.Namespace(ns)) + namespace, err := share.NewNamespaceFromBytes(ns) if err != nil { return nil, err } - blobs = append(blobs, currentBlob.Data) + log.Debugw("getting blob", "height", height, "commitment", commitment, "namespace", namespace) + currentBlob, err := s.blobServ.Get(ctx, height, namespace, commitment) + log.Debugw("got blob", "height", height, "commitment", commitment, "namespace", namespace) + if err != nil { + return nil, err + } + blobs = append(blobs, currentBlob.Data()) } return blobs, nil } // GetIDs returns IDs of all Blobs located in DA at given height. func (s *Service) GetIDs(ctx context.Context, height uint64, namespace da.Namespace) (*da.GetIDsResult, error) { + ns, err := share.NewNamespaceFromBytes(namespace) + if err != nil { + return nil, err + } + var ids []da.ID //nolint:prealloc - log.Debugw("getting ids", "height", height, "namespace", share.Namespace(namespace)) - blobs, err := s.blobServ.GetAll(ctx, height, []share.Namespace{namespace}) - log.Debugw("got ids", "height", height, "namespace", share.Namespace(namespace)) + log.Debugw("getting ids", "height", height, "namespace", ns) + blobs, err := s.blobServ.GetAll(ctx, height, []share.Namespace{ns}) + log.Debugw("got ids", "height", height, "namespace", ns) if err != nil { if strings.Contains(err.Error(), blob.ErrBlobNotFound.Error()) { return nil, nil //nolint:nilnil @@ -105,8 +114,12 @@ func (s *Service) GetIDs(ctx context.Context, height uint64, namespace da.Namesp func (s *Service) GetProofs(ctx context.Context, ids []da.ID, namespace da.Namespace) ([]da.Proof, error) { proofs := make([]da.Proof, len(ids)) for i, id := range ids { + ns, err := share.NewNamespaceFromBytes(namespace) + if err != nil { + return nil, err + } height, commitment := SplitID(id) - proof, err := s.blobServ.GetProof(ctx, height, namespace, commitment) + proof, err := s.blobServ.GetProof(ctx, height, ns, commitment) if err != nil { return nil, err } @@ -200,7 +213,11 @@ func (s *Service) blobsAndCommitments( blobs := make([]*blob.Blob, 0, len(daBlobs)) commitments := make([]da.Commitment, 0, len(daBlobs)) for _, daBlob := range daBlobs { - b, err := blob.NewBlobV0(namespace, daBlob) + ns, err := share.NewNamespaceFromBytes(namespace) + if err != nil { + return nil, nil, err + } + b, err := blob.NewBlobV0(ns, daBlob) if err != nil { return nil, nil, err } @@ -230,13 +247,17 @@ func (s *Service) Validate( proofs[i] = blobProof } for i, id := range ids { + ns, err := share.NewNamespaceFromBytes(namespace) + if err != nil { + return nil, err + } height, commitment := SplitID(id) // TODO(tzdybal): for some reason, if proof doesn't match commitment, API returns (false, "blob: // invalid proof") but analysis of the code in celestia-node implies this should never happen - // maybe it's caused by openrpc? there is no way of gently handling errors here, but returned // value is fine for us fmt.Println("proof", proofs[i] == nil, "commitment", commitment == nil) - isIncluded, _ := s.blobServ.Included(ctx, height, namespace, proofs[i], commitment) + isIncluded, _ := s.blobServ.Included(ctx, height, ns, proofs[i], commitment) included[i] = isIncluded } return included, nil diff --git a/nodebuilder/das/constructors.go b/nodebuilder/das/constructors.go index 8d6f9d1168..c3c7602740 100644 --- a/nodebuilder/das/constructors.go +++ b/nodebuilder/das/constructors.go @@ -13,9 +13,9 @@ import ( "github.com/celestiaorg/celestia-node/header" modfraud "github.com/celestiaorg/celestia-node/nodebuilder/fraud" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" ) var _ Module = (*daserStub)(nil) @@ -39,7 +39,7 @@ func newDaserStub() Module { } func newDASer( - da share.Availability, + da square.Availability, hsub libhead.Subscriber[*header.ExtendedHeader], store libhead.Store[*header.ExtendedHeader], batching datastore.Batching, diff --git a/nodebuilder/fraud/unmarshaler.go b/nodebuilder/fraud/unmarshaler.go index d5e0461f01..e5cf07272e 100644 --- a/nodebuilder/fraud/unmarshaler.go +++ b/nodebuilder/fraud/unmarshaler.go @@ -4,7 +4,7 @@ import ( "github.com/celestiaorg/go-fraud" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" ) var defaultProofUnmarshaler proofRegistry diff --git a/nodebuilder/header/constructors.go b/nodebuilder/header/constructors.go index 23947a8338..04e36d27ec 100644 --- a/nodebuilder/header/constructors.go +++ b/nodebuilder/header/constructors.go @@ -18,7 +18,7 @@ import ( modfraud "github.com/celestiaorg/celestia-node/nodebuilder/fraud" modp2p "github.com/celestiaorg/celestia-node/nodebuilder/p2p" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" ) // newP2PExchange constructs a new Exchange for headers. diff --git a/nodebuilder/init.go b/nodebuilder/init.go index 6c0854ff91..9194a092e0 100644 --- a/nodebuilder/init.go +++ b/nodebuilder/init.go @@ -10,8 +10,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/gofrs/flock" - "github.com/celestiaorg/celestia-app/v2/app" - "github.com/celestiaorg/celestia-app/v2/app/encoding" + "github.com/celestiaorg/celestia-app/v3/app" + "github.com/celestiaorg/celestia-app/v3/app/encoding" "github.com/celestiaorg/celestia-node/libs/utils" "github.com/celestiaorg/celestia-node/nodebuilder/node" diff --git a/nodebuilder/init_test.go b/nodebuilder/init_test.go index 99c93d7878..2058a00574 100644 --- a/nodebuilder/init_test.go +++ b/nodebuilder/init_test.go @@ -11,8 +11,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-app/v2/app" - "github.com/celestiaorg/celestia-app/v2/app/encoding" + "github.com/celestiaorg/celestia-app/v3/app" + "github.com/celestiaorg/celestia-app/v3/app/encoding" "github.com/celestiaorg/celestia-node/nodebuilder/node" ) diff --git a/nodebuilder/node_test.go b/nodebuilder/node_test.go index 8155d7e081..91c057b69c 100644 --- a/nodebuilder/node_test.go +++ b/nodebuilder/node_test.go @@ -17,7 +17,7 @@ import ( "github.com/celestiaorg/celestia-node/header/headertest" "github.com/celestiaorg/celestia-node/nodebuilder/node" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" ) func TestLifecycle(t *testing.T) { @@ -147,7 +147,7 @@ func TestEmptyBlockExists(t *testing.T) { // ensure an empty block exists in store - eh := headertest.RandExtendedHeaderWithRoot(t, share.EmptyEDSRoots()) + eh := headertest.RandExtendedHeaderWithRoot(t, square.EmptyEDSRoots()) err = node.ShareServ.SharesAvailable(ctx, eh) require.NoError(t, err) diff --git a/nodebuilder/p2p/module.go b/nodebuilder/p2p/module.go index 9538ce03a5..8c819373ae 100644 --- a/nodebuilder/p2p/module.go +++ b/nodebuilder/p2p/module.go @@ -6,7 +6,7 @@ import ( "go.uber.org/fx" "github.com/celestiaorg/celestia-node/nodebuilder/node" - "github.com/celestiaorg/celestia-node/share/ipld" + "github.com/celestiaorg/celestia-node/square/ipld" ) var log = logging.Logger("module/p2p") diff --git a/nodebuilder/p2p/routing.go b/nodebuilder/p2p/routing.go index 53f5377524..65a8a17da2 100644 --- a/nodebuilder/p2p/routing.go +++ b/nodebuilder/p2p/routing.go @@ -10,7 +10,7 @@ import ( "go.uber.org/fx" "github.com/celestiaorg/celestia-node/nodebuilder/node" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/discovery" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/discovery" ) func newDHT( diff --git a/nodebuilder/share/bitswap.go b/nodebuilder/share/bitswap.go index 9316075dfe..26784689ff 100644 --- a/nodebuilder/share/bitswap.go +++ b/nodebuilder/share/bitswap.go @@ -16,7 +16,7 @@ import ( "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/p2p" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/bitswap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/bitswap" "github.com/celestiaorg/celestia-node/store" ) diff --git a/nodebuilder/share/cmd/share.go b/nodebuilder/share/cmd/share.go index 1eb21a045f..8ec42a510a 100644 --- a/nodebuilder/share/cmd/share.go +++ b/nodebuilder/share/cmd/share.go @@ -8,10 +8,11 @@ import ( "github.com/spf13/cobra" + "github.com/celestiaorg/go-square/v2/share" + rpc "github.com/celestiaorg/celestia-node/api/rpc/client" cmdnode "github.com/celestiaorg/celestia-node/cmd" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share" ) func init() { @@ -127,14 +128,14 @@ var getShare = &cobra.Command{ return data } - ns := hex.EncodeToString(share.GetNamespace(sh)) + ns := hex.EncodeToString(sh.Namespace().Bytes()) return struct { Namespace string `json:"namespace"` Data []byte `json:"data"` }{ Namespace: ns, - Data: share.GetData(sh), + Data: sh.RawData(), } } return cmdnode.PrintOutput(s, err, formatter) diff --git a/nodebuilder/share/config.go b/nodebuilder/share/config.go index 6cf18332bc..00af197a83 100644 --- a/nodebuilder/share/config.go +++ b/nodebuilder/share/config.go @@ -4,11 +4,11 @@ import ( "fmt" "github.com/celestiaorg/celestia-node/nodebuilder/node" - "github.com/celestiaorg/celestia-node/share/availability/light" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/discovery" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/peers" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexeds" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexnd" + "github.com/celestiaorg/celestia-node/square/availability/light" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/discovery" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/peers" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexeds" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexnd" "github.com/celestiaorg/celestia-node/store" ) diff --git a/nodebuilder/share/constructors.go b/nodebuilder/share/constructors.go index 660117725d..c88747e945 100644 --- a/nodebuilder/share/constructors.go +++ b/nodebuilder/share/constructors.go @@ -2,15 +2,15 @@ package share import ( headerServ "github.com/celestiaorg/celestia-node/nodebuilder/header" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/getters" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/bitswap" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrex_getter" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/getters" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/bitswap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrex_getter" "github.com/celestiaorg/celestia-node/store" ) -func newShareModule(getter shwap.Getter, avail share.Availability, header headerServ.Module) Module { +func newShareModule(getter shwap.Getter, avail square.Availability, header headerServ.Module) Module { return &module{getter, avail, header} } diff --git a/nodebuilder/share/mocks/api.go b/nodebuilder/share/mocks/api.go index 682d5d8d48..1498be402a 100644 --- a/nodebuilder/share/mocks/api.go +++ b/nodebuilder/share/mocks/api.go @@ -10,7 +10,7 @@ import ( header "github.com/celestiaorg/celestia-node/header" share "github.com/celestiaorg/celestia-node/nodebuilder/share" - share0 "github.com/celestiaorg/celestia-node/share" + share0 "github.com/celestiaorg/celestia-node/square" rsmt2d "github.com/celestiaorg/rsmt2d" gomock "github.com/golang/mock/gomock" ) diff --git a/nodebuilder/share/module.go b/nodebuilder/share/module.go index 8b20c23585..5346f1c92c 100644 --- a/nodebuilder/share/module.go +++ b/nodebuilder/share/module.go @@ -12,16 +12,16 @@ import ( "github.com/celestiaorg/celestia-node/nodebuilder/node" modp2p "github.com/celestiaorg/celestia-node/nodebuilder/p2p" lightprune "github.com/celestiaorg/celestia-node/pruner/light" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/availability/full" - "github.com/celestiaorg/celestia-node/share/availability/light" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/bitswap" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/peers" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrex_getter" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexeds" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexnd" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/availability/full" + "github.com/celestiaorg/celestia-node/square/availability/light" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/bitswap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/peers" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrex_getter" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexeds" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexnd" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" "github.com/celestiaorg/celestia-node/store" ) @@ -234,14 +234,14 @@ func availabilityComponents(tp node.Type, cfg *Config) fx.Option { return la.Close(ctx) }), )), - fx.Provide(func(avail *light.ShareAvailability) share.Availability { + fx.Provide(func(avail *light.ShareAvailability) square.Availability { return avail }), ) case node.Bridge, node.Full: return fx.Options( fx.Provide(full.NewShareAvailability), - fx.Provide(func(avail *full.ShareAvailability) share.Availability { + fx.Provide(func(avail *full.ShareAvailability) square.Availability { return avail }), ) diff --git a/nodebuilder/share/opts.go b/nodebuilder/share/opts.go index cfea26dbb4..0510c1f11b 100644 --- a/nodebuilder/share/opts.go +++ b/nodebuilder/share/opts.go @@ -3,11 +3,11 @@ package share import ( "errors" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/discovery" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/peers" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrex_getter" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexeds" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexnd" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/discovery" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/peers" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrex_getter" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexeds" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexnd" "github.com/celestiaorg/celestia-node/store" ) diff --git a/nodebuilder/share/p2p_constructors.go b/nodebuilder/share/p2p_constructors.go index 62a2948845..2e8ad55b1f 100644 --- a/nodebuilder/share/p2p_constructors.go +++ b/nodebuilder/share/p2p_constructors.go @@ -14,9 +14,9 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/nodebuilder/node" modprune "github.com/celestiaorg/celestia-node/nodebuilder/pruner" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/discovery" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/peers" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/discovery" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/peers" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" ) const ( diff --git a/nodebuilder/share/share.go b/nodebuilder/share/share.go index b9d21953bf..00d32d8890 100644 --- a/nodebuilder/share/share.go +++ b/nodebuilder/share/share.go @@ -5,14 +5,15 @@ import ( "github.com/tendermint/tendermint/types" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" headerServ "github.com/celestiaorg/celestia-node/nodebuilder/header" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" ) var _ Module = (*API)(nil) @@ -110,7 +111,7 @@ func (api *API) GetSharesByNamespace( type module struct { shwap.Getter - share.Availability + square.Availability hs headerServ.Module } @@ -132,9 +133,14 @@ func (m module) GetRange(ctx context.Context, height uint64, start, end int) (*G if err != nil { return nil, err } + + shares, err := share.FromBytes(extendedDataSquare.FlattenedODS()[start:end]) + if err != nil { + return nil, err + } return &GetRangeResult{ - extendedDataSquare.FlattenedODS()[start:end], - proof, + Shares: shares, + Proof: proof, }, nil } diff --git a/nodebuilder/state/core.go b/nodebuilder/state/core.go index 39ab732368..f377fe4c6a 100644 --- a/nodebuilder/state/core.go +++ b/nodebuilder/state/core.go @@ -10,7 +10,7 @@ import ( "github.com/celestiaorg/celestia-node/nodebuilder/core" modfraud "github.com/celestiaorg/celestia-node/nodebuilder/fraud" "github.com/celestiaorg/celestia-node/nodebuilder/p2p" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" "github.com/celestiaorg/celestia-node/state" ) diff --git a/nodebuilder/store.go b/nodebuilder/store.go index e9a33d122e..e778e9924e 100644 --- a/nodebuilder/store.go +++ b/nodebuilder/store.go @@ -17,10 +17,11 @@ import ( dsbadger "github.com/ipfs/go-ds-badger4" "github.com/mitchellh/go-homedir" + "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/celestia-node/libs/keystore" nodemod "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/p2p" - "github.com/celestiaorg/celestia-node/share" ) var ( @@ -278,7 +279,7 @@ func constraintBadgerConfig() *dsbadger.Options { // 2mib default => share.Size - makes sure headers and samples are stored in value log // This *tremendously* reduces the amount of memory used by the node, up to 10 times less during // compaction - opts.ValueThreshold = share.Size + opts.ValueThreshold = share.ShareSize // make sure we don't have any limits for stored headers opts.ValueLogMaxEntries = 100000000 // run value log GC more often to spread the work over time diff --git a/nodebuilder/tests/api_test.go b/nodebuilder/tests/api_test.go index 0a4839345e..09318988fd 100644 --- a/nodebuilder/tests/api_test.go +++ b/nodebuilder/tests/api_test.go @@ -111,9 +111,10 @@ func TestBlobRPC(t *testing.T) { require.NoError(t, err) newBlob, err := blob.NewBlob( - uint8(appBlobs[0].GetShareVersion()), - appBlobs[0].Namespace().Bytes(), - appBlobs[0].GetData(), + appBlobs[0].ShareVersion(), + appBlobs[0].Namespace(), + appBlobs[0].Data(), + appBlobs[0].Signer(), ) require.NoError(t, err) diff --git a/nodebuilder/tests/blob_test.go b/nodebuilder/tests/blob_test.go index bd3c94847a..590aed2166 100644 --- a/nodebuilder/tests/blob_test.go +++ b/nodebuilder/tests/blob_test.go @@ -13,13 +13,12 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - squareblob "github.com/celestiaorg/go-square/blob" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" "github.com/celestiaorg/celestia-node/blob/blobtest" "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/tests/swamp" - "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/state" ) @@ -204,6 +203,6 @@ func TestBlobModule(t *testing.T) { // convert converts a squareblob.Blob to a blob.Blob. // convert may be deduplicated with convertBlobs from the blob package. -func convert(squareBlob *squareblob.Blob) (nodeBlob *blob.Blob, err error) { - return blob.NewBlob(uint8(squareBlob.GetShareVersion()), squareBlob.Namespace().Bytes(), squareBlob.GetData()) +func convert(squareBlob *share.Blob) (nodeBlob *blob.Blob, err error) { + return blob.NewBlob(squareBlob.ShareVersion(), squareBlob.Namespace(), squareBlob.Data(), squareBlob.Signer()) } diff --git a/nodebuilder/tests/da_test.go b/nodebuilder/tests/da_test.go index 9bbdff2b2e..63961e379f 100644 --- a/nodebuilder/tests/da_test.go +++ b/nodebuilder/tests/da_test.go @@ -12,14 +12,14 @@ import ( "github.com/libp2p/go-libp2p/core/peer" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" "github.com/celestiaorg/celestia-node/blob/blobtest" "github.com/celestiaorg/celestia-node/nodebuilder/da" "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/tests/swamp" - "github.com/celestiaorg/celestia-node/share" ) func TestDaModule(t *testing.T) { @@ -27,8 +27,9 @@ func TestDaModule(t *testing.T) { t.Cleanup(cancel) sw := swamp.NewSwamp(t, swamp.WithBlockTime(time.Second)) - namespace, err := share.NewBlobNamespaceV0([]byte("namespace")) + namespace, err := share.NewV0Namespace([]byte("namespace")) require.NoError(t, err) + require.False(t, namespace.IsReserved()) appBlobs0, err := blobtest.GenerateV0Blobs([]int{8, 4}, true) require.NoError(t, err) @@ -39,13 +40,14 @@ func TestDaModule(t *testing.T) { for _, squareBlob := range append(appBlobs0, appBlobs1...) { blob, err := blob.NewBlob( - uint8(squareBlob.GetShareVersion()), - squareBlob.Namespace().Bytes(), - squareBlob.GetData(), + squareBlob.ShareVersion(), + squareBlob.Namespace(), + squareBlob.Data(), + squareBlob.Signer(), ) require.NoError(t, err) blobs = append(blobs, blob) - daBlobs = append(daBlobs, blob.Data) + daBlobs = append(daBlobs, blob.Data()) } require.NoError(t, err) @@ -71,7 +73,7 @@ func TestDaModule(t *testing.T) { fullClient := getAdminClient(ctx, fullNode, t) lightClient := getAdminClient(ctx, lightNode, t) - ids, err := fullClient.DA.Submit(ctx, daBlobs, -1, namespace) + ids, err := fullClient.DA.Submit(ctx, daBlobs, -1, namespace.Bytes()) require.NoError(t, err) test := []struct { @@ -91,10 +93,10 @@ func TestDaModule(t *testing.T) { doFn: func(t *testing.T) { h, _ := da.SplitID(ids[0]) lightClient.Header.WaitForHeight(ctx, h) - proofs, err := lightClient.DA.GetProofs(ctx, ids, namespace) + proofs, err := lightClient.DA.GetProofs(ctx, ids, namespace.Bytes()) require.NoError(t, err) require.NotEmpty(t, proofs) - valid, err := fullClient.DA.Validate(ctx, ids, proofs, namespace) + valid, err := fullClient.DA.Validate(ctx, ids, proofs, namespace.Bytes()) require.NoError(t, err) for _, v := range valid { require.True(t, v) @@ -105,7 +107,7 @@ func TestDaModule(t *testing.T) { name: "GetIDs", doFn: func(t *testing.T) { height, _ := da.SplitID(ids[0]) - result, err := fullClient.DA.GetIDs(ctx, height, namespace) + result, err := fullClient.DA.GetIDs(ctx, height, namespace.Bytes()) require.NoError(t, err) require.EqualValues(t, ids, result.IDs) header, err := lightClient.Header.GetByHeight(ctx, height) @@ -118,7 +120,7 @@ func TestDaModule(t *testing.T) { doFn: func(t *testing.T) { h, _ := da.SplitID(ids[0]) lightClient.Header.WaitForHeight(ctx, h) - fetched, err := lightClient.DA.Get(ctx, ids, namespace) + fetched, err := lightClient.DA.Get(ctx, ids, namespace.Bytes()) require.NoError(t, err) require.Len(t, fetched, len(ids)) for i := range fetched { @@ -129,7 +131,7 @@ func TestDaModule(t *testing.T) { { name: "Commit", doFn: func(t *testing.T) { - fetched, err := fullClient.DA.Commit(ctx, daBlobs, namespace) + fetched, err := fullClient.DA.Commit(ctx, daBlobs, namespace.Bytes()) require.NoError(t, err) require.Len(t, fetched, len(ids)) for i := range fetched { diff --git a/nodebuilder/tests/fraud_test.go b/nodebuilder/tests/fraud_test.go index 524b306ac0..f3ec37c157 100644 --- a/nodebuilder/tests/fraud_test.go +++ b/nodebuilder/tests/fraud_test.go @@ -21,7 +21,7 @@ import ( "github.com/celestiaorg/celestia-node/nodebuilder/core" "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/tests/swamp" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" "github.com/celestiaorg/celestia-node/store" ) diff --git a/nodebuilder/tests/nd_test.go b/nodebuilder/tests/nd_test.go index 960062bc9e..7b295511a6 100644 --- a/nodebuilder/tests/nd_test.go +++ b/nodebuilder/tests/nd_test.go @@ -4,6 +4,7 @@ package tests import ( "context" + "testing" "time" @@ -12,15 +13,16 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/fx" + "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/celestia-node/nodebuilder" "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/p2p" "github.com/celestiaorg/celestia-node/nodebuilder/tests/swamp" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/getters" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrex_getter" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexnd" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/getters" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrex_getter" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexnd" "github.com/celestiaorg/celestia-node/store" ) @@ -68,10 +70,12 @@ func TestShrexNDFromLights(t *testing.T) { // ensure to fetch random namespace (not the reserved namespace) namespace := h.DAH.RowRoots[1][:share.NamespaceSize] + ns, err := share.NewNamespaceFromBytes(namespace) + require.NoError(t, err) - expected, err := bridgeClient.Share.GetSharesByNamespace(reqCtx, h, namespace) + expected, err := bridgeClient.Share.GetSharesByNamespace(reqCtx, h, ns) require.NoError(t, err) - got, err := lightClient.Share.GetSharesByNamespace(reqCtx, h, namespace) + got, err := lightClient.Share.GetSharesByNamespace(reqCtx, h, ns) require.NoError(t, err) require.True(t, len(got[0].Shares) > 0) @@ -142,19 +146,19 @@ func TestShrexNDFromLightsWithBadFulls(t *testing.T) { // ensure to fetch random namespace (not the reserved namespace) namespace := h.DAH.RowRoots[1][:share.NamespaceSize] - - expected, err := bridgeClient.Share.GetSharesByNamespace(reqCtx, h, namespace) + ns, err := share.NewNamespaceFromBytes(namespace) + expected, err := bridgeClient.Share.GetSharesByNamespace(reqCtx, h, ns) require.NoError(t, err) require.True(t, len(expected[0].Shares) > 0) // choose a random full to test fN := fulls[len(fulls)/2] fnClient := getAdminClient(ctx, fN, t) - gotFull, err := fnClient.Share.GetSharesByNamespace(reqCtx, h, namespace) + gotFull, err := fnClient.Share.GetSharesByNamespace(reqCtx, h, ns) require.NoError(t, err) require.True(t, len(gotFull[0].Shares) > 0) - gotLight, err := lightClient.Share.GetSharesByNamespace(reqCtx, h, namespace) + gotLight, err := lightClient.Share.GetSharesByNamespace(reqCtx, h, ns) require.NoError(t, err) require.True(t, len(gotLight[0].Shares) > 0) diff --git a/nodebuilder/tests/prune_test.go b/nodebuilder/tests/prune_test.go index 79f40dccd6..8edf6fae1b 100644 --- a/nodebuilder/tests/prune_test.go +++ b/nodebuilder/tests/prune_test.go @@ -5,6 +5,7 @@ package tests import ( "bytes" "context" + "github.com/celestiaorg/go-square/v2/share" "testing" "time" @@ -20,11 +21,11 @@ import ( "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/tests/swamp" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/peers" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrex_getter" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexeds" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexnd" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/peers" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrex_getter" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexeds" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexnd" ) // TestArchivalBlobSync tests whether a LN is able to sync historical blobs from @@ -116,7 +117,7 @@ func TestArchivalBlobSync(t *testing.T) { type archivalBlob struct { blob *blob.Blob height uint64 - root share.DataHash + root square.DataHash } archivalBlobs := make([]*archivalBlob, 0) @@ -125,17 +126,15 @@ func TestArchivalBlobSync(t *testing.T) { eh, err := archivalFN.HeaderServ.GetByHeight(ctx, uint64(i)) require.NoError(t, err) - if bytes.Equal(eh.DataHash, share.EmptyEDSRoots().Hash()) { + if bytes.Equal(eh.DataHash, square.EmptyEDSRoots().Hash()) { i++ continue } shr, err := archivalFN.ShareServ.GetShare(ctx, eh, 2, 2) require.NoError(t, err) - ns, err := share.NamespaceFromBytes(shr[:share.NamespaceSize]) - require.NoError(t, err) - blobs, err := archivalFN.BlobServ.GetAll(ctx, uint64(i), []share.Namespace{ns}) + blobs, err := archivalFN.BlobServ.GetAll(ctx, uint64(i), []share.Namespace{shr.Namespace()}) require.NoError(t, err) archivalBlobs = append(archivalBlobs, &archivalBlob{ @@ -172,7 +171,7 @@ func TestArchivalBlobSync(t *testing.T) { got, err := ln.BlobServ.Get(ctx, b.height, b.blob.Namespace(), b.blob.Commitment) require.NoError(t, err) assert.Equal(t, b.blob.Commitment, got.Commitment) - assert.Equal(t, b.blob.Data, got.Data) + assert.Equal(t, b.blob.Data(), got.Data()) } } diff --git a/nodebuilder/tests/reconstruct_test.go b/nodebuilder/tests/reconstruct_test.go index 70bcca05be..f5360395cb 100644 --- a/nodebuilder/tests/reconstruct_test.go +++ b/nodebuilder/tests/reconstruct_test.go @@ -19,8 +19,8 @@ import ( "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/p2p" "github.com/celestiaorg/celestia-node/nodebuilder/tests/swamp" - "github.com/celestiaorg/celestia-node/share/availability/light" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square/availability/light" + "github.com/celestiaorg/celestia-node/square/eds" ) /* diff --git a/nodebuilder/tests/swamp/config.go b/nodebuilder/tests/swamp/config.go index 39740c6d18..7e00541b61 100644 --- a/nodebuilder/tests/swamp/config.go +++ b/nodebuilder/tests/swamp/config.go @@ -3,7 +3,7 @@ package swamp import ( "time" - "github.com/celestiaorg/celestia-app/v2/test/util/testnode" + "github.com/celestiaorg/celestia-app/v3/test/util/testnode" "github.com/celestiaorg/celestia-node/core" ) diff --git a/nodebuilder/tests/swamp/swamp.go b/nodebuilder/tests/swamp/swamp.go index d11c994229..57d46bb64b 100644 --- a/nodebuilder/tests/swamp/swamp.go +++ b/nodebuilder/tests/swamp/swamp.go @@ -19,7 +19,7 @@ import ( "go.uber.org/fx" "golang.org/x/exp/maps" - "github.com/celestiaorg/celestia-app/v2/test/util/testnode" + "github.com/celestiaorg/celestia-app/v3/test/util/testnode" libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/celestia-node/core" diff --git a/nodebuilder/tests/swamp/swamp_tx.go b/nodebuilder/tests/swamp/swamp_tx.go index 3cfe904ab1..4d6ce6497a 100644 --- a/nodebuilder/tests/swamp/swamp_tx.go +++ b/nodebuilder/tests/swamp/swamp_tx.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/celestiaorg/celestia-app/v2/test/util/testnode" + "github.com/celestiaorg/celestia-app/v3/test/util/testnode" ) // FillBlocks produces the given amount of contiguous blocks with customizable size. diff --git a/pruner/light/pruner.go b/pruner/light/pruner.go index 5739cd8cee..bc0e1732ad 100644 --- a/pruner/light/pruner.go +++ b/pruner/light/pruner.go @@ -9,8 +9,8 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/ipld" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/ipld" ) type Pruner struct { @@ -24,7 +24,7 @@ func NewPruner(bstore blockstore.Blockstore, ds datastore.Batching) pruner.Prune func (p *Pruner) Prune(ctx context.Context, h *header.ExtendedHeader) error { dah := h.DAH - if share.DataHash(dah.Hash()).IsEmptyEDS() { + if square.DataHash(dah.Hash()).IsEmptyEDS() { return nil } @@ -41,6 +41,6 @@ func (p *Pruner) Prune(ctx context.Context, h *header.ExtendedHeader) error { return p.ds.Delete(ctx, rootKey(dah)) } -func rootKey(root *share.AxisRoots) datastore.Key { +func rootKey(root *square.AxisRoots) datastore.Key { return datastore.NewKey(root.String()) } diff --git a/share/namespace_test.go b/share/namespace_test.go deleted file mode 100644 index e6007c245e..0000000000 --- a/share/namespace_test.go +++ /dev/null @@ -1,218 +0,0 @@ -package share - -import ( - "bytes" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - appns "github.com/celestiaorg/go-square/namespace" -) - -var ( - validID = append( - appns.NamespaceVersionZeroPrefix, - bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)..., - ) - tooShortID = append(appns.NamespaceVersionZeroPrefix, []byte{1}...) - tooLongID = append(appns.NamespaceVersionZeroPrefix, bytes.Repeat([]byte{1}, NamespaceSize)...) - invalidPrefixID = bytes.Repeat([]byte{1}, NamespaceSize) -) - -func TestNewNamespaceV0(t *testing.T) { - type testCase struct { - name string - subNid []byte - expected Namespace - wantErr bool - } - testCases := []testCase{ - { - name: "8 byte id, gets left padded", - subNid: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, - expected: Namespace{ - 0x0, - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // filled zeros - 0x0, 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, - }, // id with left padding - wantErr: false, - }, - { - name: "10 byte id, no padding", - subNid: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x9, 0x10}, - expected: Namespace{ - 0x0, // version - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // filled zeros - 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0x10, - }, // id - wantErr: false, - }, - { - name: "11 byte id", - subNid: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x9, 0x10, 0x11}, - expected: []byte{}, - wantErr: true, - }, - { - name: "nil id", - subNid: nil, - expected: []byte{}, - wantErr: true, - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - got, err := NewBlobNamespaceV0(tc.subNid) - if tc.wantErr { - assert.Error(t, err) - return - } - assert.NoError(t, err) - assert.Equal(t, tc.expected, got) - }) - } -} - -func TestFrom(t *testing.T) { - type testCase struct { - name string - bytes []byte - wantErr bool - want Namespace - } - validNamespace := []byte{} - validNamespace = append(validNamespace, appns.NamespaceVersionZero) - validNamespace = append(validNamespace, appns.NamespaceVersionZeroPrefix...) - validNamespace = append(validNamespace, bytes.Repeat([]byte{0x1}, appns.NamespaceVersionZeroIDSize)...) - parityNamespace := bytes.Repeat([]byte{0xFF}, NamespaceSize) - - testCases := []testCase{ - { - name: "valid namespace", - bytes: validNamespace, - wantErr: false, - want: append([]byte{appns.NamespaceVersionZero}, validID...), - }, - { - name: "parity namespace", - bytes: parityNamespace, - wantErr: false, - want: append([]byte{appns.NamespaceVersionMax}, bytes.Repeat([]byte{0xFF}, appns.NamespaceIDSize)...), - }, - { - name: "unsupported version", - bytes: append([]byte{1}, append( - appns.NamespaceVersionZeroPrefix, - bytes.Repeat([]byte{1}, NamespaceSize-len(appns.NamespaceVersionZeroPrefix))..., - )...), - wantErr: true, - }, - { - name: "unsupported id: too short", - bytes: append([]byte{appns.NamespaceVersionZero}, tooShortID...), - wantErr: true, - }, - { - name: "unsupported id: too long", - bytes: append([]byte{appns.NamespaceVersionZero}, tooLongID...), - wantErr: true, - }, - { - name: "unsupported id: invalid prefix", - bytes: append([]byte{appns.NamespaceVersionZero}, invalidPrefixID...), - wantErr: true, - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - got, err := NamespaceFromBytes(tc.bytes) - if tc.wantErr { - assert.Error(t, err) - return - } - assert.NoError(t, err) - assert.Equal(t, tc.want, got) - }) - } -} - -func TestValidateForBlob(t *testing.T) { - type testCase struct { - name string - ns Namespace - wantErr bool - } - - validNamespace, err := NewBlobNamespaceV0(bytes.Repeat([]byte{0x1}, appns.NamespaceVersionZeroIDSize)) - require.NoError(t, err) - - testCases := []testCase{ - { - name: "valid blob namespace", - ns: validNamespace, - wantErr: false, - }, - { - name: "invalid blob namespace: parity shares namespace", - ns: ParitySharesNamespace, - wantErr: true, - }, - { - name: "invalid blob namespace: tail padding namespace", - ns: TailPaddingNamespace, - wantErr: true, - }, - { - name: "invalid blob namespace: tx namespace", - ns: TxNamespace, - wantErr: true, - }, - { - name: "invalid blob namespace: namespace version max", - ns: append([]byte{appns.NamespaceVersionMax}, bytes.Repeat([]byte{0x0}, appns.NamespaceIDSize)...), - wantErr: true, - }, - { - name: "invalid blob namespace: primary reserved namespace", - ns: primaryReservedNamespace(0x10), - wantErr: true, - }, - { - name: "invalid blob namespace: secondary reserved namespace", - ns: secondaryReservedNamespace(0x10), - wantErr: true, - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - err := tc.ns.ValidateForBlob() - - if tc.wantErr { - assert.Error(t, err) - return - } - assert.NoError(t, err) - }) - } -} - -func primaryReservedNamespace(lastByte byte) Namespace { - result := make([]byte, NamespaceSize) - result = append(result, appns.NamespaceVersionZero) - result = append(result, appns.NamespaceVersionZeroPrefix...) - result = append(result, bytes.Repeat([]byte{0x0}, appns.NamespaceVersionZeroIDSize-1)...) - result = append(result, lastByte) - return result -} - -func secondaryReservedNamespace(lastByte byte) Namespace { - result := make([]byte, NamespaceSize) - result = append(result, appns.NamespaceVersionMax) - result = append(result, bytes.Repeat([]byte{0xFF}, appns.NamespaceIDSize-1)...) - result = append(result, lastByte) - return result -} diff --git a/share/share.go b/share/share.go deleted file mode 100644 index 23d3780a09..0000000000 --- a/share/share.go +++ /dev/null @@ -1,84 +0,0 @@ -package share - -import ( - "crypto/sha256" - "fmt" - - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - "github.com/celestiaorg/go-square/shares" - "github.com/celestiaorg/nmt" - "github.com/celestiaorg/rsmt2d" -) - -// DefaultRSMT2DCodec sets the default rsmt2d.Codec for shares. -var DefaultRSMT2DCodec = appconsts.DefaultCodec - -const ( - // Size is a system-wide size of a share, including both data and namespace GetNamespace - Size = appconsts.ShareSize -) - -// MaxSquareSize is currently the maximum size supported for unerasured data in -// rsmt2d.ExtendedDataSquare. -var MaxSquareSize = appconsts.SquareSizeUpperBound(appconsts.LatestVersion) - -// Share contains the raw share data without the corresponding namespace. -// NOTE: Alias for the byte is chosen to keep maximal compatibility, especially with rsmt2d. -// Ideally, we should define reusable type elsewhere and make everyone(Core, rsmt2d, ipld) to rely -// on it. -type Share = []byte - -// GetNamespace slices Namespace out of the Share. -func GetNamespace(s Share) Namespace { - return s[:NamespaceSize] -} - -// GetData slices out data of the Share. -func GetData(s Share) []byte { - return s[NamespaceSize:] -} - -// ValidateShare checks the size of a given share. -func ValidateShare(s Share) error { - if len(s) != Size { - return fmt.Errorf("invalid share size: %d", len(s)) - } - return nil -} - -// TailPadding is a constant tail padding share exported for reuse -func TailPadding() Share { - return tailPadding -} - -// ShareWithProof contains data with corresponding Merkle Proof -type ShareWithProof struct { //nolint: revive - // Share is a full data including namespace - Share - // Proof is a Merkle Proof of current share - Proof *nmt.Proof - // Axis is a type of axis against which the share proof is computed - Axis rsmt2d.Axis -} - -// Validate validates inclusion of the share under the given root CID. -func (s *ShareWithProof) Validate(rootHash []byte, x, y, edsSize int) bool { - isParity := x >= edsSize/2 || y >= edsSize/2 - namespace := ParitySharesNamespace - if !isParity { - namespace = GetNamespace(s.Share) - } - return s.Proof.VerifyInclusion( - sha256.New(), // TODO(@Wondertan): This should be defined somewhere globally - namespace.ToNMT(), - [][]byte{s.Share}, - rootHash, - ) -} - -var tailPadding Share - -func init() { - shr := shares.TailPaddingShare() - tailPadding = shr.ToBytes() -} diff --git a/share/sharetest/testing.go b/share/sharetest/testing.go deleted file mode 100644 index f804e18ce9..0000000000 --- a/share/sharetest/testing.go +++ /dev/null @@ -1,87 +0,0 @@ -package sharetest - -import ( - "bytes" - "math/rand" - "sort" - "sync" - "testing" - "time" - - "github.com/stretchr/testify/require" - - "github.com/celestiaorg/go-square/namespace" - - "github.com/celestiaorg/celestia-node/share" -) - -// RandShares generate 'total' amount of shares filled with random data. -func RandShares(t testing.TB, total int) []share.Share { - if total&(total-1) != 0 { - t.Errorf("total must be power of 2: %d", total) - t.FailNow() - } - - shares := make([]share.Share, total) - for i := range shares { - shr := make([]byte, share.Size) - copy(share.GetNamespace(shr), RandV0Namespace()) - rndMu.Lock() - _, err := rnd.Read(share.GetData(shr)) - rndMu.Unlock() - require.NoError(t, err) - shares[i] = shr - } - sort.Slice(shares, func(i, j int) bool { return bytes.Compare(shares[i], shares[j]) < 0 }) - - return shares -} - -// RandSharesWithNamespace is same the as RandShares, but sets same namespace for all shares. -func RandSharesWithNamespace(t testing.TB, namespace share.Namespace, namespacedAmount, total int) []share.Share { - if total&(total-1) != 0 { - t.Errorf("total must be power of 2: %d", total) - t.FailNow() - } - - if namespacedAmount > total { - t.Errorf("withNamespace must be less than total: %d", total) - t.FailNow() - } - - shares := make([]share.Share, total) - rnd := rand.New(rand.NewSource(time.Now().Unix())) //nolint:gosec - for i := range shares { - shr := make([]byte, share.Size) - if i < namespacedAmount { - copy(share.GetNamespace(shr), namespace) - } else { - copy(share.GetNamespace(shr), RandV0Namespace()) - } - _, err := rnd.Read(share.GetData(shr)) - require.NoError(t, err) - shares[i] = shr - } - sort.Slice(shares, func(i, j int) bool { return bytes.Compare(shares[i], shares[j]) < 0 }) - return shares -} - -// RandV0Namespace generates random valid data namespace for testing purposes. -func RandV0Namespace() share.Namespace { - rb := make([]byte, namespace.NamespaceVersionZeroIDSize) - rndMu.Lock() - rnd.Read(rb) - rndMu.Unlock() - for { - namespace, _ := share.NewBlobNamespaceV0(rb) - if err := namespace.ValidateForData(); err != nil { - continue - } - return namespace - } -} - -var ( - rnd = rand.New(rand.NewSource(time.Now().Unix())) //nolint:gosec - rndMu sync.Mutex -) diff --git a/share/shwap/row_namespace_data_test.go b/share/shwap/row_namespace_data_test.go deleted file mode 100644 index 985f508c7b..0000000000 --- a/share/shwap/row_namespace_data_test.go +++ /dev/null @@ -1,99 +0,0 @@ -package shwap_test - -import ( - "bytes" - "context" - "slices" - "testing" - "time" - - "github.com/stretchr/testify/require" - - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/sharetest" - "github.com/celestiaorg/celestia-node/share/shwap" -) - -func TestNamespacedRowFromShares(t *testing.T) { - const odsSize = 8 - - minNamespace, err := share.NewBlobNamespaceV0(slices.Concat(bytes.Repeat([]byte{0}, 8), []byte{1, 0})) - require.NoError(t, err) - err = minNamespace.ValidateForData() - require.NoError(t, err) - - for namespacedAmount := 1; namespacedAmount < odsSize; namespacedAmount++ { - shares := sharetest.RandSharesWithNamespace(t, minNamespace, namespacedAmount, odsSize) - parity, err := share.DefaultRSMT2DCodec().Encode(shares) - require.NoError(t, err) - extended := slices.Concat(shares, parity) - - nr, err := shwap.RowNamespaceDataFromShares(extended, minNamespace, 0) - require.NoError(t, err) - require.Equal(t, namespacedAmount, len(nr.Shares)) - } -} - -func TestNamespacedRowFromSharesNonIncluded(t *testing.T) { - // TODO: this will fail until absence proof support is added - t.Skip() - - const odsSize = 8 - // Test absent namespace - shares := sharetest.RandShares(t, odsSize) - absentNs, err := share.GetNamespace(shares[0]).AddInt(1) - require.NoError(t, err) - - parity, err := share.DefaultRSMT2DCodec().Encode(shares) - require.NoError(t, err) - extended := slices.Concat(shares, parity) - - nr, err := shwap.RowNamespaceDataFromShares(extended, absentNs, 0) - require.NoError(t, err) - require.Len(t, nr.Shares, 0) - 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 TestNamespacedRowProtoEncoding(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - t.Cleanup(cancel) - - const odsSize = 8 - namespace := sharetest.RandV0Namespace() - randEDS, _ := edstest.RandEDSWithNamespace(t, namespace, odsSize, odsSize) - rsmt2d := &eds.Rsmt2D{ExtendedDataSquare: randEDS} - nd, err := eds.NamespaceData(ctx, rsmt2d, namespace) - require.NoError(t, err) - require.True(t, len(nd) > 0) - - expected := nd[0] - pb := expected.ToProto() - ndOut := shwap.RowNamespaceDataFromProto(pb) - require.Equal(t, expected, ndOut) -} diff --git a/share/availability.go b/square/availability.go similarity index 97% rename from share/availability.go rename to square/availability.go index 3373a62276..fe2f29bea0 100644 --- a/share/availability.go +++ b/square/availability.go @@ -1,4 +1,4 @@ -package share +package square import ( "context" diff --git a/share/availability/full/availability.go b/square/availability/full/availability.go similarity index 86% rename from share/availability/full/availability.go rename to square/availability/full/availability.go index 91550849c8..af6106cc27 100644 --- a/share/availability/full/availability.go +++ b/square/availability/full/availability.go @@ -10,15 +10,15 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/pruner" "github.com/celestiaorg/celestia-node/pruner/full" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/square/shwap" "github.com/celestiaorg/celestia-node/store" ) var log = logging.Logger("share/full") -// ShareAvailability implements share.Availability using the full data square +// ShareAvailability implements square.Availability using the full data square // recovery technique. It is considered "full" because it is required // to download enough shares to fully reconstruct the data square. type ShareAvailability struct { @@ -42,8 +42,8 @@ func NewShareAvailability( func (fa *ShareAvailability) SharesAvailable(ctx context.Context, header *header.ExtendedHeader) error { dah := header.DAH // if the data square is empty, we can safely link the header height in the store to an empty EDS. - if share.DataHash(dah.Hash()).IsEmptyEDS() { - err := fa.store.PutODSQ4(ctx, dah, header.Height(), share.EmptyEDS()) + if square.DataHash(dah.Hash()).IsEmptyEDS() { + err := fa.store.PutODSQ4(ctx, dah, header.Height(), square.EmptyEDS()) if err != nil { return fmt.Errorf("put empty EDS: %w", err) } @@ -71,7 +71,7 @@ func (fa *ShareAvailability) SharesAvailable(ctx context.Context, header *header log.Errorw("availability validation failed", "root", dah.String(), "err", err.Error()) var byzantineErr *byzantine.ErrByzantine if errors.Is(err, shwap.ErrNotFound) || errors.Is(err, context.DeadlineExceeded) && !errors.As(err, &byzantineErr) { - return share.ErrNotAvailable + return square.ErrNotAvailable } return err } diff --git a/share/availability/full/availability_test.go b/square/availability/full/availability_test.go similarity index 86% rename from share/availability/full/availability_test.go rename to square/availability/full/availability_test.go index 95f8bda533..4a03cace50 100644 --- a/share/availability/full/availability_test.go +++ b/square/availability/full/availability_test.go @@ -9,10 +9,10 @@ import ( "github.com/stretchr/testify/require" "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/getters/mock" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/getters/mock" "github.com/celestiaorg/celestia-node/store" ) @@ -22,7 +22,7 @@ func TestSharesAvailable(t *testing.T) { // RandServiceWithSquare creates a NewShareAvailability inside, so we can test it eds := edstest.RandEDS(t, 16) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) eh := headertest.RandExtendedHeaderWithRoot(t, roots) @@ -51,7 +51,7 @@ func TestSharesAvailable_StoredEds(t *testing.T) { defer cancel() eds := edstest.RandEDS(t, 4) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) eh := headertest.RandExtendedHeaderWithRoot(t, roots) require.NoError(t, err) @@ -82,7 +82,7 @@ func TestSharesAvailable_ErrNotAvailable(t *testing.T) { defer cancel() eds := edstest.RandEDS(t, 4) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) eh := headertest.RandExtendedHeaderWithRoot(t, roots) require.NoError(t, err) @@ -94,6 +94,6 @@ func TestSharesAvailable_ErrNotAvailable(t *testing.T) { for _, getterErr := range errors { getter.EXPECT().GetEDS(gomock.Any(), gomock.Any()).Return(nil, getterErr) err := avail.SharesAvailable(ctx, eh) - require.ErrorIs(t, err, share.ErrNotAvailable) + require.ErrorIs(t, err, square.ErrNotAvailable) } } diff --git a/share/availability/full/reconstruction_test.go b/square/availability/full/reconstruction_test.go similarity index 96% rename from share/availability/full/reconstruction_test.go rename to square/availability/full/reconstruction_test.go index 179a458d36..e52b75d127 100644 --- a/share/availability/full/reconstruction_test.go +++ b/square/availability/full/reconstruction_test.go @@ -12,10 +12,10 @@ package full // "golang.org/x/sync/errgroup" // // "github.com/celestiaorg/celestia-node/header/headertest" -// "github.com/celestiaorg/celestia-node/share" -// "github.com/celestiaorg/celestia-node/share/availability/light" -// availability_test "github.com/celestiaorg/celestia-node/share/availability/test" -// "github.com/celestiaorg/celestia-node/share/eds" +// "github.com/celestiaorg/celestia-node/square" +// "github.com/celestiaorg/celestia-node/square/availability/light" +// availability_test "github.com/celestiaorg/celestia-node/square/availability/test" +// "github.com/celestiaorg/celestia-node/square/eds" //) // // func init() { @@ -260,7 +260,7 @@ package full // // // check that any of the fulls cannot reconstruct on their own // err := errg.Wait() -// require.ErrorIs(t, err, share.ErrNotAvailable) +// require.ErrorIs(t, err, square.ErrNotAvailable) // cancelErr() // // // but after they connect diff --git a/share/availability/full/testing.go b/square/availability/full/testing.go similarity index 62% rename from share/availability/full/testing.go rename to square/availability/full/testing.go index 9ebe3f1c18..fae51c53ca 100644 --- a/share/availability/full/testing.go +++ b/square/availability/full/testing.go @@ -1,45 +1,46 @@ package full // -// import ( +//import ( // "context" +// // "testing" // "time" // // "github.com/ipfs/go-datastore" // "github.com/stretchr/testify/require" // -// "github.com/celestiaorg/celestia-node/share" -// availability_test "github.com/celestiaorg/celestia-node/share/availability/test" -// "github.com/celestiaorg/celestia-node/share/eds" -// "github.com/celestiaorg/celestia-node/share/getters" -// "github.com/celestiaorg/celestia-node/share/ipld" -// "github.com/celestiaorg/celestia-node/share/p2p/discovery" +// "github.com/celestiaorg/celestia-node/square" +// availability_test "github.com/celestiaorg/celestia-node/square/availability/test" +// "github.com/celestiaorg/celestia-node/square/eds" +// "github.com/celestiaorg/celestia-node/square/getters" +// "github.com/celestiaorg/celestia-node/square/ipld" +// "github.com/celestiaorg/celestia-node/square/p2p/discovery" //) // //// 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.AxisRoots) { +//func GetterWithRandSquare(t *testing.T, n int) (square.Getter, *square.AxisRoots) { // bServ := ipld.NewMemBlockservice() -// getter := getters.NewIPLDGetter(bServ) +// 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, *square.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 square.Getter) *ShareAvailability { // params := discovery.DefaultParameters() // params.AdvertiseInterval = time.Second // params.PeersLimit = 10 diff --git a/share/availability/light/availability.go b/square/availability/light/availability.go similarity index 91% rename from share/availability/light/availability.go rename to square/availability/light/availability.go index 5b1e144de0..1154c6a435 100644 --- a/share/availability/light/availability.go +++ b/square/availability/light/availability.go @@ -11,8 +11,8 @@ import ( logging "github.com/ipfs/go-log/v2" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap" ) var ( @@ -21,7 +21,7 @@ var ( writeBatchSize = 2048 ) -// ShareAvailability implements share.Availability using Data Availability Sampling technique. +// ShareAvailability implements square.Availability using Data Availability Sampling technique. // It is light because it does not require the downloading of all the data to verify // its availability. It is assumed that there are a lot of lightAvailability instances // on the network doing sampling over the same Root to collectively verify its availability. @@ -62,7 +62,7 @@ func NewShareAvailability( func (la *ShareAvailability) SharesAvailable(ctx context.Context, header *header.ExtendedHeader) error { dah := header.DAH // short-circuit if the given root is an empty data square - if share.DataHash(dah.Hash()).IsEmptyEDS() { + if square.DataHash(dah.Hash()).IsEmptyEDS() { return nil } @@ -125,7 +125,7 @@ func (la *ShareAvailability) SharesAvailable(ctx context.Context, header *header if errors.Is(ctx.Err(), context.Canceled) { // Availability did not complete due to context cancellation, return context error instead of - // share.ErrNotAvailable + // square.ErrNotAvailable return ctx.Err() } @@ -144,12 +144,12 @@ func (la *ShareAvailability) SharesAvailable(ctx context.Context, header *header "root", dah.String(), "failed_samples", failedSamples, ) - return share.ErrNotAvailable + return square.ErrNotAvailable } return nil } -func rootKey(root *share.AxisRoots) datastore.Key { +func rootKey(root *square.AxisRoots) datastore.Key { return datastore.NewKey(root.String()) } diff --git a/share/availability/light/availability_test.go b/square/availability/light/availability_test.go similarity index 84% rename from share/availability/light/availability_test.go rename to square/availability/light/availability_test.go index b8ec9db784..f2bd6d420f 100644 --- a/share/availability/light/availability_test.go +++ b/square/availability/light/availability_test.go @@ -10,15 +10,16 @@ import ( "github.com/ipfs/go-datastore" "github.com/stretchr/testify/require" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/getters/mock" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/getters/mock" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" ) func TestSharesAvailableCaches(t *testing.T) { @@ -26,7 +27,7 @@ func TestSharesAvailableCaches(t *testing.T) { defer cancel() eds := edstest.RandEDS(t, 16) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) eh := headertest.RandExtendedHeaderWithRoot(t, roots) @@ -35,7 +36,12 @@ func TestSharesAvailableCaches(t *testing.T) { GetShare(gomock.Any(), eh, gomock.Any(), gomock.Any()). DoAndReturn( func(_ context.Context, _ *header.ExtendedHeader, row, col int) (share.Share, error) { - return eds.GetCell(uint(row), uint(col)), nil + rawSh := eds.GetCell(uint(row), uint(col)) + sh, err := share.NewShare(rawSh) + if err != nil { + return share.Share{}, err + } + return *sh, nil }). AnyTimes() @@ -66,7 +72,7 @@ func TestSharesAvailableHitsCache(t *testing.T) { getter := mock.NewMockGetter(gomock.NewController(t)) getter.EXPECT(). GetShare(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). - Return(nil, shrex.ErrNotFound). + Return(share.Share{}, shrex.ErrNotFound). AnyTimes() ds := datastore.NewMapDatastore() @@ -78,7 +84,7 @@ func TestSharesAvailableHitsCache(t *testing.T) { // store doesn't actually have the eds err := avail.SharesAvailable(ctx, eh) - require.ErrorIs(t, err, share.ErrNotAvailable) + require.ErrorIs(t, err, square.ErrNotAvailable) // put success result in cache err = avail.ds.Put(ctx, rootKey(roots), []byte{}) @@ -98,7 +104,7 @@ func TestSharesAvailableEmptyRoot(t *testing.T) { avail := NewShareAvailability(getter, ds) // request for empty eds - eh := headertest.RandExtendedHeaderWithRoot(t, share.EmptyEDSRoots()) + eh := headertest.RandExtendedHeaderWithRoot(t, square.EmptyEDSRoots()) err := avail.SharesAvailable(ctx, eh) require.NoError(t, err) } @@ -113,17 +119,17 @@ func TestSharesAvailableFailed(t *testing.T) { // create new eds, that is not available by getter eds := edstest.RandEDS(t, 16) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) eh := headertest.RandExtendedHeaderWithRoot(t, roots) // getter doesn't have the eds, so it should fail getter.EXPECT(). GetShare(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). - Return(nil, shrex.ErrNotFound). + Return(share.Share{}, shrex.ErrNotFound). AnyTimes() err = avail.SharesAvailable(ctx, eh) - require.ErrorIs(t, err, share.ErrNotAvailable) + require.ErrorIs(t, err, square.ErrNotAvailable) // cache should have failed results now result, err := avail.ds.Get(ctx, rootKey(roots)) @@ -177,7 +183,7 @@ func (m onceGetter) GetShare(_ context.Context, _ *header.ExtendedHeader, row, c delete(m.available, s) return share.Share{}, nil } - return share.Share{}, share.ErrNotAvailable + return share.Share{}, square.ErrNotAvailable } func (m onceGetter) GetEDS(_ context.Context, _ *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) { diff --git a/share/availability/light/options.go b/square/availability/light/options.go similarity index 100% rename from share/availability/light/options.go rename to square/availability/light/options.go diff --git a/share/availability/light/sample.go b/square/availability/light/sample.go similarity index 100% rename from share/availability/light/sample.go rename to square/availability/light/sample.go diff --git a/share/availability/light/sample_test.go b/square/availability/light/sample_test.go similarity index 100% rename from share/availability/light/sample_test.go rename to square/availability/light/sample_test.go diff --git a/share/availability/light/testing.go b/square/availability/light/testing.go similarity index 89% rename from share/availability/light/testing.go rename to square/availability/light/testing.go index a7ef3248c4..224e2425a3 100644 --- a/share/availability/light/testing.go +++ b/square/availability/light/testing.go @@ -13,10 +13,10 @@ package light // // "github.com/celestiaorg/celestia-node/header" // "github.com/celestiaorg/celestia-node/header/headertest" -// "github.com/celestiaorg/celestia-node/share" -// availability_test "github.com/celestiaorg/celestia-node/share/availability/test" -// "github.com/celestiaorg/celestia-node/share/getters" -// "github.com/celestiaorg/celestia-node/share/ipld" +// "github.com/celestiaorg/celestia-node/square" +// availability_test "github.com/celestiaorg/celestia-node/square/availability/test" +// "github.com/celestiaorg/celestia-node/square/getters" +// "github.com/celestiaorg/celestia-node/square/ipld" //) // //// GetterWithRandSquare provides a share.Getter filled with 'n' NMT trees of 'n' random shares, @@ -40,7 +40,7 @@ package light //} // //// 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.AxisRoots) { +// func RandNode(dn *availability_test.TestDagNet, squareSize int) (*availability_test.TestNode, *square.AxisRoots) { // nd := Node(dn) // return nd, availability_test.RandFillBS(dn.T, squareSize, nd.BlockService) //} @@ -92,7 +92,7 @@ package light // delete(m.available, s) // return share.Share{}, nil // } -// return share.Share{}, share.ErrNotAvailable +// return share.Share{}, square.ErrNotAvailable //} // // func (m onceGetter) GetEDS(_ context.Context, _ *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) { diff --git a/share/availability/mocks/availability.go b/square/availability/mocks/availability.go similarity index 100% rename from share/availability/mocks/availability.go rename to square/availability/mocks/availability.go diff --git a/share/availability/test/testing.go b/square/availability/test/testing.go similarity index 92% rename from share/availability/test/testing.go rename to square/availability/test/testing.go index 6a8f1906ca..6296290c4c 100644 --- a/share/availability/test/testing.go +++ b/square/availability/test/testing.go @@ -17,23 +17,24 @@ import ( mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/ipld" - "github.com/celestiaorg/celestia-node/share/sharetest" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/ipld" + "github.com/celestiaorg/celestia-node/square/shwap" ) // RandFillBS fills the given BlockService with a random block of a given size. -func RandFillBS(t *testing.T, n int, bServ blockservice.BlockService) *share.AxisRoots { - shares := sharetest.RandShares(t, n*n) +func RandFillBS(t *testing.T, n int, bServ blockservice.BlockService) *square.AxisRoots { + shares := share.RandShares(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.AxisRoots { +func FillBS(t *testing.T, bServ blockservice.BlockService, shares []share.Share) *square.AxisRoots { eds, err := ipld.AddShares(context.TODO(), shares, bServ) require.NoError(t, err) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) return roots } @@ -41,7 +42,7 @@ func FillBS(t *testing.T, bServ blockservice.BlockService, shares []share.Share) type TestNode struct { net *TestDagNet shwap.Getter - share.Availability + square.Availability blockservice.BlockService host.Host } diff --git a/share/doc.go b/square/doc.go similarity index 88% rename from share/doc.go rename to square/doc.go index 6c6426472f..c28ee5cdab 100644 --- a/share/doc.go +++ b/square/doc.go @@ -1,5 +1,5 @@ /* -Package share contains logic related to the retrieval and random sampling of shares of +Package square contains logic related to the retrieval and random sampling of shares of block data. Though this package contains several useful methods for getting specific shares and/or @@ -14,4 +14,4 @@ the block's availability on the network). Full Availability implementation samples for as many shares as necessary to fully reconstruct the block data. */ -package share +package square diff --git a/share/eds/accessor.go b/square/eds/accessor.go similarity index 80% rename from share/eds/accessor.go rename to square/eds/accessor.go index ca0b475bb2..a290d2aed0 100644 --- a/share/eds/accessor.go +++ b/square/eds/accessor.go @@ -4,23 +4,24 @@ import ( "context" "io" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap" ) // EmptyAccessor is an accessor of an empty EDS block. -var EmptyAccessor = &Rsmt2D{ExtendedDataSquare: share.EmptyEDS()} +var EmptyAccessor = &Rsmt2D{ExtendedDataSquare: square.EmptyEDS()} // Accessor is an interface for accessing extended data square data. type Accessor interface { // Size returns square size of the Accessor. Size(ctx context.Context) int // DataHash returns data hash of the Accessor. - DataHash(ctx context.Context) (share.DataHash, error) - // AxisRoots returns share.AxisRoots (DataAvailabilityHeader) of the Accessor. - AxisRoots(ctx context.Context) (*share.AxisRoots, error) + DataHash(ctx context.Context) (square.DataHash, error) + // AxisRoots returns square.AxisRoots (DataAvailabilityHeader) of the Accessor. + AxisRoots(ctx context.Context) (*square.AxisRoots, error) // Sample returns share and corresponding proof for row and column indices. Implementation can // choose which axis to use for proof. Chosen axis for proof should be indicated in the returned // Sample. diff --git a/share/eds/axis_half.go b/square/eds/axis_half.go similarity index 75% rename from share/eds/axis_half.go rename to square/eds/axis_half.go index 6b48676fe2..d5ef406be8 100644 --- a/share/eds/axis_half.go +++ b/square/eds/axis_half.go @@ -3,11 +3,13 @@ package eds import ( "fmt" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap" ) -var codec = share.DefaultRSMT2DCodec() +var codec = square.DefaultRSMT2DCodec() // AxisHalf represents a half of data for a row or column in the EDS. type AxisHalf struct { @@ -39,15 +41,20 @@ func extendShares(original []share.Share) ([]share.Share, error) { return nil, fmt.Errorf("original shares are empty") } - parity, err := codec.Encode(original) + parity, err := codec.Encode(share.ToBytes(original)) if err != nil { return nil, fmt.Errorf("encoding: %w", err) } + parityShrs, err := share.FromBytes(parity) + if err != nil { + return nil, err + } + sqLen := len(original) * 2 shares := make([]share.Share, sqLen) copy(shares, original) - copy(shares[sqLen/2:], parity) + copy(shares[sqLen/2:], parityShrs) return shares, nil } @@ -61,9 +68,10 @@ func reconstructShares(parity []share.Share) ([]share.Share, error) { for i := sqLen / 2; i < sqLen; i++ { shares[i] = parity[i-sqLen/2] } - _, err := codec.Decode(shares) + shrs, err := codec.Decode(share.ToBytes(shares)) if err != nil { return nil, fmt.Errorf("reconstructing: %w", err) } - return shares, nil + + return share.FromBytes(shrs) } diff --git a/share/eds/axis_half_test.go b/square/eds/axis_half_test.go similarity index 83% rename from share/eds/axis_half_test.go rename to square/eds/axis_half_test.go index 752add5acd..6974080523 100644 --- a/share/eds/axis_half_test.go +++ b/square/eds/axis_half_test.go @@ -5,11 +5,11 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/go-square/v2/share" ) func TestExtendAxisHalf(t *testing.T) { - shares := sharetest.RandShares(t, 16) + shares := share.RandShares(16) original := AxisHalf{ Shares: shares, diff --git a/share/eds/byzantine/bad_encoding.go b/square/eds/byzantine/bad_encoding.go similarity index 95% rename from share/eds/byzantine/bad_encoding.go rename to square/eds/byzantine/bad_encoding.go index 7e1386a863..8687e7ce1f 100644 --- a/share/eds/byzantine/bad_encoding.go +++ b/square/eds/byzantine/bad_encoding.go @@ -5,13 +5,13 @@ import ( "errors" "fmt" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" "github.com/celestiaorg/go-fraud" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share" - pb "github.com/celestiaorg/celestia-node/share/eds/byzantine/pb" + "github.com/celestiaorg/celestia-node/square" + pb "github.com/celestiaorg/celestia-node/square/eds/byzantine/pb" ) const ( @@ -88,10 +88,14 @@ func (p *BadEncodingProof) UnmarshalBinary(data []byte) error { if err := in.Unmarshal(data); err != nil { return err } + sh, err := ProtoToShare(in.Shares) + if err != nil { + return err + } befp := &BadEncodingProof{ headerHash: in.HeaderHash, BlockHeight: in.Height, - Shares: ProtoToShare(in.Shares), + Shares: sh, Index: in.Index, Axis: rsmt2d.Axis(in.Axis), } @@ -184,10 +188,10 @@ func (p *BadEncodingProof) Validate(hdr *header.ExtendedHeader) error { log.Debugf("%s: %s at index %d", invalidProofPrefix, errIncorrectShare, index) return errIncorrectShare } - shares[index] = shr.Share + shares[index] = shr.Share.ToBytes() } - codec := share.DefaultRSMT2DCodec() + codec := square.DefaultRSMT2DCodec() // We can conclude that the proof is valid in case we proved the inclusion of `Shares` but // the row/col can't be reconstructed, or the building of NMTree fails. diff --git a/share/eds/byzantine/bad_encoding_test.go b/square/eds/byzantine/bad_encoding_test.go similarity index 89% rename from share/eds/byzantine/bad_encoding_test.go rename to square/eds/byzantine/bad_encoding_test.go index f4dbe84e31..c226b2a5cb 100644 --- a/share/eds/byzantine/bad_encoding_test.go +++ b/square/eds/byzantine/bad_encoding_test.go @@ -13,15 +13,15 @@ import ( "github.com/stretchr/testify/require" core "github.com/tendermint/tendermint/types" - "github.com/celestiaorg/celestia-app/v2/test/util/malicious" + "github.com/celestiaorg/celestia-app/v3/test/util/malicious" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/ipld" - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/ipld" ) func TestBEFP_Validate(t *testing.T) { @@ -29,14 +29,14 @@ func TestBEFP_Validate(t *testing.T) { defer t.Cleanup(cancel) bServ := ipld.NewMemBlockservice() - square := edstest.RandByzantineEDS(t, 16) - roots, err := share.NewAxisRoots(square) + byzSquare := edstest.RandByzantineEDS(t, 16) + roots, err := square.NewAxisRoots(byzSquare) require.NoError(t, err) - err = ipld.ImportEDS(ctx, square, bServ) + err = ipld.ImportEDS(ctx, byzSquare, bServ) require.NoError(t, err) var errRsmt2d *rsmt2d.ErrByzantineData - err = square.Repair(roots.RowRoots, roots.ColumnRoots) + err = byzSquare.Repair(roots.RowRoots, roots.ColumnRoots) require.ErrorAs(t, err, &errRsmt2d) byzantine := NewErrByzantine(ctx, bServ.Blockstore(), roots, errRsmt2d) @@ -64,7 +64,7 @@ func TestBEFP_Validate(t *testing.T) { name: "invalid BEFP for valid header", prepareFn: func() error { validSquare := edstest.RandEDS(t, 2) - validRoots, err := share.NewAxisRoots(validSquare) + validRoots, err := square.NewAxisRoots(validSquare) require.NoError(t, err) err = ipld.ImportEDS(ctx, validSquare, bServ) require.NoError(t, err) @@ -89,7 +89,7 @@ func TestBEFP_Validate(t *testing.T) { name: "incorrect share with Proof", prepareFn: func() error { // break the first shareWithProof to test negative case - sh := sharetest.RandShares(t, 2) + sh := share.RandShares(2) nmtProof := nmt.NewInclusionProof(0, 1, nil, false) befp.Shares[0] = &ShareWithProof{sh[0], &nmtProof, rsmt2d.Row} return proof.Validate(&header.ExtendedHeader{DAH: roots}) @@ -160,12 +160,12 @@ func TestIncorrectBadEncodingFraudProof(t *testing.T) { bServ := ipld.NewMemBlockservice() squareSize := 8 - shares := sharetest.RandShares(t, squareSize*squareSize) + shares := share.RandShares(squareSize * squareSize) eds, err := ipld.AddShares(ctx, shares, bServ) require.NoError(t, err) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) // get an arbitrary row @@ -215,12 +215,12 @@ func TestBEFP_ValidateOutOfOrderShares(t *testing.T) { batchAddr := ipld.NewNmtNodeAdder(ctx, bServ, ipld.MaxSizeBatchOption(size*2)) eds, err := rsmt2d.ImportExtendedDataSquare(shares, - share.DefaultRSMT2DCodec(), + square.DefaultRSMT2DCodec(), malicious.NewConstructor(uint64(size), nmt.NodeVisitor(batchAddr.Visit)), ) require.NoError(t, err, "failure to recompute the extended data square") - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) var errRsmt2d *rsmt2d.ErrByzantineData @@ -252,7 +252,7 @@ func newNamespacedBlockService() *namespacedBlockService { sha256NamespaceFlagged := uint64(0x7701) // register the nmt hasher to validate the order of namespaces mhcore.Register(sha256NamespaceFlagged, func() hash.Hash { - nh := nmt.NewNmtHasher(share.NewSHA256Hasher(), share.NamespaceSize, true) + nh := nmt.NewNmtHasher(square.NewSHA256Hasher(), share.NamespaceSize, true) nh.Reset() return nh }) @@ -265,7 +265,7 @@ func newNamespacedBlockService() *namespacedBlockService { Codec: sha256NamespaceFlagged, MhType: sha256NamespaceFlagged, // equals to NmtHasher.Size() - MhLength: share.NewSHA256Hasher().Size() + 2*share.NamespaceSize, + MhLength: square.NewSHA256Hasher().Size() + 2*share.NamespaceSize, } return bs } diff --git a/share/eds/byzantine/byzantine.go b/square/eds/byzantine/byzantine.go similarity index 75% rename from share/eds/byzantine/byzantine.go rename to square/eds/byzantine/byzantine.go index 8f7b7c3a3b..80f015529c 100644 --- a/share/eds/byzantine/byzantine.go +++ b/square/eds/byzantine/byzantine.go @@ -6,10 +6,11 @@ import ( "github.com/ipfs/boxo/blockstore" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/ipld" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/ipld" ) // ErrByzantine is a thrown when recovered data square is not correct @@ -32,17 +33,22 @@ func (e *ErrByzantine) Error() string { func NewErrByzantine( ctx context.Context, bStore blockstore.Blockstore, - roots *share.AxisRoots, + roots *square.AxisRoots, errByz *rsmt2d.ErrByzantineData, ) error { sharesWithProof := make([]*ShareWithProof, len(errByz.Shares)) bGetter := ipld.NewBlockservice(bStore, nil) var count int - for index, share := range errByz.Shares { - if len(share) == 0 { + for index, shr := range errByz.Shares { + if len(shr) == 0 { continue } - swp, err := GetShareWithProof(ctx, bGetter, roots, share, errByz.Axis, int(errByz.Index), index) + sh, err := share.NewShare(shr) + if err != nil { + log.Warn("failed to create share", "index", index, "err", err) + continue + } + swp, err := GetShareWithProof(ctx, bGetter, roots, *sh, errByz.Axis, int(errByz.Index), index) if err != nil { log.Warn("requesting proof failed", "errByz", errByz, diff --git a/share/eds/byzantine/pb/share.pb.go b/square/eds/byzantine/pb/share.pb.go similarity index 87% rename from share/eds/byzantine/pb/share.pb.go rename to square/eds/byzantine/pb/share.pb.go index af79d48b13..d31b409560 100644 --- a/share/eds/byzantine/pb/share.pb.go +++ b/square/eds/byzantine/pb/share.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: share/eds/byzantine/pb/share.proto +// source: square/eds/byzantine/pb/share.proto package share_eds_byzantine_pb @@ -45,7 +45,7 @@ func (x Axis) String() string { } func (Axis) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_d28ce8f160a920d1, []int{0} + return fileDescriptor_5c467604cd602917, []int{0} } type Share struct { @@ -58,7 +58,7 @@ func (m *Share) Reset() { *m = Share{} } func (m *Share) String() string { return proto.CompactTextString(m) } func (*Share) ProtoMessage() {} func (*Share) Descriptor() ([]byte, []int) { - return fileDescriptor_d28ce8f160a920d1, []int{0} + return fileDescriptor_5c467604cd602917, []int{0} } func (m *Share) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -120,7 +120,7 @@ func (m *BadEncoding) Reset() { *m = BadEncoding{} } func (m *BadEncoding) String() string { return proto.CompactTextString(m) } func (*BadEncoding) ProtoMessage() {} func (*BadEncoding) Descriptor() ([]byte, []int) { - return fileDescriptor_d28ce8f160a920d1, []int{1} + return fileDescriptor_5c467604cd602917, []int{1} } func (m *BadEncoding) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -191,31 +191,31 @@ func init() { } func init() { - proto.RegisterFile("share/eds/byzantine/pb/share.proto", fileDescriptor_d28ce8f160a920d1) -} - -var fileDescriptor_d28ce8f160a920d1 = []byte{ - // 310 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0x31, 0x4b, 0xc4, 0x30, - 0x1c, 0xc5, 0x1b, 0xaf, 0x3d, 0xf1, 0x7f, 0x7a, 0x1e, 0x41, 0x8e, 0x20, 0x1a, 0xca, 0x81, 0x50, - 0x1c, 0x52, 0x39, 0x71, 0x71, 0xf3, 0x54, 0x38, 0x41, 0x38, 0x89, 0x83, 0x73, 0x62, 0xe2, 0xb5, - 0x4b, 0x5b, 0x9a, 0x0e, 0xd5, 0xc1, 0xcf, 0xe0, 0x87, 0x72, 0x70, 0xbc, 0xd1, 0x51, 0xda, 0x2f, - 0x22, 0x4d, 0x8b, 0x3a, 0x28, 0xb8, 0xbd, 0xf7, 0xf2, 0x0b, 0x79, 0x8f, 0xc0, 0xc4, 0x44, 0x22, - 0xd7, 0xa1, 0x56, 0x26, 0x94, 0x8f, 0x4f, 0x22, 0x29, 0xe2, 0x44, 0x87, 0x99, 0x0c, 0x6d, 0xcc, - 0xb2, 0x3c, 0x2d, 0x52, 0x3c, 0x6e, 0x8d, 0x56, 0x86, 0x7d, 0x31, 0x2c, 0x93, 0xbb, 0xc3, 0x4c, - 0x86, 0x59, 0x9e, 0xa6, 0x0f, 0x2d, 0x37, 0x79, 0x06, 0xef, 0xb6, 0x21, 0x31, 0x06, 0xf7, 0x42, - 0x14, 0x82, 0x20, 0x1f, 0x05, 0x9b, 0xdc, 0x6a, 0x7c, 0x00, 0xde, 0x4d, 0xc3, 0x92, 0x35, 0x1f, - 0x05, 0x83, 0xe9, 0x36, 0xeb, 0x6e, 0x4a, 0x66, 0x63, 0xde, 0x9e, 0xe2, 0x53, 0xd8, 0xb0, 0xe2, - 0xac, 0x8c, 0x0d, 0xe9, 0xf9, 0x28, 0x18, 0x4e, 0xf7, 0xd8, 0xef, 0xef, 0x33, 0x51, 0xc6, 0x86, - 0x7f, 0xe3, 0x93, 0x57, 0x04, 0x83, 0x99, 0x50, 0x97, 0xc9, 0x7d, 0xaa, 0xe2, 0x64, 0x89, 0x29, - 0xc0, 0x5c, 0x0b, 0xa5, 0xf3, 0xb9, 0x30, 0x51, 0x57, 0xe6, 0x47, 0x82, 0xc7, 0xd0, 0x9f, 0xeb, - 0x78, 0x19, 0x15, 0xb6, 0x93, 0xcb, 0x3b, 0x87, 0x4f, 0xa0, 0x6f, 0x77, 0x34, 0x05, 0x7a, 0xc1, - 0x60, 0xba, 0xff, 0x57, 0x01, 0x4b, 0xf1, 0x0e, 0xc6, 0x3b, 0xe0, 0x5d, 0x25, 0x4a, 0x97, 0xc4, - 0xf5, 0x51, 0xb0, 0xc5, 0x5b, 0x83, 0x8f, 0xc0, 0xb5, 0x5b, 0xbc, 0x7f, 0x6c, 0xb1, 0xe4, 0x21, - 0x01, 0xb7, 0x71, 0x78, 0x1d, 0x7a, 0x7c, 0x71, 0x37, 0x72, 0x1a, 0x71, 0xbe, 0xb8, 0x1e, 0xa1, - 0x19, 0x79, 0xab, 0x28, 0x5a, 0x55, 0x14, 0x7d, 0x54, 0x14, 0xbd, 0xd4, 0xd4, 0x59, 0xd5, 0xd4, - 0x79, 0xaf, 0xa9, 0x23, 0xfb, 0xf6, 0x07, 0x8e, 0x3f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x0f, 0x5d, - 0x8d, 0x6c, 0xcf, 0x01, 0x00, 0x00, + proto.RegisterFile("square/eds/byzantine/pb/share.proto", fileDescriptor_5c467604cd602917) +} + +var fileDescriptor_5c467604cd602917 = []byte{ + // 316 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0xc1, 0x4b, 0xfb, 0x30, + 0x1c, 0xc5, 0x9b, 0xdf, 0xda, 0xfd, 0xf0, 0x3b, 0x9d, 0x23, 0xc8, 0x08, 0xa2, 0xa1, 0x4c, 0x84, + 0xe2, 0x21, 0x95, 0x89, 0x17, 0x6f, 0x4e, 0x85, 0x09, 0xc2, 0x24, 0x1e, 0x3c, 0x27, 0x26, 0x6e, + 0xbd, 0xb4, 0xb5, 0xa9, 0x50, 0x3d, 0xf8, 0x37, 0xf8, 0x47, 0x79, 0xf0, 0xb8, 0xa3, 0x47, 0x69, + 0xff, 0x11, 0x69, 0x5a, 0xd4, 0x83, 0x82, 0xb7, 0xf7, 0x5e, 0x3e, 0x21, 0xef, 0x11, 0xd8, 0x31, + 0x77, 0xf7, 0x22, 0xd3, 0xa1, 0x56, 0x26, 0x94, 0x0f, 0x8f, 0x22, 0xce, 0xa3, 0x58, 0x87, 0xa9, + 0x0c, 0xcd, 0x42, 0x64, 0x9a, 0xa5, 0x59, 0x92, 0x27, 0x78, 0xd8, 0x18, 0xad, 0x0c, 0xfb, 0x64, + 0x58, 0x2a, 0x37, 0xfb, 0xa9, 0x0c, 0xd3, 0x2c, 0x49, 0x6e, 0x1b, 0x6e, 0xf4, 0x04, 0xde, 0x55, + 0x4d, 0x62, 0x0c, 0xee, 0xa9, 0xc8, 0x05, 0x41, 0x3e, 0x0a, 0x56, 0xb9, 0xd5, 0x78, 0x17, 0xbc, + 0xcb, 0x9a, 0x25, 0xff, 0x7c, 0x14, 0xf4, 0xc6, 0xeb, 0xac, 0xbd, 0x29, 0x99, 0x8d, 0x79, 0x73, + 0x8a, 0x8f, 0x60, 0xc5, 0x8a, 0xe3, 0x22, 0x32, 0xa4, 0xe3, 0xa3, 0xa0, 0x3f, 0xde, 0x62, 0x3f, + 0xbf, 0xcf, 0x44, 0x11, 0x19, 0xfe, 0x85, 0x8f, 0x5e, 0x10, 0xf4, 0x26, 0x42, 0x9d, 0xc5, 0x37, + 0x89, 0x8a, 0xe2, 0x39, 0xa6, 0x00, 0x53, 0x2d, 0x94, 0xce, 0xa6, 0xc2, 0x2c, 0xda, 0x32, 0xdf, + 0x12, 0x3c, 0x84, 0xee, 0x54, 0x47, 0xf3, 0x45, 0x6e, 0x3b, 0xb9, 0xbc, 0x75, 0xf8, 0x10, 0xba, + 0x76, 0x47, 0x5d, 0xa0, 0x13, 0xf4, 0xc6, 0xdb, 0xbf, 0x15, 0xb0, 0x14, 0x6f, 0x61, 0xbc, 0x01, + 0xde, 0x79, 0xac, 0x74, 0x41, 0x5c, 0x1f, 0x05, 0x6b, 0xbc, 0x31, 0x78, 0x1f, 0x5c, 0xbb, 0xc5, + 0xfb, 0xc3, 0x16, 0x4b, 0xee, 0x11, 0x70, 0x6b, 0x87, 0xff, 0x43, 0x87, 0xcf, 0xae, 0x07, 0x4e, + 0x2d, 0x4e, 0x66, 0x17, 0x03, 0x34, 0x21, 0xaf, 0x25, 0x45, 0xcb, 0x92, 0xa2, 0xf7, 0x92, 0xa2, + 0xe7, 0x8a, 0x3a, 0xcb, 0x8a, 0x3a, 0x6f, 0x15, 0x75, 0x64, 0xd7, 0xfe, 0xc0, 0xc1, 0x47, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x7c, 0x07, 0xc6, 0x14, 0xd0, 0x01, 0x00, 0x00, } func (m *Share) Marshal() (dAtA []byte, err error) { diff --git a/share/eds/byzantine/pb/share.proto b/square/eds/byzantine/pb/share.proto similarity index 100% rename from share/eds/byzantine/pb/share.proto rename to square/eds/byzantine/pb/share.proto diff --git a/share/eds/byzantine/share_proof.go b/square/eds/byzantine/share_proof.go similarity index 77% rename from share/eds/byzantine/share_proof.go rename to square/eds/byzantine/share_proof.go index 4dd2c082b6..5d94159a0a 100644 --- a/share/eds/byzantine/share_proof.go +++ b/square/eds/byzantine/share_proof.go @@ -7,13 +7,14 @@ import ( "github.com/ipfs/boxo/blockservice" logging "github.com/ipfs/go-log/v2" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" nmt_pb "github.com/celestiaorg/nmt/pb" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - pb "github.com/celestiaorg/celestia-node/share/eds/byzantine/pb" - "github.com/celestiaorg/celestia-node/share/ipld" + "github.com/celestiaorg/celestia-node/square" + pb "github.com/celestiaorg/celestia-node/square/eds/byzantine/pb" + "github.com/celestiaorg/celestia-node/square/ipld" ) var log = logging.Logger("share/byzantine") @@ -29,7 +30,7 @@ type ShareWithProof struct { } // Validate validates inclusion of the share under the given root CID. -func (s *ShareWithProof) Validate(roots *share.AxisRoots, axisType rsmt2d.Axis, axisIdx, shrIdx int) bool { +func (s *ShareWithProof) Validate(roots *square.AxisRoots, axisType rsmt2d.Axis, axisIdx, shrIdx int) bool { var rootHash []byte switch axisType { case rsmt2d.Row: @@ -42,12 +43,12 @@ func (s *ShareWithProof) Validate(roots *share.AxisRoots, axisType rsmt2d.Axis, isParity := shrIdx >= edsSize/2 || axisIdx >= edsSize/2 namespace := share.ParitySharesNamespace if !isParity { - namespace = share.GetNamespace(s.Share) + namespace = s.Share.Namespace() } return s.Proof.VerifyInclusion( - share.NewSHA256Hasher(), - namespace.ToNMT(), - [][]byte{s.Share}, + square.NewSHA256Hasher(), + namespace.Bytes(), + [][]byte{s.Share.ToBytes()}, rootHash, ) } @@ -56,9 +57,8 @@ func (s *ShareWithProof) ShareWithProofToProto() *pb.Share { if s == nil { return &pb.Share{} } - return &pb.Share{ - Data: s.Share, + Data: s.Share.ToBytes(), Proof: &nmt_pb.Proof{ Start: int64(s.Proof.Start()), End: int64(s.Proof.End()), @@ -75,7 +75,7 @@ func (s *ShareWithProof) ShareWithProofToProto() *pb.Share { func GetShareWithProof( ctx context.Context, bGetter blockservice.BlockGetter, - roots *share.AxisRoots, + roots *square.AxisRoots, share share.Share, axisType rsmt2d.Axis, axisIdx, shrIdx int, ) (*ShareWithProof, error) { @@ -114,20 +114,24 @@ func GetShareWithProof( return nil, errors.New("failed to collect proof") } -func ProtoToShare(protoShares []*pb.Share) []*ShareWithProof { +func ProtoToShare(protoShares []*pb.Share) ([]*ShareWithProof, error) { shares := make([]*ShareWithProof, len(protoShares)) - for i, share := range protoShares { - if share.Proof == nil { + for i, protoSh := range protoShares { + if protoSh.Proof == nil { continue } - proof := ProtoToProof(share.Proof) + proof := ProtoToProof(protoSh.Proof) + sh, err := share.NewShare(protoSh.Data) + if err != nil { + return nil, err + } shares[i] = &ShareWithProof{ - Share: share.Data, + Share: *sh, Proof: &proof, - Axis: rsmt2d.Axis(share.ProofAxis), + Axis: rsmt2d.Axis(protoSh.ProofAxis), } } - return shares + return shares, nil } func ProtoToProof(protoProof *nmt_pb.Proof) nmt.Proof { @@ -139,7 +143,7 @@ func ProtoToProof(protoProof *nmt_pb.Proof) nmt.Proof { ) } -func rootHashForCoordinates(r *share.AxisRoots, axisType rsmt2d.Axis, x, y int) []byte { +func rootHashForCoordinates(r *square.AxisRoots, axisType rsmt2d.Axis, x, y int) []byte { if axisType == rsmt2d.Row { return r.RowRoots[y] } diff --git a/share/eds/close_once.go b/square/eds/close_once.go similarity index 85% rename from share/eds/close_once.go rename to square/eds/close_once.go index 2150ff7232..13b2df177b 100644 --- a/share/eds/close_once.go +++ b/square/eds/close_once.go @@ -6,10 +6,11 @@ import ( "io" "sync/atomic" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap" ) var _ AccessorStreamer = (*closeOnce)(nil) @@ -42,14 +43,14 @@ func (c *closeOnce) Size(ctx context.Context) int { return c.f.Size(ctx) } -func (c *closeOnce) DataHash(ctx context.Context) (share.DataHash, error) { +func (c *closeOnce) DataHash(ctx context.Context) (square.DataHash, error) { if c.closed.Load() { return nil, errAccessorClosed } return c.f.DataHash(ctx) } -func (c *closeOnce) AxisRoots(ctx context.Context) (*share.AxisRoots, error) { +func (c *closeOnce) AxisRoots(ctx context.Context) (*square.AxisRoots, error) { if c.closed.Load() { return nil, errAccessorClosed } diff --git a/share/eds/close_once_test.go b/square/eds/close_once_test.go similarity index 83% rename from share/eds/close_once_test.go rename to square/eds/close_once_test.go index c31d9ba099..58da79d840 100644 --- a/share/eds/close_once_test.go +++ b/square/eds/close_once_test.go @@ -8,10 +8,11 @@ import ( "github.com/stretchr/testify/require" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap" ) func TestWithClosedOnce(t *testing.T) { @@ -50,12 +51,12 @@ func (s *stubEdsAccessorCloser) Size(context.Context) int { return 0 } -func (s *stubEdsAccessorCloser) DataHash(context.Context) (share.DataHash, error) { - return share.DataHash{}, nil +func (s *stubEdsAccessorCloser) DataHash(context.Context) (square.DataHash, error) { + return square.DataHash{}, nil } -func (s *stubEdsAccessorCloser) AxisRoots(context.Context) (*share.AxisRoots, error) { - return &share.AxisRoots{}, nil +func (s *stubEdsAccessorCloser) AxisRoots(context.Context) (*square.AxisRoots, error) { + return &square.AxisRoots{}, nil } func (s *stubEdsAccessorCloser) Sample(context.Context, int, int) (shwap.Sample, error) { diff --git a/share/eds/edstest/testing.go b/square/eds/edstest/testing.go similarity index 69% rename from share/eds/edstest/testing.go rename to square/eds/edstest/testing.go index 56d5b3f4b7..8eb11409bb 100644 --- a/share/eds/edstest/testing.go +++ b/square/eds/edstest/testing.go @@ -7,24 +7,22 @@ import ( "github.com/stretchr/testify/require" coretypes "github.com/tendermint/tendermint/types" - "github.com/celestiaorg/celestia-app/v2/app" - "github.com/celestiaorg/celestia-app/v2/app/encoding" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - "github.com/celestiaorg/celestia-app/v2/pkg/da" - "github.com/celestiaorg/celestia-app/v2/pkg/user" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" - "github.com/celestiaorg/celestia-app/v2/test/util/blobfactory" - "github.com/celestiaorg/celestia-app/v2/test/util/testfactory" - "github.com/celestiaorg/celestia-app/v2/x/blob/types" - "github.com/celestiaorg/go-square/blob" - "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/celestia-app/v3/app" + "github.com/celestiaorg/celestia-app/v3/app/encoding" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + "github.com/celestiaorg/celestia-app/v3/pkg/da" + "github.com/celestiaorg/celestia-app/v3/pkg/user" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/test/util/blobfactory" + "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" + blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" appshares "github.com/celestiaorg/go-square/shares" - "github.com/celestiaorg/go-square/square" + libSquare "github.com/celestiaorg/go-square/square" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/celestia-node/square" ) const ( @@ -35,10 +33,10 @@ const ( func RandByzantineEDS(t testing.TB, odsSize int, options ...nmt.Option) *rsmt2d.ExtendedDataSquare { eds := RandEDS(t, odsSize) shares := eds.Flattened() - copy(share.GetData(shares[0]), share.GetData(shares[1])) // corrupting eds + copy(shares[0][share.NamespaceSize:], shares[1][share.NamespaceSize:]) // corrupting eds eds, err := rsmt2d.ImportExtendedDataSquare( shares, - share.DefaultRSMT2DCodec(), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize), options...), ) require.NoError(t, err, "failure to recompute the extended data square") @@ -47,10 +45,10 @@ func RandByzantineEDS(t testing.TB, odsSize int, options ...nmt.Option) *rsmt2d. // RandEDS generates EDS filled with the random data with the given size for original square. func RandEDS(t testing.TB, odsSize int) *rsmt2d.ExtendedDataSquare { - shares := sharetest.RandShares(t, odsSize*odsSize) + shares := share.RandShares(odsSize * odsSize) eds, err := rsmt2d.ComputeExtendedDataSquare( - shares, - share.DefaultRSMT2DCodec(), + share.ToBytes(shares), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize)), ) require.NoError(t, err, "failure to recompute the extended data square") @@ -59,15 +57,15 @@ func RandEDS(t testing.TB, odsSize int) *rsmt2d.ExtendedDataSquare { // RandEDSWithTailPadding generates EDS of given ODS size filled with randomized and tail padding shares. func RandEDSWithTailPadding(t testing.TB, odsSize, padding int) *rsmt2d.ExtendedDataSquare { - shares := sharetest.RandShares(t, odsSize*odsSize) + shares := share.RandShares(odsSize * odsSize) for i := len(shares) - padding; i < len(shares); i++ { - paddingShare := appshares.TailPaddingShare() - shares[i] = paddingShare.ToBytes() + paddingShare := share.TailPaddingShare() + shares[i] = paddingShare } eds, err := rsmt2d.ComputeExtendedDataSquare( - shares, - share.DefaultRSMT2DCodec(), + share.ToBytes(shares), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize)), ) require.NoError(t, err, "failure to recompute the extended data square") @@ -80,21 +78,21 @@ func RandEDSWithNamespace( t testing.TB, namespace share.Namespace, namespacedAmount, odsSize int, -) (*rsmt2d.ExtendedDataSquare, *share.AxisRoots) { - shares := sharetest.RandSharesWithNamespace(t, namespace, namespacedAmount, odsSize*odsSize) +) (*rsmt2d.ExtendedDataSquare, *square.AxisRoots) { + shares := share.RandSharesWithNamespace(namespace, namespacedAmount, odsSize*odsSize) eds, err := rsmt2d.ComputeExtendedDataSquare( - shares, - share.DefaultRSMT2DCodec(), + share.ToBytes(shares), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize)), ) require.NoError(t, err, "failure to recompute the extended data square") - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) return eds, roots } -// RandomAxisRoots generates random share.AxisRoots for the given eds size. -func RandomAxisRoots(t testing.TB, edsSize int) *share.AxisRoots { +// RandomAxisRoots generates random square.AxisRoots for the given eds size. +func RandomAxisRoots(t testing.TB, edsSize int) *square.AxisRoots { roots := make([][]byte, edsSize*2) for i := range roots { root := make([]byte, edsSize) @@ -105,7 +103,7 @@ func RandomAxisRoots(t testing.TB, edsSize int) *share.AxisRoots { rows := roots[:edsSize] cols := roots[edsSize:] - return &share.AxisRoots{ + return &square.AxisRoots{ RowRoots: rows, ColumnRoots: cols, } @@ -117,9 +115,9 @@ func GenerateTestBlock( t *testing.T, blobSize, numberOfTransactions int, ) ( - []*types.MsgPayForBlobs, - []*blob.Blob, - []namespace.Namespace, + []*blobtypes.MsgPayForBlobs, + []*share.Blob, + []share.Namespace, *rsmt2d.ExtendedDataSquare, coretypes.Txs, *da.DataAvailabilityHeader, @@ -133,7 +131,7 @@ func GenerateTestBlock( txs := make(coretypes.Txs, 0) txs = append(txs, coreTxs...) - dataSquare, err := square.Construct( + dataSquare, err := libSquare.Construct( txs.ToSliceOfBytes(), appconsts.SquareSizeUpperBound(appconsts.LatestVersion), appconsts.SubtreeRootThreshold(appconsts.LatestVersion), @@ -159,10 +157,10 @@ func GenerateTestBlock( func createTestBlobTransactions( t *testing.T, numberOfTransactions, size int, -) ([]namespace.Namespace, []*types.MsgPayForBlobs, []*blob.Blob, []coretypes.Tx) { - nss := make([]namespace.Namespace, 0) - msgs := make([]*types.MsgPayForBlobs, 0) - blobs := make([]*blob.Blob, 0) +) ([]share.Namespace, []*blobtypes.MsgPayForBlobs, []*share.Blob, []coretypes.Tx) { + nss := make([]share.Namespace, 0) + msgs := make([]*blobtypes.MsgPayForBlobs, 0) + blobs := make([]*share.Blob, 0) coreTxs := make([]coretypes.Tx, 0) config := encoding.MakeConfig(app.ModuleEncodingRegisters...) keyring := testfactory.TestKeyring(config.Codec, accountName) @@ -187,11 +185,11 @@ func createTestBlobTransaction( t *testing.T, signer *user.Signer, size int, -) (namespace.Namespace, *types.MsgPayForBlobs, *blob.Blob, coretypes.Tx) { - ns := namespace.RandomBlobNamespace() +) (share.Namespace, *blobtypes.MsgPayForBlobs, *share.Blob, coretypes.Tx) { + ns := share.RandomBlobNamespace() account := signer.Account(accountName) msg, b := blobfactory.RandMsgPayForBlobsWithNamespaceAndSigner(account.Address().String(), ns, size) - cTx, _, err := signer.CreatePayForBlobs(accountName, []*blob.Blob{b}) + cTx, _, err := signer.CreatePayForBlobs(accountName, []*share.Blob{b}) require.NoError(t, err) return ns, msg, b, cTx } diff --git a/share/eds/nd.go b/square/eds/nd.go similarity index 79% rename from share/eds/nd.go rename to square/eds/nd.go index 36de7a0234..1ba186e083 100644 --- a/share/eds/nd.go +++ b/square/eds/nd.go @@ -4,8 +4,10 @@ import ( "context" "fmt" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap" ) // NamespaceData extracts shares for a specific namespace from an EDS, considering @@ -20,7 +22,7 @@ func NamespaceData( if err != nil { return nil, fmt.Errorf("failed to get AxisRoots: %w", err) } - rowIdxs := share.RowsWithNamespace(roots, namespace) + rowIdxs := square.RowsWithNamespace(roots, namespace) rows := make(shwap.NamespaceData, len(rowIdxs)) for i, idx := range rowIdxs { rows[i], err = eds.RowNamespaceData(ctx, namespace, idx) diff --git a/share/eds/nd_test.go b/square/eds/nd_test.go similarity index 81% rename from share/eds/nd_test.go rename to square/eds/nd_test.go index d711c811bd..dba512a644 100644 --- a/share/eds/nd_test.go +++ b/square/eds/nd_test.go @@ -7,8 +7,9 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square/eds/edstest" ) func TestNamespaceData(t *testing.T) { @@ -17,7 +18,7 @@ func TestNamespaceData(t *testing.T) { const odsSize = 8 sharesAmount := odsSize * odsSize - namespace := sharetest.RandV0Namespace() + namespace := share.RandomNamespace() for amount := 1; amount < sharesAmount; amount++ { eds, root := edstest.RandEDSWithNamespace(t, namespace, amount, odsSize) rsmt2d := &Rsmt2D{ExtendedDataSquare: eds} diff --git a/share/eds/proof.go b/square/eds/proof.go similarity index 92% rename from share/eds/proof.go rename to square/eds/proof.go index 58b34d3b79..2e9d8912cc 100644 --- a/share/eds/proof.go +++ b/square/eds/proof.go @@ -6,8 +6,8 @@ import ( coretypes "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" - pkgproof "github.com/celestiaorg/celestia-app/v2/pkg/proof" - "github.com/celestiaorg/go-square/shares" + pkgproof "github.com/celestiaorg/celestia-app/v3/pkg/proof" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" ) @@ -16,7 +16,7 @@ import ( func ProveShares(eds *rsmt2d.ExtendedDataSquare, start, end int) (*types.ShareProof, error) { log.Debugw("proving share range", "start", start, "end", end) - odsShares, err := shares.FromBytes(eds.FlattenedODS()) + odsShares, err := share.FromBytes(eds.FlattenedODS()) if err != nil { return nil, err } @@ -25,7 +25,7 @@ func ProveShares(eds *rsmt2d.ExtendedDataSquare, start, end int) (*types.SharePr return nil, err } log.Debugw("generating the share proof", "start", start, "end", end) - proof, err := pkgproof.NewShareInclusionProofFromEDS(eds, nID, shares.NewRange(start, end)) + proof, err := pkgproof.NewShareInclusionProofFromEDS(eds, nID, share.NewRange(start, end)) if err != nil { return nil, err } diff --git a/share/eds/proofs_cache.go b/square/eds/proofs_cache.go similarity index 93% rename from share/eds/proofs_cache.go rename to square/eds/proofs_cache.go index 3090f46322..6f28240a11 100644 --- a/share/eds/proofs_cache.go +++ b/square/eds/proofs_cache.go @@ -12,13 +12,14 @@ import ( blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/ipld" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/ipld" + "github.com/celestiaorg/celestia-node/square/shwap" ) var _ AccessorStreamer = (*proofsCache)(nil) @@ -33,9 +34,9 @@ type proofsCache struct { // size caches the size of the data square size atomic.Int32 // dataHash caches the data hash - dataHash atomic.Pointer[share.DataHash] + dataHash atomic.Pointer[square.DataHash] // rootsCache caches the axis roots - rootsCache atomic.Pointer[share.AxisRoots] + rootsCache atomic.Pointer[square.AxisRoots] // axisCacheLock protects proofCache axisCacheLock sync.RWMutex // axisCache caches the axis Shares and proofs. Index in the slice corresponds to the axis type. @@ -83,7 +84,7 @@ func (c *proofsCache) Size(ctx context.Context) int { return int(size) } -func (c *proofsCache) DataHash(ctx context.Context) (share.DataHash, error) { +func (c *proofsCache) DataHash(ctx context.Context) (square.DataHash, error) { dataHash := c.dataHash.Load() if dataHash != nil { return *dataHash, nil @@ -96,7 +97,7 @@ func (c *proofsCache) DataHash(ctx context.Context) (share.DataHash, error) { return loaded, nil } -func (c *proofsCache) AxisRoots(ctx context.Context) (*share.AxisRoots, error) { +func (c *proofsCache) AxisRoots(ctx context.Context) (*square.AxisRoots, error) { roots := c.rootsCache.Load() if roots != nil { return roots, nil @@ -165,7 +166,7 @@ func (c *proofsCache) axisWithProofs(ctx context.Context, axisType rsmt2d.Axis, nmt.NodeVisitor(adder.VisitFn()), ) for _, shr := range ax.shares { - err := tree.Push(shr) + err := tree.Push(shr.ToBytes()) if err != nil { return axisWithProofs{}, fmt.Errorf("push shares: %w", err) } @@ -317,7 +318,7 @@ func (c *proofsCache) getShare(rowIdx, colIdx int) ([]byte, error) { if half.IsParity { colIdx -= odsSize } - return half.Shares[colIdx], nil + return half.Shares[colIdx].ToBytes(), nil } // if share index is from opposite part of axis, obtain full axis shares @@ -325,7 +326,7 @@ func (c *proofsCache) getShare(rowIdx, colIdx int) ([]byte, error) { if err != nil { return nil, fmt.Errorf("reading axis shares: %w", err) } - return shares[colIdx], nil + return shares[colIdx].ToBytes(), nil } // rowProofsGetter implements blockservice.BlockGetter interface diff --git a/share/eds/proofs_cache_test.go b/square/eds/proofs_cache_test.go similarity index 100% rename from share/eds/proofs_cache_test.go rename to square/eds/proofs_cache_test.go diff --git a/share/eds/read.go b/square/eds/read.go similarity index 80% rename from share/eds/read.go rename to square/eds/read.go index 83149ca1ce..0090a7c1a9 100644 --- a/share/eds/read.go +++ b/square/eds/read.go @@ -7,13 +7,15 @@ import ( "fmt" "io" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" ) // ReadAccessor reads up EDS out of the io.Reader until io.EOF and provides. -func ReadAccessor(ctx context.Context, reader io.Reader, root *share.AxisRoots) (*Rsmt2D, error) { +func ReadAccessor(ctx context.Context, reader io.Reader, root *square.AxisRoots) (*Rsmt2D, error) { odsSize := len(root.RowRoots) / 2 - shares, err := ReadShares(reader, share.Size, odsSize) + shares, err := ReadShares(reader, share.ShareSize, odsSize) if err != nil { return nil, fmt.Errorf("failed to read eds from ods bytes: %w", err) } @@ -43,19 +45,22 @@ func ReadShares(r io.Reader, shareSize, odsSize int) ([]share.Share, error) { shares := make([]share.Share, odsSize*odsSize) var total int for i := range shares { - shr := make(share.Share, shareSize) + shr := make([]byte, shareSize) n, err := io.ReadFull(r, shr) if errors.Is(err, io.EOF) { for ; i < len(shares); i++ { - shares[i] = share.TailPadding() + shares[i] = share.TailPaddingShare() } return shares, nil } if err != nil { return nil, fmt.Errorf("reading shares: %w, bytes read: %v", err, total+n) } - - shares[i] = shr + newShare, err := share.NewShare(shr) + if err != nil { + return nil, err + } + shares[i] = *newShare total += n } return shares, nil diff --git a/share/eds/retriever.go b/square/eds/retriever.go similarity index 93% rename from share/eds/retriever.go rename to square/eds/retriever.go index c3483809af..53b79aacd7 100644 --- a/share/eds/retriever.go +++ b/square/eds/retriever.go @@ -15,13 +15,14 @@ import ( "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" - "github.com/celestiaorg/celestia-node/share/ipld" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/square/ipld" ) var ( @@ -56,7 +57,7 @@ func NewRetriever(bServ blockservice.BlockService) *Retriever { // data square and reconstructs the other three quadrants (3/4). If the requested quadrant is not // available within RetrieveQuadrantTimeout, it starts requesting another quadrant until either the // data is reconstructed, context is canceled or ErrByzantine is generated. -func (r *Retriever) Retrieve(ctx context.Context, roots *share.AxisRoots) (*rsmt2d.ExtendedDataSquare, error) { +func (r *Retriever) Retrieve(ctx context.Context, roots *square.AxisRoots) (*rsmt2d.ExtendedDataSquare, error) { ctx, cancel := context.WithCancel(ctx) defer cancel() // cancels all the ongoing requests if reconstruction succeeds early @@ -106,7 +107,7 @@ func (r *Retriever) Retrieve(ctx context.Context, roots *share.AxisRoots) (*rsmt // quadrant request retries. Also, provides an API // to reconstruct the block once enough shares are fetched. type retrievalSession struct { - roots *share.AxisRoots + roots *square.AxisRoots bget blockservice.BlockGetter adder *ipld.NmtNodeAdder @@ -124,7 +125,7 @@ type retrievalSession struct { } // newSession creates a new retrieval session and kicks off requesting process. -func (r *Retriever) newSession(ctx context.Context, roots *share.AxisRoots) (*retrievalSession, error) { +func (r *Retriever) newSession(ctx context.Context, roots *square.AxisRoots) (*retrievalSession, error) { size := len(roots.RowRoots) adder := ipld.NewNmtNodeAdder(ctx, r.bServ, ipld.MaxSizeBatchOption(size)) @@ -142,7 +143,7 @@ func (r *Retriever) newSession(ctx context.Context, roots *share.AxisRoots) (*re return &tree } - square, err := rsmt2d.NewExtendedDataSquare(share.DefaultRSMT2DCodec(), treeFn, uint(size), share.Size) + square, err := rsmt2d.NewExtendedDataSquare(square.DefaultRSMT2DCodec(), treeFn, uint(size), share.ShareSize) if err != nil { return nil, err } @@ -279,7 +280,7 @@ func (rs *retrievalSession) doRequest(ctx context.Context, q *quadrant) { // and go get shares of left or the right side of the whole col/row axis // the left or the right side of the tree represent some portion of the quadrant // which we put into the rs.square share-by-share by calculating shares' indexes using q.index - ipld.GetShares(ctx, rs.bget, nd.Links()[q.x].Cid, size, func(j int, share share.Share) { + ipld.GetShares(ctx, rs.bget, nd.Links()[q.x].Cid, size, func(j int, rawShare []byte) { // NOTE: Each share can appear twice here, for a Row and Col, respectively. // These shares are always equal, and we allow only the first one to be written // in the square. @@ -306,7 +307,7 @@ func (rs *retrievalSession) doRequest(ctx context.Context, q *quadrant) { if rs.isReconstructed() { return } - if err := rs.square.SetCell(uint(x), uint(y), share); err != nil { + if err := rs.square.SetCell(uint(x), uint(y), rawShare); err != nil { // safe to ignore as: // * share size already verified // * the same share might come from either Row or Col diff --git a/share/eds/retriever_no_race_test.go b/square/eds/retriever_no_race_test.go similarity index 74% rename from share/eds/retriever_no_race_test.go rename to square/eds/retriever_no_race_test.go index e9b8dc1634..43165a0bce 100644 --- a/share/eds/retriever_no_race_test.go +++ b/square/eds/retriever_no_race_test.go @@ -9,14 +9,15 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/ipld" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/ipld" ) func TestRetriever_ByzantineError(t *testing.T) { @@ -36,7 +37,7 @@ func TestRetriever_ByzantineError(t *testing.T) { batchAdder := ipld.NewNmtNodeAdder(ctx, bserv, ipld.MaxSizeBatchOption(width*2)) attackerEDS, err := rsmt2d.ImportExtendedDataSquare( shares, - share.DefaultRSMT2DCodec(), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(width), nmt.NodeVisitor(batchAdder.Visit)), ) @@ -45,7 +46,7 @@ func TestRetriever_ByzantineError(t *testing.T) { require.NoError(t, err) // ensure we rcv an error - roots, err := share.NewAxisRoots(attackerEDS) + roots, err := square.NewAxisRoots(attackerEDS) require.NoError(t, err) r := NewRetriever(bserv) _, err = r.Retrieve(ctx, roots) diff --git a/share/eds/retriever_quadrant.go b/square/eds/retriever_quadrant.go similarity index 94% rename from share/eds/retriever_quadrant.go rename to square/eds/retriever_quadrant.go index 97a5b332f2..6450926948 100644 --- a/share/eds/retriever_quadrant.go +++ b/square/eds/retriever_quadrant.go @@ -8,8 +8,8 @@ import ( "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/ipld" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/ipld" ) const ( @@ -49,7 +49,7 @@ type quadrant struct { // newQuadrants constructs a slice of quadrants from DAHeader. // There are always 4 quadrants per each source (row and col), so 8 in total. // The ordering of quadrants is random. -func newQuadrants(roots *share.AxisRoots) []*quadrant { +func newQuadrants(roots *square.AxisRoots) []*quadrant { // combine all the roots into one slice, so they can be easily accessible by index daRoots := [][][]byte{ roots.RowRoots, diff --git a/share/eds/retriever_test.go b/square/eds/retriever_test.go similarity index 92% rename from share/eds/retriever_test.go rename to square/eds/retriever_test.go index 2381b7cd75..1fd2c4632f 100644 --- a/share/eds/retriever_test.go +++ b/square/eds/retriever_test.go @@ -11,15 +11,15 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/ipld" - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/ipld" ) func TestRetriever_Retrieve(t *testing.T) { @@ -41,12 +41,12 @@ func TestRetriever_Retrieve(t *testing.T) { {"16x16(med)", 16}, {"32x32(med)", 32}, {"64x64(med)", 64}, - {"128x128(max)", share.MaxSquareSize}, + {"128x128(max)", square.MaxSquareSize}, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { // generate EDS - shares := sharetest.RandShares(t, tc.squareSize*tc.squareSize) + shares := share.RandShares(tc.squareSize * tc.squareSize) in, err := ipld.AddShares(ctx, shares, bServ) require.NoError(t, err) @@ -54,7 +54,7 @@ func TestRetriever_Retrieve(t *testing.T) { ctx, cancel := context.WithTimeout(ctx, time.Minute*5) // the timeout is big for the max size which is long defer cancel() - roots, err := share.NewAxisRoots(in) + roots, err := square.NewAxisRoots(in) require.NoError(t, err) out, err := r.Retrieve(ctx, roots) require.NoError(t, err) @@ -75,11 +75,11 @@ func TestRetriever_MultipleRandQuadrants(t *testing.T) { r := NewRetriever(bServ) // generate EDS - shares := sharetest.RandShares(t, squareSize*squareSize) + shares := share.RandShares(squareSize * squareSize) in, err := ipld.AddShares(ctx, shares, bServ) require.NoError(t, err) - roots, err := share.NewAxisRoots(in) + roots, err := square.NewAxisRoots(in) require.NoError(t, err) ses, err := r.newSession(ctx, roots) require.NoError(t, err) diff --git a/share/eds/rsmt2d.go b/square/eds/rsmt2d.go similarity index 68% rename from share/eds/rsmt2d.go rename to square/eds/rsmt2d.go index 416e3530a5..0dfc044498 100644 --- a/share/eds/rsmt2d.go +++ b/square/eds/rsmt2d.go @@ -5,11 +5,12 @@ import ( "fmt" "io" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap" ) var _ AccessorStreamer = (*Rsmt2D)(nil) @@ -25,17 +26,17 @@ func (eds *Rsmt2D) Size(context.Context) int { } // DataHash returns data hash of the Accessor. -func (eds *Rsmt2D) DataHash(context.Context) (share.DataHash, error) { - roots, err := share.NewAxisRoots(eds.ExtendedDataSquare) +func (eds *Rsmt2D) DataHash(context.Context) (square.DataHash, error) { + roots, err := square.NewAxisRoots(eds.ExtendedDataSquare) if err != nil { - return share.DataHash{}, fmt.Errorf("while creating data root: %w", err) + return square.DataHash{}, fmt.Errorf("while creating data root: %w", err) } return roots.Hash(), nil } // AxisRoots returns AxisRoots of the Accessor. -func (eds *Rsmt2D) AxisRoots(context.Context) (*share.AxisRoots, error) { - roots, err := share.NewAxisRoots(eds.ExtendedDataSquare) +func (eds *Rsmt2D) AxisRoots(context.Context) (*square.AxisRoots, error) { + roots, err := square.NewAxisRoots(eds.ExtendedDataSquare) if err != nil { return nil, fmt.Errorf("while creating axis roots: %w", err) } @@ -57,11 +58,14 @@ func (eds *Rsmt2D) SampleForProofAxis( proofType rsmt2d.Axis, ) (shwap.Sample, error) { axisIdx, shrIdx := relativeIndexes(rowIdx, colIdx, proofType) - shares := getAxis(eds.ExtendedDataSquare, proofType, axisIdx) + shares, err := getAxis(eds.ExtendedDataSquare, proofType, axisIdx) + if err != nil { + return shwap.Sample{}, err + } tree := wrapper.NewErasuredNamespacedMerkleTree(uint64(eds.Width()/2), uint(axisIdx)) for _, shr := range shares { - err := tree.Push(shr) + err := tree.Push(shr.ToBytes()) if err != nil { return shwap.Sample{}, fmt.Errorf("while pushing shares to NMT: %w", err) } @@ -81,7 +85,10 @@ func (eds *Rsmt2D) SampleForProofAxis( // AxisHalf returns Shares for the first half of the axis of the given type and index. func (eds *Rsmt2D) AxisHalf(_ context.Context, axisType rsmt2d.Axis, axisIdx int) (AxisHalf, error) { - shares := getAxis(eds.ExtendedDataSquare, axisType, axisIdx) + shares, err := getAxis(eds.ExtendedDataSquare, axisType, axisIdx) + if err != nil { + return AxisHalf{}, fmt.Errorf("while getting axis share: %w", err) + } halfShares := shares[:eds.Width()/2] return AxisHalf{ Shares: halfShares, @@ -91,9 +98,13 @@ func (eds *Rsmt2D) AxisHalf(_ context.Context, axisType rsmt2d.Axis, axisIdx int // HalfRow constructs a new shwap.Row from an Extended Data Square based on the specified index and // side. -func (eds *Rsmt2D) HalfRow(idx int, side shwap.RowSide) shwap.Row { +func (eds *Rsmt2D) HalfRow(idx int, side shwap.RowSide) (shwap.Row, error) { shares := eds.ExtendedDataSquare.Row(uint(idx)) - return shwap.RowFromShares(shares, side) + sh, err := share.FromBytes(shares) + if err != nil { + return shwap.Row{}, fmt.Errorf("while converting shares from bytes: %w", err) + } + return shwap.RowFromShares(sh, side), nil } // RowNamespaceData returns data for the given namespace and row index. @@ -103,13 +114,17 @@ func (eds *Rsmt2D) RowNamespaceData( rowIdx int, ) (shwap.RowNamespaceData, error) { shares := eds.Row(uint(rowIdx)) - return shwap.RowNamespaceDataFromShares(shares, namespace, rowIdx) + sh, err := share.FromBytes(shares) + if err != nil { + return shwap.RowNamespaceData{}, fmt.Errorf("while converting shares from bytes: %w", err) + } + return shwap.RowNamespaceDataFromShares(sh, namespace, rowIdx) } // Shares returns data (ODS) shares extracted from the EDS. It returns new copy of the shares each // time. func (eds *Rsmt2D) Shares(_ context.Context) ([]share.Share, error) { - return eds.ExtendedDataSquare.FlattenedODS(), nil + return share.FromBytes(eds.ExtendedDataSquare.FlattenedODS()) } func (eds *Rsmt2D) Close() error { @@ -129,7 +144,7 @@ func (eds *Rsmt2D) Reader() (io.Reader, error) { // Rsmt2DFromShares constructs an Extended Data Square from shares. func Rsmt2DFromShares(shares []share.Share, odsSize int) (*Rsmt2D, error) { treeFn := wrapper.NewConstructor(uint64(odsSize)) - eds, err := rsmt2d.ComputeExtendedDataSquare(shares, share.DefaultRSMT2DCodec(), treeFn) + eds, err := rsmt2d.ComputeExtendedDataSquare(share.ToBytes(shares), square.DefaultRSMT2DCodec(), treeFn) if err != nil { return &Rsmt2D{}, fmt.Errorf("computing extended data square: %w", err) } @@ -137,12 +152,14 @@ func Rsmt2DFromShares(shares []share.Share, odsSize int) (*Rsmt2D, error) { return &Rsmt2D{eds}, nil } -func getAxis(eds *rsmt2d.ExtendedDataSquare, axisType rsmt2d.Axis, axisIdx int) []share.Share { +func getAxis(eds *rsmt2d.ExtendedDataSquare, axisType rsmt2d.Axis, axisIdx int) ([]share.Share, error) { switch axisType { case rsmt2d.Row: - return eds.Row(uint(axisIdx)) + sh, err := share.FromBytes(eds.Row(uint(axisIdx))) + return sh, err case rsmt2d.Col: - return eds.Col(uint(axisIdx)) + sh, err := share.FromBytes(eds.Col(uint(axisIdx))) + return sh, err default: panic("unknown axis") } diff --git a/share/eds/rsmt2d_test.go b/square/eds/rsmt2d_test.go similarity index 78% rename from share/eds/rsmt2d_test.go rename to square/eds/rsmt2d_test.go index a639aa96e0..58ee60211c 100644 --- a/share/eds/rsmt2d_test.go +++ b/square/eds/rsmt2d_test.go @@ -7,11 +7,12 @@ import ( "github.com/stretchr/testify/require" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" ) func TestRsmt2dAccessor(t *testing.T) { @@ -36,12 +37,13 @@ func TestRsmt2dHalfRow(t *testing.T) { for rowIdx := 0; rowIdx < odsSize*2; rowIdx++ { for _, side := range []shwap.RowSide{shwap.Left, shwap.Right} { - row := eds.HalfRow(rowIdx, side) + row, err := eds.HalfRow(rowIdx, side) + require.NoError(t, err) want := eds.Row(uint(rowIdx)) shares, err := row.Shares() require.NoError(t, err) - require.Equal(t, want, shares) + require.Equal(t, want, share.ToBytes(shares)) } } } @@ -58,7 +60,7 @@ func TestRsmt2dSampleForProofAxis(t *testing.T) { require.NoError(t, err) want := eds.GetCell(uint(rowIdx), uint(colIdx)) - require.Equal(t, want, sample.Share) + require.Equal(t, want, sample.Share.ToBytes()) require.Equal(t, proofType, sample.ProofType) require.NotNil(t, sample.Proof) require.Equal(t, sample.Proof.End()-sample.Proof.Start(), 1) @@ -68,9 +70,9 @@ func TestRsmt2dSampleForProofAxis(t *testing.T) { } } -func randRsmt2dAccsessor(t *testing.T, size int) (Rsmt2D, *share.AxisRoots) { +func randRsmt2dAccsessor(t *testing.T, size int) (Rsmt2D, *square.AxisRoots) { eds := edstest.RandEDS(t, size) - root, err := share.NewAxisRoots(eds) + root, err := square.NewAxisRoots(eds) require.NoError(t, err) return Rsmt2D{ExtendedDataSquare: eds}, root } diff --git a/share/eds/share_reader.go b/square/eds/share_reader.go similarity index 100% rename from share/eds/share_reader.go rename to square/eds/share_reader.go diff --git a/share/eds/share_reader_test.go b/square/eds/share_reader_test.go similarity index 87% rename from share/eds/share_reader_test.go rename to square/eds/share_reader_test.go index 3cd67a08cd..cb4e6d19ff 100644 --- a/share/eds/share_reader_test.go +++ b/square/eds/share_reader_test.go @@ -8,8 +8,9 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square/eds/edstest" ) func TestShareReader(t *testing.T) { @@ -23,7 +24,7 @@ func TestShareReader(t *testing.T) { reader := NewShareReader(odsSize, getShare) readBytes, err := readWithRandomBuffer(reader, 1024) require.NoError(t, err) - expected := make([]byte, 0, odsSize*odsSize*share.Size) + expected := make([]byte, 0, odsSize*odsSize*share.ShareSize) for _, share := range eds.FlattenedODS() { expected = append(expected, share...) } diff --git a/share/eds/testing.go b/square/eds/testing.go similarity index 89% rename from share/eds/testing.go rename to square/eds/testing.go index 8549cf3ca1..f7a1bf0f89 100644 --- a/share/eds/testing.go +++ b/square/eds/testing.go @@ -10,13 +10,13 @@ import ( "github.com/stretchr/testify/require" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/sharetest" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" ) type ( @@ -84,7 +84,7 @@ func testEDSes(t *testing.T, sizes ...int) map[string]*rsmt2d.ExtendedDataSquare testEDSes[fmt.Sprintf("PaddedODS:%d", size)] = paddingEds } - testEDSes["EmptyODS"] = share.EmptyEDS() + testEDSes["EmptyODS"] = square.EmptyEDS() return testEDSes } @@ -110,12 +110,12 @@ func testAccessorDataHash( ) { acc := createAccessor(t, eds) - expected, err := share.NewAxisRoots(eds) + expected, err := square.NewAxisRoots(eds) require.NoError(t, err) datahash, err := acc.DataHash(ctx) require.NoError(t, err) - require.Equal(t, share.DataHash(expected.Hash()), datahash) + require.Equal(t, square.DataHash(expected.Hash()), datahash) } func testAccessorAxisRoots( @@ -126,7 +126,7 @@ func testAccessorAxisRoots( ) { acc := createAccessor(t, eds) - expected, err := share.NewAxisRoots(eds) + expected, err := square.NewAxisRoots(eds) require.NoError(t, err) roots, err := acc.AxisRoots(ctx) @@ -143,7 +143,7 @@ func testAccessorSample( width := int(eds.Width()) t.Run("single thread", func(t *testing.T) { acc := createAccessor(t, eds) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) // t.Parallel() this fails the test for some reason for rowIdx := 0; rowIdx < width; rowIdx++ { @@ -156,7 +156,7 @@ func testAccessorSample( t.Run("parallel", func(t *testing.T) { t.Parallel() acc := createAccessor(t, eds) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) wg := sync.WaitGroup{} for rowIdx := 0; rowIdx < width; rowIdx++ { @@ -174,7 +174,7 @@ func testAccessorSample( t.Run("random", func(t *testing.T) { t.Parallel() acc := createAccessor(t, eds) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) wg := sync.WaitGroup{} @@ -194,7 +194,7 @@ func testSample( ctx context.Context, t *testing.T, acc Accessor, - roots *share.AxisRoots, + roots *square.AxisRoots, rowIdx, colIdx int, ) { shr, err := acc.Sample(ctx, rowIdx, colIdx) @@ -214,7 +214,7 @@ func testAccessorRowNamespaceData( t.Parallel() // generate EDS with random data and some Shares with the same namespace sharesAmount := odsSize * odsSize - namespace := sharetest.RandV0Namespace() + namespace := share.RandomNamespace() // test with different amount of shares for amount := 1; amount < sharesAmount; amount++ { // select random amount of shares, but not less than 1 @@ -250,7 +250,7 @@ func testAccessorRowNamespaceData( t.Parallel() // generate EDS with random data and some Shares with the same namespace eds := edstest.RandEDS(t, odsSize) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) // loop over first half of the rows, because the second half is parity and does not contain @@ -258,7 +258,10 @@ func testAccessorRowNamespaceData( for i, root := range roots.RowRoots[:odsSize] { // select namespace that within the range of root namespaces, but is not included maxNs := nmt.MaxNamespace(root, share.NamespaceSize) - absentNs, err := share.Namespace(maxNs).AddInt(-1) + ns, err := share.NewNamespaceFromBytes(maxNs) + require.NoError(t, err) + + absentNs, err := share.AddInt(ns, -1) require.NoError(t, err) acc := createAccessor(t, eds) @@ -293,9 +296,13 @@ func testAccessorAxisHalf( var expected []share.Share if half.IsParity { - expected = getAxis(eds, axisType, axisIdx)[odsSize:] + expected, err = getAxis(eds, axisType, axisIdx) + require.NoError(t, err) + expected = expected[odsSize:] } else { - expected = getAxis(eds, axisType, axisIdx)[:odsSize] + expected, err = getAxis(eds, axisType, axisIdx) + require.NoError(t, err) + expected = expected[:odsSize] } require.Equal(t, expected, half.Shares) @@ -317,11 +324,15 @@ func testAccessorAxisHalf( var expected []share.Share if half.IsParity { - expected = getAxis(eds, axisType, idx)[odsSize:] + expected, err = getAxis(eds, axisType, idx) + require.NoError(t, err) + expected = expected[odsSize:] } else { - expected = getAxis(eds, axisType, idx)[:odsSize] + expected, err = getAxis(eds, axisType, idx) + require.NoError(t, err) + expected = expected[:odsSize] } - + require.NoError(t, err) require.Equal(t, expected, half.Shares) }(axisType, i) } @@ -346,7 +357,9 @@ func testAccessorShares( shares, err := acc.Shares(ctx) require.NoError(t, err) expected := eds.FlattenedODS() - require.Equal(t, expected, shares) + sh, err := share.FromBytes(expected) + require.NoError(t, err) + require.Equal(t, sh, shares) }() } wg.Wait() @@ -377,7 +390,7 @@ func testReader(ctx context.Context, t *testing.T, eds *rsmt2d.ExtendedDataSquar reader, err := as.Reader() require.NoError(t, err) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) actual, err := ReadAccessor(ctx, reader, roots) diff --git a/share/eds/validation.go b/square/eds/validation.go similarity index 94% rename from share/eds/validation.go rename to square/eds/validation.go index 41ec6c45c4..c8d7c632f7 100644 --- a/share/eds/validation.go +++ b/square/eds/validation.go @@ -6,10 +6,10 @@ import ( "fmt" "sync/atomic" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square/shwap" ) var _ Accessor = validation{} diff --git a/share/eds/validation_test.go b/square/eds/validation_test.go similarity index 92% rename from share/eds/validation_test.go rename to square/eds/validation_test.go index 4be8dc7230..0d0b3bf42e 100644 --- a/share/eds/validation_test.go +++ b/square/eds/validation_test.go @@ -7,11 +7,11 @@ import ( "github.com/stretchr/testify/require" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/sharetest" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" ) func TestValidation_Sample(t *testing.T) { @@ -91,7 +91,7 @@ func TestValidation_RowNamespaceData(t *testing.T) { accessor := &Rsmt2D{ExtendedDataSquare: randEDS} validation := WithValidation(AccessorAndStreamer(accessor, nil)) - ns := sharetest.RandV0Namespace() + ns := share.RandomNamespace() _, err := validation.RowNamespaceData(context.Background(), ns, tt.rowIdx) if tt.expectFail { require.ErrorIs(t, err, shwap.ErrInvalidID) diff --git a/share/empty.go b/square/empty.go similarity index 76% rename from share/empty.go rename to square/empty.go index 4ffd6ade82..b683715a3e 100644 --- a/share/empty.go +++ b/square/empty.go @@ -1,13 +1,12 @@ -package share +package square import ( "bytes" "fmt" "sync" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - "github.com/celestiaorg/celestia-app/v2/pkg/da" - "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/celestia-app/v3/pkg/da" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" ) @@ -30,7 +29,7 @@ func EmptyEDS() *rsmt2d.ExtendedDataSquare { } // EmptyBlockShares returns the shares of the empty block. -func EmptyBlockShares() []Share { +func EmptyBlockShares() []share.Share { initEmpty() return emptyBlockShares } @@ -40,7 +39,7 @@ var ( emptyBlockDataHash DataHash emptyBlockRoots *AxisRoots emptyBlockEDS *rsmt2d.ExtendedDataSquare - emptyBlockShares []Share + emptyBlockShares []share.Share ) // initEmpty enables lazy initialization for constant empty block data. @@ -50,10 +49,10 @@ func initEmpty() { func computeEmpty() { // compute empty block EDS and DAH for it - result := shares.TailPaddingShares(appconsts.MinShareCount) - emptyBlockShares = shares.ToBytes(result) + result := share.TailPaddingShares(share.MinShareCount) + rawEmptyBlockShares := share.ToBytes(result) - eds, err := da.ExtendShares(emptyBlockShares) + eds, err := da.ExtendShares(rawEmptyBlockShares) if err != nil { panic(fmt.Errorf("failed to create empty EDS: %w", err)) } @@ -69,6 +68,11 @@ func computeEmpty() { "expected %s, got %s", minDAH.String(), emptyBlockRoots.String())) } + sh := eds.FlattenedODS() + emptyBlockShares, err = share.FromBytes(sh) + if err != nil { + panic(fmt.Errorf("failed to create shares: %w", err)) + } // precompute Hash, so it's cached internally to avoid potential races emptyBlockDataHash = emptyBlockRoots.Hash() } diff --git a/share/ipld/add.go b/square/ipld/add.go similarity index 90% rename from share/ipld/add.go rename to square/ipld/add.go index 42705557ae..f200f28309 100644 --- a/share/ipld/add.go +++ b/square/ipld/add.go @@ -6,12 +6,13 @@ import ( "github.com/ipfs/boxo/blockservice" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" ) // AddShares erasures and extends shares to blockservice.BlockService using the provided @@ -30,8 +31,8 @@ func AddShares( // create the nmt wrapper to generate row and col commitments // recompute the eds eds, err := rsmt2d.ComputeExtendedDataSquare( - shares, - share.DefaultRSMT2DCodec(), + share.ToBytes(shares), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(squareSize), nmt.NodeVisitor(batchAdder.Visit)), ) @@ -63,7 +64,7 @@ func ImportShares( // recompute the eds eds, err := rsmt2d.ImportExtendedDataSquare( shares, - share.DefaultRSMT2DCodec(), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(squareSize/2), nmt.NodeVisitor(batchAdder.Visit)), ) diff --git a/share/ipld/blockserv.go b/square/ipld/blockserv.go similarity index 100% rename from share/ipld/blockserv.go rename to square/ipld/blockserv.go diff --git a/share/ipld/delete.go b/square/ipld/delete.go similarity index 100% rename from share/ipld/delete.go rename to square/ipld/delete.go diff --git a/share/ipld/delete_test.go b/square/ipld/delete_test.go similarity index 94% rename from share/ipld/delete_test.go rename to square/ipld/delete_test.go index 745c938822..e6953ba5f3 100644 --- a/share/ipld/delete_test.go +++ b/square/ipld/delete_test.go @@ -12,7 +12,7 @@ import ( "github.com/ipfs/go-datastore/sync" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/go-square/v2/share" ) func TestDeleteNode_FullSquare(t *testing.T) { @@ -21,7 +21,7 @@ func TestDeleteNode_FullSquare(t *testing.T) { defer cancel() bServ := NewMemBlockservice() - shares := sharetest.RandShares(t, size*size) + shares := share.RandShares(size * size) eds, err := AddShares(ctx, shares, bServ) require.NoError(t, err) @@ -63,7 +63,7 @@ func TestDeleteNode_Sample(t *testing.T) { defer cancel() full := NewMemBlockservice() - shares := sharetest.RandShares(t, size*size) + shares := share.RandShares(size * size) eds, err := AddShares(ctx, shares, full) require.NoError(t, err) diff --git a/share/ipld/get.go b/square/ipld/get.go similarity index 97% rename from share/ipld/get.go rename to square/ipld/get.go index 9e85f7ccc9..a5769adf40 100644 --- a/share/ipld/get.go +++ b/square/ipld/get.go @@ -11,7 +11,7 @@ import ( "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" ) // NumWorkersLimit sets global limit for workers spawned by GetShares. @@ -26,7 +26,7 @@ import ( // // TODO(@Wondertan): This assumes we have parallelized DASer implemented. Sync the values once it is shipped. // TODO(@Wondertan): Allow configuration of values without global state. -var NumWorkersLimit = share.MaxSquareSize * share.MaxSquareSize / 2 * NumConcurrentSquares +var NumWorkersLimit = square.MaxSquareSize * square.MaxSquareSize / 2 * NumConcurrentSquares // NumConcurrentSquares limits the amount of squares that are fetched // concurrently/simultaneously. diff --git a/share/ipld/get_shares.go b/square/ipld/get_shares.go similarity index 79% rename from share/ipld/get_shares.go rename to square/ipld/get_shares.go index 773e09c7d0..5872daeb41 100644 --- a/share/ipld/get_shares.go +++ b/square/ipld/get_shares.go @@ -7,9 +7,8 @@ import ( "github.com/ipfs/go-cid" format "github.com/ipfs/go-ipld-format" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" - - "github.com/celestiaorg/celestia-node/share" ) // GetShare fetches and returns the data for leaf `leafIndex` of root `rootCid`. @@ -22,18 +21,22 @@ func GetShare( ) (share.Share, error) { nd, err := GetLeaf(ctx, bGetter, rootCid, leafIndex, totalLeafs) if err != nil { - return nil, err + return share.Share{}, err } - return leafToShare(nd), nil + sh, err := share.NewShare(nd.RawData()[share.NamespaceSize:]) + if err != nil { + return share.Share{}, err + } + return *sh, nil } // GetShares walks the tree of a given root and puts shares into the given 'put' func. // Does not return any error, and returns/unblocks only on success // (got all shares) or on context cancellation. -func GetShares(ctx context.Context, bg blockservice.BlockGetter, root cid.Cid, shares int, put func(int, share.Share)) { +func GetShares(ctx context.Context, bg blockservice.BlockGetter, root cid.Cid, shares int, put func(int, []byte)) { putNode := func(i int, leaf format.Node) { - put(i, leafToShare(leaf)) + put(i, leaf.RawData()[share.NamespaceSize:]) } GetLeaves(ctx, bg, root, shares, putNode) } @@ -63,15 +66,12 @@ func GetSharesByNamespace( shares := make([]share.Share, len(leaves)) for i, leaf := range leaves { if leaf != nil { - shares[i] = leafToShare(leaf) + sh, err := share.NewShare(leaf.RawData()[share.NamespaceSize:]) + if err != nil { + return nil, nil, err + } + shares[i] = *sh } } return shares, data.Proof(), nil } - -// leafToShare converts an NMT leaf into a Share. -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 share.GetData(nd.RawData()) -} diff --git a/share/ipld/get_shares_test.go b/square/ipld/get_shares_test.go similarity index 85% rename from share/ipld/get_shares_test.go rename to square/ipld/get_shares_test.go index 220c00d015..75399d77bf 100644 --- a/share/ipld/get_shares_test.go +++ b/square/ipld/get_shares_test.go @@ -1,7 +1,6 @@ package ipld import ( - "bytes" "context" "errors" mrand "math/rand" @@ -15,13 +14,13 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" ) func TestGetShare(t *testing.T) { @@ -32,7 +31,7 @@ func TestGetShare(t *testing.T) { bServ := NewMemBlockservice() // generate random shares for the nmt - shares := sharetest.RandShares(t, size*size) + shares := share.RandShares(size * size) eds, err := AddShares(ctx, shares, bServ) require.NoError(t, err) @@ -54,8 +53,8 @@ func TestBlockRecovery(t *testing.T) { extendedShareCount := extendedSquareWidth * extendedSquareWidth // generate test data - quarterShares := sharetest.RandShares(t, shareCount) - allShares := sharetest.RandShares(t, shareCount) + quarterShares := share.RandShares(shareCount) + allShares := share.RandShares(shareCount) testCases := []struct { name string @@ -74,8 +73,8 @@ func TestBlockRecovery(t *testing.T) { squareSize := utils.SquareSize(len(tc.shares)) testEds, err := rsmt2d.ComputeExtendedDataSquare( - tc.shares, - share.DefaultRSMT2DCodec(), + share.ToBytes(tc.shares), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(squareSize), ) require.NoError(t, err) @@ -92,7 +91,7 @@ func TestBlockRecovery(t *testing.T) { rdata := removeRandShares(flat, tc.d) testEds, err = rsmt2d.ImportExtendedDataSquare( rdata, - share.DefaultRSMT2DCodec(), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(squareSize), ) require.NoError(t, err) @@ -105,7 +104,7 @@ func TestBlockRecovery(t *testing.T) { } assert.NoError(t, err) - reds, err := rsmt2d.ImportExtendedDataSquare(rdata, share.DefaultRSMT2DCodec(), wrapper.NewConstructor(squareSize)) + reds, err := rsmt2d.ImportExtendedDataSquare(rdata, square.DefaultRSMT2DCodec(), wrapper.NewConstructor(squareSize)) require.NoError(t, err) // check that the squares are equal assert.Equal(t, testEds.Flattened(), reds.Flattened()) @@ -115,18 +114,18 @@ func TestBlockRecovery(t *testing.T) { func Test_ConvertEDStoShares(t *testing.T) { squareWidth := 16 - shares := sharetest.RandShares(t, squareWidth*squareWidth) + shares := share.RandShares(squareWidth * squareWidth) // compute extended square testEds, err := rsmt2d.ComputeExtendedDataSquare( - shares, - share.DefaultRSMT2DCodec(), + share.ToBytes(shares), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(squareWidth)), ) require.NoError(t, err) resshares := testEds.FlattenedODS() - require.Equal(t, shares, resshares) + require.Equal(t, share.ToBytes(shares), resshares) } // removes d shares from data @@ -152,15 +151,15 @@ func TestGetSharesByNamespace(t *testing.T) { tests := []struct { rawData []share.Share }{ - {rawData: sharetest.RandShares(t, 4)}, - {rawData: sharetest.RandShares(t, 16)}, + {rawData: share.RandShares(4)}, + {rawData: share.RandShares(16)}, } for i, tt := range tests { t.Run(strconv.Itoa(i), func(t *testing.T) { // choose random namespace from rand shares expected := tt.rawData[len(tt.rawData)/2] - namespace := share.GetNamespace(expected) + namespace := expected.Namespace() // change rawData to contain several shares with same namespace tt.rawData[(len(tt.rawData)/2)+1] = expected @@ -194,12 +193,12 @@ func TestCollectLeavesByNamespace_IncompleteData(t *testing.T) { t.Cleanup(cancel) bServ := NewMemBlockservice() - shares := sharetest.RandShares(t, 16) + shares := share.RandShares(16) // set all shares to the same namespace id - namespace := share.GetNamespace(shares[0]) + namespace := shares[0].Namespace() for _, shr := range shares { - copy(share.GetNamespace(shr), namespace) + copy(shr.Namespace().Bytes(), namespace.Bytes()) } eds, err := AddShares(ctx, shares, bServ) @@ -238,7 +237,7 @@ func TestCollectLeavesByNamespace_AbsentNamespaceId(t *testing.T) { t.Cleanup(cancel) bServ := NewMemBlockservice() - shares := sharetest.RandShares(t, 1024) + shares := share.RandShares(1024) // set all shares to the same namespace namespaces, err := randomNamespaces(5) @@ -252,10 +251,10 @@ func TestCollectLeavesByNamespace_AbsentNamespaceId(t *testing.T) { secondNamespaceFrom := mrand.Intn(len(shares)-2) + 1 for i, shr := range shares { if i < secondNamespaceFrom { - copy(share.GetNamespace(shr), minIncluded) + copy(shr.Namespace().Bytes(), minIncluded.Bytes()) continue } - copy(share.GetNamespace(shr), maxIncluded) + copy(shr.Namespace().Bytes(), maxIncluded.Bytes()) } tests := []struct { @@ -283,10 +282,10 @@ func TestCollectLeavesByNamespace_MultipleRowsContainingSameNamespaceId(t *testi t.Cleanup(cancel) bServ := NewMemBlockservice() - shares := sharetest.RandShares(t, 16) + shares := share.RandShares(16) // set all shares to the same namespace and data but the last one - namespace := share.GetNamespace(shares[0]) + namespace := shares[0].Namespace() commonNamespaceData := shares[0] for i, nspace := range shares { @@ -294,7 +293,7 @@ func TestCollectLeavesByNamespace_MultipleRowsContainingSameNamespaceId(t *testi break } - copy(nspace, commonNamespaceData) + copy(nspace.ToBytes(), commonNamespaceData.ToBytes()) } eds, err := AddShares(ctx, shares, bServ) @@ -315,7 +314,9 @@ 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, share.GetData(node.RawData())) + sh, err := share.NewShare(node.RawData()[share.NamespaceSize:]) + require.NoError(t, err) + assert.Equal(t, commonNamespaceData, *sh) } } } @@ -328,9 +329,9 @@ func TestGetSharesWithProofsByNamespace(t *testing.T) { tests := []struct { rawData []share.Share }{ - {rawData: sharetest.RandShares(t, 4)}, - {rawData: sharetest.RandShares(t, 16)}, - {rawData: sharetest.RandShares(t, 64)}, + {rawData: share.RandShares(4)}, + {rawData: share.RandShares(16)}, + {rawData: share.RandShares(64)}, } for i, tt := range tests { @@ -345,7 +346,7 @@ func TestGetSharesWithProofsByNamespace(t *testing.T) { } expected := tt.rawData[from] - namespace := share.GetNamespace(expected) + namespace := expected.Namespace() // change rawData to contain several shares with same namespace for i := from; i <= to; i++ { @@ -374,22 +375,22 @@ func TestGetSharesWithProofsByNamespace(t *testing.T) { // construct nodes from shares by prepending namespace var leaves [][]byte for _, shr := range rowShares { - leaves = append(leaves, append(share.GetNamespace(shr), shr...)) + leaves = append(leaves, append(shr.Namespace().Bytes(), shr.ToBytes()...)) } // verify namespace verified := proof.VerifyNamespace( - share.NewSHA256Hasher(), - namespace.ToNMT(), + square.NewSHA256Hasher(), + namespace.Bytes(), leaves, row) require.True(t, verified) // verify inclusion verified = proof.VerifyInclusion( - share.NewSHA256Hasher(), - namespace.ToNMT(), - rowShares, + square.NewSHA256Hasher(), + namespace.Bytes(), + share.ToBytes(rowShares), row) require.True(t, verified) } @@ -424,7 +425,10 @@ func TestBatchSize(t *testing.T) { bs := NewMemBlockservice() randEds := edstest.RandEDS(t, tt.origWidth) - _, err := AddShares(ctx, randEds.FlattenedODS(), bs) + + shrs, err := share.FromBytes(randEds.FlattenedODS()) + require.NoError(t, err) + _, err = AddShares(ctx, shrs, bs) require.NoError(t, err) out, err := bs.Blockstore().AllKeysChan(ctx) @@ -478,7 +482,7 @@ func assertNoRowContainsNID( // if no error returned, check absence proof foundAbsenceRows++ - verified := data.Proof().VerifyNamespace(share.NewSHA256Hasher(), namespace.ToNMT(), nil, rowRoot) + verified := data.Proof().VerifyNamespace(square.NewSHA256Hasher(), namespace.Bytes(), nil, rowRoot) require.True(t, verified) } @@ -492,8 +496,8 @@ func assertNoRowContainsNID( func randomNamespaces(total int) ([]share.Namespace, error) { namespaces := make([]share.Namespace, total) for i := range namespaces { - namespaces[i] = sharetest.RandV0Namespace() + namespaces[i] = share.RandomNamespace() } - sort.Slice(namespaces, func(i, j int) bool { return bytes.Compare(namespaces[i], namespaces[j]) < 0 }) + sort.Slice(namespaces, func(i, j int) bool { return namespaces[i].IsLessThan(namespaces[j]) }) return namespaces, nil } diff --git a/share/ipld/namespace_data.go b/square/ipld/namespace_data.go similarity index 97% rename from share/ipld/namespace_data.go rename to square/ipld/namespace_data.go index 13cd958b47..2c2ddaf3df 100644 --- a/share/ipld/namespace_data.go +++ b/square/ipld/namespace_data.go @@ -11,10 +11,10 @@ import ( "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square/shwap" ) var ErrNamespaceOutsideRange = shwap.ErrNamespaceOutsideRange @@ -71,7 +71,7 @@ func NewNamespaceData(maxShares int, namespace share.Namespace, options ...Optio } func (n *NamespaceData) validate(rootCid cid.Cid) error { - if err := n.namespace.Validate(); err != nil { + if err := share.ValidateUserNamespace(n.namespace.Version(), n.namespace.ID()); err != nil { return err } diff --git a/share/ipld/nmt.go b/square/ipld/nmt.go similarity index 93% rename from share/ipld/nmt.go rename to square/ipld/nmt.go index 0a433372b2..c96c081168 100644 --- a/share/ipld/nmt.go +++ b/square/ipld/nmt.go @@ -16,10 +16,10 @@ import ( mh "github.com/multiformats/go-multihash" mhcore "github.com/multiformats/go-multihash/core" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" ) var log = logging.Logger("ipld") @@ -42,7 +42,7 @@ const ( InnerNodeSize = NmtHashSize * 2 // LeafNodeSize is the size of data in leaf nodes. - LeafNodeSize = share.NamespaceSize + appconsts.ShareSize + LeafNodeSize = share.NamespaceSize + share.ShareSize // cidPrefixSize is the size of the prepended buffer of the CID encoding // for NamespacedSha256. For more information, see: @@ -58,7 +58,7 @@ const ( func init() { // required for Bitswap to hash and verify inbound data correctly mhcore.Register(sha256NamespaceFlagged, func() hash.Hash { - nh := nmt.NewNmtHasher(share.NewSHA256Hasher(), share.NamespaceSize, true) + nh := nmt.NewNmtHasher(square.NewSHA256Hasher(), share.NamespaceSize, true) nh.Reset() return nh }) @@ -157,7 +157,7 @@ func MustCidFromNamespacedSha256(hash []byte) cid.Cid { // Translate transforms square coordinates into IPLD NMT tree path to a leaf node. // It also adds randomization to evenly spread fetching from Rows and Columns. -func Translate(roots *share.AxisRoots, row, col int) (cid.Cid, int) { +func Translate(roots *square.AxisRoots, row, col int) (cid.Cid, int) { if rand.Intn(2) == 0 { //nolint:gosec return MustCidFromNamespacedSha256(roots.ColumnRoots[col]), row } diff --git a/share/ipld/nmt_adder.go b/square/ipld/nmt_adder.go similarity index 100% rename from share/ipld/nmt_adder.go rename to square/ipld/nmt_adder.go diff --git a/share/ipld/nmt_test.go b/square/ipld/nmt_test.go similarity index 85% rename from share/ipld/nmt_test.go rename to square/ipld/nmt_test.go index 040c68ec1d..a2133492c8 100644 --- a/share/ipld/nmt_test.go +++ b/square/ipld/nmt_test.go @@ -9,8 +9,8 @@ import ( "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" ) // TestNamespaceFromCID checks that deriving the Namespaced hash from @@ -26,7 +26,7 @@ func TestNamespaceFromCID(t *testing.T) { for i, tt := range tests { t.Run(strconv.Itoa(i), func(t *testing.T) { - roots, err := share.NewAxisRoots(tt.eds) + roots, err := square.NewAxisRoots(tt.eds) require.NoError(t, err) // check to make sure NamespacedHash is correctly derived from CID for _, row := range roots.RowRoots { diff --git a/share/ipld/proof_collector.go b/square/ipld/proof_collector.go similarity index 100% rename from share/ipld/proof_collector.go rename to square/ipld/proof_collector.go diff --git a/share/ipld/proofs.go b/square/ipld/proofs.go similarity index 100% rename from share/ipld/proofs.go rename to square/ipld/proofs.go diff --git a/share/ipld/proofs_test.go b/square/ipld/proofs_test.go similarity index 79% rename from share/ipld/proofs_test.go rename to square/ipld/proofs_test.go index 7ff438e577..ca28499b82 100644 --- a/share/ipld/proofs_test.go +++ b/square/ipld/proofs_test.go @@ -7,11 +7,11 @@ import ( "github.com/stretchr/testify/require" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/sharetest" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap" ) func TestGetProof(t *testing.T) { @@ -21,11 +21,11 @@ func TestGetProof(t *testing.T) { defer cancel() bServ := NewMemBlockservice() - shares := sharetest.RandShares(t, width*width) + shares := share.RandShares(width * width) in, err := AddShares(ctx, shares, bServ) require.NoError(t, err) - axisRoots, err := share.NewAxisRoots(in) + axisRoots, err := square.NewAxisRoots(in) require.NoError(t, err) for _, proofType := range []rsmt2d.Axis{rsmt2d.Row, rsmt2d.Col} { @@ -45,8 +45,10 @@ func TestGetProof(t *testing.T) { node, err := GetLeaf(ctx, bServ, rootCid, shrIdx, int(in.Width())) require.NoError(t, err) + sh, err := share.NewShare(node.RawData()[share.NamespaceSize:]) + require.NoError(t, err) sample := shwap.Sample{ - Share: share.GetData(node.RawData()), + Share: *sh, Proof: &proof, ProofType: proofType, } diff --git a/share/ipld/test_helpers.go b/square/ipld/test_helpers.go similarity index 100% rename from share/ipld/test_helpers.go rename to square/ipld/test_helpers.go diff --git a/share/ipld/utils.go b/square/ipld/utils.go similarity index 51% rename from share/ipld/utils.go rename to square/ipld/utils.go index b74d1d937d..1333dddd78 100644 --- a/share/ipld/utils.go +++ b/square/ipld/utils.go @@ -3,12 +3,14 @@ package ipld import ( "github.com/ipfs/go-cid" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" ) -// FilterRootByNamespace returns the row roots from the given share.AxisRoots that contain the +// FilterRootByNamespace returns the row roots from the given square.AxisRoots that contain the // namespace. -func FilterRootByNamespace(root *share.AxisRoots, namespace share.Namespace) []cid.Cid { +func FilterRootByNamespace(root *square.AxisRoots, namespace share.Namespace) []cid.Cid { rowRootCIDs := make([]cid.Cid, 0, len(root.RowRoots)) for _, row := range root.RowRoots { if !namespace.IsOutsideRange(row, row) { diff --git a/share/namespace.go b/square/namespace.go similarity index 96% rename from share/namespace.go rename to square/namespace.go index 8e1c5b4bb1..65c5a0390c 100644 --- a/share/namespace.go +++ b/square/namespace.go @@ -1,4 +1,4 @@ -package share +package square import ( "bytes" @@ -8,6 +8,7 @@ import ( "fmt" appns "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt/namespace" ) @@ -75,10 +76,10 @@ func (n Namespace) ToNMT() namespace.ID { return namespace.ID(n) } -// ToAppNamespace converts the Namespace to App's definition of Namespace. -// TODO: Unify types between node and app -func (n Namespace) ToAppNamespace() appns.Namespace { - return appns.Namespace{Version: n.Version(), ID: n.ID()} +// // ToAppNamespace converts the Namespace to App's definition of Namespace. +// // TODO: Unify types between node and app +func (n Namespace) ToAppNamespace() (share.Namespace, error) { + return share.NewNamespace(n.Version(), n.ID()) } // Len reports the total length of the namespace. diff --git a/share/root.go b/square/root.go similarity index 92% rename from share/root.go rename to square/root.go index ee912c4df2..f4c1045662 100644 --- a/share/root.go +++ b/square/root.go @@ -1,4 +1,4 @@ -package share +package square import ( "bytes" @@ -7,7 +7,8 @@ import ( "fmt" "hash" - "github.com/celestiaorg/celestia-app/v2/pkg/da" + "github.com/celestiaorg/celestia-app/v3/pkg/da" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" ) @@ -58,7 +59,7 @@ func NewAxisRoots(eds *rsmt2d.ExtendedDataSquare) (*AxisRoots, error) { // RowsWithNamespace inspects the AxisRoots for the Namespace and provides // a slices of Row indexes containing the namespace. -func RowsWithNamespace(root *AxisRoots, namespace Namespace) (idxs []int) { +func RowsWithNamespace(root *AxisRoots, namespace share.Namespace) (idxs []int) { for i, row := range root.RowRoots { if !namespace.IsOutsideRange(row, row) { idxs = append(idxs, i) diff --git a/square/share.go b/square/share.go new file mode 100644 index 0000000000..696a6bc948 --- /dev/null +++ b/square/share.go @@ -0,0 +1,40 @@ +package square + +import ( + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/nmt" + "github.com/celestiaorg/rsmt2d" +) + +// DefaultRSMT2DCodec sets the default rsmt2d.Codec for shares. +var DefaultRSMT2DCodec = appconsts.DefaultCodec + +// MaxSquareSize is currently the maximum size supported for unerasured data in +// rsmt2d.ExtendedDataSquare. +var MaxSquareSize = appconsts.SquareSizeUpperBound(appconsts.LatestVersion) + +// ShareWithProof contains data with corresponding Merkle Proof +type ShareWithProof struct { //nolint: revive + // Share is a full data including namespace + share.Share + // Proof is a Merkle Proof of current share + Proof *nmt.Proof + // Axis is a type of axis against which the share proof is computed + Axis rsmt2d.Axis +} + +// Validate validates inclusion of the share under the given root CID. +func (s *ShareWithProof) Validate(rootHash []byte, x, y, edsSize int) bool { + isParity := x >= edsSize/2 || y >= edsSize/2 + namespace := share.ParitySharesNamespace + if !isParity { + namespace = s.Share.Namespace() + } + return s.Proof.VerifyInclusion( + NewSHA256Hasher(), + namespace.Bytes(), + [][]byte{s.Share.ToBytes()}, + rootHash, + ) +} diff --git a/share/shwap/eds.go b/square/shwap/eds.go similarity index 100% rename from share/shwap/eds.go rename to square/shwap/eds.go diff --git a/share/shwap/eds_id.go b/square/shwap/eds_id.go similarity index 100% rename from share/shwap/eds_id.go rename to square/shwap/eds_id.go diff --git a/share/shwap/eds_id_test.go b/square/shwap/eds_id_test.go similarity index 100% rename from share/shwap/eds_id_test.go rename to square/shwap/eds_id_test.go diff --git a/share/shwap/getter.go b/square/shwap/getter.go similarity index 97% rename from share/shwap/getter.go rename to square/shwap/getter.go index 8a2b3389f5..dfbe36432e 100644 --- a/share/shwap/getter.go +++ b/square/shwap/getter.go @@ -5,10 +5,10 @@ import ( "errors" "fmt" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share" ) var ( diff --git a/share/shwap/getters/cascade.go b/square/shwap/getters/cascade.go similarity index 96% rename from share/shwap/getters/cascade.go rename to square/shwap/getters/cascade.go index bcd36f64c0..5aeddafd30 100644 --- a/share/shwap/getters/cascade.go +++ b/square/shwap/getters/cascade.go @@ -10,13 +10,13 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/byzantine" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/square/shwap" ) var ( @@ -55,7 +55,7 @@ func (cg *CascadeGetter) GetShare( if row >= upperBound || col >= upperBound { err := shwap.ErrOutOfBounds span.RecordError(err) - return nil, err + return share.Share{}, err } get := func(ctx context.Context, get shwap.Getter) (share.Share, error) { return get.GetShare(ctx, header, row, col) diff --git a/share/shwap/getters/cascade_test.go b/square/shwap/getters/cascade_test.go similarity index 97% rename from share/shwap/getters/cascade_test.go rename to square/shwap/getters/cascade_test.go index a23568006f..0012780fbf 100644 --- a/share/shwap/getters/cascade_test.go +++ b/square/shwap/getters/cascade_test.go @@ -12,8 +12,8 @@ import ( "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/getters/mock" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/getters/mock" ) func TestCascadeGetter(t *testing.T) { diff --git a/share/shwap/getters/mock/getter.go b/square/shwap/getters/mock/getter.go similarity index 93% rename from share/shwap/getters/mock/getter.go rename to square/shwap/getters/mock/getter.go index 64e04a5132..5eb7be8ef6 100644 --- a/share/shwap/getters/mock/getter.go +++ b/square/shwap/getters/mock/getter.go @@ -9,8 +9,8 @@ import ( reflect "reflect" header "github.com/celestiaorg/celestia-node/header" - share "github.com/celestiaorg/celestia-node/share" - shwap "github.com/celestiaorg/celestia-node/share/shwap" + shwap "github.com/celestiaorg/celestia-node/square/shwap" + share "github.com/celestiaorg/go-square/v2/share" rsmt2d "github.com/celestiaorg/rsmt2d" gomock "github.com/golang/mock/gomock" ) @@ -54,10 +54,10 @@ func (mr *MockGetterMockRecorder) GetEDS(arg0, arg1 interface{}) *gomock.Call { } // GetShare mocks base method. -func (m *MockGetter) GetShare(arg0 context.Context, arg1 *header.ExtendedHeader, arg2, arg3 int) ([]byte, error) { +func (m *MockGetter) GetShare(arg0 context.Context, arg1 *header.ExtendedHeader, arg2, arg3 int) (share.Share, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetShare", arg0, arg1, arg2, arg3) - ret0, _ := ret[0].([]byte) + ret0, _ := ret[0].(share.Share) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/share/shwap/getters/testing.go b/square/shwap/getters/testing.go similarity index 77% rename from share/shwap/getters/testing.go rename to square/shwap/getters/testing.go index 3714aa5260..a9eb55d034 100644 --- a/share/shwap/getters/testing.go +++ b/square/shwap/getters/testing.go @@ -7,20 +7,21 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-app/v2/pkg/da" + "github.com/celestiaorg/celestia-app/v3/pkg/da" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" ) // TestGetter provides a testing SingleEDSGetter and the root of the EDS it holds. func TestGetter(t *testing.T) (shwap.Getter, *header.ExtendedHeader) { eds := edstest.RandEDS(t, 8) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) eh := headertest.RandExtendedHeaderWithRoot(t, roots) require.NoError(t, err) return &SingleEDSGetter{ @@ -42,9 +43,14 @@ func (seg *SingleEDSGetter) GetShare( ) (share.Share, error) { err := seg.checkRoots(header.DAH) if err != nil { - return nil, err + return share.Share{}, err + } + rawSh := seg.EDS.GetCell(uint(row), uint(col)) + sh, err := share.NewShare(rawSh) + if err != nil { + return share.Share{}, err } - return seg.EDS.GetCell(uint(row), uint(col)), nil + return *sh, nil } // GetEDS returns a kept EDS if the correct root is given. @@ -65,7 +71,7 @@ func (seg *SingleEDSGetter) GetSharesByNamespace(context.Context, *header.Extend panic("SingleEDSGetter: GetSharesByNamespace is not implemented") } -func (seg *SingleEDSGetter) checkRoots(roots *share.AxisRoots) error { +func (seg *SingleEDSGetter) checkRoots(roots *square.AxisRoots) error { dah, err := da.NewDataAvailabilityHeader(seg.EDS) if err != nil { return err diff --git a/share/shwap/namespace_data.go b/square/shwap/namespace_data.go similarity index 89% rename from share/shwap/namespace_data.go rename to square/shwap/namespace_data.go index 656b886f2a..730d4e1c41 100644 --- a/share/shwap/namespace_data.go +++ b/square/shwap/namespace_data.go @@ -5,7 +5,9 @@ import ( "fmt" "io" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" ) // NamespaceDataName is the name identifier for the namespace data container. @@ -27,8 +29,8 @@ func (nd NamespaceData) Flatten() []share.Share { } // Verify checks the integrity of the NamespaceData against a provided root and namespace. -func (nd NamespaceData) Verify(root *share.AxisRoots, namespace share.Namespace) error { - rowIdxs := share.RowsWithNamespace(root, namespace) +func (nd NamespaceData) Verify(root *square.AxisRoots, namespace share.Namespace) error { + rowIdxs := square.RowsWithNamespace(root, namespace) if len(rowIdxs) != len(nd) { return fmt.Errorf("expected %d rows, found %d rows", len(rowIdxs), len(nd)) } diff --git a/share/shwap/namespace_data_id.go b/square/shwap/namespace_data_id.go similarity index 91% rename from share/shwap/namespace_data_id.go rename to square/shwap/namespace_data_id.go index 63b5f22948..1488e41ba3 100644 --- a/share/shwap/namespace_data_id.go +++ b/square/shwap/namespace_data_id.go @@ -4,7 +4,7 @@ import ( "fmt" "io" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/go-square/v2/share" ) // NamespaceDataIDSize defines the total size of a NamespaceDataID in bytes, combining the @@ -48,7 +48,11 @@ func NamespaceDataIDFromBinary(data []byte) (NamespaceDataID, error) { return NamespaceDataID{}, fmt.Errorf("error unmarshaling EDSID: %w", err) } - ns := share.Namespace(data[EdsIDSize:]) + ns, err := share.NewNamespaceFromBytes(data[EdsIDSize:]) + if err != nil { + return NamespaceDataID{}, fmt.Errorf("error unmarshaling namespace: %w", err) + } + ndid := NamespaceDataID{ EdsID: edsID, DataNamespace: ns, @@ -107,7 +111,8 @@ func (ndid NamespaceDataID) Validate() error { if err := ndid.EdsID.Validate(); err != nil { return fmt.Errorf("validating RowID: %w", err) } - if err := ndid.DataNamespace.ValidateForData(); err != nil { + + if err := share.ValidateForData(ndid.DataNamespace); err != nil { return fmt.Errorf("%w: validating DataNamespace: %w", ErrInvalidID, err) } return nil @@ -116,5 +121,5 @@ func (ndid NamespaceDataID) Validate() error { // appendTo helps in appending the binary form of DataNamespace to the serialized RowID data. func (ndid NamespaceDataID) appendTo(data []byte) []byte { data = ndid.EdsID.appendTo(data) - return append(data, ndid.DataNamespace...) + return append(data, ndid.DataNamespace.Bytes()...) } diff --git a/share/shwap/namespace_data_id_test.go b/square/shwap/namespace_data_id_test.go similarity index 87% rename from share/shwap/namespace_data_id_test.go rename to square/shwap/namespace_data_id_test.go index 94b0a39703..daab44cdcf 100644 --- a/share/shwap/namespace_data_id_test.go +++ b/square/shwap/namespace_data_id_test.go @@ -7,11 +7,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/go-square/v2/share" ) func TestNamespaceDataID(t *testing.T) { - ns := sharetest.RandV0Namespace() + ns := share.RandomNamespace() id, err := NewNamespaceDataID(1, ns) require.NoError(t, err) @@ -29,7 +29,7 @@ func TestNamespaceDataID(t *testing.T) { } func TestNamespaceDataIDReaderWriter(t *testing.T) { - ns := sharetest.RandV0Namespace() + ns := share.RandomNamespace() id, err := NewNamespaceDataID(1, ns) require.NoError(t, err) diff --git a/share/shwap/p2p/bitswap/bitswap.go b/square/shwap/p2p/bitswap/bitswap.go similarity index 100% rename from share/shwap/p2p/bitswap/bitswap.go rename to square/shwap/p2p/bitswap/bitswap.go diff --git a/share/shwap/p2p/bitswap/block.go b/square/shwap/p2p/bitswap/block.go similarity index 89% rename from share/shwap/p2p/bitswap/block.go rename to square/shwap/p2p/bitswap/block.go index 940afb5bc2..d42697722c 100644 --- a/share/shwap/p2p/bitswap/block.go +++ b/square/shwap/p2p/bitswap/block.go @@ -6,8 +6,8 @@ import ( "github.com/ipfs/go-cid" logger "github.com/ipfs/go-log/v2" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" ) var log = logger.Logger("shwap/bitswap") @@ -30,7 +30,7 @@ type Block interface { Marshal() ([]byte, error) // UnmarshalFn returns closure that unmarshal the Block with the Shwap container. // Unmarshalling involves data validation against the given AxisRoots. - UnmarshalFn(*share.AxisRoots) UnmarshalFn + UnmarshalFn(*square.AxisRoots) UnmarshalFn } // UnmarshalFn is a closure produced by a Block that unmarshalls and validates diff --git a/share/shwap/p2p/bitswap/block_fetch.go b/square/shwap/p2p/bitswap/block_fetch.go similarity index 98% rename from share/shwap/p2p/bitswap/block_fetch.go rename to square/shwap/p2p/bitswap/block_fetch.go index 7d7dcd1c90..55011cbc82 100644 --- a/share/shwap/p2p/bitswap/block_fetch.go +++ b/square/shwap/p2p/bitswap/block_fetch.go @@ -11,7 +11,7 @@ import ( blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" ) // WithFetcher instructs [Fetch] to use the given Fetcher. @@ -37,7 +37,7 @@ func WithStore(store blockstore.Blockstore) FetchOption { func Fetch( ctx context.Context, exchg exchange.Interface, - root *share.AxisRoots, + root *square.AxisRoots, blks []Block, opts ...FetchOption, ) error { @@ -62,7 +62,7 @@ func Fetch( func fetch( ctx context.Context, exchg exchange.Interface, - root *share.AxisRoots, + root *square.AxisRoots, blks []Block, opts ...FetchOption, ) error { diff --git a/share/shwap/p2p/bitswap/block_fetch_test.go b/square/shwap/p2p/bitswap/block_fetch_test.go similarity index 98% rename from share/shwap/p2p/bitswap/block_fetch_test.go rename to square/shwap/p2p/bitswap/block_fetch_test.go index 6642801efe..872a8f8a66 100644 --- a/share/shwap/p2p/bitswap/block_fetch_test.go +++ b/square/shwap/p2p/bitswap/block_fetch_test.go @@ -20,7 +20,7 @@ import ( "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square/eds" ) func TestFetch_Options(t *testing.T) { diff --git a/share/shwap/p2p/bitswap/block_proto.go b/square/shwap/p2p/bitswap/block_proto.go similarity index 92% rename from share/shwap/p2p/bitswap/block_proto.go rename to square/shwap/p2p/bitswap/block_proto.go index 8cab645705..6ab0243abf 100644 --- a/share/shwap/p2p/bitswap/block_proto.go +++ b/square/shwap/p2p/bitswap/block_proto.go @@ -5,7 +5,7 @@ import ( "github.com/ipfs/go-cid" - bitswappb "github.com/celestiaorg/celestia-node/share/shwap/p2p/bitswap/pb" + bitswappb "github.com/celestiaorg/celestia-node/square/shwap/p2p/bitswap/pb" ) // marshalProto wraps the given Block in composition protobuf and marshals it. diff --git a/share/shwap/p2p/bitswap/block_registry.go b/square/shwap/p2p/bitswap/block_registry.go similarity index 100% rename from share/shwap/p2p/bitswap/block_registry.go rename to square/shwap/p2p/bitswap/block_registry.go diff --git a/share/shwap/p2p/bitswap/block_store.go b/square/shwap/p2p/bitswap/block_store.go similarity index 98% rename from share/shwap/p2p/bitswap/block_store.go rename to square/shwap/p2p/bitswap/block_store.go index b1a5f1554e..69fa072d61 100644 --- a/share/shwap/p2p/bitswap/block_store.go +++ b/square/shwap/p2p/bitswap/block_store.go @@ -9,7 +9,7 @@ import ( "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square/eds" "github.com/celestiaorg/celestia-node/store" ) diff --git a/share/shwap/p2p/bitswap/block_test.go b/square/shwap/p2p/bitswap/block_test.go similarity index 92% rename from share/shwap/p2p/bitswap/block_test.go rename to square/shwap/p2p/bitswap/block_test.go index 39bb55bc14..e953eb0546 100644 --- a/share/shwap/p2p/bitswap/block_test.go +++ b/square/shwap/p2p/bitswap/block_test.go @@ -13,8 +13,8 @@ import ( dssync "github.com/ipfs/go-datastore/sync" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" ) const ( @@ -103,7 +103,7 @@ func (t *testBlock) Marshal() ([]byte, error) { return t.data, nil } -func (t *testBlock) UnmarshalFn(*share.AxisRoots) UnmarshalFn { +func (t *testBlock) UnmarshalFn(*square.AxisRoots) UnmarshalFn { return func(bytes, _ []byte) error { t.data = bytes time.Sleep(time.Millisecond * 1) diff --git a/share/shwap/p2p/bitswap/cid.go b/square/shwap/p2p/bitswap/cid.go similarity index 100% rename from share/shwap/p2p/bitswap/cid.go rename to square/shwap/p2p/bitswap/cid.go diff --git a/share/shwap/p2p/bitswap/getter.go b/square/shwap/p2p/bitswap/getter.go similarity index 92% rename from share/shwap/p2p/bitswap/getter.go rename to square/shwap/p2p/bitswap/getter.go index 9c55650a44..a346032b3e 100644 --- a/share/shwap/p2p/bitswap/getter.go +++ b/square/shwap/p2p/bitswap/getter.go @@ -11,13 +11,14 @@ import ( "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap" ) var tracer = otel.Tracer("shwap/bitswap") @@ -120,11 +121,11 @@ func (g *Getter) GetShare( ) (share.Share, error) { shrs, err := g.GetShares(ctx, hdr, []int{row}, []int{col}) if err != nil { - return nil, err + return share.Share{}, err } if len(shrs) != 1 { - return nil, fmt.Errorf("expected 1 share row, got %d", len(shrs)) + return share.Share{}, fmt.Errorf("expected 1 share row, got %d", len(shrs)) } return shrs[0], nil @@ -186,14 +187,14 @@ func (g *Getter) GetSharesByNamespace( hdr *header.ExtendedHeader, ns share.Namespace, ) (shwap.NamespaceData, error) { - if err := ns.ValidateForData(); err != nil { + if err := share.ValidateForData(ns); err != nil { return nil, err } ctx, span := tracer.Start(ctx, "get-shares-by-namespace") defer span.End() - rowIdxs := share.RowsWithNamespace(hdr.DAH, ns) + rowIdxs := square.RowsWithNamespace(hdr.DAH, ns) blks := make([]Block, len(rowIdxs)) for i, rowNdIdx := range rowIdxs { rndblk, err := NewEmptyRowNamespaceDataBlock(hdr.Height(), rowNdIdx, ns, len(hdr.DAH.RowRoots)) @@ -241,7 +242,7 @@ func (g *Getter) session(ctx context.Context, hdr *header.ExtendedHeader) exchan // edsFromRows imports given Rows and computes EDS out of them, assuming enough Rows were provided. // It is designed to reuse Row halves computed during verification on [Fetch] level. -func edsFromRows(roots *share.AxisRoots, rows []shwap.Row) (*rsmt2d.ExtendedDataSquare, error) { +func edsFromRows(roots *square.AxisRoots, rows []shwap.Row) (*rsmt2d.ExtendedDataSquare, error) { shrs := make([]share.Share, len(roots.RowRoots)*len(roots.RowRoots)) for i, row := range rows { rowShrs, err := row.Shares() @@ -255,8 +256,8 @@ func edsFromRows(roots *share.AxisRoots, rows []shwap.Row) (*rsmt2d.ExtendedData } square, err := rsmt2d.ImportExtendedDataSquare( - shrs, - share.DefaultRSMT2DCodec(), + share.ToBytes(shrs), + square.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(len(roots.RowRoots)/2)), ) if err != nil { diff --git a/share/shwap/p2p/bitswap/getter_test.go b/square/shwap/p2p/bitswap/getter_test.go similarity index 54% rename from share/shwap/p2p/bitswap/getter_test.go rename to square/shwap/p2p/bitswap/getter_test.go index 757c34d7a0..64365ed7f2 100644 --- a/share/shwap/p2p/bitswap/getter_test.go +++ b/square/shwap/p2p/bitswap/getter_test.go @@ -5,19 +5,22 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" ) func TestEDSFromRows(t *testing.T) { edsIn := edstest.RandEDS(t, 8) - roots, err := share.NewAxisRoots(edsIn) + roots, err := square.NewAxisRoots(edsIn) require.NoError(t, err) rows := make([]shwap.Row, edsIn.Width()/2) for i := range edsIn.Width() / 2 { - rowShrs := edsIn.Row(i)[:edsIn.Width()/2] + rowShrs, err := share.FromBytes(edsIn.Row(i)[:edsIn.Width()/2]) + require.NoError(t, err) rows[i] = shwap.NewRow(rowShrs, shwap.Left) } diff --git a/share/shwap/p2p/bitswap/pb/bitswap.pb.go b/square/shwap/p2p/bitswap/pb/bitswap.pb.go similarity index 85% rename from share/shwap/p2p/bitswap/pb/bitswap.pb.go rename to square/shwap/p2p/bitswap/pb/bitswap.pb.go index a84077e9ef..e1f425c41b 100644 --- a/share/shwap/p2p/bitswap/pb/bitswap.pb.go +++ b/square/shwap/p2p/bitswap/pb/bitswap.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: share/shwap/p2p/bitswap/pb/bitswap.proto +// source: square/shwap/p2p/bitswap/pb/bitswap.proto package pb @@ -31,7 +31,7 @@ func (m *Block) Reset() { *m = Block{} } func (m *Block) String() string { return proto.CompactTextString(m) } func (*Block) ProtoMessage() {} func (*Block) Descriptor() ([]byte, []int) { - return fileDescriptor_09fd4e2ff1d5ce94, []int{0} + return fileDescriptor_98329a1d35a94c34, []int{0} } func (m *Block) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -79,22 +79,22 @@ func init() { } func init() { - proto.RegisterFile("share/shwap/p2p/bitswap/pb/bitswap.proto", fileDescriptor_09fd4e2ff1d5ce94) + proto.RegisterFile("square/shwap/p2p/bitswap/pb/bitswap.proto", fileDescriptor_98329a1d35a94c34) } -var fileDescriptor_09fd4e2ff1d5ce94 = []byte{ - // 171 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x28, 0xce, 0x48, 0x2c, - 0x4a, 0xd5, 0x2f, 0xce, 0x28, 0x4f, 0x2c, 0xd0, 0x2f, 0x30, 0x2a, 0xd0, 0x4f, 0xca, 0x2c, 0x29, - 0x06, 0xb3, 0x93, 0x60, 0x4c, 0xbd, 0x82, 0xa2, 0xfc, 0x92, 0x7c, 0x21, 0x76, 0x28, 0x57, 0xc9, - 0x9c, 0x8b, 0xd5, 0x29, 0x27, 0x3f, 0x39, 0x5b, 0x48, 0x80, 0x8b, 0x39, 0x39, 0x33, 0x45, 0x82, - 0x51, 0x81, 0x51, 0x83, 0x27, 0x08, 0xc4, 0x14, 0x92, 0xe1, 0xe2, 0x4c, 0xce, 0xcf, 0x2b, 0x49, - 0xcc, 0xcc, 0x4b, 0x2d, 0x92, 0x60, 0x02, 0x8b, 0x23, 0x04, 0x9c, 0x22, 0x4f, 0x3c, 0x92, 0x63, - 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, - 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0xca, 0x3e, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, - 0x3f, 0x57, 0x3f, 0x39, 0x35, 0x27, 0xb5, 0xb8, 0x24, 0x33, 0x31, 0xbf, 0x28, 0x1d, 0xce, 0xd6, - 0xcd, 0xcb, 0x4f, 0x01, 0x39, 0x12, 0x97, 0x53, 0x93, 0xd8, 0xc0, 0x6e, 0x34, 0x06, 0x04, 0x00, - 0x00, 0xff, 0xff, 0xe7, 0x9c, 0x32, 0xc5, 0xcf, 0x00, 0x00, 0x00, +var fileDescriptor_98329a1d35a94c34 = []byte{ + // 172 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x2c, 0x2e, 0x2c, 0x4d, + 0x2c, 0x4a, 0xd5, 0x2f, 0xce, 0x28, 0x4f, 0x2c, 0xd0, 0x2f, 0x30, 0x2a, 0xd0, 0x4f, 0xca, 0x2c, + 0x29, 0x06, 0xb3, 0x93, 0x60, 0x4c, 0xbd, 0x82, 0xa2, 0xfc, 0x92, 0x7c, 0x21, 0x76, 0x28, 0x57, + 0xc9, 0x9c, 0x8b, 0xd5, 0x29, 0x27, 0x3f, 0x39, 0x5b, 0x48, 0x80, 0x8b, 0x39, 0x39, 0x33, 0x45, + 0x82, 0x51, 0x81, 0x51, 0x83, 0x27, 0x08, 0xc4, 0x14, 0x92, 0xe1, 0xe2, 0x4c, 0xce, 0xcf, 0x2b, + 0x49, 0xcc, 0xcc, 0x4b, 0x2d, 0x92, 0x60, 0x02, 0x8b, 0x23, 0x04, 0x9c, 0xa2, 0x4e, 0x3c, 0x92, + 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, + 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0xca, 0x21, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, + 0x39, 0x3f, 0x57, 0x3f, 0x39, 0x35, 0x27, 0xb5, 0xb8, 0x24, 0x33, 0x31, 0xbf, 0x28, 0x1d, 0xce, + 0xd6, 0xcd, 0xcb, 0x4f, 0x49, 0xd5, 0xc7, 0xe3, 0xd6, 0x24, 0x36, 0xb0, 0x23, 0x8d, 0x01, 0x01, + 0x00, 0x00, 0xff, 0xff, 0x7d, 0xd5, 0x78, 0x73, 0xd1, 0x00, 0x00, 0x00, } func (m *Block) Marshal() (dAtA []byte, err error) { diff --git a/share/shwap/p2p/bitswap/pb/bitswap.proto b/square/shwap/p2p/bitswap/pb/bitswap.proto similarity index 70% rename from share/shwap/p2p/bitswap/pb/bitswap.proto rename to square/shwap/p2p/bitswap/pb/bitswap.proto index 3ba19aa49c..b620e98b60 100644 --- a/share/shwap/p2p/bitswap/pb/bitswap.proto +++ b/square/shwap/p2p/bitswap/pb/bitswap.proto @@ -1,7 +1,7 @@ // Defined in CIP-19 https://github.com/celestiaorg/CIPs/blob/82aeb7dfc472105a11babffd548c730c899a3d24/cips/cip-19.md syntax = "proto3"; package bitswap; -option go_package = "github.com/celestiaorg/celestia-node/share/shwap/p2p/bitswap/pb"; +option go_package = "github.com/celestiaorg/celestia-node/square/shwap/p2p/bitswap/pb"; message Block { bytes cid = 1; diff --git a/share/shwap/p2p/bitswap/row_block.go b/square/shwap/p2p/bitswap/row_block.go similarity index 84% rename from share/shwap/p2p/bitswap/row_block.go rename to square/shwap/p2p/bitswap/row_block.go index 41ff19e791..cfc57dc765 100644 --- a/share/shwap/p2p/bitswap/row_block.go +++ b/square/shwap/p2p/bitswap/row_block.go @@ -8,10 +8,10 @@ import ( "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" - shwappb "github.com/celestiaorg/celestia-node/share/shwap/pb" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" + shwappb "github.com/celestiaorg/celestia-node/square/shwap/pb" ) const ( @@ -96,7 +96,7 @@ func (rb *RowBlock) Populate(ctx context.Context, eds eds.Accessor) error { return nil } -func (rb *RowBlock) UnmarshalFn(root *share.AxisRoots) UnmarshalFn { +func (rb *RowBlock) UnmarshalFn(root *square.AxisRoots) UnmarshalFn { return func(cntrData, idData []byte) error { if !rb.Container.IsEmpty() { return nil @@ -116,8 +116,12 @@ func (rb *RowBlock) UnmarshalFn(root *share.AxisRoots) UnmarshalFn { return fmt.Errorf("unmarshaling Row for %+v: %w", rb.ID, err) } - cntr := shwap.RowFromProto(&row) - if err := cntr.Verify(root, rb.ID.RowIndex); err != nil { + cntr, err := shwap.RowFromProto(&row) + if err != nil { + return fmt.Errorf("unmarshaling Row: %w", err) + } + + if err = cntr.Verify(root, rb.ID.RowIndex); err != nil { return fmt.Errorf("validating Row for %+v: %w", rb.ID, err) } diff --git a/share/shwap/p2p/bitswap/row_block_test.go b/square/shwap/p2p/bitswap/row_block_test.go similarity index 82% rename from share/shwap/p2p/bitswap/row_block_test.go rename to square/shwap/p2p/bitswap/row_block_test.go index f609683da5..9b48338957 100644 --- a/share/shwap/p2p/bitswap/row_block_test.go +++ b/square/shwap/p2p/bitswap/row_block_test.go @@ -7,8 +7,8 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" ) func TestRow_FetchRoundtrip(t *testing.T) { @@ -16,7 +16,7 @@ func TestRow_FetchRoundtrip(t *testing.T) { defer cancel() eds := edstest.RandEDS(t, 4) - root, err := share.NewAxisRoots(eds) + root, err := square.NewAxisRoots(eds) require.NoError(t, err) exchange := newExchangeOverEDS(ctx, t, eds) diff --git a/share/shwap/p2p/bitswap/row_namespace_data_block.go b/square/shwap/p2p/bitswap/row_namespace_data_block.go similarity index 86% rename from share/shwap/p2p/bitswap/row_namespace_data_block.go rename to square/shwap/p2p/bitswap/row_namespace_data_block.go index 312f231027..76778b0f53 100644 --- a/share/shwap/p2p/bitswap/row_namespace_data_block.go +++ b/square/shwap/p2p/bitswap/row_namespace_data_block.go @@ -6,10 +6,12 @@ import ( "github.com/ipfs/go-cid" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" - shwappb "github.com/celestiaorg/celestia-node/share/shwap/pb" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" + shwappb "github.com/celestiaorg/celestia-node/square/shwap/pb" ) const ( @@ -100,7 +102,7 @@ func (rndb *RowNamespaceDataBlock) Populate(ctx context.Context, eds eds.Accesso return nil } -func (rndb *RowNamespaceDataBlock) UnmarshalFn(root *share.AxisRoots) UnmarshalFn { +func (rndb *RowNamespaceDataBlock) UnmarshalFn(root *square.AxisRoots) UnmarshalFn { return func(cntrData, idData []byte) error { if !rndb.Container.IsEmpty() { return nil @@ -120,7 +122,10 @@ func (rndb *RowNamespaceDataBlock) UnmarshalFn(root *share.AxisRoots) UnmarshalF return fmt.Errorf("unmarshaling RowNamespaceData for %+v: %w", rndb.ID, err) } - cntr := shwap.RowNamespaceDataFromProto(&rnd) + cntr, err := shwap.RowNamespaceDataFromProto(&rnd) + if err != nil { + return fmt.Errorf("unmarshaling RowNamespaceData for %+v: %w", rndb.ID, err) + } if err := cntr.Verify(root, rndb.ID.DataNamespace, rndb.ID.RowIndex); err != nil { return fmt.Errorf("validating RowNamespaceData for %+v: %w", rndb.ID, err) } diff --git a/share/shwap/p2p/bitswap/row_namespace_data_block_test.go b/square/shwap/p2p/bitswap/row_namespace_data_block_test.go similarity index 75% rename from share/shwap/p2p/bitswap/row_namespace_data_block_test.go rename to square/shwap/p2p/bitswap/row_namespace_data_block_test.go index 27deee8823..fecf5494ca 100644 --- a/share/shwap/p2p/bitswap/row_namespace_data_block_test.go +++ b/square/shwap/p2p/bitswap/row_namespace_data_block_test.go @@ -7,20 +7,21 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" ) func TestRowNamespaceData_FetchRoundtrip(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() - namespace := sharetest.RandV0Namespace() + namespace := share.RandomNamespace() eds, root := edstest.RandEDSWithNamespace(t, namespace, 64, 16) exchange := newExchangeOverEDS(ctx, t, eds) - rowIdxs := share.RowsWithNamespace(root, namespace) + rowIdxs := square.RowsWithNamespace(root, namespace) blks := make([]Block, len(rowIdxs)) for i, rowIdx := range rowIdxs { blk, err := NewEmptyRowNamespaceDataBlock(1, rowIdx, namespace, len(root.RowRoots)) diff --git a/share/shwap/p2p/bitswap/sample_block.go b/square/shwap/p2p/bitswap/sample_block.go similarity index 84% rename from share/shwap/p2p/bitswap/sample_block.go rename to square/shwap/p2p/bitswap/sample_block.go index c96c5f4d3f..d7e7fdd884 100644 --- a/share/shwap/p2p/bitswap/sample_block.go +++ b/square/shwap/p2p/bitswap/sample_block.go @@ -6,10 +6,10 @@ import ( "github.com/ipfs/go-cid" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" - shwappb "github.com/celestiaorg/celestia-node/share/shwap/pb" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" + shwappb "github.com/celestiaorg/celestia-node/square/shwap/pb" ) const ( @@ -95,7 +95,7 @@ func (sb *SampleBlock) Populate(ctx context.Context, eds eds.Accessor) error { return nil } -func (sb *SampleBlock) UnmarshalFn(root *share.AxisRoots) UnmarshalFn { +func (sb *SampleBlock) UnmarshalFn(root *square.AxisRoots) UnmarshalFn { return func(cntrData, idData []byte) error { if !sb.Container.IsEmpty() { return nil @@ -115,8 +115,12 @@ func (sb *SampleBlock) UnmarshalFn(root *share.AxisRoots) UnmarshalFn { return fmt.Errorf("unmarshaling Sample for %+v: %w", sb.ID, err) } - cntr := shwap.SampleFromProto(&sample) - if err := cntr.Verify(root, sb.ID.RowIndex, sb.ID.ShareIndex); err != nil { + cntr, err := shwap.SampleFromProto(&sample) + if err != nil { + return fmt.Errorf("unmarshaling Sample for %+v: %w", sb.ID, err) + } + + if err = cntr.Verify(root, sb.ID.RowIndex, sb.ID.ShareIndex); err != nil { return fmt.Errorf("validating Sample for %+v: %w", sb.ID, err) } diff --git a/share/shwap/p2p/bitswap/sample_block_test.go b/square/shwap/p2p/bitswap/sample_block_test.go similarity index 85% rename from share/shwap/p2p/bitswap/sample_block_test.go rename to square/shwap/p2p/bitswap/sample_block_test.go index 2a28e7e4c9..ec7364e71f 100644 --- a/share/shwap/p2p/bitswap/sample_block_test.go +++ b/square/shwap/p2p/bitswap/sample_block_test.go @@ -7,8 +7,8 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" ) func TestSample_FetchRoundtrip(t *testing.T) { @@ -16,7 +16,7 @@ func TestSample_FetchRoundtrip(t *testing.T) { defer cancel() eds := edstest.RandEDS(t, 32) - root, err := share.NewAxisRoots(eds) + root, err := square.NewAxisRoots(eds) require.NoError(t, err) exchange := newExchangeOverEDS(ctx, t, eds) diff --git a/share/shwap/p2p/discovery/backoff.go b/square/shwap/p2p/discovery/backoff.go similarity index 100% rename from share/shwap/p2p/discovery/backoff.go rename to square/shwap/p2p/discovery/backoff.go diff --git a/share/shwap/p2p/discovery/backoff_test.go b/square/shwap/p2p/discovery/backoff_test.go similarity index 100% rename from share/shwap/p2p/discovery/backoff_test.go rename to square/shwap/p2p/discovery/backoff_test.go diff --git a/share/shwap/p2p/discovery/dht.go b/square/shwap/p2p/discovery/dht.go similarity index 100% rename from share/shwap/p2p/discovery/dht.go rename to square/shwap/p2p/discovery/dht.go diff --git a/share/shwap/p2p/discovery/discovery.go b/square/shwap/p2p/discovery/discovery.go similarity index 100% rename from share/shwap/p2p/discovery/discovery.go rename to square/shwap/p2p/discovery/discovery.go diff --git a/share/shwap/p2p/discovery/discovery_test.go b/square/shwap/p2p/discovery/discovery_test.go similarity index 100% rename from share/shwap/p2p/discovery/discovery_test.go rename to square/shwap/p2p/discovery/discovery_test.go diff --git a/share/shwap/p2p/discovery/metrics.go b/square/shwap/p2p/discovery/metrics.go similarity index 100% rename from share/shwap/p2p/discovery/metrics.go rename to square/shwap/p2p/discovery/metrics.go diff --git a/share/shwap/p2p/discovery/options.go b/square/shwap/p2p/discovery/options.go similarity index 100% rename from share/shwap/p2p/discovery/options.go rename to square/shwap/p2p/discovery/options.go diff --git a/share/shwap/p2p/discovery/set.go b/square/shwap/p2p/discovery/set.go similarity index 100% rename from share/shwap/p2p/discovery/set.go rename to square/shwap/p2p/discovery/set.go diff --git a/share/shwap/p2p/discovery/set_test.go b/square/shwap/p2p/discovery/set_test.go similarity index 100% rename from share/shwap/p2p/discovery/set_test.go rename to square/shwap/p2p/discovery/set_test.go diff --git a/share/shwap/p2p/shrex/doc.go b/square/shwap/p2p/shrex/doc.go similarity index 100% rename from share/shwap/p2p/shrex/doc.go rename to square/shwap/p2p/shrex/doc.go diff --git a/share/shwap/p2p/shrex/error.go b/square/shwap/p2p/shrex/error.go similarity index 100% rename from share/shwap/p2p/shrex/error.go rename to square/shwap/p2p/shrex/error.go diff --git a/share/shwap/p2p/shrex/error_test.go b/square/shwap/p2p/shrex/error_test.go similarity index 100% rename from share/shwap/p2p/shrex/error_test.go rename to square/shwap/p2p/shrex/error_test.go diff --git a/share/shwap/p2p/shrex/errors.go b/square/shwap/p2p/shrex/errors.go similarity index 100% rename from share/shwap/p2p/shrex/errors.go rename to square/shwap/p2p/shrex/errors.go diff --git a/share/shwap/p2p/shrex/metrics.go b/square/shwap/p2p/shrex/metrics.go similarity index 100% rename from share/shwap/p2p/shrex/metrics.go rename to square/shwap/p2p/shrex/metrics.go diff --git a/share/shwap/p2p/shrex/middleware.go b/square/shwap/p2p/shrex/middleware.go similarity index 100% rename from share/shwap/p2p/shrex/middleware.go rename to square/shwap/p2p/shrex/middleware.go diff --git a/share/shwap/p2p/shrex/params.go b/square/shwap/p2p/shrex/params.go similarity index 100% rename from share/shwap/p2p/shrex/params.go rename to square/shwap/p2p/shrex/params.go diff --git a/share/shwap/p2p/shrex/pb/shrex.pb.go b/square/shwap/p2p/shrex/pb/shrex.pb.go similarity index 81% rename from share/shwap/p2p/shrex/pb/shrex.pb.go rename to square/shwap/p2p/shrex/pb/shrex.pb.go index 88322b1985..48171b5135 100644 --- a/share/shwap/p2p/shrex/pb/shrex.pb.go +++ b/square/shwap/p2p/shrex/pb/shrex.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: share/shwap/p2p/shrex/pb/shrex.proto +// source: square/shwap/p2p/shrex/pb/shrex.proto package pb @@ -50,7 +50,7 @@ func (x Status) String() string { } func (Status) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_68dfd78ade756110, []int{0} + return fileDescriptor_ade548694c6c6a45, []int{0} } type Response struct { @@ -61,7 +61,7 @@ func (m *Response) Reset() { *m = Response{} } func (m *Response) String() string { return proto.CompactTextString(m) } func (*Response) ProtoMessage() {} func (*Response) Descriptor() ([]byte, []int) { - return fileDescriptor_68dfd78ade756110, []int{0} + return fileDescriptor_ade548694c6c6a45, []int{0} } func (m *Response) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -103,25 +103,25 @@ func init() { } func init() { - proto.RegisterFile("share/shwap/p2p/shrex/pb/shrex.proto", fileDescriptor_68dfd78ade756110) + proto.RegisterFile("square/shwap/p2p/shrex/pb/shrex.proto", fileDescriptor_ade548694c6c6a45) } -var fileDescriptor_68dfd78ade756110 = []byte{ +var fileDescriptor_ade548694c6c6a45 = []byte{ // 218 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x29, 0xce, 0x48, 0x2c, - 0x4a, 0xd5, 0x2f, 0xce, 0x28, 0x4f, 0x2c, 0xd0, 0x2f, 0x30, 0x2a, 0xd0, 0x2f, 0xce, 0x28, 0x4a, - 0xad, 0xd0, 0x2f, 0x48, 0x82, 0x30, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x95, 0xb4, 0xb9, 0x38, - 0x82, 0x52, 0x8b, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, 0x85, 0xe4, 0xb9, 0xd8, 0x8a, 0x4b, 0x12, 0x4b, - 0x4a, 0x8b, 0x25, 0x18, 0x15, 0x18, 0x35, 0xf8, 0x8c, 0xd8, 0xf5, 0x82, 0xc1, 0xdc, 0x20, 0xa8, - 0xb0, 0x96, 0x15, 0x17, 0x1b, 0x44, 0x44, 0x88, 0x9b, 0x8b, 0xdd, 0xd3, 0x2f, 0xcc, 0xd1, 0xc7, - 0xd3, 0x45, 0x80, 0x41, 0x88, 0x8d, 0x8b, 0xc9, 0xdf, 0x5b, 0x80, 0x51, 0x88, 0x97, 0x8b, 0xd3, - 0xcf, 0x3f, 0x24, 0xde, 0xcd, 0x3f, 0xd4, 0xcf, 0x45, 0x80, 0x49, 0x88, 0x87, 0x8b, 0xc3, 0xd3, - 0x2f, 0xc4, 0x35, 0xc8, 0xcf, 0xd1, 0x47, 0x80, 0xd9, 0x29, 0xfc, 0xc4, 0x23, 0x39, 0xc6, 0x0b, - 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, - 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x6c, 0xd3, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, - 0xf5, 0x93, 0x53, 0x73, 0x52, 0x8b, 0x4b, 0x32, 0x13, 0xf3, 0x8b, 0xd2, 0xe1, 0x6c, 0xdd, 0xbc, - 0xfc, 0x14, 0x90, 0x3f, 0xb0, 0xfb, 0x26, 0x89, 0x0d, 0xec, 0x11, 0x63, 0x40, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xd8, 0xb0, 0x4b, 0x58, 0xf0, 0x00, 0x00, 0x00, + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2d, 0x2e, 0x2c, 0x4d, + 0x2c, 0x4a, 0xd5, 0x2f, 0xce, 0x28, 0x4f, 0x2c, 0xd0, 0x2f, 0x30, 0x2a, 0xd0, 0x2f, 0xce, 0x28, + 0x4a, 0xad, 0xd0, 0x2f, 0x48, 0x82, 0x30, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x95, 0xb4, 0xb9, + 0x38, 0x82, 0x52, 0x8b, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, 0x85, 0xe4, 0xb9, 0xd8, 0x8a, 0x4b, 0x12, + 0x4b, 0x4a, 0x8b, 0x25, 0x18, 0x15, 0x18, 0x35, 0xf8, 0x8c, 0xd8, 0xf5, 0x82, 0xc1, 0xdc, 0x20, + 0xa8, 0xb0, 0x96, 0x15, 0x17, 0x1b, 0x44, 0x44, 0x88, 0x9b, 0x8b, 0xdd, 0xd3, 0x2f, 0xcc, 0xd1, + 0xc7, 0xd3, 0x45, 0x80, 0x41, 0x88, 0x8d, 0x8b, 0xc9, 0xdf, 0x5b, 0x80, 0x51, 0x88, 0x97, 0x8b, + 0xd3, 0xcf, 0x3f, 0x24, 0xde, 0xcd, 0x3f, 0xd4, 0xcf, 0x45, 0x80, 0x49, 0x88, 0x87, 0x8b, 0xc3, + 0xd3, 0x2f, 0xc4, 0x35, 0xc8, 0xcf, 0xd1, 0x47, 0x80, 0xd9, 0x29, 0xe2, 0xc4, 0x23, 0x39, 0xc6, + 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, + 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0xec, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, + 0x73, 0xf5, 0x93, 0x53, 0x73, 0x52, 0x8b, 0x4b, 0x32, 0x13, 0xf3, 0x8b, 0xd2, 0xe1, 0x6c, 0xdd, + 0xbc, 0xfc, 0x94, 0x54, 0x7d, 0x9c, 0xde, 0x49, 0x62, 0x03, 0xfb, 0xc4, 0x18, 0x10, 0x00, 0x00, + 0xff, 0xff, 0x5d, 0x99, 0xc5, 0x28, 0xf2, 0x00, 0x00, 0x00, } func (m *Response) Marshal() (dAtA []byte, err error) { diff --git a/share/shwap/p2p/shrex/pb/shrex.proto b/square/shwap/p2p/shrex/pb/shrex.proto similarity index 69% rename from share/shwap/p2p/shrex/pb/shrex.proto rename to square/shwap/p2p/shrex/pb/shrex.proto index 7b3a57227d..0dac0f433b 100644 --- a/share/shwap/p2p/shrex/pb/shrex.proto +++ b/square/shwap/p2p/shrex/pb/shrex.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -option go_package = "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/pb"; +option go_package = "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/pb"; enum Status { INVALID = 0; diff --git a/share/shwap/p2p/shrex/peers/doc.go b/square/shwap/p2p/shrex/peers/doc.go similarity index 100% rename from share/shwap/p2p/shrex/peers/doc.go rename to square/shwap/p2p/shrex/peers/doc.go diff --git a/share/shwap/p2p/shrex/peers/manager.go b/square/shwap/p2p/shrex/peers/manager.go similarity index 97% rename from share/shwap/p2p/shrex/peers/manager.go rename to square/shwap/p2p/shrex/peers/manager.go index 857c5ee937..9c77496932 100644 --- a/share/shwap/p2p/shrex/peers/manager.go +++ b/square/shwap/p2p/shrex/peers/manager.go @@ -20,8 +20,8 @@ import ( libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" ) const ( @@ -202,7 +202,7 @@ func (m *Manager) Stop(ctx context.Context) error { // nodes, it will wait until any peer appear in either source or timeout happen. // After fetching data using given peer, caller is required to call returned DoneFunc using // appropriate result value -func (m *Manager) Peer(ctx context.Context, datahash share.DataHash, height uint64, +func (m *Manager) Peer(ctx context.Context, datahash square.DataHash, height uint64, ) (peer.ID, DoneFunc, error) { p := m.validatedPool(datahash.String(), height) @@ -255,7 +255,7 @@ func (m *Manager) UpdateNodePool(peerID peer.ID, isAdded bool) { func (m *Manager) newPeer( ctx context.Context, - datahash share.DataHash, + datahash square.DataHash, peerID peer.ID, source peerSource, poolSize int, @@ -271,7 +271,7 @@ func (m *Manager) newPeer( return peerID, m.doneFunc(datahash, peerID, source), nil } -func (m *Manager) doneFunc(datahash share.DataHash, peerID peer.ID, source peerSource) DoneFunc { +func (m *Manager) doneFunc(datahash square.DataHash, peerID peer.ID, source peerSource) DoneFunc { return func(result result) { log.Debugw("set peer result", "hash", datahash.String(), @@ -437,7 +437,7 @@ func (m *Manager) isBlacklistedPeer(peerID peer.ID) bool { return !m.connGater.InterceptPeerDial(peerID) } -func (m *Manager) isBlacklistedHash(hash share.DataHash) bool { +func (m *Manager) isBlacklistedHash(hash square.DataHash) bool { m.lock.Lock() defer m.lock.Unlock() return m.blacklistedHashes[hash.String()] diff --git a/share/shwap/p2p/shrex/peers/manager_test.go b/square/shwap/p2p/shrex/peers/manager_test.go similarity index 97% rename from share/shwap/p2p/shrex/peers/manager_test.go rename to square/shwap/p2p/shrex/peers/manager_test.go index c18a2c340c..3dbf242841 100644 --- a/share/shwap/p2p/shrex/peers/manager_test.go +++ b/square/shwap/p2p/shrex/peers/manager_test.go @@ -21,9 +21,9 @@ import ( libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/discovery" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/discovery" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" ) func TestManager(t *testing.T) { @@ -127,13 +127,13 @@ func TestManager(t *testing.T) { // create unvalidated pool peerID := peer.ID("peer1") msg := shrexsub.Notification{ - DataHash: share.DataHash("datahash1datahash1datahash1datahash1datahash1"), + DataHash: square.DataHash("datahash1datahash1datahash1datahash1datahash1"), Height: 2, } manager.Validate(ctx, peerID, msg) // create validated pool - validDataHash := share.DataHash("datahash2") + validDataHash := square.DataHash("datahash2") manager.nodes.add("full") // add FN to unblock Peer call manager.Peer(ctx, validDataHash, h.Height()) //nolint:errcheck require.Len(t, manager.pools, 3) @@ -237,7 +237,7 @@ func TestManager(t *testing.T) { // create shrexSub msg with height lower than first header from headerSub msg := shrexsub.Notification{ - DataHash: share.DataHash("datahash"), + DataHash: square.DataHash("datahash"), Height: h.Height() - 1, } result := manager.Validate(ctx, "peer", msg) @@ -265,7 +265,7 @@ func TestManager(t *testing.T) { // create shrexSub msg with height lower than first header from headerSub msg := shrexsub.Notification{ - DataHash: share.DataHash("datahash"), + DataHash: square.DataHash("datahash"), Height: h.Height() - 1, } result := manager.Validate(ctx, "peer", msg) @@ -308,7 +308,7 @@ func TestManager(t *testing.T) { // create shrexSub msg with height lower than storedPoolsAmount msg := shrexsub.Notification{ - DataHash: share.DataHash("datahash"), + DataHash: square.DataHash("datahash"), Height: h.Height() - storedPoolsAmount - 3, } result := manager.Validate(ctx, "peer", msg) diff --git a/share/shwap/p2p/shrex/peers/metrics.go b/square/shwap/p2p/shrex/peers/metrics.go similarity index 99% rename from share/shwap/p2p/shrex/peers/metrics.go rename to square/shwap/p2p/shrex/peers/metrics.go index d401d6a4fc..67bdb5caf0 100644 --- a/share/shwap/p2p/shrex/peers/metrics.go +++ b/square/shwap/p2p/shrex/peers/metrics.go @@ -13,7 +13,7 @@ import ( "go.opentelemetry.io/otel/metric" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" ) const ( diff --git a/share/shwap/p2p/shrex/peers/options.go b/square/shwap/p2p/shrex/peers/options.go similarity index 97% rename from share/shwap/p2p/shrex/peers/options.go rename to square/shwap/p2p/shrex/peers/options.go index e268550853..7a4a5e10cf 100644 --- a/share/shwap/p2p/shrex/peers/options.go +++ b/square/shwap/p2p/shrex/peers/options.go @@ -7,7 +7,7 @@ import ( libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" ) type Parameters struct { diff --git a/share/shwap/p2p/shrex/peers/pool.go b/square/shwap/p2p/shrex/peers/pool.go similarity index 100% rename from share/shwap/p2p/shrex/peers/pool.go rename to square/shwap/p2p/shrex/peers/pool.go diff --git a/share/shwap/p2p/shrex/peers/pool_test.go b/square/shwap/p2p/shrex/peers/pool_test.go similarity index 100% rename from share/shwap/p2p/shrex/peers/pool_test.go rename to square/shwap/p2p/shrex/peers/pool_test.go diff --git a/share/shwap/p2p/shrex/peers/timedqueue.go b/square/shwap/p2p/shrex/peers/timedqueue.go similarity index 100% rename from share/shwap/p2p/shrex/peers/timedqueue.go rename to square/shwap/p2p/shrex/peers/timedqueue.go diff --git a/share/shwap/p2p/shrex/peers/timedqueue_test.go b/square/shwap/p2p/shrex/peers/timedqueue_test.go similarity index 100% rename from share/shwap/p2p/shrex/peers/timedqueue_test.go rename to square/shwap/p2p/shrex/peers/timedqueue_test.go diff --git a/share/shwap/p2p/shrex/recovery.go b/square/shwap/p2p/shrex/recovery.go similarity index 100% rename from share/shwap/p2p/shrex/recovery.go rename to square/shwap/p2p/shrex/recovery.go diff --git a/share/shwap/p2p/shrex/shrex_getter/shrex.go b/square/shwap/p2p/shrex/shrex_getter/shrex.go similarity index 92% rename from share/shwap/p2p/shrex/shrex_getter/shrex.go rename to square/shwap/p2p/shrex/shrex_getter/shrex.go index 6d9d25115f..099d62272e 100644 --- a/share/shwap/p2p/shrex/shrex_getter/shrex.go +++ b/square/shwap/p2p/shrex/shrex_getter/shrex.go @@ -13,17 +13,18 @@ import ( "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/libs/utils" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/peers" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexeds" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexnd" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/peers" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexeds" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexnd" ) var ( @@ -146,7 +147,7 @@ func (sg *Getter) Stop(ctx context.Context) error { } func (sg *Getter) GetShare(context.Context, *header.ExtendedHeader, int, int) (share.Share, error) { - return nil, fmt.Errorf("getter/shrex: GetShare %w", shwap.ErrOperationNotSupported) + return share.Share{}, fmt.Errorf("getter/shrex: GetShare %w", shwap.ErrOperationNotSupported) } func (sg *Getter) GetEDS(ctx context.Context, header *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) { @@ -157,8 +158,8 @@ func (sg *Getter) GetEDS(ctx context.Context, header *header.ExtendedHeader) (*r }() // short circuit if the data root is empty - if header.DAH.Equals(share.EmptyEDSRoots()) { - return share.EmptyEDS(), nil + if header.DAH.Equals(square.EmptyEDSRoots()) { + return square.EmptyEDS(), nil } var attempt int @@ -218,7 +219,7 @@ func (sg *Getter) GetSharesByNamespace( header *header.ExtendedHeader, namespace share.Namespace, ) (shwap.NamespaceData, error) { - if err := namespace.ValidateForData(); err != nil { + if err := share.ValidateForData(namespace); err != nil { return nil, err } var ( @@ -234,7 +235,7 @@ func (sg *Getter) GetSharesByNamespace( // verify that the namespace could exist inside the roots before starting network requests dah := header.DAH - rowIdxs := share.RowsWithNamespace(dah, namespace) + rowIdxs := square.RowsWithNamespace(dah, namespace) if len(rowIdxs) == 0 { return shwap.NamespaceData{}, nil } diff --git a/share/shwap/p2p/shrex/shrex_getter/shrex_test.go b/square/shwap/p2p/shrex/shrex_getter/shrex_test.go similarity index 77% rename from share/shwap/p2p/shrex/shrex_getter/shrex_test.go rename to square/shwap/p2p/shrex/shrex_getter/shrex_test.go index 05dc01103c..908ac7f2bd 100644 --- a/share/shwap/p2p/shrex/shrex_getter/shrex_test.go +++ b/square/shwap/p2p/shrex/shrex_getter/shrex_test.go @@ -17,6 +17,7 @@ import ( "github.com/stretchr/testify/require" libhead "github.com/celestiaorg/go-header" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" @@ -24,14 +25,13 @@ import ( "github.com/celestiaorg/celestia-node/header/headertest" "github.com/celestiaorg/celestia-node/pruner/full" "github.com/celestiaorg/celestia-node/pruner/light" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/sharetest" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/peers" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexeds" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexnd" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/peers" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexeds" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexnd" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" "github.com/celestiaorg/celestia-node/store" ) @@ -71,7 +71,7 @@ func TestShrexGetter(t *testing.T) { // generate test data size := 64 - namespace := sharetest.RandV0Namespace() + namespace := share.RandomNamespace() height := height.Add(1) randEDS, roots := edstest.RandEDSWithNamespace(t, namespace, size*size, size) eh := headertest.RandExtendedHeaderWithRoot(t, roots) @@ -126,10 +126,10 @@ func TestShrexGetter(t *testing.T) { }) // namespace inside root range - nID, err := addToNamespace(maxNamespace, -1) + nID, err := share.AddInt(maxNamespace, -1) require.NoError(t, err) // check for namespace to be between max and min namespace in root - require.Len(t, share.RowsWithNamespace(roots, nID), 1) + require.Len(t, square.RowsWithNamespace(roots, nID), 1) emptyShares, err := getter.GetSharesByNamespace(ctx, eh, nID) require.NoError(t, err) @@ -138,10 +138,10 @@ func TestShrexGetter(t *testing.T) { require.Nil(t, emptyShares.Verify(roots, nID)) // namespace outside root range - nID, err = addToNamespace(maxNamespace, 1) + nID, err = share.AddInt(maxNamespace, 1) require.NoError(t, err) // check for namespace to be not in root - require.Len(t, share.RowsWithNamespace(roots, nID), 0) + require.Len(t, square.RowsWithNamespace(roots, nID), 0) emptyShares, err = getter.GetSharesByNamespace(ctx, eh, nID) require.NoError(t, err) @@ -167,10 +167,10 @@ func TestShrexGetter(t *testing.T) { Height: height, }) - namespace, err := addToNamespace(maxNamespace, 1) + namespace, err := share.AddInt(maxNamespace, 1) require.NoError(t, err) // check for namespace to be not in root - require.Len(t, share.RowsWithNamespace(roots, namespace), 0) + require.Len(t, square.RowsWithNamespace(roots, namespace), 0) emptyShares, err := getter.GetSharesByNamespace(ctx, eh, namespace) require.NoError(t, err) @@ -277,12 +277,14 @@ func newStore(t *testing.T) (*store.Store, error) { return store.NewStore(store.DefaultParameters(), t.TempDir()) } -func generateTestEDS(t *testing.T) (*rsmt2d.ExtendedDataSquare, *share.AxisRoots, share.Namespace) { +func generateTestEDS(t *testing.T) (*rsmt2d.ExtendedDataSquare, *square.AxisRoots, share.Namespace) { eds := edstest.RandEDS(t, 4) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) max := nmt.MaxNamespace(roots.RowRoots[(len(roots.RowRoots))/2-1], share.NamespaceSize) - return eds, roots, max + ns, err := share.NewNamespaceFromBytes(max) + require.NoError(t, err) + return eds, roots, ns } func testManager( @@ -354,21 +356,21 @@ func addToNamespace(namespace share.Namespace, val int) (share.Namespace, error) return namespace, nil } // Convert the input integer to a byte slice and add it to result slice - result := make([]byte, len(namespace)) + result := make([]byte, namespace.Len()) if val > 0 { - binary.BigEndian.PutUint64(result[len(namespace)-8:], uint64(val)) + binary.BigEndian.PutUint64(result[namespace.Len()-8:], uint64(val)) } else { - binary.BigEndian.PutUint64(result[len(namespace)-8:], uint64(-val)) + binary.BigEndian.PutUint64(result[namespace.Len()-8:], uint64(-val)) } // Perform addition byte by byte var carry int - for i := len(namespace) - 1; i >= 0; i-- { + for i := namespace.Len() - 1; i >= 0; i-- { var sum int if val > 0 { - sum = int(namespace[i]) + int(result[i]) + carry + sum = int(namespace.Bytes()[i]) + int(result[i]) + carry } else { - sum = int(namespace[i]) - int(result[i]) + carry + sum = int(namespace.Bytes()[i]) - int(result[i]) + carry } switch { @@ -387,62 +389,8 @@ func addToNamespace(namespace share.Namespace, val int) (share.Namespace, error) // Handle any remaining carry if carry != 0 { - return nil, errors.New("namespace overflow") + return share.Namespace{}, errors.New("namespace overflow") } - return result, nil -} - -func TestAddToNamespace(t *testing.T) { - testCases := []struct { - name string - value int - input share.Namespace - expected share.Namespace - expectedError error - }{ - { - name: "Positive value addition", - value: 42, - input: share.Namespace{0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}, - expected: share.Namespace{0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x2b}, - expectedError: nil, - }, - { - name: "Negative value addition", - value: -42, - input: share.Namespace{0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}, - expected: share.Namespace{0x1, 0x1, 0x1, 0x1, 0x1, 0x01, 0x1, 0x1, 0x1, 0x0, 0xd7}, - expectedError: nil, - }, - { - name: "Overflow error", - value: 1, - input: share.Namespace{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, - expected: nil, - expectedError: errors.New("namespace overflow"), - }, - { - name: "Overflow error negative", - value: -1, - input: share.Namespace{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, - expected: nil, - expectedError: errors.New("namespace overflow"), - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - result, err := addToNamespace(tc.input, tc.value) - if tc.expectedError == nil { - require.NoError(t, err) - require.Equal(t, tc.expected, result) - return - } - require.Error(t, err) - if err.Error() != tc.expectedError.Error() { - t.Errorf("Unexpected error message. Expected: %v, Got: %v", tc.expectedError, err) - } - }) - } + return share.NewNamespaceFromBytes(result) } diff --git a/share/shwap/p2p/shrex/shrexeds/client.go b/square/shwap/p2p/shrex/shrexeds/client.go similarity index 93% rename from share/shwap/p2p/shrex/shrexeds/client.go rename to square/shwap/p2p/shrex/shrexeds/client.go index 5239c407f9..88038f568b 100644 --- a/share/shwap/p2p/shrex/shrexeds/client.go +++ b/square/shwap/p2p/shrex/shrexeds/client.go @@ -17,11 +17,11 @@ import ( "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" - shrexpb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/pb" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" + shrexpb "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/pb" ) // Client is responsible for requesting EDSs for blocksync over the ShrEx/EDS protocol. @@ -49,7 +49,7 @@ func NewClient(params *Parameters, host host.Host) (*Client, error) { // RequestEDS requests the ODS from the given peers and returns the EDS upon success. func (c *Client) RequestEDS( ctx context.Context, - root *share.AxisRoots, + root *square.AxisRoots, height uint64, peer peer.ID, ) (*rsmt2d.ExtendedDataSquare, error) { @@ -86,7 +86,7 @@ func (c *Client) RequestEDS( func (c *Client) doRequest( ctx context.Context, - root *share.AxisRoots, + root *square.AxisRoots, height uint64, to peer.ID, ) (*rsmt2d.ExtendedDataSquare, error) { diff --git a/share/shwap/p2p/shrex/shrexeds/doc.go b/square/shwap/p2p/shrex/shrexeds/doc.go similarity index 100% rename from share/shwap/p2p/shrex/shrexeds/doc.go rename to square/shwap/p2p/shrex/shrexeds/doc.go diff --git a/share/shwap/p2p/shrex/shrexeds/exchange_test.go b/square/shwap/p2p/shrex/shrexeds/exchange_test.go similarity index 90% rename from share/shwap/p2p/shrex/shrexeds/exchange_test.go rename to square/shwap/p2p/shrex/shrexeds/exchange_test.go index 89e1dafa1c..76e3e2e2ee 100644 --- a/share/shwap/p2p/shrex/shrexeds/exchange_test.go +++ b/square/shwap/p2p/shrex/shrexeds/exchange_test.go @@ -12,10 +12,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" "github.com/celestiaorg/celestia-node/store" ) @@ -30,7 +30,7 @@ func TestExchange_RequestEDS(t *testing.T) { // Testcase: EDS is immediately available t.Run("EDS_Available", func(t *testing.T) { eds := edstest.RandEDS(t, 4) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) height := uint64(1) err = store.PutODSQ4(ctx, roots, height, eds) @@ -44,7 +44,7 @@ func TestExchange_RequestEDS(t *testing.T) { // Testcase: EDS is unavailable initially, but is found after multiple requests t.Run("EDS_AvailableAfterDelay", func(t *testing.T) { eds := edstest.RandEDS(t, 4) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) height := uint64(666) @@ -72,7 +72,7 @@ func TestExchange_RequestEDS(t *testing.T) { // Testcase: Invalid request excludes peer from round-robin, stopping request t.Run("EDS_InvalidRequest", func(t *testing.T) { - emptyRoot := share.EmptyEDSRoots() + emptyRoot := square.EmptyEDSRoots() height := uint64(0) requestedEDS, err := client.RequestEDS(ctx, emptyRoot, height, server.host.ID()) assert.ErrorIs(t, err, shwap.ErrInvalidID) @@ -83,7 +83,7 @@ func TestExchange_RequestEDS(t *testing.T) { timeoutCtx, cancel := context.WithTimeout(ctx, time.Second) t.Cleanup(cancel) eds := edstest.RandEDS(t, 4) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) height := uint64(668) _, err = client.RequestEDS(timeoutCtx, roots, height, server.host.ID()) @@ -119,7 +119,7 @@ func TestExchange_RequestEDS(t *testing.T) { middleware.RateLimitHandler(mockHandler)) // take server concurrency slots with blocked requests - emptyRoot := share.EmptyEDSRoots() + emptyRoot := square.EmptyEDSRoots() for i := 0; i < rateLimit; i++ { go func(i int) { client.RequestEDS(ctx, emptyRoot, 1, server.host.ID()) //nolint:errcheck diff --git a/share/shwap/p2p/shrex/shrexeds/params.go b/square/shwap/p2p/shrex/shrexeds/params.go similarity index 90% rename from share/shwap/p2p/shrex/shrexeds/params.go rename to square/shwap/p2p/shrex/shrexeds/params.go index c5d76fecb2..d3f46a1fd3 100644 --- a/share/shwap/p2p/shrex/shrexeds/params.go +++ b/square/shwap/p2p/shrex/shrexeds/params.go @@ -5,8 +5,8 @@ import ( logging "github.com/ipfs/go-log/v2" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" ) const protocolString = shrex.ProtocolString + shwap.EDSName diff --git a/share/shwap/p2p/shrex/shrexeds/server.go b/square/shwap/p2p/shrex/shrexeds/server.go similarity index 95% rename from share/shwap/p2p/shrex/shrexeds/server.go rename to square/shwap/p2p/shrex/shrexeds/server.go index 0367e7d82e..296acc6051 100644 --- a/share/shwap/p2p/shrex/shrexeds/server.go +++ b/square/shwap/p2p/shrex/shrexeds/server.go @@ -15,10 +15,10 @@ import ( "github.com/celestiaorg/go-libp2p-messenger/serde" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" - shrexpb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/pb" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" + shrexpb "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/pb" "github.com/celestiaorg/celestia-node/store" ) diff --git a/share/shwap/p2p/shrex/shrexnd/client.go b/square/shwap/p2p/shrex/shrexnd/client.go similarity index 94% rename from share/shwap/p2p/shrex/shrexnd/client.go rename to square/shwap/p2p/shrex/shrexnd/client.go index a7029a348a..b9fe86d14c 100644 --- a/share/shwap/p2p/shrex/shrexnd/client.go +++ b/square/shwap/p2p/shrex/shrexnd/client.go @@ -14,12 +14,12 @@ import ( "github.com/libp2p/go-libp2p/core/protocol" "github.com/celestiaorg/go-libp2p-messenger/serde" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" - shrexpb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/pb" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" + shrexpb "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/pb" ) // Client implements client side of shrex/nd protocol to obtain namespaced shares data from remote @@ -53,7 +53,7 @@ func (c *Client) RequestND( namespace share.Namespace, peer peer.ID, ) (shwap.NamespaceData, error) { - if err := namespace.ValidateForData(); err != nil { + if err := share.ValidateForData(namespace); err != nil { return nil, err } diff --git a/share/shwap/p2p/shrex/shrexnd/doc.go b/square/shwap/p2p/shrex/shrexnd/doc.go similarity index 100% rename from share/shwap/p2p/shrex/shrexnd/doc.go rename to square/shwap/p2p/shrex/shrexnd/doc.go diff --git a/share/shwap/p2p/shrex/shrexnd/exchange_test.go b/square/shwap/p2p/shrex/shrexnd/exchange_test.go similarity index 85% rename from share/shwap/p2p/shrex/shrexnd/exchange_test.go rename to square/shwap/p2p/shrex/shrexnd/exchange_test.go index 81abdfba26..ea2e07eb06 100644 --- a/share/shwap/p2p/shrex/shrexnd/exchange_test.go +++ b/square/shwap/p2p/shrex/shrexnd/exchange_test.go @@ -12,10 +12,11 @@ import ( mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/sharetest" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" "github.com/celestiaorg/celestia-node/store" ) @@ -32,7 +33,7 @@ func TestExchange_RequestND_NotFound(t *testing.T) { ctx, cancel := context.WithTimeout(ctx, time.Second) t.Cleanup(cancel) - namespace := sharetest.RandV0Namespace() + namespace := share.RandomNamespace() height := height.Add(1) _, err := client.RequestND(ctx, height, namespace, server.host.ID()) require.ErrorIs(t, err, shrex.ErrNotFound) @@ -43,14 +44,14 @@ func TestExchange_RequestND_NotFound(t *testing.T) { t.Cleanup(cancel) eds := edstest.RandEDS(t, 4) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) height := height.Add(1) err = edsStore.PutODSQ4(ctx, roots, height, eds) require.NoError(t, err) - namespace := sharetest.RandV0Namespace() + namespace := share.RandomNamespace() emptyShares, err := client.RequestND(ctx, height, namespace, server.host.ID()) require.NoError(t, err) require.Empty(t, emptyShares.Flatten()) @@ -94,13 +95,13 @@ func TestExchange_RequestND(t *testing.T) { // take server concurrency slots with blocked requests for i := 0; i < rateLimit; i++ { go func(i int) { - client.RequestND(ctx, 1, sharetest.RandV0Namespace(), server.host.ID()) //nolint:errcheck + client.RequestND(ctx, 1, share.RandomNamespace(), server.host.ID()) //nolint:errcheck }(i) } // wait until all server slots are taken wg.Wait() - _, err = client.RequestND(ctx, 1, sharetest.RandV0Namespace(), server.host.ID()) + _, err = client.RequestND(ctx, 1, share.RandomNamespace(), server.host.ID()) require.ErrorIs(t, err, shrex.ErrRateLimited) }) } diff --git a/share/shwap/p2p/shrex/shrexnd/params.go b/square/shwap/p2p/shrex/shrexnd/params.go similarity index 87% rename from share/shwap/p2p/shrex/shrexnd/params.go rename to square/shwap/p2p/shrex/shrexnd/params.go index 5544ae6b27..6003921c1e 100644 --- a/share/shwap/p2p/shrex/shrexnd/params.go +++ b/square/shwap/p2p/shrex/shrexnd/params.go @@ -5,8 +5,8 @@ import ( logging "github.com/ipfs/go-log/v2" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" ) const protocolString = shrex.ProtocolString + shwap.NamespaceDataName diff --git a/share/shwap/p2p/shrex/shrexnd/server.go b/square/shwap/p2p/shrex/shrexnd/server.go similarity index 96% rename from share/shwap/p2p/shrex/shrexnd/server.go rename to square/shwap/p2p/shrex/shrexnd/server.go index 0193c91ae1..20a7098b74 100644 --- a/share/shwap/p2p/shrex/shrexnd/server.go +++ b/square/shwap/p2p/shrex/shrexnd/server.go @@ -14,10 +14,10 @@ import ( "github.com/celestiaorg/go-libp2p-messenger/serde" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" - "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" - shrexpb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/pb" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" + shrexpb "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/pb" "github.com/celestiaorg/celestia-node/store" ) diff --git a/share/shwap/p2p/shrex/shrexsub/doc.go b/square/shwap/p2p/shrex/shrexsub/doc.go similarity index 100% rename from share/shwap/p2p/shrex/shrexsub/doc.go rename to square/shwap/p2p/shrex/shrexsub/doc.go diff --git a/share/shwap/p2p/shrex/shrexsub/pb/notification.pb.go b/square/shwap/p2p/shrex/shrexsub/pb/notification.pb.go similarity index 84% rename from share/shwap/p2p/shrex/shrexsub/pb/notification.pb.go rename to square/shwap/p2p/shrex/shrexsub/pb/notification.pb.go index c7cddbba5c..a04cbc56ac 100644 --- a/share/shwap/p2p/shrex/shrexsub/pb/notification.pb.go +++ b/square/shwap/p2p/shrex/shrexsub/pb/notification.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: share/shwap/p2p/shrex/shrexsub/pb/notification.proto +// source: square/shwap/p2p/shrex/shrexsub/pb/notification.proto package share_p2p_shrex_sub @@ -31,7 +31,7 @@ func (m *RecentEDSNotification) Reset() { *m = RecentEDSNotification{} } func (m *RecentEDSNotification) String() string { return proto.CompactTextString(m) } func (*RecentEDSNotification) ProtoMessage() {} func (*RecentEDSNotification) Descriptor() ([]byte, []int) { - return fileDescriptor_c16b670e7e556100, []int{0} + return fileDescriptor_3a5bf8ca81a1e1ac, []int{0} } func (m *RecentEDSNotification) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -79,23 +79,23 @@ func init() { } func init() { - proto.RegisterFile("share/shwap/p2p/shrex/shrexsub/pb/notification.proto", fileDescriptor_c16b670e7e556100) + proto.RegisterFile("square/shwap/p2p/shrex/shrexsub/pb/notification.proto", fileDescriptor_3a5bf8ca81a1e1ac) } -var fileDescriptor_c16b670e7e556100 = []byte{ - // 183 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x29, 0xce, 0x48, 0x2c, - 0x4a, 0xd5, 0x2f, 0xce, 0x28, 0x4f, 0x2c, 0xd0, 0x2f, 0x30, 0x2a, 0xd0, 0x2f, 0xce, 0x28, 0x4a, - 0xad, 0x80, 0x90, 0xc5, 0xa5, 0x49, 0xfa, 0x05, 0x49, 0xfa, 0x79, 0xf9, 0x25, 0x99, 0x69, 0x99, - 0xc9, 0x89, 0x25, 0x99, 0xf9, 0x79, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xc2, 0x60, 0x5d, - 0x7a, 0x05, 0x46, 0x05, 0x7a, 0x60, 0x95, 0x7a, 0xc5, 0xa5, 0x49, 0x4a, 0x3e, 0x5c, 0xa2, 0x41, - 0xa9, 0xc9, 0xa9, 0x79, 0x25, 0xae, 0x2e, 0xc1, 0x7e, 0x48, 0x7a, 0x84, 0xc4, 0xb8, 0xd8, 0x32, - 0x52, 0x33, 0xd3, 0x33, 0x4a, 0x24, 0x18, 0x15, 0x18, 0x35, 0x58, 0x82, 0xa0, 0x3c, 0x21, 0x69, - 0x2e, 0xce, 0x94, 0xc4, 0x92, 0xc4, 0xf8, 0x8c, 0xc4, 0xe2, 0x0c, 0x09, 0x26, 0x05, 0x46, 0x0d, - 0x9e, 0x20, 0x0e, 0x90, 0x80, 0x47, 0x62, 0x71, 0x86, 0x93, 0xc4, 0x89, 0x47, 0x72, 0x8c, 0x17, - 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, - 0x37, 0x1e, 0xcb, 0x31, 0x24, 0xb1, 0x81, 0xdd, 0x60, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xc0, - 0x55, 0x8a, 0x06, 0xbb, 0x00, 0x00, 0x00, +var fileDescriptor_3a5bf8ca81a1e1ac = []byte{ + // 187 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x2d, 0x2e, 0x2c, 0x4d, + 0x2c, 0x4a, 0xd5, 0x2f, 0xce, 0x28, 0x4f, 0x2c, 0xd0, 0x2f, 0x30, 0x2a, 0xd0, 0x2f, 0xce, 0x28, + 0x4a, 0xad, 0x80, 0x90, 0xc5, 0xa5, 0x49, 0xfa, 0x05, 0x49, 0xfa, 0x79, 0xf9, 0x25, 0x99, 0x69, + 0x99, 0xc9, 0x89, 0x25, 0x99, 0xf9, 0x79, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xc2, 0xc5, + 0x19, 0x89, 0x45, 0xa9, 0x7a, 0x05, 0x46, 0x05, 0x7a, 0x60, 0x95, 0x7a, 0xc5, 0xa5, 0x49, 0x4a, + 0x3e, 0x5c, 0xa2, 0x41, 0xa9, 0xc9, 0xa9, 0x79, 0x25, 0xae, 0x2e, 0xc1, 0x7e, 0x48, 0x7a, 0x84, + 0xc4, 0xb8, 0xd8, 0x32, 0x52, 0x33, 0xd3, 0x33, 0x4a, 0x24, 0x18, 0x15, 0x18, 0x35, 0x58, 0x82, + 0xa0, 0x3c, 0x21, 0x69, 0x2e, 0xce, 0x94, 0xc4, 0x92, 0xc4, 0xf8, 0x8c, 0xc4, 0xe2, 0x0c, 0x09, + 0x26, 0x05, 0x46, 0x0d, 0x9e, 0x20, 0x0e, 0x90, 0x80, 0x47, 0x62, 0x71, 0x86, 0x93, 0xc4, 0x89, + 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, + 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x24, 0xb1, 0x81, 0xdd, 0x60, 0x0c, 0x08, 0x00, + 0x00, 0xff, 0xff, 0x3f, 0x50, 0x64, 0x8f, 0xbc, 0x00, 0x00, 0x00, } func (m *RecentEDSNotification) Marshal() (dAtA []byte, err error) { diff --git a/share/shwap/p2p/shrex/shrexsub/pb/notification.proto b/square/shwap/p2p/shrex/shrexsub/pb/notification.proto similarity index 100% rename from share/shwap/p2p/shrex/shrexsub/pb/notification.proto rename to square/shwap/p2p/shrex/shrexsub/pb/notification.proto diff --git a/share/shwap/p2p/shrex/shrexsub/pubsub.go b/square/shwap/p2p/shrex/shrexsub/pubsub.go similarity index 96% rename from share/shwap/p2p/shrex/shrexsub/pubsub.go rename to square/shwap/p2p/shrex/shrexsub/pubsub.go index d1861cfe12..f2f49233a3 100644 --- a/share/shwap/p2p/shrex/shrexsub/pubsub.go +++ b/square/shwap/p2p/shrex/shrexsub/pubsub.go @@ -9,8 +9,8 @@ import ( "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/peer" - "github.com/celestiaorg/celestia-node/share" - pb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub/pb" + "github.com/celestiaorg/celestia-node/square" + pb "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub/pb" ) var log = logging.Logger("shrex-sub") @@ -30,7 +30,7 @@ type BroadcastFn func(context.Context, Notification) error // Notification is the format of message sent by Broadcaster type Notification struct { - DataHash share.DataHash + DataHash square.DataHash Height uint64 } diff --git a/share/shwap/p2p/shrex/shrexsub/pubsub_test.go b/square/shwap/p2p/shrex/shrexsub/pubsub_test.go similarity index 97% rename from share/shwap/p2p/shrex/shrexsub/pubsub_test.go rename to square/shwap/p2p/shrex/shrexsub/pubsub_test.go index 59602da29b..ecaf8519e5 100644 --- a/share/shwap/p2p/shrex/shrexsub/pubsub_test.go +++ b/square/shwap/p2p/shrex/shrexsub/pubsub_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/rand" - pb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub/pb" + pb "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub/pb" ) func TestPubSub(t *testing.T) { diff --git a/share/shwap/p2p/shrex/shrexsub/subscription.go b/square/shwap/p2p/shrex/shrexsub/subscription.go similarity index 94% rename from share/shwap/p2p/shrex/shrexsub/subscription.go rename to square/shwap/p2p/shrex/shrexsub/subscription.go index 5021f090c2..d65928e2c3 100644 --- a/share/shwap/p2p/shrex/shrexsub/subscription.go +++ b/square/shwap/p2p/shrex/shrexsub/subscription.go @@ -6,7 +6,7 @@ import ( pubsub "github.com/libp2p/go-libp2p-pubsub" - pb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub/pb" + pb "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub/pb" ) // Subscription is a wrapper over pubsub.Subscription that handles diff --git a/share/shwap/pb/shwap.pb.go b/square/shwap/pb/shwap.pb.go similarity index 89% rename from share/shwap/pb/shwap.pb.go rename to square/shwap/pb/shwap.pb.go index 000bf78ca7..12a158882e 100644 --- a/share/shwap/pb/shwap.pb.go +++ b/square/shwap/pb/shwap.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: share/shwap/pb/shwap.proto +// source: square/shwap/pb/shwap.proto package pb @@ -45,7 +45,7 @@ func (x AxisType) String() string { } func (AxisType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_9431653f3c9f0bcb, []int{0} + return fileDescriptor_d53f2247170ec31c, []int{0} } type Row_HalfSide int32 @@ -70,7 +70,7 @@ func (x Row_HalfSide) String() string { } func (Row_HalfSide) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_9431653f3c9f0bcb, []int{0, 0} + return fileDescriptor_d53f2247170ec31c, []int{0, 0} } type Row struct { @@ -82,7 +82,7 @@ func (m *Row) Reset() { *m = Row{} } func (m *Row) String() string { return proto.CompactTextString(m) } func (*Row) ProtoMessage() {} func (*Row) Descriptor() ([]byte, []int) { - return fileDescriptor_9431653f3c9f0bcb, []int{0} + return fileDescriptor_d53f2247170ec31c, []int{0} } func (m *Row) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -135,7 +135,7 @@ func (m *Sample) Reset() { *m = Sample{} } func (m *Sample) String() string { return proto.CompactTextString(m) } func (*Sample) ProtoMessage() {} func (*Sample) Descriptor() ([]byte, []int) { - return fileDescriptor_9431653f3c9f0bcb, []int{1} + return fileDescriptor_d53f2247170ec31c, []int{1} } func (m *Sample) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -194,7 +194,7 @@ func (m *RowNamespaceData) Reset() { *m = RowNamespaceData{} } func (m *RowNamespaceData) String() string { return proto.CompactTextString(m) } func (*RowNamespaceData) ProtoMessage() {} func (*RowNamespaceData) Descriptor() ([]byte, []int) { - return fileDescriptor_9431653f3c9f0bcb, []int{2} + return fileDescriptor_d53f2247170ec31c, []int{2} } func (m *RowNamespaceData) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -245,7 +245,7 @@ func (m *Share) Reset() { *m = Share{} } func (m *Share) String() string { return proto.CompactTextString(m) } func (*Share) ProtoMessage() {} func (*Share) Descriptor() ([]byte, []int) { - return fileDescriptor_9431653f3c9f0bcb, []int{3} + return fileDescriptor_d53f2247170ec31c, []int{3} } func (m *Share) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -290,34 +290,34 @@ func init() { proto.RegisterType((*Share)(nil), "shwap.Share") } -func init() { proto.RegisterFile("share/shwap/pb/shwap.proto", fileDescriptor_9431653f3c9f0bcb) } +func init() { proto.RegisterFile("square/shwap/pb/shwap.proto", fileDescriptor_d53f2247170ec31c) } -var fileDescriptor_9431653f3c9f0bcb = []byte{ - // 381 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x4f, 0x6b, 0xe2, 0x40, - 0x18, 0xc6, 0x33, 0x1b, 0xe3, 0xc6, 0x57, 0xd1, 0x30, 0x7b, 0x09, 0xee, 0x92, 0x95, 0xb0, 0x0b, - 0xb2, 0x60, 0xb2, 0xe8, 0x27, 0xd8, 0xbf, 0xb5, 0x60, 0x6b, 0x19, 0x85, 0x42, 0x2f, 0x61, 0x62, - 0x46, 0x13, 0x88, 0x9d, 0x21, 0x49, 0x49, 0x3d, 0xf7, 0xd0, 0x6b, 0x3f, 0x56, 0x8f, 0x1e, 0x7b, - 0x2c, 0xfa, 0x45, 0x4a, 0x26, 0xb1, 0x14, 0xda, 0x43, 0x6f, 0xbf, 0xcc, 0xf3, 0xcc, 0xbc, 0xcf, - 0x13, 0x5e, 0xe8, 0xa6, 0x21, 0x4d, 0x98, 0x9b, 0x86, 0x39, 0x15, 0xae, 0xf0, 0x4b, 0x70, 0x44, - 0xc2, 0x33, 0x8e, 0x35, 0xf9, 0xd1, 0x6d, 0x0b, 0xdf, 0x15, 0x09, 0xe7, 0xcb, 0xf2, 0xd8, 0xbe, - 0x45, 0xa0, 0x12, 0x9e, 0xe3, 0x01, 0x34, 0xe5, 0xe5, 0xd4, 0x0b, 0x69, 0xbc, 0x34, 0x51, 0x4f, - 0xed, 0x37, 0x87, 0x2d, 0xa7, 0x7c, 0x61, 0x56, 0x28, 0x04, 0x4a, 0xc3, 0x98, 0xc6, 0x4b, 0xfc, - 0x13, 0x1a, 0x85, 0xcf, 0x4b, 0xa3, 0x80, 0x99, 0x1f, 0x7a, 0xa8, 0xdf, 0x1e, 0x7e, 0xaa, 0xcc, - 0x84, 0xe7, 0x4e, 0xe1, 0x99, 0x45, 0x01, 0x23, 0x7a, 0x58, 0x91, 0xfd, 0x15, 0xf4, 0xc3, 0x29, - 0xd6, 0xa1, 0x36, 0xf9, 0xf7, 0x7f, 0x6e, 0x28, 0xb8, 0x01, 0x1a, 0x39, 0x3e, 0x1a, 0xcf, 0x0d, - 0x64, 0xdf, 0x20, 0xa8, 0xcf, 0xe8, 0x5a, 0xc4, 0x0c, 0xdb, 0xa0, 0xc9, 0x59, 0x26, 0xea, 0xa1, - 0x57, 0x31, 0x4a, 0x09, 0x7f, 0x07, 0x4d, 0xf6, 0x90, 0xd3, 0x9b, 0xc3, 0x8e, 0x53, 0xb5, 0xf2, - 0x9d, 0xb3, 0x02, 0x48, 0xa9, 0x62, 0x07, 0x40, 0x82, 0x97, 0x6d, 0x04, 0x33, 0x55, 0x99, 0xb4, - 0x53, 0xbd, 0xf7, 0xeb, 0x3a, 0x4a, 0xe7, 0x1b, 0xc1, 0x48, 0x43, 0x5a, 0x0a, 0xb4, 0x3d, 0x30, - 0x08, 0xcf, 0x4f, 0xe9, 0x9a, 0xa5, 0x82, 0x2e, 0xd8, 0x5f, 0x9a, 0x51, 0xfc, 0x0d, 0xea, 0x65, - 0xf5, 0x37, 0x7f, 0x4b, 0xa5, 0xbd, 0x33, 0x90, 0xfd, 0x19, 0x34, 0x79, 0x0f, 0x63, 0xa8, 0x05, - 0x34, 0xa3, 0xb2, 0x63, 0x8b, 0x48, 0xfe, 0xf1, 0x05, 0xf4, 0x43, 0x28, 0xfc, 0x11, 0x54, 0x32, - 0x3d, 0x37, 0x94, 0x02, 0xfe, 0x4c, 0x27, 0x06, 0xfa, 0x7d, 0x72, 0xbf, 0xb3, 0xd0, 0x76, 0x67, - 0xa1, 0xc7, 0x9d, 0x85, 0xee, 0xf6, 0x96, 0xb2, 0xdd, 0x5b, 0xca, 0xc3, 0xde, 0x52, 0x2e, 0x46, - 0xab, 0x28, 0x0b, 0xaf, 0x7c, 0x67, 0xc1, 0xd7, 0xee, 0x82, 0xc5, 0x2c, 0xcd, 0x22, 0xca, 0x93, - 0xd5, 0x33, 0x0f, 0x2e, 0x79, 0x50, 0xec, 0xc5, 0xcb, 0xed, 0xf0, 0xeb, 0x72, 0x03, 0x46, 0x4f, - 0x01, 0x00, 0x00, 0xff, 0xff, 0x67, 0xb6, 0xc0, 0x8b, 0x36, 0x02, 0x00, 0x00, +var fileDescriptor_d53f2247170ec31c = []byte{ + // 383 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x4f, 0x8b, 0xda, 0x40, + 0x18, 0xc6, 0x33, 0x8d, 0xb1, 0xf1, 0x55, 0x34, 0x4c, 0x2f, 0xa1, 0x96, 0x54, 0x42, 0x0b, 0x52, + 0x30, 0x29, 0xb6, 0x5f, 0xa0, 0xff, 0x2d, 0x88, 0x96, 0x51, 0x28, 0xf4, 0x12, 0x26, 0x66, 0x34, + 0x81, 0xd8, 0x99, 0x66, 0x22, 0xa9, 0xe7, 0x1e, 0x7a, 0xdd, 0x8f, 0xb5, 0x47, 0x8f, 0x7b, 0x5c, + 0xf4, 0x8b, 0x2c, 0x99, 0xc4, 0x3d, 0xec, 0xee, 0x61, 0x6f, 0xbf, 0xcc, 0xf3, 0x64, 0xde, 0xe7, + 0x19, 0x5e, 0xe8, 0xcb, 0x3f, 0x3b, 0x9a, 0x31, 0x5f, 0xc6, 0x05, 0x15, 0xbe, 0x08, 0x2b, 0xf0, + 0x44, 0xc6, 0x73, 0x8e, 0x0d, 0xf5, 0xf1, 0xbc, 0x2b, 0x42, 0x5f, 0x64, 0x9c, 0xaf, 0xab, 0x63, + 0xf7, 0x3f, 0x02, 0x9d, 0xf0, 0x02, 0x8f, 0xa0, 0x2d, 0x63, 0x9a, 0x31, 0x19, 0xc4, 0x34, 0x5d, + 0xdb, 0x68, 0xa0, 0x0f, 0xdb, 0xe3, 0x8e, 0x57, 0xdd, 0xb0, 0x28, 0x15, 0x02, 0x95, 0x61, 0x42, + 0xd3, 0x35, 0x7e, 0x0b, 0xad, 0xd2, 0x17, 0xc8, 0x24, 0x62, 0xf6, 0x93, 0x01, 0x1a, 0x76, 0xc7, + 0xcf, 0x6a, 0x33, 0xe1, 0x85, 0x57, 0x7a, 0x16, 0x49, 0xc4, 0x88, 0x19, 0xd7, 0xe4, 0xbe, 0x04, + 0xf3, 0x7c, 0x8a, 0x4d, 0x68, 0x4c, 0xbf, 0x7c, 0x5d, 0x5a, 0x1a, 0x6e, 0x81, 0x41, 0xbe, 0x7f, + 0x9b, 0x2c, 0x2d, 0xe4, 0xfe, 0x43, 0xd0, 0x5c, 0xd0, 0xad, 0x48, 0x19, 0x76, 0xc1, 0x50, 0xb3, + 0x6c, 0x34, 0x40, 0xf7, 0x62, 0x54, 0x12, 0x7e, 0x0d, 0x86, 0xea, 0xa1, 0xa6, 0xb7, 0xc7, 0x3d, + 0xaf, 0x6e, 0x15, 0x7a, 0x3f, 0x4a, 0x20, 0x95, 0x8a, 0x3d, 0x00, 0x05, 0x41, 0xbe, 0x17, 0xcc, + 0xd6, 0x55, 0xd2, 0x5e, 0x7d, 0xdf, 0x87, 0xbf, 0x89, 0x5c, 0xee, 0x05, 0x23, 0x2d, 0x65, 0x29, + 0xd1, 0x0d, 0xc0, 0x22, 0xbc, 0x98, 0xd1, 0x2d, 0x93, 0x82, 0xae, 0xd8, 0x67, 0x9a, 0x53, 0xfc, + 0x0a, 0x9a, 0x55, 0xf5, 0x07, 0x9f, 0xa5, 0xd6, 0x1e, 0x19, 0xc8, 0xed, 0x83, 0xa1, 0xfe, 0xc3, + 0x18, 0x1a, 0x11, 0xcd, 0xa9, 0xea, 0xd8, 0x21, 0x8a, 0xdf, 0xbc, 0x00, 0xf3, 0x1c, 0x0a, 0x3f, + 0x05, 0x9d, 0xcc, 0x7f, 0x5a, 0x5a, 0x09, 0x9f, 0xe6, 0x53, 0x0b, 0x7d, 0x9c, 0x5d, 0x1e, 0x1d, + 0x74, 0x38, 0x3a, 0xe8, 0xfa, 0xe8, 0xa0, 0x8b, 0x93, 0xa3, 0x1d, 0x4e, 0x8e, 0x76, 0x75, 0x72, + 0xb4, 0x5f, 0xef, 0x37, 0x49, 0x1e, 0xef, 0x42, 0x6f, 0xc5, 0xb7, 0xfe, 0x8a, 0xa5, 0x4c, 0xe6, + 0x09, 0xe5, 0xd9, 0xe6, 0x96, 0x47, 0xbf, 0x79, 0xc4, 0xfc, 0x3b, 0xeb, 0x11, 0x36, 0xd5, 0x0a, + 0xbc, 0xbb, 0x09, 0x00, 0x00, 0xff, 0xff, 0x80, 0x9c, 0x55, 0xe0, 0x38, 0x02, 0x00, 0x00, } func (m *Row) Marshal() (dAtA []byte, err error) { diff --git a/share/shwap/pb/shwap.proto b/square/shwap/pb/shwap.proto similarity index 89% rename from share/shwap/pb/shwap.proto rename to square/shwap/pb/shwap.proto index d7daea568a..444844f055 100644 --- a/share/shwap/pb/shwap.proto +++ b/square/shwap/pb/shwap.proto @@ -1,7 +1,7 @@ // Defined in CIP-19 https://github.com/celestiaorg/CIPs/blob/82aeb7dfc472105a11babffd548c730c899a3d24/cips/cip-19.md syntax = "proto3"; package shwap; -option go_package = "github.com/celestiaorg/celestia-node/share/shwap/pb"; +option go_package = "github.com/celestiaorg/celestia-node/square/shwap/pb"; import "pb/proof.proto"; // celestiaorg/nmt/pb/proof.proto diff --git a/share/shwap/row.go b/square/shwap/row.go similarity index 84% rename from share/shwap/row.go rename to square/shwap/row.go index 4e362beee2..b4298c27ab 100644 --- a/share/shwap/row.go +++ b/square/shwap/row.go @@ -4,10 +4,11 @@ import ( "bytes" "fmt" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" + "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap/pb" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap/pb" ) // RowName is the name identifier for the row container. @@ -49,11 +50,15 @@ func RowFromShares(shares []share.Share, side RowSide) Row { } // RowFromProto converts a protobuf Row to a Row structure. -func RowFromProto(r *pb.Row) Row { +func RowFromProto(r *pb.Row) (Row, error) { + shrs, err := SharesFromProto(r.SharesHalf) + if err != nil { + return Row{}, err + } return Row{ - halfShares: SharesFromProto(r.SharesHalf), + halfShares: shrs, side: sideFromProto(r.GetHalfSide()), - } + }, nil } // Shares reconstructs the complete row shares from the half provided, using RSMT2D for data @@ -67,7 +72,12 @@ func (r Row) Shares() ([]share.Share, error) { for i, share := range r.halfShares { shares[i+offset] = share } - return share.DefaultRSMT2DCodec().Decode(shares) + + rowShares, err := square.DefaultRSMT2DCodec().Decode(share.ToBytes(shares)) + if err != nil { + return nil, err + } + return share.FromBytes(rowShares) } // ToProto converts the Row to its protobuf representation. @@ -85,7 +95,7 @@ func (r Row) IsEmpty() bool { // Verify checks if the row's shares match the expected number from the root data and validates // the side of the row. -func (r Row) Verify(roots *share.AxisRoots, idx int) error { +func (r Row) Verify(roots *square.AxisRoots, idx int) error { if len(r.halfShares) == 0 { return fmt.Errorf("empty half row") } @@ -93,9 +103,6 @@ func (r Row) Verify(roots *share.AxisRoots, idx int) error { if len(r.halfShares) != expectedShares { return fmt.Errorf("shares size doesn't match root size: %d != %d", len(r.halfShares), expectedShares) } - if err := ValidateShares(r.halfShares); err != nil { - return fmt.Errorf("invalid shares: %w", err) - } if r.side != Left && r.side != Right { return fmt.Errorf("invalid RowSide: %d", r.side) } @@ -108,7 +115,7 @@ func (r Row) Verify(roots *share.AxisRoots, idx int) error { // verifyInclusion verifies the integrity of the row's shares against the provided root hash for the // given row index. -func (r Row) verifyInclusion(roots *share.AxisRoots, idx int) error { +func (r Row) verifyInclusion(roots *square.AxisRoots, idx int) error { shrs, err := r.Shares() if err != nil { return fmt.Errorf("while extending shares: %w", err) @@ -117,7 +124,7 @@ func (r Row) verifyInclusion(roots *share.AxisRoots, idx int) error { sqrLn := uint64(len(shrs) / 2) tree := wrapper.NewErasuredNamespacedMerkleTree(sqrLn, uint(idx)) for _, s := range shrs { - if err := tree.Push(s); err != nil { + if err := tree.Push(s.ToBytes()); err != nil { return fmt.Errorf("while pushing shares to NMT: %w", err) } } diff --git a/share/shwap/row_id.go b/square/shwap/row_id.go similarity index 100% rename from share/shwap/row_id.go rename to square/shwap/row_id.go diff --git a/share/shwap/row_id_test.go b/square/shwap/row_id_test.go similarity index 100% rename from share/shwap/row_id_test.go rename to square/shwap/row_id_test.go diff --git a/share/shwap/row_namespace_data.go b/square/shwap/row_namespace_data.go similarity index 84% rename from share/shwap/row_namespace_data.go rename to square/shwap/row_namespace_data.go index e92f264aa0..e658856fd9 100644 --- a/share/shwap/row_namespace_data.go +++ b/square/shwap/row_namespace_data.go @@ -5,14 +5,15 @@ import ( "fmt" "io" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" "github.com/celestiaorg/go-libp2p-messenger/serde" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" nmt_pb "github.com/celestiaorg/nmt/pb" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap/pb" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap/pb" ) // RowNamespaceDataName is the name identifier for the row namespace data container. @@ -39,13 +40,13 @@ func RowNamespaceDataFromShares( tree := wrapper.NewErasuredNamespacedMerkleTree(uint64(len(shares)/2), uint(rowIndex)) nmtTree := nmt.New( appconsts.NewBaseHashFunc(), - nmt.NamespaceIDSize(appconsts.NamespaceSize), + nmt.NamespaceIDSize(share.NamespaceSize), nmt.IgnoreMaxNamespace(true), ) tree.SetTree(nmtTree) for _, shr := range shares { - if err := tree.Push(shr); err != nil { + if err := tree.Push(shr.ToBytes()); err != nil { return RowNamespaceData{}, fmt.Errorf("failed to build tree for row %d: %w", rowIndex, err) } } @@ -60,7 +61,7 @@ func RowNamespaceDataFromShares( var from, count int for i := range len(shares) / 2 { - if namespace.Equals(share.GetNamespace(shares[i])) { + if namespace.Equals(shares[i].Namespace()) { if count == 0 { from = i } @@ -74,7 +75,7 @@ func RowNamespaceDataFromShares( // if count is 0, then the namespace is not present in the shares. Return non-inclusion proof. if count == 0 { - proof, err := nmtTree.ProveNamespace(namespace.ToNMT()) + proof, err := nmtTree.ProveNamespace(namespace.Bytes()) if err != nil { return RowNamespaceData{}, fmt.Errorf("failed to generate non-inclusion proof for row %d: %w", rowIndex, err) } @@ -99,7 +100,7 @@ func RowNamespaceDataFromShares( } // RowNamespaceDataFromProto constructs RowNamespaceData out of its protobuf representation. -func RowNamespaceDataFromProto(row *pb.RowNamespaceData) RowNamespaceData { +func RowNamespaceDataFromProto(row *pb.RowNamespaceData) (RowNamespaceData, error) { var proof nmt.Proof if row.GetProof().GetLeafHash() != nil { proof = nmt.NewAbsenceProof( @@ -118,10 +119,15 @@ func RowNamespaceDataFromProto(row *pb.RowNamespaceData) RowNamespaceData { ) } + shares, err := SharesFromProto(row.GetShares()) + if err != nil { + return RowNamespaceData{}, err + } + return RowNamespaceData{ - Shares: SharesFromProto(row.GetShares()), + Shares: shares, Proof: &proof, - } + }, nil } // ToProto converts RowNamespaceData to its protobuf representation for serialization. @@ -144,7 +150,7 @@ func (rnd RowNamespaceData) IsEmpty() bool { } // Verify checks validity of the RowNamespaceData against the AxisRoots, Namespace and Row index. -func (rnd RowNamespaceData) Verify(roots *share.AxisRoots, namespace share.Namespace, rowIdx int) error { +func (rnd RowNamespaceData) Verify(roots *square.AxisRoots, namespace share.Namespace, rowIdx int) error { if rnd.Proof == nil || rnd.Proof.IsEmptyProof() { return fmt.Errorf("nil proof") } @@ -156,10 +162,6 @@ func (rnd RowNamespaceData) Verify(roots *share.AxisRoots, namespace share.Names return fmt.Errorf("non-empty shares with absence proof for row %d", rowIdx) } - if err := ValidateShares(rnd.Shares); err != nil { - return fmt.Errorf("invalid shares: %w", err) - } - rowRoot := roots.RowRoots[rowIdx] if namespace.IsOutsideRange(rowRoot, rowRoot) { return fmt.Errorf("namespace out of range for row %d", rowIdx) @@ -175,16 +177,16 @@ func (rnd RowNamespaceData) Verify(roots *share.AxisRoots, namespace share.Names func (rnd RowNamespaceData) verifyInclusion(rowRoot []byte, namespace share.Namespace) bool { leaves := make([][]byte, 0, len(rnd.Shares)) for _, sh := range rnd.Shares { - namespaceBytes := share.GetNamespace(sh) - leave := make([]byte, len(sh)+len(namespaceBytes)) + namespaceBytes := sh.Namespace().Bytes() + leave := make([]byte, len(sh.ToBytes())+len(namespaceBytes)) copy(leave, namespaceBytes) - copy(leave[len(namespaceBytes):], sh) + copy(leave[len(namespaceBytes):], sh.ToBytes()) // rework leaves = append(leaves, leave) } return rnd.Proof.VerifyNamespace( - share.NewSHA256Hasher(), - namespace.ToNMT(), + square.NewSHA256Hasher(), + namespace.Bytes(), leaves, rowRoot, ) @@ -199,8 +201,8 @@ func (rnd *RowNamespaceData) ReadFrom(reader io.Reader) (int64, error) { return int64(n), fmt.Errorf("reading RowNamespaceData: %w", err) } - *rnd = RowNamespaceDataFromProto(&pbrnd) - return int64(n), nil + *rnd, err = RowNamespaceDataFromProto(&pbrnd) + return int64(n), err } // WriteTo writes length-delimited protobuf representation of RowNamespaceData. diff --git a/share/shwap/row_namespace_data_id.go b/square/shwap/row_namespace_data_id.go similarity index 94% rename from share/shwap/row_namespace_data_id.go rename to square/shwap/row_namespace_data_id.go index 9ae87e0ee4..cdada45b03 100644 --- a/share/shwap/row_namespace_data_id.go +++ b/square/shwap/row_namespace_data_id.go @@ -4,7 +4,7 @@ import ( "fmt" "io" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/go-square/v2/share" ) // RowNamespaceDataIDSize defines the total size of a RowNamespaceDataID in bytes, combining the @@ -55,9 +55,10 @@ func RowNamespaceDataIDFromBinary(data []byte) (RowNamespaceDataID, error) { return RowNamespaceDataID{}, fmt.Errorf("unmarshaling RowID: %w", err) } + ns, err := share.NewNamespaceFromBytes(data[RowIDSize:]) rndid := RowNamespaceDataID{ RowID: rid, - DataNamespace: data[RowIDSize:], + DataNamespace: ns, } if err := rndid.Validate(); err != nil { return RowNamespaceDataID{}, fmt.Errorf("validating RowNamespaceDataID: %w", err) @@ -122,7 +123,7 @@ func (rndid RowNamespaceDataID) Validate() error { if err := rndid.RowID.Validate(); err != nil { return fmt.Errorf("validating RowID: %w", err) } - if err := rndid.DataNamespace.ValidateForData(); err != nil { + if err := share.ValidateForData(rndid.DataNamespace); err != nil { return fmt.Errorf("%w: validating DataNamespace: %w", ErrInvalidID, err) } @@ -132,5 +133,5 @@ func (rndid RowNamespaceDataID) Validate() error { // appendTo helps in appending the binary form of DataNamespace to the serialized RowID data. func (rndid RowNamespaceDataID) appendTo(data []byte) []byte { data = rndid.RowID.appendTo(data) - return append(data, rndid.DataNamespace...) + return append(data, rndid.DataNamespace.Bytes()...) } diff --git a/share/shwap/row_namespace_data_id_test.go b/square/shwap/row_namespace_data_id_test.go similarity index 88% rename from share/shwap/row_namespace_data_id_test.go rename to square/shwap/row_namespace_data_id_test.go index dd3aa6b689..658072c58a 100644 --- a/share/shwap/row_namespace_data_id_test.go +++ b/square/shwap/row_namespace_data_id_test.go @@ -7,12 +7,12 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/go-square/v2/share" ) func TestRowNamespaceDataID(t *testing.T) { edsSize := 4 - ns := sharetest.RandV0Namespace() + ns := share.RandomNamespace() id, err := NewRowNamespaceDataID(1, 1, ns, edsSize) require.NoError(t, err) @@ -31,7 +31,7 @@ func TestRowNamespaceDataID(t *testing.T) { func TestRowNamespaceDataIDReaderWriter(t *testing.T) { edsSize := 4 - ns := sharetest.RandV0Namespace() + ns := share.RandomNamespace() id, err := NewRowNamespaceDataID(1, 1, ns, edsSize) require.NoError(t, err) diff --git a/square/shwap/row_namespace_data_test.go b/square/shwap/row_namespace_data_test.go new file mode 100644 index 0000000000..b120919d13 --- /dev/null +++ b/square/shwap/row_namespace_data_test.go @@ -0,0 +1,107 @@ +package shwap_test + +import ( + "bytes" + "context" + "slices" + "testing" + "time" + + "github.com/stretchr/testify/require" + + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" +) + +func TestNamespacedRowFromShares(t *testing.T) { + const odsSize = 8 + + minNamespace, err := share.NewV0Namespace(slices.Concat(bytes.Repeat([]byte{0}, 8), []byte{1, 0})) + require.NoError(t, err) + err = share.ValidateForData(minNamespace) + require.NoError(t, err) + + for namespacedAmount := 1; namespacedAmount < odsSize; namespacedAmount++ { + shares := share.RandSharesWithNamespace(minNamespace, namespacedAmount, odsSize) + parity, err := square.DefaultRSMT2DCodec().Encode(share.ToBytes(shares)) + require.NoError(t, err) + + paritySh, err := share.FromBytes(parity) + require.NoError(t, err) + extended := slices.Concat(shares, paritySh) + + nr, err := shwap.RowNamespaceDataFromShares(extended, minNamespace, 0) + require.NoError(t, err) + require.Equal(t, namespacedAmount, len(nr.Shares)) + } +} + +//func TestNamespacedRowFromSharesNonIncluded(t *testing.T) { +// // TODO: this will fail until absence proof support is added +// t.Skip() +// +// const odsSize = 8 +// // Test absent namespace +// shares := share.RandShares( odsSize) +// absentNs, err := square.GetNamespace(shares[0]).AddInt(1) +// require.NoError(t, err) +// +// parity, err := square.DefaultRSMT2DCodec().Encode(shares) +// require.NoError(t, err) +// extended := slices.Concat(shares, parity) +// +// shrs, err := share.FromBytes(extended) +// require.NoError(t, err) +// +// nr, err := shwap.RowNamespaceDataFromShares(shrs, absentNs, 0) +// require.NoError(t, err) +// require.Len(t, nr.Shares, 0) +// 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 := square.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) + t.Cleanup(cancel) + + const odsSize = 8 + namespace := share.RandomNamespace() + randEDS, _ := edstest.RandEDSWithNamespace(t, namespace, odsSize, odsSize) + rsmt2d := &eds.Rsmt2D{ExtendedDataSquare: randEDS} + nd, err := eds.NamespaceData(ctx, rsmt2d, namespace) + require.NoError(t, err) + require.True(t, len(nd) > 0) + + expected := nd[0] + pb := expected.ToProto() + ndOut, err := shwap.RowNamespaceDataFromProto(pb) + require.NoError(t, err) + require.Equal(t, expected, ndOut) +} diff --git a/share/shwap/row_test.go b/square/shwap/row_test.go similarity index 74% rename from share/shwap/row_test.go rename to square/shwap/row_test.go index 353007b3a6..9bb9aded59 100644 --- a/share/shwap/row_test.go +++ b/square/shwap/row_test.go @@ -5,8 +5,10 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" ) func TestRowFromShares(t *testing.T) { @@ -15,7 +17,9 @@ func TestRowFromShares(t *testing.T) { for rowIdx := 0; rowIdx < odsSize*2; rowIdx++ { for _, side := range []RowSide{Left, Right} { - shares := eds.Row(uint(rowIdx)) + shrs := eds.Row(uint(rowIdx)) + shares, err := share.FromBytes(shrs) + require.NoError(t, err) row := RowFromShares(shares, side) extended, err := row.Shares() require.NoError(t, err) @@ -36,15 +40,17 @@ func TestRowFromShares(t *testing.T) { func TestRowValidate(t *testing.T) { const odsSize = 8 eds := edstest.RandEDS(t, odsSize) - root, err := share.NewAxisRoots(eds) + root, err := square.NewAxisRoots(eds) require.NoError(t, err) for rowIdx := 0; rowIdx < odsSize*2; rowIdx++ { for _, side := range []RowSide{Left, Right} { - shares := eds.Row(uint(rowIdx)) + shrs := eds.Row(uint(rowIdx)) + shares, err := share.FromBytes(shrs) + require.NoError(t, err) row := RowFromShares(shares, side) - err := row.Verify(root, rowIdx) + err = row.Verify(root, rowIdx) require.NoError(t, err) err = row.Verify(root, rowIdx) require.NoError(t, err) @@ -54,9 +60,11 @@ func TestRowValidate(t *testing.T) { func TestRowValidateNegativeCases(t *testing.T) { eds := edstest.RandEDS(t, 8) // Generate a random Extended Data Square of size 8 - root, err := share.NewAxisRoots(eds) + root, err := square.NewAxisRoots(eds) + require.NoError(t, err) + shrs := eds.Row(0) + shares, err := share.FromBytes(shrs) require.NoError(t, err) - shares := eds.Row(0) row := RowFromShares(shares, Left) // Test with incorrect side specification @@ -67,7 +75,9 @@ func TestRowValidateNegativeCases(t *testing.T) { // Test with invalid shares (more shares than expected) incorrectShares := make([]share.Share, (eds.Width()/2)+1) // Adding an extra share for i := range incorrectShares { - incorrectShares[i] = eds.GetCell(uint(i), 0) + shr, err := share.NewShare(eds.GetCell(uint(i), 0)) + require.NoError(t, err) + incorrectShares[i] = *shr } invalidRow := Row{halfShares: incorrectShares, side: Left} err = invalidRow.Verify(root, 0) @@ -90,11 +100,14 @@ func TestRowProtoEncoding(t *testing.T) { for rowIdx := 0; rowIdx < odsSize*2; rowIdx++ { for _, side := range []RowSide{Left, Right} { - shares := eds.Row(uint(rowIdx)) + shrs := eds.Row(uint(rowIdx)) + shares, err := share.FromBytes(shrs) + require.NoError(t, err) row := RowFromShares(shares, side) pb := row.ToProto() - rowOut := RowFromProto(pb) + rowOut, err := RowFromProto(pb) + require.NoError(t, err) require.Equal(t, row, rowOut) } } @@ -105,9 +118,11 @@ func TestRowProtoEncoding(t *testing.T) { func BenchmarkRowValidate(b *testing.B) { const odsSize = 32 eds := edstest.RandEDS(b, odsSize) - root, err := share.NewAxisRoots(eds) + root, err := square.NewAxisRoots(eds) + require.NoError(b, err) + shrs := eds.Row(0) + shares, err := share.FromBytes(shrs) require.NoError(b, err) - shares := eds.Row(0) row := RowFromShares(shares, Left) b.ResetTimer() diff --git a/share/shwap/sample.go b/square/shwap/sample.go similarity index 82% rename from share/shwap/sample.go rename to square/shwap/sample.go index 48ae22088a..2e24918e0a 100644 --- a/share/shwap/sample.go +++ b/square/shwap/sample.go @@ -4,13 +4,14 @@ import ( "errors" "fmt" - "github.com/celestiaorg/celestia-app/v2/pkg/wrapper" + "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" nmt_pb "github.com/celestiaorg/nmt/pb" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap/pb" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/shwap/pb" ) // SampleName is the name identifier for the sample container. @@ -33,7 +34,7 @@ type Sample struct { func SampleFromShares(shares []share.Share, proofType rsmt2d.Axis, axisIdx, shrIdx int) (Sample, error) { tree := wrapper.NewErasuredNamespacedMerkleTree(uint64(len(shares)/2), uint(axisIdx)) for _, shr := range shares { - err := tree.Push(shr) + err := tree.Push(shr.ToBytes()) if err != nil { return Sample{}, err } @@ -52,24 +53,30 @@ func SampleFromShares(shares []share.Share, proofType rsmt2d.Axis, axisIdx, shrI } // SampleFromProto converts a protobuf Sample back into its domain model equivalent. -func SampleFromProto(s *pb.Sample) Sample { +func SampleFromProto(s *pb.Sample) (Sample, error) { proof := nmt.NewInclusionProof( int(s.GetProof().GetStart()), int(s.GetProof().GetEnd()), s.GetProof().GetNodes(), s.GetProof().GetIsMaxNamespaceIgnored(), ) + + shrs, err := ShareFromProto(s.GetShare()) + if err != nil { + return Sample{}, err + } + return Sample{ - Share: ShareFromProto(s.GetShare()), + Share: shrs, Proof: &proof, ProofType: rsmt2d.Axis(s.GetProofType()), - } + }, nil } // ToProto converts a Sample into its protobuf representation for serialization purposes. func (s Sample) ToProto() *pb.Sample { return &pb.Sample{ - Share: &pb.Share{Data: s.Share}, + Share: &pb.Share{Data: s.Share.ToBytes()}, Proof: &nmt_pb.Proof{ Start: int64(s.Proof.Start()), End: int64(s.Proof.End()), @@ -88,13 +95,10 @@ func (s Sample) IsEmpty() bool { // Verify checks the inclusion of the share using its Merkle proof under the specified AxisRoots. // Returns an error if the proof is invalid or does not correspond to the indicated proof type. -func (s Sample) Verify(roots *share.AxisRoots, rowIdx, colIdx int) error { +func (s Sample) Verify(roots *square.AxisRoots, rowIdx, colIdx int) error { if s.Proof == nil || s.Proof.IsEmptyProof() { return errors.New("nil proof") } - if err := share.ValidateShare(s.Share); err != nil { - return err - } if s.ProofType != rsmt2d.Row && s.ProofType != rsmt2d.Col { return fmt.Errorf("invalid SampleProofType: %d", s.ProofType) } @@ -105,14 +109,14 @@ func (s Sample) Verify(roots *share.AxisRoots, rowIdx, colIdx int) error { } // verifyInclusion checks if the share is included in the given root hash at the specified indices. -func (s Sample) verifyInclusion(roots *share.AxisRoots, rowIdx, colIdx int) bool { +func (s Sample) verifyInclusion(roots *square.AxisRoots, rowIdx, colIdx int) bool { size := len(roots.RowRoots) namespace := inclusionNamespace(s.Share, rowIdx, colIdx, size) - rootHash := share.RootHashForCoordinates(roots, s.ProofType, uint(rowIdx), uint(colIdx)) + rootHash := square.RootHashForCoordinates(roots, s.ProofType, uint(rowIdx), uint(colIdx)) return s.Proof.VerifyInclusion( - share.NewSHA256Hasher(), - namespace.ToNMT(), - [][]byte{s.Share}, + square.NewSHA256Hasher(), + namespace.Bytes(), + [][]byte{s.Share.ToBytes()}, rootHash, ) } @@ -126,5 +130,5 @@ func inclusionNamespace(sh share.Share, rowIdx, colIdx, squareSize int) share.Na if isParity { return share.ParitySharesNamespace } - return share.GetNamespace(sh) + return sh.Namespace() } diff --git a/share/shwap/sample_id.go b/square/shwap/sample_id.go similarity index 100% rename from share/shwap/sample_id.go rename to square/shwap/sample_id.go diff --git a/share/shwap/sample_id_test.go b/square/shwap/sample_id_test.go similarity index 100% rename from share/shwap/sample_id_test.go rename to square/shwap/sample_id_test.go diff --git a/share/shwap/sample_test.go b/square/shwap/sample_test.go similarity index 83% rename from share/shwap/sample_test.go rename to square/shwap/sample_test.go index ea57f68e94..a2b4aa1e53 100644 --- a/share/shwap/sample_test.go +++ b/square/shwap/sample_test.go @@ -6,18 +6,19 @@ import ( "github.com/stretchr/testify/require" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" ) func TestSampleValidate(t *testing.T) { const odsSize = 8 randEDS := edstest.RandEDS(t, odsSize) - root, err := share.NewAxisRoots(randEDS) + root, err := square.NewAxisRoots(randEDS) require.NoError(t, err) inMem := eds.Rsmt2D{ExtendedDataSquare: randEDS} @@ -37,7 +38,7 @@ func TestSampleValidate(t *testing.T) { func TestSampleNegativeVerifyInclusion(t *testing.T) { const odsSize = 8 randEDS := edstest.RandEDS(t, odsSize) - root, err := share.NewAxisRoots(randEDS) + root, err := square.NewAxisRoots(randEDS) require.NoError(t, err) inMem := eds.Rsmt2D{ExtendedDataSquare: randEDS} @@ -51,7 +52,11 @@ func TestSampleNegativeVerifyInclusion(t *testing.T) { require.ErrorIs(t, err, shwap.ErrFailedVerification) // Corrupt the share - sample.Share[0] ^= 0xFF + b := sample.Share.ToBytes() + b[0] ^= 0xFF + shr, err := share.NewShare(b) + require.NoError(t, err) + sample.Share = *shr err = sample.Verify(root, 0, 0) require.ErrorIs(t, err, shwap.ErrFailedVerification) @@ -82,7 +87,7 @@ func TestSampleProtoEncoding(t *testing.T) { require.NoError(t, err) pb := sample.ToProto() - sampleOut := shwap.SampleFromProto(pb) + sampleOut, err := shwap.SampleFromProto(pb) require.NoError(t, err) require.Equal(t, sample, sampleOut) } @@ -95,7 +100,7 @@ func TestSampleProtoEncoding(t *testing.T) { func BenchmarkSampleValidate(b *testing.B) { const odsSize = 32 randEDS := edstest.RandEDS(b, odsSize) - root, err := share.NewAxisRoots(randEDS) + root, err := square.NewAxisRoots(randEDS) require.NoError(b, err) inMem := eds.Rsmt2D{ExtendedDataSquare: randEDS} sample, err := inMem.SampleForProofAxis(0, 0, rsmt2d.Row) diff --git a/share/shwap/share.go b/square/shwap/share.go similarity index 59% rename from share/shwap/share.go rename to square/shwap/share.go index a7f7ef67b7..76b68e0eff 100644 --- a/share/shwap/share.go +++ b/square/shwap/share.go @@ -3,18 +3,23 @@ package shwap import ( "fmt" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/shwap/pb" + "github.com/celestiaorg/go-square/v2/share" + + "github.com/celestiaorg/celestia-node/square/shwap/pb" ) // ShareFromProto converts a protobuf Share object to the application's internal share // representation. It returns nil if the input protobuf Share is nil, ensuring safe handling of nil // values. -func ShareFromProto(s *pb.Share) share.Share { +func ShareFromProto(s *pb.Share) (share.Share, error) { if s == nil { - return nil + return share.Share{}, nil + } + sh, err := share.NewShare(s.Data) + if err != nil { + return share.Share{}, err } - return s.Data + return *sh, err } // SharesToProto converts a slice of Shares from the application's internal representation to a @@ -23,27 +28,21 @@ func ShareFromProto(s *pb.Share) share.Share { func SharesToProto(shrs []share.Share) []*pb.Share { protoShares := make([]*pb.Share, len(shrs)) for i, shr := range shrs { - protoShares[i] = &pb.Share{Data: shr} + protoShares[i] = &pb.Share{Data: shr.ToBytes()} } return protoShares } // SharesFromProto converts a slice of protobuf Share objects to the application's internal slice // of Shares. It ensures that each Share is correctly transformed using the ShareFromProto function. -func SharesFromProto(shrs []*pb.Share) []share.Share { +func SharesFromProto(shrs []*pb.Share) ([]share.Share, error) { shares := make([]share.Share, len(shrs)) + var err error for i, shr := range shrs { - shares[i] = ShareFromProto(shr) - } - return shares -} - -// ValidateShares takes the slice of shares and checks their conformance to share format. -func ValidateShares(shares []share.Share) error { - for i, shr := range shares { - if err := share.ValidateShare(shr); err != nil { - return fmt.Errorf("while validating share at index %d: %w", i, err) + shares[i], err = ShareFromProto(shr) + if err != nil { + return nil, fmt.Errorf("invalid share at index %d: %w", i, err) } } - return nil + return shares, nil } diff --git a/state/core_access.go b/state/core_access.go index 6cd8fe7a58..f36798c261 100644 --- a/state/core_access.go +++ b/state/core_access.go @@ -22,10 +22,10 @@ import ( "google.golang.org/grpc/connectivity" "google.golang.org/grpc/credentials/insecure" - "github.com/celestiaorg/celestia-app/v2/app" - "github.com/celestiaorg/celestia-app/v2/app/encoding" - apperrors "github.com/celestiaorg/celestia-app/v2/app/errors" - "github.com/celestiaorg/celestia-app/v2/pkg/user" + "github.com/celestiaorg/celestia-app/v3/app" + "github.com/celestiaorg/celestia-app/v3/app/encoding" + apperrors "github.com/celestiaorg/celestia-app/v3/app/errors" + "github.com/celestiaorg/celestia-app/v3/pkg/user" libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/celestia-node/header" @@ -220,7 +220,7 @@ func (ca *CoreAccessor) SubmitPayForBlob( if gas == 0 { blobSizes := make([]uint32, len(appblobs)) for i, blob := range appblobs { - blobSizes[i] = uint32(len(blob.GetData())) + blobSizes[i] = uint32(len(blob.Data())) } gas = estimateGasForBlobs(blobSizes) } diff --git a/state/core_access_test.go b/state/core_access_test.go index 8853cb17be..f44057bbea 100644 --- a/state/core_access_test.go +++ b/state/core_access_test.go @@ -14,14 +14,12 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-app/v2/app" - appconsts "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - genesis "github.com/celestiaorg/celestia-app/v2/test/util/genesis" - "github.com/celestiaorg/celestia-app/v2/test/util/testnode" - apptypes "github.com/celestiaorg/celestia-app/v2/x/blob/types" - squareblob "github.com/celestiaorg/go-square/blob" - - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-app/v3/app" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + "github.com/celestiaorg/celestia-app/v3/test/util/genesis" + "github.com/celestiaorg/celestia-app/v3/test/util/testnode" + apptypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" + "github.com/celestiaorg/go-square/v2/share" ) func TestSubmitPayForBlob(t *testing.T) { @@ -34,30 +32,33 @@ func TestSubmitPayForBlob(t *testing.T) { _ = ca.Stop(ctx) }) - ns, err := share.NewBlobNamespaceV0([]byte("namespace")) + ns, err := share.NewV0Namespace([]byte("namespace")) + require.NoError(t, err) + require.False(t, ns.IsReserved()) + require.NoError(t, err) - blobbyTheBlob, err := apptypes.NewBlob(ns.ToAppNamespace(), []byte("data"), 0) + blobbyTheBlob, err := share.NewV0Blob(ns, []byte("data")) require.NoError(t, err) testcases := []struct { name string - blobs []*squareblob.Blob + blobs []*share.Blob gasPrice float64 gasLim uint64 expErr error }{ { name: "empty blobs", - blobs: []*squareblob.Blob{}, + blobs: []*share.Blob{}, gasPrice: DefaultGasPrice, gasLim: 0, expErr: errors.New("state: no blobs provided"), }, { name: "good blob with user provided gas and fees", - blobs: []*squareblob.Blob{blobbyTheBlob}, + blobs: []*share.Blob{blobbyTheBlob}, gasPrice: 0.005, - gasLim: apptypes.DefaultEstimateGas([]uint32{uint32(len(blobbyTheBlob.GetData()))}), + gasLim: apptypes.DefaultEstimateGas([]uint32{uint32(blobbyTheBlob.DataLen())}), expErr: nil, }, // TODO: add more test cases. The problem right now is that the celestia-app doesn't diff --git a/state/integration_test.go b/state/integration_test.go index 5a9a0892ea..8680b4d181 100644 --- a/state/integration_test.go +++ b/state/integration_test.go @@ -16,9 +16,9 @@ import ( rpcclient "github.com/tendermint/tendermint/rpc/client" "google.golang.org/grpc" - "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" - "github.com/celestiaorg/celestia-app/v2/test/util/genesis" - "github.com/celestiaorg/celestia-app/v2/test/util/testnode" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + "github.com/celestiaorg/celestia-app/v3/test/util/genesis" + "github.com/celestiaorg/celestia-app/v3/test/util/testnode" libhead "github.com/celestiaorg/go-header" "github.com/celestiaorg/celestia-node/core" diff --git a/state/state.go b/state/state.go index 5f09bcc19b..bb423bba34 100644 --- a/state/state.go +++ b/state/state.go @@ -8,7 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" coretypes "github.com/tendermint/tendermint/types" - squareblob "github.com/celestiaorg/go-square/blob" + "github.com/celestiaorg/go-square/v2/share" ) // Balance is an alias to the Coin type from Cosmos-SDK. @@ -27,7 +27,7 @@ type Address struct { } // Blob is an alias of Blob from go-square. -type Blob = squareblob.Blob +type Blob = share.Blob // ValAddress is an alias to the ValAddress type from Cosmos-SDK. type ValAddress = sdk.ValAddress diff --git a/state/tx_config.go b/state/tx_config.go index 0c0ea5e372..179a33050a 100644 --- a/state/tx_config.go +++ b/state/tx_config.go @@ -8,8 +8,8 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" sdktypes "github.com/cosmos/cosmos-sdk/types" - "github.com/celestiaorg/celestia-app/v2/pkg/user" - apptypes "github.com/celestiaorg/celestia-app/v2/x/blob/types" + "github.com/celestiaorg/celestia-app/v3/pkg/user" + apptypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" ) const ( diff --git a/store/cache/accessor_cache.go b/store/cache/accessor_cache.go index 893c73b7a9..2b99bfee13 100644 --- a/store/cache/accessor_cache.go +++ b/store/cache/accessor_cache.go @@ -10,7 +10,7 @@ import ( lru "github.com/hashicorp/golang-lru/v2" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square/eds" ) const defaultCloseTimeout = time.Minute diff --git a/store/cache/accessor_cache_test.go b/store/cache/accessor_cache_test.go index 876a4fdc5a..16fd7d1a7d 100644 --- a/store/cache/accessor_cache_test.go +++ b/store/cache/accessor_cache_test.go @@ -11,11 +11,12 @@ import ( "github.com/stretchr/testify/require" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" ) func TestAccessorCache(t *testing.T) { @@ -306,11 +307,11 @@ func (m *mockAccessor) Size(context.Context) int { panic("implement me") } -func (m *mockAccessor) DataHash(context.Context) (share.DataHash, error) { +func (m *mockAccessor) DataHash(context.Context) (square.DataHash, error) { panic("implement me") } -func (m *mockAccessor) AxisRoots(context.Context) (*share.AxisRoots, error) { +func (m *mockAccessor) AxisRoots(context.Context) (*square.AxisRoots, error) { panic("implement me") } diff --git a/store/cache/cache.go b/store/cache/cache.go index 10e7dffcb3..6e5438913a 100644 --- a/store/cache/cache.go +++ b/store/cache/cache.go @@ -7,7 +7,7 @@ import ( logging "github.com/ipfs/go-log/v2" "go.opentelemetry.io/otel" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square/eds" ) var ( diff --git a/store/cache/doublecache.go b/store/cache/doublecache.go index d0fb2c47b9..f06bd06fe7 100644 --- a/store/cache/doublecache.go +++ b/store/cache/doublecache.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square/eds" ) // DoubleCache represents a Cache that looks into multiple caches one by one. diff --git a/store/cache/noop.go b/store/cache/noop.go index 1a8aeb16c2..5be2eef20b 100644 --- a/store/cache/noop.go +++ b/store/cache/noop.go @@ -4,11 +4,12 @@ import ( "context" "io" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" ) var _ Cache = (*NoopCache)(nil) @@ -50,12 +51,12 @@ func (n NoopFile) Size(context.Context) int { return 0 } -func (n NoopFile) DataHash(context.Context) (share.DataHash, error) { - return share.DataHash{}, nil +func (n NoopFile) DataHash(context.Context) (square.DataHash, error) { + return square.DataHash{}, nil } -func (n NoopFile) AxisRoots(context.Context) (*share.AxisRoots, error) { - return &share.AxisRoots{}, nil +func (n NoopFile) AxisRoots(context.Context) (*square.AxisRoots, error) { + return &square.AxisRoots{}, nil } func (n NoopFile) Sample(context.Context, int, int) (shwap.Sample, error) { diff --git a/store/file/codec_test.go b/store/file/codec_test.go index 857c16aff0..0ab9b7c5bb 100644 --- a/store/file/codec_test.go +++ b/store/file/codec_test.go @@ -7,7 +7,7 @@ import ( "github.com/klauspost/reedsolomon" "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/share/sharetest" + "github.com/celestiaorg/go-square/v2/share" ) func BenchmarkCodec(b *testing.B) { @@ -70,13 +70,13 @@ func BenchmarkCodec(b *testing.B) { func newShards(b testing.TB, size int, fillParity bool) [][]byte { shards := make([][]byte, size) - original := sharetest.RandShares(b, size/2) - copy(shards, original) + original := share.RandShares(size / 2) + copy(shards, share.ToBytes(original)) if fillParity { // fill with parity empty Shares for j := len(original); j < len(shards); j++ { - shards[j] = make([]byte, len(original[0])) + shards[j] = make([]byte, share.ShareSize) } } return shards diff --git a/store/file/header.go b/store/file/header.go index 7c2d8c7924..bb5f891870 100644 --- a/store/file/header.go +++ b/store/file/header.go @@ -5,7 +5,7 @@ import ( "fmt" "io" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" ) // headerVOSize is the size of the headerV0 in bytes. It has more space than the headerV0 struct @@ -23,7 +23,7 @@ type headerV0 struct { shareSize uint16 squareSize uint16 - datahash share.DataHash + datahash square.DataHash } type fileVersion uint8 @@ -75,7 +75,7 @@ func (h *headerV0) Size() int { func (h *headerV0) RootsSize() int { // axis roots are stored in two parts: row roots and column roots, each part has size equal to // the square size. Thus, the total amount of roots is equal to the square size * 2. - return share.AxisRootSize * h.SquareSize() * 2 + return square.AxisRootSize * h.SquareSize() * 2 } func (h *headerV0) OffsetWithRoots() int { diff --git a/store/file/ods.go b/store/file/ods.go index 8ade66bf53..fd6285971a 100644 --- a/store/file/ods.go +++ b/store/file/ods.go @@ -9,11 +9,12 @@ import ( "os" "sync" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" ) var _ eds.AccessorStreamer = (*ODS)(nil) @@ -33,7 +34,7 @@ type ODS struct { // repeated file reads. - Serving full ODS data by Shares(). // Storing the square in memory allows for efficient single-read operations, avoiding the need for // piecemeal reads by rows or columns, and facilitates quick access to data for these operations. - ods square + ods dataSquare // disableCache is a flag that, when set to true, disables the in-memory cache of the original data // Used for testing and benchmarking purposes, this flag allows for the evaluation of the // performance. @@ -45,7 +46,7 @@ type ODS struct { // It may leave partially written file if any of the writes fail. func CreateODS( path string, - roots *share.AxisRoots, + roots *square.AxisRoots, eds *rsmt2d.ExtendedDataSquare, ) error { mod := os.O_RDWR | os.O_CREATE | os.O_EXCL // ensure we fail if already exist @@ -56,7 +57,7 @@ func CreateODS( hdr := &headerV0{ fileVersion: fileV0, - shareSize: share.Size, + shareSize: share.ShareSize, squareSize: uint16(eds.Width()), datahash: roots.Hash(), } @@ -70,7 +71,7 @@ func CreateODS( } // writeQ4File full ODS content into OS File. -func writeODSFile(f *os.File, axisRoots *share.AxisRoots, eds *rsmt2d.ExtendedDataSquare, hdr *headerV0) error { +func writeODSFile(f *os.File, axisRoots *square.AxisRoots, eds *rsmt2d.ExtendedDataSquare, hdr *headerV0) error { // buffering gives us ~4x speed up buf := bufio.NewWriterSize(f, writeBufferSize) @@ -100,11 +101,15 @@ func writeODS(w io.Writer, eds *rsmt2d.ExtendedDataSquare) error { for i := range eds.Width() / 2 { for j := range eds.Width() / 2 { shr := eds.GetCell(i, j) // TODO: Avoid copying inside GetCell - if share.GetNamespace(shr).Equals(share.TailPaddingNamespace) { + ns, err := share.NewNamespace(shr[share.VersionIndex], shr[share.VersionIndex:share.NamespaceIDSize]) + if err != nil { + return fmt.Errorf("creating namespace: %w", err) + } + if ns.Equals(share.TailPaddingNamespace) { return nil } - _, err := w.Write(shr) + _, err = w.Write(shr) if err != nil { return fmt.Errorf("writing share: %w", err) } @@ -114,7 +119,7 @@ func writeODS(w io.Writer, eds *rsmt2d.ExtendedDataSquare) error { } // writeAxisRoots writes RowRoots followed by ColumnRoots. -func writeAxisRoots(w io.Writer, roots *share.AxisRoots) error { +func writeAxisRoots(w io.Writer, roots *square.AxisRoots) error { for _, root := range roots.RowRoots { if _, err := w.Write(root); err != nil { return fmt.Errorf("writing row roots: %w", err) @@ -162,13 +167,13 @@ func (o *ODS) size() int { } // DataHash returns root hash of Accessor's underlying EDS. -func (o *ODS) DataHash(context.Context) (share.DataHash, error) { +func (o *ODS) DataHash(context.Context) (square.DataHash, error) { return o.hdr.datahash, nil } // AxisRoots reads AxisRoots stored in the file. AxisRoots are stored after the header and before // the ODS data. -func (o *ODS) AxisRoots(context.Context) (*share.AxisRoots, error) { +func (o *ODS) AxisRoots(context.Context) (*square.AxisRoots, error) { roots := make([]byte, o.hdr.RootsSize()) n, err := o.fl.ReadAt(roots, int64(o.hdr.Size())) if err != nil { @@ -180,10 +185,10 @@ func (o *ODS) AxisRoots(context.Context) (*share.AxisRoots, error) { rowRoots := make([][]byte, o.size()) colRoots := make([][]byte, o.size()) for i := 0; i < o.size(); i++ { - rowRoots[i] = roots[i*share.AxisRootSize : (i+1)*share.AxisRootSize] - colRoots[i] = roots[(o.size()+i)*share.AxisRootSize : (o.size()+i+1)*share.AxisRootSize] + rowRoots[i] = roots[i*square.AxisRootSize : (i+1)*square.AxisRootSize] + colRoots[i] = roots[(o.size()+i)*square.AxisRootSize : (o.size()+i+1)*square.AxisRootSize] } - axisRoots := &share.AxisRoots{ + axisRoots := &square.AxisRoots{ RowRoots: rowRoots, ColumnRoots: colRoots, } @@ -316,7 +321,7 @@ func (o *ODS) readAxisHalf(axisType rsmt2d.Axis, axisIdx int) (eds.AxisHalf, err }, nil } -func (o *ODS) readODS() (square, error) { +func (o *ODS) readODS() (dataSquare, error) { if !o.disableCache { o.lock.RLock() ods := o.ods @@ -377,10 +382,14 @@ func readRowHalf(r io.ReaderAt, rowIdx int, hdr *headerV0, offset int) ([]share. if i > shrsRead-1 { // partial or empty row was read // fill the rest with tail padding it - shares[i] = share.TailPadding() + shares[i] = share.TailPaddingShare() continue } - shares[i] = axsData[i*hdr.ShareSize() : (i+1)*hdr.ShareSize()] + sh, err := share.NewShare(axsData[i*hdr.ShareSize() : (i+1)*hdr.ShareSize()]) + if err != nil { + return nil, err + } + shares[i] = *sh } return shares, nil } @@ -394,7 +403,7 @@ func readColHalf(r io.ReaderAt, colIdx int, hdr *headerV0, offset int) ([]share. pos := colIdx + i*odsLn offset := offset + pos*hdr.ShareSize() - shr := make(share.Share, hdr.ShareSize()) + shr := make([]byte, hdr.ShareSize()) n, err := r.ReadAt(shr, int64(offset)) if err != nil && !errors.Is(err, io.EOF) { // unknown error @@ -404,12 +413,17 @@ func readColHalf(r io.ReaderAt, colIdx int, hdr *headerV0, offset int) ([]share. // no shares left // fill the rest with tail padding for ; i < len(shares); i++ { - shares[i] = share.TailPadding() + shares[i] = share.TailPaddingShare() } return shares, nil } + + sh, err := share.NewShare(shr) + if err != nil { + return nil, err + } // we got a share - shares[i] = shr + shares[i] = *sh } return shares, nil } diff --git a/store/file/ods_q4.go b/store/file/ods_q4.go index 70c48b5749..e6b4cae8e3 100644 --- a/store/file/ods_q4.go +++ b/store/file/ods_q4.go @@ -9,11 +9,12 @@ import ( "sync" "sync/atomic" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" ) var _ eds.AccessorStreamer = (*ODSQ4)(nil) @@ -36,7 +37,7 @@ type ODSQ4 struct { // CreateODSQ4 creates ODS and Q4 files under the given FS paths. func CreateODSQ4( pathODS, pathQ4 string, - roots *share.AxisRoots, + roots *square.AxisRoots, eds *rsmt2d.ExtendedDataSquare, ) error { errCh := make(chan error) @@ -102,11 +103,11 @@ func (odsq4 *ODSQ4) Size(ctx context.Context) int { return odsq4.ods.Size(ctx) } -func (odsq4 *ODSQ4) DataHash(ctx context.Context) (share.DataHash, error) { +func (odsq4 *ODSQ4) DataHash(ctx context.Context) (square.DataHash, error) { return odsq4.ods.DataHash(ctx) } -func (odsq4 *ODSQ4) AxisRoots(ctx context.Context) (*share.AxisRoots, error) { +func (odsq4 *ODSQ4) AxisRoots(ctx context.Context) (*square.AxisRoots, error) { return odsq4.ods.AxisRoots(ctx) } diff --git a/store/file/ods_q4_test.go b/store/file/ods_q4_test.go index 4d9d852e05..24476f4d4b 100644 --- a/store/file/ods_q4_test.go +++ b/store/file/ods_q4_test.go @@ -9,11 +9,12 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/rand" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/eds/edstest" ) func TestCreateODSQ4File(t *testing.T) { @@ -26,7 +27,7 @@ func TestCreateODSQ4File(t *testing.T) { shares, err := odsq4.Shares(ctx) require.NoError(t, err) expected := edsIn.FlattenedODS() - require.Equal(t, expected, shares) + require.Equal(t, expected, share.ToBytes(shares)) require.NoError(t, odsq4.Close()) } @@ -89,7 +90,7 @@ func createODSQ4Accessor(t testing.TB, eds *rsmt2d.ExtendedDataSquare) eds.Acces func createODSQ4File(t testing.TB, eds *rsmt2d.ExtendedDataSquare) *ODSQ4 { path := t.TempDir() + "/" + strconv.Itoa(rand.Intn(1000)) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) pathODS, pathQ4 := path+".ods", path+".q4" err = CreateODSQ4(pathODS, pathQ4, roots, eds) diff --git a/store/file/ods_test.go b/store/file/ods_test.go index 2866072019..dbd1485dfa 100644 --- a/store/file/ods_test.go +++ b/store/file/ods_test.go @@ -9,11 +9,12 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/rand" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/eds/edstest" ) func TestCreateODSFile(t *testing.T) { @@ -22,18 +23,18 @@ func TestCreateODSFile(t *testing.T) { edsIn := edstest.RandEDS(t, 8) f := createODSFile(t, edsIn) - readRoots, err := share.NewAxisRoots(edsIn) + readRoots, err := square.NewAxisRoots(edsIn) require.NoError(t, err) shares, err := f.Shares(ctx) require.NoError(t, err) expected := edsIn.FlattenedODS() - require.Equal(t, expected, shares) + require.Equal(t, expected, share.ToBytes(shares)) roots, err := f.AxisRoots(ctx) require.NoError(t, err) - require.Equal(t, share.DataHash(roots.Hash()), f.hdr.datahash) + require.Equal(t, square.DataHash(roots.Hash()), f.hdr.datahash) require.True(t, roots.Equals(readRoots)) require.NoError(t, f.Close()) } @@ -47,7 +48,7 @@ func TestReadODSFromFile(t *testing.T) { for i, row := range ods { original := eds.Row(uint(i))[:eds.Width()/2] require.True(t, len(original) == len(row)) - require.Equal(t, original, row) + require.Equal(t, original, share.ToBytes(row)) } } @@ -159,7 +160,7 @@ func createCachedStreamer(t testing.TB, eds *rsmt2d.ExtendedDataSquare) eds.Acce func createODSFile(t testing.TB, eds *rsmt2d.ExtendedDataSquare) *ODS { path := t.TempDir() + "/" + strconv.Itoa(rand.Intn(1000)) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) err = CreateODS(path, roots, eds) require.NoError(t, err) diff --git a/store/file/q4.go b/store/file/q4.go index 503ecfb397..139ed28806 100644 --- a/store/file/q4.go +++ b/store/file/q4.go @@ -9,7 +9,7 @@ import ( "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square/eds" ) // q4 stores the fourth quadrant of the square. diff --git a/store/file/square.go b/store/file/square.go index c1a432e3a8..a12cf41c03 100644 --- a/store/file/square.go +++ b/store/file/square.go @@ -6,47 +6,47 @@ import ( "golang.org/x/sync/errgroup" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square/eds" ) -type square [][]share.Share +type dataSquare [][]share.Share // readSquare reads Shares from the reader and returns a square. It assumes that the reader is // positioned at the beginning of the Shares. It knows the size of the Shares and the size of the // square, so reads from reader are limited to exactly the amount of data required. -func readSquare(r io.Reader, shareSize, edsSize int) (square, error) { +func readSquare(r io.Reader, shareSize, edsSize int) (dataSquare, error) { odsLn := edsSize / 2 shares, err := eds.ReadShares(r, shareSize, odsLn) if err != nil { return nil, fmt.Errorf("reading shares: %w", err) } - square := make(square, odsLn) + square := make(dataSquare, odsLn) for i := range square { square[i] = shares[i*odsLn : (i+1)*odsLn] } return square, nil } -func (s square) reader() (io.Reader, error) { +func (s dataSquare) reader() (io.Reader, error) { if s == nil { return nil, fmt.Errorf("ods file not cached") } getShare := func(rowIdx, colIdx int) ([]byte, error) { - return s[rowIdx][colIdx], nil + return s[rowIdx][colIdx].ToBytes(), nil } reader := eds.NewShareReader(s.size(), getShare) return reader, nil } -func (s square) size() int { +func (s dataSquare) size() int { return len(s) } -func (s square) shares() ([]share.Share, error) { +func (s dataSquare) shares() ([]share.Share, error) { shares := make([]share.Share, 0, s.size()*s.size()) for _, row := range s { shares = append(shares, row...) @@ -54,7 +54,7 @@ func (s square) shares() ([]share.Share, error) { return shares, nil } -func (s square) axisHalf(axisType rsmt2d.Axis, axisIdx int) (eds.AxisHalf, error) { +func (s dataSquare) axisHalf(axisType rsmt2d.Axis, axisIdx int) (eds.AxisHalf, error) { if s == nil { return eds.AxisHalf{}, fmt.Errorf("square is nil") } @@ -83,7 +83,7 @@ func (s square) axisHalf(axisType rsmt2d.Axis, axisIdx int) (eds.AxisHalf, error }, nil } -func (s square) computeAxisHalf( +func (s dataSquare) computeAxisHalf( axisType rsmt2d.Axis, axisIdx int, ) (eds.AxisHalf, error) { @@ -106,9 +106,9 @@ func (s square) computeAxisHalf( shards := make([][]byte, s.size()*2) if half.IsParity { - copy(shards[s.size():], half.Shares) + copy(shards[s.size():], share.ToBytes(half.Shares)) } else { - copy(shards, half.Shares) + copy(shards, share.ToBytes(half.Shares)) } target := make([]bool, s.size()*2) @@ -119,7 +119,11 @@ func (s square) computeAxisHalf( return fmt.Errorf("reconstruct some: %w", err) } - shares[i] = shards[axisIdx] + shard, err := share.NewShare(shards[axisIdx]) + if err != nil { + return fmt.Errorf("creating share: %w", err) + } + shares[i] = *shard return nil }) } diff --git a/store/getter.go b/store/getter.go index 7a78aa8fc5..e436aa0489 100644 --- a/store/getter.go +++ b/store/getter.go @@ -5,13 +5,13 @@ import ( "errors" "fmt" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/square/shwap" ) var _ shwap.Getter = (*Getter)(nil) @@ -28,9 +28,9 @@ func (g *Getter) GetShare(ctx context.Context, h *header.ExtendedHeader, row, co acc, err := g.store.GetByHeight(ctx, h.Height()) if err != nil { if errors.Is(err, ErrNotFound) { - return nil, shwap.ErrNotFound + return share.Share{}, shwap.ErrNotFound } - return nil, fmt.Errorf("get accessor from store:%w", err) + return share.Share{}, fmt.Errorf("get accessor from store:%w", err) } logger := log.With( "height", h.Height(), @@ -41,7 +41,7 @@ func (g *Getter) GetShare(ctx context.Context, h *header.ExtendedHeader, row, co sample, err := acc.Sample(ctx, row, col) if err != nil { - return nil, fmt.Errorf("get sample from accessor:%w", err) + return share.Share{}, fmt.Errorf("get sample from accessor:%w", err) } return sample.Share, nil } diff --git a/store/getter_test.go b/store/getter_test.go index 9e2b06feda..5693e2cc57 100644 --- a/store/getter_test.go +++ b/store/getter_test.go @@ -7,10 +7,11 @@ import ( "github.com/stretchr/testify/require" + "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/share/eds/edstest" - "github.com/celestiaorg/celestia-node/share/sharetest" - "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/square/shwap" ) func TestStoreGetter(t *testing.T) { @@ -37,7 +38,7 @@ func TestStoreGetter(t *testing.T) { for j := 0; j < squareSize; j++ { share, err := sg.GetShare(ctx, eh, i, j) require.NoError(t, err) - require.Equal(t, eds.GetCell(uint(i), uint(j)), share) + require.Equal(t, eds.GetCell(uint(i), uint(j)), share.ToBytes()) } } @@ -66,7 +67,7 @@ func TestStoreGetter(t *testing.T) { }) t.Run("GetSharesByNamespace", func(t *testing.T) { - ns := sharetest.RandV0Namespace() + ns := share.RandomNamespace() eds, roots := edstest.RandEDSWithNamespace(t, ns, 8, 16) eh := headertest.RandExtendedHeaderWithRoot(t, roots) height := height.Add(1) @@ -79,7 +80,7 @@ func TestStoreGetter(t *testing.T) { require.NoError(t, shares.Verify(eh.DAH, ns)) // namespace not found - randNamespace := sharetest.RandV0Namespace() + randNamespace := share.RandomNamespace() emptyShares, err := sg.GetSharesByNamespace(ctx, eh, randNamespace) require.NoError(t, err) require.Empty(t, emptyShares.Flatten()) diff --git a/store/store.go b/store/store.go index ac8951e50b..c6d7cd5426 100644 --- a/store/store.go +++ b/store/store.go @@ -14,8 +14,8 @@ import ( "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds" "github.com/celestiaorg/celestia-node/store/cache" "github.com/celestiaorg/celestia-node/store/file" ) @@ -92,7 +92,7 @@ func (s *Store) Stop(context.Context) error { func (s *Store) PutODSQ4( ctx context.Context, - roots *share.AxisRoots, + roots *square.AxisRoots, height uint64, square *rsmt2d.ExtendedDataSquare, ) error { @@ -101,7 +101,7 @@ func (s *Store) PutODSQ4( func (s *Store) PutODS( ctx context.Context, - roots *share.AxisRoots, + roots *square.AxisRoots, height uint64, square *rsmt2d.ExtendedDataSquare, ) error { @@ -110,12 +110,12 @@ func (s *Store) PutODS( func (s *Store) put( ctx context.Context, - roots *share.AxisRoots, + roots *square.AxisRoots, height uint64, - square *rsmt2d.ExtendedDataSquare, + dataSquare *rsmt2d.ExtendedDataSquare, writeQ4 bool, ) error { - datahash := share.DataHash(roots.Hash()) + datahash := square.DataHash(roots.Hash()) // we don't need to store empty EDS, just link the height to the empty file if datahash.IsEmptyEDS() { lock := s.stripLock.byHeight(height) @@ -126,7 +126,7 @@ func (s *Store) put( } // put to cache before writing to make it accessible while write is happening - accessor := &eds.Rsmt2D{ExtendedDataSquare: square} + accessor := &eds.Rsmt2D{ExtendedDataSquare: dataSquare} acc, err := s.cache.GetOrLoad(ctx, height, accessorLoader(accessor)) if err != nil { log.Warnf("failed to put Accessor in the recent cache: %s", err) @@ -142,9 +142,9 @@ func (s *Store) put( var exists bool if writeQ4 { - exists, err = s.createODSQ4File(square, roots, height) + exists, err = s.createODSQ4File(dataSquare, roots, height) } else { - exists, err = s.createODSFile(square, roots, height) + exists, err = s.createODSFile(dataSquare, roots, height) } if exists { @@ -152,17 +152,17 @@ func (s *Store) put( return nil } if err != nil { - s.metrics.observePut(ctx, time.Since(tNow), square.Width(), writeQ4, true) + s.metrics.observePut(ctx, time.Since(tNow), dataSquare.Width(), writeQ4, true) return fmt.Errorf("creating file: %w", err) } - s.metrics.observePut(ctx, time.Since(tNow), square.Width(), writeQ4, false) + s.metrics.observePut(ctx, time.Since(tNow), dataSquare.Width(), writeQ4, false) return nil } func (s *Store) createODSQ4File( square *rsmt2d.ExtendedDataSquare, - roots *share.AxisRoots, + roots *square.AxisRoots, height uint64, ) (bool, error) { pathODS := s.hashToPath(roots.Hash(), odsFileExt) @@ -197,7 +197,7 @@ func (s *Store) createODSQ4File( func (s *Store) createODSFile( square *rsmt2d.ExtendedDataSquare, - roots *share.AxisRoots, + roots *square.AxisRoots, height uint64, ) (bool, error) { pathODS := s.hashToPath(roots.Hash(), odsFileExt) @@ -228,7 +228,7 @@ func (s *Store) createODSFile( return false, nil } -func (s *Store) linkHeight(datahash share.DataHash, height uint64) error { +func (s *Store) linkHeight(datahash square.DataHash, height uint64) error { // create hard link with height as name pathOds := s.hashToPath(datahash, odsFileExt) linktoOds := s.heightToPath(height, odsFileExt) @@ -244,15 +244,15 @@ func (s *Store) linkHeight(datahash share.DataHash, height uint64) error { // It overrides existing empty file to ensure disk format is always consistent with the canonical // in-mem representation. func (s *Store) populateEmptyFile() error { - pathOds := s.hashToPath(share.EmptyEDSDataHash(), odsFileExt) - pathQ4 := s.hashToPath(share.EmptyEDSDataHash(), q4FileExt) + pathOds := s.hashToPath(square.EmptyEDSDataHash(), odsFileExt) + pathQ4 := s.hashToPath(square.EmptyEDSDataHash(), q4FileExt) err := errors.Join(remove(pathOds), remove(pathQ4)) if err != nil { return fmt.Errorf("cleaning old empty EDS file: %w", err) } - err = file.CreateODSQ4(pathOds, pathQ4, share.EmptyEDSRoots(), eds.EmptyAccessor.ExtendedDataSquare) + err = file.CreateODSQ4(pathOds, pathQ4, square.EmptyEDSRoots(), eds.EmptyAccessor.ExtendedDataSquare) if err != nil { return fmt.Errorf("creating fresh empty EDS file: %w", err) } @@ -260,7 +260,7 @@ func (s *Store) populateEmptyFile() error { return nil } -func (s *Store) GetByHash(ctx context.Context, datahash share.DataHash) (eds.AccessorStreamer, error) { +func (s *Store) GetByHash(ctx context.Context, datahash square.DataHash) (eds.AccessorStreamer, error) { if datahash.IsEmptyEDS() { return eds.EmptyAccessor, nil } @@ -274,7 +274,7 @@ func (s *Store) GetByHash(ctx context.Context, datahash share.DataHash) (eds.Acc return f, err } -func (s *Store) getByHash(ctx context.Context, datahash share.DataHash) (eds.AccessorStreamer, error) { +func (s *Store) getByHash(ctx context.Context, datahash square.DataHash) (eds.AccessorStreamer, error) { path := s.hashToPath(datahash, odsFileExt) return s.openAccessor(ctx, path) } @@ -323,7 +323,7 @@ func (s *Store) openAccessor(ctx context.Context, path string) (eds.AccessorStre return wrapAccessor(odsQ4), nil } -func (s *Store) HasByHash(ctx context.Context, datahash share.DataHash) (bool, error) { +func (s *Store) HasByHash(ctx context.Context, datahash square.DataHash) (bool, error) { if datahash.IsEmptyEDS() { return true, nil } @@ -338,7 +338,7 @@ func (s *Store) HasByHash(ctx context.Context, datahash share.DataHash) (bool, e return exist, err } -func (s *Store) hasByHash(datahash share.DataHash) (bool, error) { +func (s *Store) hasByHash(datahash square.DataHash) (bool, error) { // For now, we assume that if ODS exists, the Q4 exists as well. path := s.hashToPath(datahash, odsFileExt) return exists(path) @@ -367,7 +367,7 @@ func (s *Store) hasByHeight(height uint64) (bool, error) { return exists(pathODS) } -func (s *Store) RemoveODSQ4(ctx context.Context, height uint64, datahash share.DataHash) error { +func (s *Store) RemoveODSQ4(ctx context.Context, height uint64, datahash square.DataHash) error { lock := s.stripLock.byHashAndHeight(datahash, height) lock.lock() defer lock.unlock() @@ -378,7 +378,7 @@ func (s *Store) RemoveODSQ4(ctx context.Context, height uint64, datahash share.D return err } -func (s *Store) removeODSQ4(height uint64, datahash share.DataHash) error { +func (s *Store) removeODSQ4(height uint64, datahash square.DataHash) error { if err := s.removeODS(height, datahash); err != nil { return fmt.Errorf("removing ODS: %w", err) } @@ -388,7 +388,7 @@ func (s *Store) removeODSQ4(height uint64, datahash share.DataHash) error { return nil } -func (s *Store) removeODS(height uint64, datahash share.DataHash) error { +func (s *Store) removeODS(height uint64, datahash square.DataHash) error { if err := s.cache.Remove(height); err != nil { return fmt.Errorf("removing from cache: %w", err) } @@ -410,7 +410,7 @@ func (s *Store) removeODS(height uint64, datahash share.DataHash) error { return nil } -func (s *Store) RemoveQ4(ctx context.Context, height uint64, datahash share.DataHash) error { +func (s *Store) RemoveQ4(ctx context.Context, height uint64, datahash square.DataHash) error { lock := s.stripLock.byHashAndHeight(datahash, height) lock.lock() defer lock.unlock() @@ -421,7 +421,7 @@ func (s *Store) RemoveQ4(ctx context.Context, height uint64, datahash share.Data return err } -func (s *Store) removeQ4(height uint64, datahash share.DataHash) error { +func (s *Store) removeQ4(height uint64, datahash square.DataHash) error { // if datahash is empty, we don't need to remove the Q4 file if datahash.IsEmptyEDS() { return nil @@ -439,7 +439,7 @@ func (s *Store) removeQ4(height uint64, datahash share.DataHash) error { return nil } -func (s *Store) hashToPath(datahash share.DataHash, ext string) string { +func (s *Store) hashToPath(datahash square.DataHash, ext string) string { return filepath.Join(s.basepath, blocksPath, datahash.String()) + ext } diff --git a/store/store_cache.go b/store/store_cache.go index 7d9de15cb1..fd7cb751ab 100644 --- a/store/store_cache.go +++ b/store/store_cache.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/square/eds" "github.com/celestiaorg/celestia-node/store/cache" ) diff --git a/store/store_test.go b/store/store_test.go index cb038e5349..6e25f2512b 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -10,10 +10,11 @@ import ( "github.com/stretchr/testify/require" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/share" - "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/square/eds/edstest" "github.com/celestiaorg/celestia-node/store/cache" ) @@ -67,7 +68,7 @@ func TestEDSStore(t *testing.T) { require.NoError(t, err) require.NoError(t, f.Close()) expected := eds.FlattenedODS() - require.Equal(t, expected, fromFile) + require.Equal(t, expected, share.ToBytes(fromFile)) }) t.Run("Second Put should be noop", func(t *testing.T) { @@ -105,7 +106,7 @@ func TestEDSStore(t *testing.T) { require.NoError(t, err) require.NoError(t, f.Close()) expected := eds.FlattenedODS() - require.Equal(t, expected, fromFile) + require.Equal(t, expected, share.ToBytes(fromFile)) }) t.Run("GetByHash", func(t *testing.T) { @@ -123,7 +124,7 @@ func TestEDSStore(t *testing.T) { require.NoError(t, err) require.NoError(t, f.Close()) expected := eds.FlattenedODS() - require.Equal(t, expected, fromFile) + require.Equal(t, expected, share.ToBytes(fromFile)) }) t.Run("Does not exist", func(t *testing.T) { @@ -147,8 +148,8 @@ func TestEDSStore(t *testing.T) { require.NoError(t, err) height := height.Add(1) - hash := share.EmptyEDSDataHash() - err = edsStore.PutODSQ4(ctx, share.EmptyEDSRoots(), height, share.EmptyEDS()) + hash := square.EmptyEDSDataHash() + err = edsStore.PutODSQ4(ctx, square.EmptyEDSRoots(), height, square.EmptyEDS()) require.NoError(t, err) ensureAmountFileAndLinks(t, dir, 0, 1) @@ -173,7 +174,7 @@ func TestEDSStore(t *testing.T) { // removing file that does not exist should be noop missingHeight := height.Add(1) - err = edsStore.RemoveODSQ4(ctx, missingHeight, share.DataHash{0x01, 0x02}) + err = edsStore.RemoveODSQ4(ctx, missingHeight, square.DataHash{0x01, 0x02}) require.NoError(t, err) eds, roots := randomEDS(t) @@ -209,8 +210,8 @@ func TestEDSStore(t *testing.T) { require.NoError(t, err) height := height.Add(1) - hash := share.EmptyEDSDataHash() - err = edsStore.PutODSQ4(ctx, share.EmptyEDSRoots(), height, share.EmptyEDS()) + hash := square.EmptyEDSDataHash() + err = edsStore.PutODSQ4(ctx, square.EmptyEDSRoots(), height, square.EmptyEDS()) require.NoError(t, err) // empty file is not counted as a file ensureAmountFileAndLinks(t, dir, 0, 1) @@ -255,8 +256,8 @@ func TestEDSStore(t *testing.T) { }) t.Run("empty EDS returned by hash", func(t *testing.T) { - eds := share.EmptyEDS() - roots, err := share.NewAxisRoots(eds) + eds := square.EmptyEDS() + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) // assert that the empty file exists @@ -273,8 +274,8 @@ func TestEDSStore(t *testing.T) { }) t.Run("empty EDS returned by height", func(t *testing.T) { - eds := share.EmptyEDS() - roots, err := share.NewAxisRoots(eds) + eds := square.EmptyEDS() + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) height := height.Add(1) @@ -300,8 +301,8 @@ func TestEDSStore(t *testing.T) { edsStore, err := NewStore(DefaultParameters(), dir) require.NoError(t, err) - eds := share.EmptyEDS() - roots, err := share.NewAxisRoots(eds) + eds := square.EmptyEDS() + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) from, to := 10, 20 @@ -342,7 +343,7 @@ func BenchmarkStore(b *testing.B) { b.Cleanup(cancel) eds := edstest.RandEDS(b, 128) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(b, err) // BenchmarkStore/put_128-16 186 6623266 ns/op @@ -393,9 +394,9 @@ func BenchmarkStore(b *testing.B) { }) } -func randomEDS(t testing.TB) (*rsmt2d.ExtendedDataSquare, *share.AxisRoots) { +func randomEDS(t testing.TB) (*rsmt2d.ExtendedDataSquare, *square.AxisRoots) { eds := edstest.RandEDS(t, 4) - roots, err := share.NewAxisRoots(eds) + roots, err := square.NewAxisRoots(eds) require.NoError(t, err) return eds, roots @@ -421,7 +422,7 @@ func hasByHashAndHeight( t testing.TB, store *Store, ctx context.Context, - hash share.DataHash, + hash square.DataHash, height uint64, hasByHash, hasByHeight bool, ) { diff --git a/store/striplock.go b/store/striplock.go index 4738453c77..eb23facab2 100644 --- a/store/striplock.go +++ b/store/striplock.go @@ -3,7 +3,7 @@ package store import ( "sync" - "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/square" ) // TODO: move to utils @@ -31,14 +31,14 @@ func (l *striplock) byHeight(height uint64) *sync.RWMutex { return l.heights[lkIdx] } -func (l *striplock) byHash(datahash share.DataHash) *sync.RWMutex { +func (l *striplock) byHash(datahash square.DataHash) *sync.RWMutex { // Use the last 2 bytes of the hash as key to distribute the locks last := uint16(datahash[len(datahash)-1]) | uint16(datahash[len(datahash)-2])<<8 lkIdx := last % uint16(len(l.datahashes)) return l.datahashes[lkIdx] } -func (l *striplock) byHashAndHeight(datahash share.DataHash, height uint64) *multiLock { +func (l *striplock) byHashAndHeight(datahash square.DataHash, height uint64) *multiLock { return &multiLock{[]*sync.RWMutex{l.byHash(datahash), l.byHeight(height)}} }