From 3b1ddaaa94f1e2cfc59aaa978e6cd02090929234 Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Mon, 7 Oct 2024 13:29:46 +0300 Subject: [PATCH] return share package back --- api/docgen/examples.go | 10 +- api/gateway/availability.go | 4 +- api/gateway/share.go | 24 +- api/gateway/share_test.go | 10 +- blob/blob.go | 32 ++- blob/blob_test.go | 6 +- blob/blobtest/testing.go | 22 +- blob/commitment_proof.go | 6 +- blob/helper.go | 10 +- blob/helper_test.go | 20 +- blob/parser.go | 14 +- blob/service.go | 54 ++-- blob/service_test.go | 90 +++---- cmd/cel-shed/shwap.go | 2 +- cmd/util.go | 8 +- cmd/util_test.go | 4 +- core/eds.go | 10 +- core/eds_test.go | 10 +- core/exchange_test.go | 12 +- core/header_test.go | 4 +- core/listener.go | 2 +- core/listener_no_race_test.go | 4 +- core/listener_test.go | 2 +- das/coordinator.go | 2 +- das/coordinator_test.go | 6 +- das/daser.go | 10 +- das/daser_test.go | 12 +- das/worker.go | 2 +- docs/adr/adr-011-blocksync-overhaul-part-1.md | 2 +- header/headertest/fraud/testing.go | 4 +- header/headertest/testing.go | 12 +- libs/edssser/edssser.go | 10 +- nodebuilder/blob/blob.go | 38 +-- nodebuilder/blob/cmd/blob.go | 4 +- nodebuilder/blob/module.go | 2 +- nodebuilder/core/module.go | 2 +- nodebuilder/da/service.go | 14 +- nodebuilder/das/constructors.go | 8 +- nodebuilder/fraud/unmarshaler.go | 2 +- nodebuilder/header/constructors.go | 2 +- nodebuilder/node_test.go | 4 +- nodebuilder/p2p/module.go | 2 +- nodebuilder/p2p/routing.go | 2 +- nodebuilder/share/bitswap.go | 2 +- nodebuilder/share/cmd/share.go | 4 +- nodebuilder/share/config.go | 10 +- nodebuilder/share/constructors.go | 12 +- nodebuilder/share/mocks/api.go | 6 +- nodebuilder/share/module.go | 22 +- nodebuilder/share/opts.go | 10 +- nodebuilder/share/p2p_constructors.go | 6 +- nodebuilder/share/share.go | 40 +-- nodebuilder/state/core.go | 2 +- nodebuilder/state/state.go | 8 +- nodebuilder/state/stub.go | 4 +- nodebuilder/store.go | 6 +- nodebuilder/tests/blob_test.go | 8 +- nodebuilder/tests/da_test.go | 4 +- nodebuilder/tests/fraud_test.go | 2 +- nodebuilder/tests/nd_test.go | 18 +- nodebuilder/tests/prune_test.go | 18 +- nodebuilder/tests/reconstruct_test.go | 4 +- nodebuilder/tests/sync_test.go | 8 +- pruner/light/pruner.go | 8 +- {square => share}/availability.go | 2 +- .../availability/full/availability.go | 16 +- .../availability/full/availability_test.go | 16 +- .../availability/full/reconstruction_test.go | 10 +- .../availability/full/testing.go | 22 +- .../availability/light/availability.go | 14 +- .../availability/light/availability_test.go | 40 +-- .../availability/light/options.go | 0 .../availability/light/sample.go | 2 +- .../availability/light/sample_test.go | 0 .../availability/light/testing.go | 32 +-- .../availability/mocks/availability.go | 0 .../availability/test/testing.go | 18 +- {square => share}/doc.go | 4 +- {square => share}/eds/accessor.go | 18 +- {square => share}/eds/axis_half.go | 28 +-- {square => share}/eds/axis_half_test.go | 4 +- .../eds/byzantine/bad_encoding.go | 8 +- .../eds/byzantine/bad_encoding_test.go | 26 +- {square => share}/eds/byzantine/byzantine.go | 12 +- .../eds/byzantine/pb/share.pb.go | 58 ++--- .../eds/byzantine/pb/share.proto | 0 .../eds/byzantine/share_proof.go | 26 +- {square => share}/eds/close_once.go | 14 +- {square => share}/eds/close_once_test.go | 22 +- {square => share}/eds/edstest/testing.go | 62 ++--- {square => share}/eds/nd.go | 10 +- {square => share}/eds/nd_test.go | 6 +- {square => share}/eds/proof.go | 6 +- {square => share}/eds/proofs_cache.go | 28 +-- {square => share}/eds/proofs_cache_test.go | 0 {square => share}/eds/read.go | 16 +- {square => share}/eds/retriever.go | 20 +- .../eds/retriever_no_race_test.go | 16 +- {square => share}/eds/retriever_quadrant.go | 8 +- {square => share}/eds/retriever_test.go | 20 +- {square => share}/eds/rsmt2d.go | 38 +-- {square => share}/eds/rsmt2d_test.go | 14 +- {square => share}/eds/share_reader.go | 0 {square => share}/eds/share_reader_test.go | 6 +- {square => share}/eds/testing.go | 42 ++-- {square => share}/eds/validation.go | 6 +- {square => share}/eds/validation_test.go | 8 +- {square => share}/empty.go | 16 +- {square => share}/ipld/add.go | 12 +- {square => share}/ipld/blockserv.go | 0 {square => share}/ipld/delete.go | 0 {square => share}/ipld/delete_test.go | 6 +- {square => share}/ipld/get.go | 4 +- {square => share}/ipld/get_shares.go | 20 +- {square => share}/ipld/get_shares_test.go | 78 +++--- {square => share}/ipld/namespace_data.go | 10 +- {square => share}/ipld/nmt.go | 12 +- {square => share}/ipld/nmt_adder.go | 0 {square => share}/ipld/nmt_test.go | 6 +- {square => share}/ipld/proof_collector.go | 0 {square => share}/ipld/proofs.go | 0 {square => share}/ipld/proofs_test.go | 12 +- {square => share}/ipld/test_helpers.go | 0 {square => share}/ipld/utils.go | 8 +- {square => share}/root.go | 10 +- {square => share}/share.go | 8 +- {square => share}/shwap/eds.go | 2 +- {square => share}/shwap/eds_id.go | 0 {square => share}/shwap/eds_id_test.go | 0 {square => share}/shwap/getter.go | 6 +- {square => share}/shwap/getters/cascade.go | 14 +- .../shwap/getters/cascade_test.go | 4 +- .../shwap/getters/mock/getter.go | 2 +- {square => share}/shwap/getters/testing.go | 22 +- {square => share}/shwap/namespace_data.go | 12 +- {square => share}/shwap/namespace_data_id.go | 12 +- .../shwap/namespace_data_id_test.go | 6 +- .../shwap/p2p/bitswap/bitswap.go | 0 {square => share}/shwap/p2p/bitswap/block.go | 6 +- .../shwap/p2p/bitswap/block_fetch.go | 6 +- .../shwap/p2p/bitswap/block_fetch_test.go | 2 +- .../shwap/p2p/bitswap/block_proto.go | 2 +- .../shwap/p2p/bitswap/block_registry.go | 0 .../shwap/p2p/bitswap/block_store.go | 2 +- .../shwap/p2p/bitswap/block_test.go | 6 +- {square => share}/shwap/p2p/bitswap/cid.go | 0 {square => share}/shwap/p2p/bitswap/getter.go | 32 +-- .../shwap/p2p/bitswap/getter_test.go | 12 +- .../shwap/p2p/bitswap/pb/bitswap.pb.go | 32 +-- .../shwap/p2p/bitswap/pb/bitswap.proto | 2 +- .../shwap/p2p/bitswap/row_block.go | 10 +- .../shwap/p2p/bitswap/row_block_test.go | 6 +- .../p2p/bitswap/row_namespace_data_block.go | 14 +- .../bitswap/row_namespace_data_block_test.go | 10 +- .../shwap/p2p/bitswap/sample_block.go | 10 +- .../shwap/p2p/bitswap/sample_block_test.go | 6 +- .../shwap/p2p/discovery/backoff.go | 0 .../shwap/p2p/discovery/backoff_test.go | 0 {square => share}/shwap/p2p/discovery/dht.go | 0 .../shwap/p2p/discovery/discovery.go | 0 .../shwap/p2p/discovery/discovery_test.go | 0 .../shwap/p2p/discovery/metrics.go | 0 .../shwap/p2p/discovery/options.go | 0 {square => share}/shwap/p2p/discovery/set.go | 0 .../shwap/p2p/discovery/set_test.go | 0 {square => share}/shwap/p2p/shrex/doc.go | 2 +- {square => share}/shwap/p2p/shrex/error.go | 0 .../shwap/p2p/shrex/error_test.go | 0 {square => share}/shwap/p2p/shrex/errors.go | 0 {square => share}/shwap/p2p/shrex/metrics.go | 0 .../shwap/p2p/shrex/middleware.go | 0 {square => share}/shwap/p2p/shrex/params.go | 0 .../shwap/p2p/shrex/pb/shrex.pb.go | 38 +-- .../shwap/p2p/shrex/pb/shrex.proto | 2 +- .../shwap/p2p/shrex/peers/doc.go | 0 .../shwap/p2p/shrex/peers/manager.go | 12 +- .../shwap/p2p/shrex/peers/manager_test.go | 16 +- .../shwap/p2p/shrex/peers/metrics.go | 2 +- .../shwap/p2p/shrex/peers/options.go | 2 +- .../shwap/p2p/shrex/peers/pool.go | 0 .../shwap/p2p/shrex/peers/pool_test.go | 0 .../shwap/p2p/shrex/peers/timedqueue.go | 0 .../shwap/p2p/shrex/peers/timedqueue_test.go | 0 {square => share}/shwap/p2p/shrex/recovery.go | 0 .../shwap/p2p/shrex/shrex_getter/shrex.go | 30 +-- .../p2p/shrex/shrex_getter/shrex_test.go | 52 ++-- .../shwap/p2p/shrex/shrexeds/client.go | 14 +- .../shwap/p2p/shrex/shrexeds/doc.go | 2 +- .../shwap/p2p/shrex/shrexeds/exchange_test.go | 18 +- .../shwap/p2p/shrex/shrexeds/params.go | 4 +- .../shwap/p2p/shrex/shrexeds/server.go | 8 +- .../shwap/p2p/shrex/shrexnd/client.go | 16 +- .../shwap/p2p/shrex/shrexnd/doc.go | 4 +- .../shwap/p2p/shrex/shrexnd/exchange_test.go | 18 +- .../shwap/p2p/shrex/shrexnd/params.go | 4 +- .../shwap/p2p/shrex/shrexnd/server.go | 8 +- .../shwap/p2p/shrex/shrexsub/doc.go | 2 +- .../p2p/shrex/shrexsub/pb/notification.pb.go | 38 +-- .../p2p/shrex/shrexsub/pb/notification.proto | 2 +- .../shwap/p2p/shrex/shrexsub/pubsub.go | 6 +- .../shwap/p2p/shrex/shrexsub/pubsub_test.go | 2 +- .../shwap/p2p/shrex/shrexsub/subscription.go | 2 +- {square => share}/shwap/pb/shwap.pb.go | 68 ++--- {square => share}/shwap/pb/shwap.proto | 2 +- {square => share}/shwap/row.go | 28 +-- {square => share}/shwap/row_id.go | 2 +- {square => share}/shwap/row_id_test.go | 0 {square => share}/shwap/row_namespace_data.go | 24 +- .../shwap/row_namespace_data_id.go | 14 +- .../shwap/row_namespace_data_id_test.go | 6 +- .../shwap/row_namespace_data_test.go | 32 +-- {square => share}/shwap/row_test.go | 30 +-- {square => share}/shwap/sample.go | 32 +-- {square => share}/shwap/sample_id.go | 0 {square => share}/shwap/sample_id_test.go | 0 {square => share}/shwap/sample_test.go | 18 +- {square => share}/shwap/share.go | 18 +- square/namespace.go | 233 ------------------ state/core_access.go | 4 +- state/core_access_test.go | 12 +- store/cache/accessor_cache.go | 2 +- store/cache/accessor_cache_test.go | 16 +- store/cache/cache.go | 2 +- store/cache/doublecache.go | 2 +- store/cache/noop.go | 22 +- store/file/codec_test.go | 8 +- store/file/header.go | 6 +- store/file/ods.go | 62 ++--- store/file/ods_q4.go | 18 +- store/file/ods_q4_test.go | 12 +- store/file/ods_test.go | 18 +- store/file/q4.go | 4 +- store/file/square.go | 34 +-- store/getter.go | 16 +- store/getter_test.go | 10 +- store/store.go | 56 ++--- store/store_cache.go | 2 +- store/store_test.go | 42 ++-- store/striplock.go | 6 +- 239 files changed, 1387 insertions(+), 1618 deletions(-) rename {square => share}/availability.go (97%) rename {square => share}/availability/full/availability.go (83%) rename {square => share}/availability/full/availability_test.go (86%) rename {square => share}/availability/full/reconstruction_test.go (96%) rename {square => share}/availability/full/testing.go (63%) rename {square => share}/availability/light/availability.go (91%) rename {square => share}/availability/light/availability_test.go (83%) rename {square => share}/availability/light/options.go (100%) rename {square => share}/availability/light/sample.go (98%) rename {square => share}/availability/light/sample_test.go (100%) rename {square => share}/availability/light/testing.go (70%) rename {square => share}/availability/mocks/availability.go (100%) rename {square => share}/availability/test/testing.go (92%) rename {square => share}/doc.go (88%) rename {square => share}/eds/accessor.go (72%) rename {square => share}/eds/axis_half.go (62%) rename {square => share}/eds/axis_half_test.go (84%) rename {square => share}/eds/byzantine/bad_encoding.go (97%) rename {square => share}/eds/byzantine/bad_encoding_test.go (92%) rename {square => share}/eds/byzantine/byzantine.go (87%) rename {square => share}/eds/byzantine/pb/share.pb.go (87%) rename {square => share}/eds/byzantine/pb/share.proto (100%) rename {square => share}/eds/byzantine/share_proof.go (84%) rename {square => share}/eds/close_once.go (80%) rename {square => share}/eds/close_once_test.go (72%) rename {square => share}/eds/edstest/testing.go (78%) rename {square => share}/eds/nd.go (75%) rename {square => share}/eds/nd_test.go (81%) rename {square => share}/eds/proof.go (94%) rename {square => share}/eds/proofs_cache.go (92%) rename {square => share}/eds/proofs_cache_test.go (100%) rename {square => share}/eds/read.go (77%) rename {square => share}/eds/retriever.go (94%) rename {square => share}/eds/retriever_no_race_test.go (72%) rename {square => share}/eds/retriever_quadrant.go (92%) rename {square => share}/eds/retriever_test.go (92%) rename {square => share}/eds/rsmt2d.go (78%) rename {square => share}/eds/rsmt2d_test.go (83%) rename {square => share}/eds/share_reader.go (100%) rename {square => share}/eds/share_reader_test.go (86%) rename {square => share}/eds/testing.go (92%) rename {square => share}/eds/validation.go (92%) rename {square => share}/eds/validation_test.go (92%) rename {square => share}/empty.go (82%) rename {square => share}/ipld/add.go (91%) rename {square => share}/ipld/blockserv.go (100%) rename {square => share}/ipld/delete.go (100%) rename {square => share}/ipld/delete_test.go (95%) rename {square => share}/ipld/get.go (97%) rename {square => share}/ipld/get_shares.go (79%) rename {square => share}/ipld/get_shares_test.go (87%) rename {square => share}/ipld/namespace_data.go (96%) rename {square => share}/ipld/nmt.go (92%) rename {square => share}/ipld/nmt_adder.go (100%) rename {square => share}/ipld/nmt_test.go (85%) rename {square => share}/ipld/proof_collector.go (100%) rename {square => share}/ipld/proofs.go (100%) rename {square => share}/ipld/proofs_test.go (81%) rename {square => share}/ipld/test_helpers.go (100%) rename {square => share}/ipld/utils.go (51%) rename {square => share}/root.go (89%) rename {square => share}/share.go (89%) rename {square => share}/shwap/eds.go (68%) rename {square => share}/shwap/eds_id.go (100%) rename {square => share}/shwap/eds_id_test.go (100%) rename {square => share}/shwap/getter.go (89%) rename {square => share}/shwap/getters/cascade.go (93%) rename {square => share}/shwap/getters/cascade_test.go (97%) rename {square => share}/shwap/getters/mock/getter.go (98%) rename {square => share}/shwap/getters/testing.go (79%) rename {square => share}/shwap/namespace_data.go (85%) rename {square => share}/shwap/namespace_data_id.go (90%) rename {square => share}/shwap/namespace_data_id_test.go (88%) rename {square => share}/shwap/p2p/bitswap/bitswap.go (100%) rename {square => share}/shwap/p2p/bitswap/block.go (89%) rename {square => share}/shwap/p2p/bitswap/block_fetch.go (98%) rename {square => share}/shwap/p2p/bitswap/block_fetch_test.go (98%) rename {square => share}/shwap/p2p/bitswap/block_proto.go (92%) rename {square => share}/shwap/p2p/bitswap/block_registry.go (100%) rename {square => share}/shwap/p2p/bitswap/block_store.go (98%) rename {square => share}/shwap/p2p/bitswap/block_test.go (92%) rename {square => share}/shwap/p2p/bitswap/cid.go (100%) rename {square => share}/shwap/p2p/bitswap/getter.go (90%) rename {square => share}/shwap/p2p/bitswap/getter_test.go (57%) rename {square => share}/shwap/p2p/bitswap/pb/bitswap.pb.go (85%) rename {square => share}/shwap/p2p/bitswap/pb/bitswap.proto (70%) rename {square => share}/shwap/p2p/bitswap/row_block.go (90%) rename {square => share}/shwap/p2p/bitswap/row_block_test.go (82%) rename {square => share}/shwap/p2p/bitswap/row_namespace_data_block.go (89%) rename {square => share}/shwap/p2p/bitswap/row_namespace_data_block_test.go (76%) rename {square => share}/shwap/p2p/bitswap/sample_block.go (90%) rename {square => share}/shwap/p2p/bitswap/sample_block_test.go (85%) rename {square => share}/shwap/p2p/discovery/backoff.go (100%) rename {square => share}/shwap/p2p/discovery/backoff_test.go (100%) rename {square => share}/shwap/p2p/discovery/dht.go (100%) rename {square => share}/shwap/p2p/discovery/discovery.go (100%) rename {square => share}/shwap/p2p/discovery/discovery_test.go (100%) rename {square => share}/shwap/p2p/discovery/metrics.go (100%) rename {square => share}/shwap/p2p/discovery/options.go (100%) rename {square => share}/shwap/p2p/discovery/set.go (100%) rename {square => share}/shwap/p2p/discovery/set_test.go (100%) rename {square => share}/shwap/p2p/shrex/doc.go (94%) rename {square => share}/shwap/p2p/shrex/error.go (100%) rename {square => share}/shwap/p2p/shrex/error_test.go (100%) rename {square => share}/shwap/p2p/shrex/errors.go (100%) rename {square => share}/shwap/p2p/shrex/metrics.go (100%) rename {square => share}/shwap/p2p/shrex/middleware.go (100%) rename {square => share}/shwap/p2p/shrex/params.go (100%) rename {square => share}/shwap/p2p/shrex/pb/shrex.pb.go (81%) rename {square => share}/shwap/p2p/shrex/pb/shrex.proto (69%) rename {square => share}/shwap/p2p/shrex/peers/doc.go (100%) rename {square => share}/shwap/p2p/shrex/peers/manager.go (97%) rename {square => share}/shwap/p2p/shrex/peers/manager_test.go (97%) rename {square => share}/shwap/p2p/shrex/peers/metrics.go (99%) rename {square => share}/shwap/p2p/shrex/peers/options.go (97%) rename {square => share}/shwap/p2p/shrex/peers/pool.go (100%) rename {square => share}/shwap/p2p/shrex/peers/pool_test.go (100%) rename {square => share}/shwap/p2p/shrex/peers/timedqueue.go (100%) rename {square => share}/shwap/p2p/shrex/peers/timedqueue_test.go (100%) rename {square => share}/shwap/p2p/shrex/recovery.go (100%) rename {square => share}/shwap/p2p/shrex/shrex_getter/shrex.go (90%) rename {square => share}/shwap/p2p/shrex/shrex_getter/shrex_test.go (87%) rename {square => share}/shwap/p2p/shrex/shrexeds/client.go (93%) rename {square => share}/shwap/p2p/shrex/shrexeds/doc.go (98%) rename {square => share}/shwap/p2p/shrex/shrexeds/exchange_test.go (90%) rename {square => share}/shwap/p2p/shrex/shrexeds/params.go (90%) rename {square => share}/shwap/p2p/shrex/shrexeds/server.go (95%) rename {square => share}/shwap/p2p/shrex/shrexnd/client.go (92%) rename {square => share}/shwap/p2p/shrex/shrexnd/doc.go (91%) rename {square => share}/shwap/p2p/shrex/shrexnd/exchange_test.go (85%) rename {square => share}/shwap/p2p/shrex/shrexnd/params.go (87%) rename {square => share}/shwap/p2p/shrex/shrexnd/server.go (96%) rename {square => share}/shwap/p2p/shrex/shrexsub/doc.go (97%) rename {square => share}/shwap/p2p/shrex/shrexsub/pb/notification.pb.go (83%) rename {square => share}/shwap/p2p/shrex/shrexsub/pb/notification.proto (75%) rename {square => share}/shwap/p2p/shrex/shrexsub/pubsub.go (96%) rename {square => share}/shwap/p2p/shrex/shrexsub/pubsub_test.go (97%) rename {square => share}/shwap/p2p/shrex/shrexsub/subscription.go (94%) rename {square => share}/shwap/pb/shwap.pb.go (89%) rename {square => share}/shwap/pb/shwap.proto (89%) rename {square => share}/shwap/row.go (80%) rename {square => share}/shwap/row_id.go (99%) rename {square => share}/shwap/row_id_test.go (100%) rename {square => share}/shwap/row_namespace_data.go (90%) rename {square => share}/shwap/row_namespace_data_id.go (88%) rename {square => share}/shwap/row_namespace_data_id_test.go (89%) rename {square => share}/shwap/row_namespace_data_test.go (71%) rename {square => share}/shwap/row_test.go (80%) rename {square => share}/shwap/sample.go (75%) rename {square => share}/shwap/sample_id.go (100%) rename {square => share}/shwap/sample_id_test.go (100%) rename {square => share}/shwap/sample_test.go (87%) rename {square => share}/shwap/share.go (70%) delete mode 100644 square/namespace.go diff --git a/api/docgen/examples.go b/api/docgen/examples.go index acb5fdb08a..dff8e0baa8 100644 --- a/api/docgen/examples.go +++ b/api/docgen/examples.go @@ -22,15 +22,15 @@ import ( "github.com/celestiaorg/go-fraud" libhead "github.com/celestiaorg/go-header" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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/square" - "github.com/celestiaorg/celestia-node/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/byzantine" "github.com/celestiaorg/celestia-node/state" ) @@ -80,7 +80,7 @@ var ExampleValues = map[reflect.Type]interface{}{ } func init() { - addToExampleValues(square.EmptyEDS()) + addToExampleValues(share.EmptyEDS()) addr, err := sdk.AccAddressFromBech32("celestia1377k5an3f94v6wyaceu0cf4nq6gk2jtpc46g7h") if err != nil { panic(err) @@ -166,7 +166,7 @@ func init() { // randomly generated namespace that's used in the blob example above // (AAAAAAAAAAAAAAAAAAAAAAAAAAAAAMJ/xGlNMdE=) - namespace, err := share.NewV0Namespace([]byte{0xc2, 0x7f, 0xc4, 0x69, 0x4d, 0x31, 0xd1}) + namespace, err := gosquare.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 f9372018af..e8e96083d5 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/square" + "github.com/celestiaorg/celestia-node/share" ) 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, square.ErrNotAvailable): + case errors.Is(err, share.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 f6b5156ab4..8e5b898b5a 100644 --- a/api/gateway/share.go +++ b/api/gateway/share.go @@ -9,7 +9,7 @@ import ( "github.com/gorilla/mux" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) const ( @@ -22,8 +22,8 @@ var namespaceKey = "nid" // NamespacedSharesResponse represents the response to a // SharesByNamespace request. type NamespacedSharesResponse struct { - Shares []share.Share `json:"shares"` - Height uint64 `json:"height"` + Shares []gosquare.Share `json:"shares"` + Height uint64 `json:"height"` } // NamespacedDataResponse represents the response to a @@ -88,7 +88,7 @@ func (h *Handler) handleDataByNamespaceRequest(w http.ResponseWriter, r *http.Re } } -func (h *Handler) getShares(ctx context.Context, height uint64, namespace share.Namespace) ([]share.Share, error) { +func (h *Handler) getShares(ctx context.Context, height uint64, namespace gosquare.Namespace) ([]gosquare.Share, error) { header, err := h.header.GetByHeight(ctx, height) if err != nil { return nil, err @@ -102,8 +102,8 @@ func (h *Handler) getShares(ctx context.Context, height uint64, namespace share. return shares.Flatten(), nil } -func dataFromShares(input []share.Share) (data [][]byte, err error) { - sequences, err := share.ParseShares(input, false) +func dataFromShares(input []gosquare.Share) (data [][]byte, err error) { + sequences, err := gosquare.ParseShares(input, false) if err != nil { return nil, err } @@ -117,24 +117,24 @@ func dataFromShares(input []share.Share) (data [][]byte, err error) { return data, nil } -func parseGetByNamespaceArgs(r *http.Request) (height uint64, namespace share.Namespace, err error) { +func parseGetByNamespaceArgs(r *http.Request) (height uint64, namespace gosquare.Namespace, err error) { vars := mux.Vars(r) // if a height was given, parse it, otherwise get namespaced shares/data from the latest header if strHeight, ok := vars[heightKey]; ok { height, err = strconv.ParseUint(strHeight, 10, 64) if err != nil { - return 0, share.Namespace{}, err + return 0, gosquare.Namespace{}, err } } hexNamespace := vars[namespaceKey] nsString, err := hex.DecodeString(hexNamespace) if err != nil { - return 0, share.Namespace{}, err + return 0, gosquare.Namespace{}, err } - ns, err := share.NewNamespaceFromBytes(nsString) + ns, err := gosquare.NewNamespaceFromBytes(nsString) if err != nil { - return 0, share.Namespace{}, err + return 0, gosquare.Namespace{}, err } namespace = ns - return height, namespace, share.ValidateForData(namespace) + return height, namespace, gosquare.ValidateForData(namespace) } diff --git a/api/gateway/share_test.go b/api/gateway/share_test.go index b51d043f73..53c20bdbb6 100644 --- a/api/gateway/share_test.go +++ b/api/gateway/share_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) func Test_dataFromShares(t *testing.T) { @@ -16,10 +16,10 @@ func Test_dataFromShares(t *testing.T) { []byte("BEEEEAHP"), } - ns := share.RandomNamespace() - sss := share.NewSparseShareSplitter() + ns := gosquare.RandomNamespace() + sss := gosquare.NewSparseShareSplitter() for _, data := range testData { - b, err := share.NewBlob(ns, data, share.ShareVersionZero, nil) + b, err := gosquare.NewBlob(ns, data, gosquare.ShareVersionZero, nil) require.NoError(t, err) require.NoError(t, sss.Write(b)) } @@ -32,7 +32,7 @@ func Test_dataFromShares(t *testing.T) { rawSSSShares[i] = d } - shrs, err := share.FromBytes(rawSSSShares) + shrs, err := gosquare.FromBytes(rawSSSShares) require.NoError(t, err) parsedSSSShares, err := dataFromShares(shrs) require.NoError(t, err) diff --git a/blob/blob.go b/blob/blob.go index d2c41fae6a..dbf9e7475e 100644 --- a/blob/blob.go +++ b/blob/blob.go @@ -10,7 +10,7 @@ import ( 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" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" ) @@ -59,7 +59,7 @@ func (p Proof) equal(input Proof) error { // Blob represents any application-specific binary data that anyone can submit to Celestia. type Blob struct { - *share.Blob `json:"blob"` + *gosquare.Blob `json:"blob"` Commitment Commitment `json:"commitment"` @@ -70,33 +70,31 @@ 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(share.ShareVersionZero, namespace, data, nil) +func NewBlobV0(namespace gosquare.Namespace, data []byte) (*Blob, error) { + return NewBlob(gosquare.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) +func NewBlobV1(namespace gosquare.Namespace, data, signer []byte) (*Blob, error) { + return NewBlob(gosquare.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, signer []byte) (*Blob, error) { +func NewBlob(shareVersion uint8, namespace gosquare.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 := share.ValidateForData(namespace); err != nil { + if err := gosquare.ValidateForData(namespace); err != nil { return nil, fmt.Errorf("invalid user namespace: %w", err) } - if !namespace.IsUsableNamespace() { - return nil, fmt.Errorf("parity of tail padding namespaces %s are not allowed", namespace.ID()) - } - if namespace.IsReserved() { - return nil, fmt.Errorf("reserved namespace %s is not allowed", namespace.ID()) + + if !gosquare.IsBlobNamespace(namespace) { + return nil, fmt.Errorf("namespace %s is not a blob namespace", namespace) } - squareBlob, err := share.NewBlob(namespace, data, shareVersion, signer) + squareBlob, err := gosquare.NewBlob(namespace, data, shareVersion, signer) if err != nil { return nil, err } @@ -109,7 +107,7 @@ func NewBlob(shareVersion uint8, namespace share.Namespace, data, signer []byte) } // Namespace returns blob's namespace. -func (b *Blob) Namespace() share.Namespace { +func (b *Blob) Namespace() gosquare.Namespace { return b.Blob.Namespace() } @@ -129,7 +127,7 @@ 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 + return gosquare.SparseSharesNeeded(s[0].SequenceLen()), nil } // Signer returns blob's author. @@ -169,7 +167,7 @@ func (b *Blob) UnmarshalJSON(data []byte) error { return err } - ns, err := share.NewNamespaceFromBytes(jsonBlob.Namespace) + ns, err := gosquare.NewNamespaceFromBytes(jsonBlob.Namespace) if err != nil { return err } diff --git a/blob/blob_test.go b/blob/blob_test.go index 20871706d5..9ea7dcf49a 100644 --- a/blob/blob_test.go +++ b/blob/blob_test.go @@ -9,7 +9,7 @@ import ( "github.com/celestiaorg/go-square/merkle" "github.com/celestiaorg/go-square/v2/inclusion" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob/blobtest" ) @@ -50,7 +50,7 @@ func TestBlob(t *testing.T) { name: "verify namespace", expectedRes: func(t *testing.T) { ns := blob[0].Namespace() - require.NoError(t, share.ValidateUserNamespace(ns.Version(), ns.ID())) + require.NoError(t, gosquare.ValidateUserNamespace(ns.Version(), ns.ID())) }, }, { @@ -91,7 +91,7 @@ func TestBlob(t *testing.T) { } } -func convertBlobs(appBlobs ...*share.Blob) ([]*Blob, error) { +func convertBlobs(appBlobs ...*gosquare.Blob) ([]*Blob, error) { blobs := make([]*Blob, 0, len(appBlobs)) for _, appBlob := range appBlobs { blob, err := NewBlob(appBlob.ShareVersion(), appBlob.Namespace(), appBlob.Data(), appBlob.Signer()) diff --git a/blob/blobtest/testing.go b/blob/blobtest/testing.go index e509e36af3..6443ae1c9a 100644 --- a/blob/blobtest/testing.go +++ b/blob/blobtest/testing.go @@ -1,31 +1,31 @@ package blobtest import ( + "encoding/binary" "fmt" tmrand "github.com/tendermint/tendermint/libs/rand" "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" - "github.com/celestiaorg/go-square/shares" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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) ([]*share.Blob, error) { - blobs := make([]*share.Blob, 0, len(sizes)) +func GenerateV0Blobs(sizes []int, sameNamespace bool) ([]*gosquare.Blob, error) { + blobs := make([]*gosquare.Blob, 0, len(sizes)) for _, size := range sizes { - size := RawBlobSize(share.FirstSparseShareContentSize * size) + size := RawBlobSize(gosquare.FirstSparseShareContentSize * size) appBlob := testfactory.GenerateRandomBlob(size) if !sameNamespace { - namespace, err := share.NewV0Namespace(tmrand.Bytes(7)) + namespace, err := gosquare.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()) + appBlob, err = gosquare.NewV0Blob(namespace, appBlob.Data()) if err != nil { return nil, err } @@ -37,5 +37,11 @@ func GenerateV0Blobs(sizes []int, sameNamespace bool) ([]*share.Blob, error) { } func RawBlobSize(totalSize int) int { - return totalSize - shares.DelimLen(uint64(totalSize)) + return totalSize - delimLen(uint64(totalSize)) +} + +// delimLen calculates the length of the delimiter for a given unit size +func delimLen(size uint64) int { + lenBuf := make([]byte, binary.MaxVarintLen64) + return binary.PutUvarint(lenBuf, size) } diff --git a/blob/commitment_proof.go b/blob/commitment_proof.go index d59614a693..68fbc33c28 100644 --- a/blob/commitment_proof.go +++ b/blob/commitment_proof.go @@ -8,7 +8,7 @@ import ( "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" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/nmt/namespace" ) @@ -81,7 +81,7 @@ func (commitmentProof *CommitmentProof) Validate() error { } // Verify verifies that a commitment proof is valid, i.e., the subtree roots commit -// to some data that was posted to a square. +// to some data that was posted to a share. // Expects the commitment proof to be properly formulated and validated // using the Validate() function. func (commitmentProof *CommitmentProof) Verify(root []byte, subtreeRootThreshold int) (bool, error) { @@ -94,7 +94,7 @@ func (commitmentProof *CommitmentProof) Verify(root []byte, subtreeRootThreshold return false, err } - nmtHasher := nmt.NewNmtHasher(appconsts.NewBaseHashFunc(), share.NamespaceSize, true) + nmtHasher := nmt.NewNmtHasher(appconsts.NewBaseHashFunc(), gosquare.NamespaceSize, true) // computes the total number of shares proven. numberOfShares := 0 diff --git a/blob/helper.go b/blob/helper.go index 3b81fce5be..076861548e 100644 --- a/blob/helper.go +++ b/blob/helper.go @@ -4,16 +4,16 @@ import ( "fmt" "sort" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) // BlobsToShares accepts blobs and convert them to the Shares. -func BlobsToShares(nodeBlobs ...*Blob) ([]share.Share, error) { +func BlobsToShares(nodeBlobs ...*Blob) ([]gosquare.Share, error) { sort.Slice(nodeBlobs, func(i, j int) bool { return nodeBlobs[i].Blob.Namespace().Compare(nodeBlobs[j].Blob.Namespace()) < 0 }) - splitter := share.NewSparseShareSplitter() + splitter := gosquare.NewSparseShareSplitter() for i, nodeBlob := range nodeBlobs { err := splitter.Write(nodeBlob.Blob) if err != nil { @@ -25,8 +25,8 @@ func BlobsToShares(nodeBlobs ...*Blob) ([]share.Share, error) { } // ToAppBlobs converts node's blob type to the blob type from go-square. -func ToAppBlobs(blobs ...*Blob) []*share.Blob { - appBlobs := make([]*share.Blob, len(blobs)) +func ToAppBlobs(blobs ...*Blob) []*gosquare.Blob { + appBlobs := make([]*gosquare.Blob, len(blobs)) for i := range blobs { appBlobs[i] = blobs[i].Blob } diff --git a/blob/helper_test.go b/blob/helper_test.go index f4ac403b97..9fb6992d67 100644 --- a/blob/helper_test.go +++ b/blob/helper_test.go @@ -7,17 +7,17 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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 := share.MustNewV0Namespace(bytes.Repeat([]byte{0xa}, 10)) - namespaceB := share.MustNewV0Namespace(bytes.Repeat([]byte{0xb}, 10)) + namespaceA := gosquare.MustNewV0Namespace(bytes.Repeat([]byte{0xa}, 10)) + namespaceB := gosquare.MustNewV0Namespace(bytes.Repeat([]byte{0xb}, 10)) - blobA, err := NewBlob(share.ShareVersionZero, namespaceA, []byte("dataA"), nil) + blobA, err := NewBlob(gosquare.ShareVersionZero, namespaceA, []byte("dataA"), nil) require.NoError(t, err) - blobB, err := NewBlob(share.ShareVersionZero, namespaceB, []byte("dataB"), nil) + blobB, err := NewBlob(gosquare.ShareVersionZero, namespaceB, []byte("dataB"), nil) require.NoError(t, err) got, err := BlobsToShares(blobB, blobA) @@ -29,15 +29,15 @@ func TestBlobsToShares(t *testing.T) { } func TestToAppBlobs(t *testing.T) { - namespaceA := share.MustNewV0Namespace(bytes.Repeat([]byte{0xa}, 10)) - namespaceB := share.MustNewV0Namespace(bytes.Repeat([]byte{0xb}, 10)) + namespaceA := gosquare.MustNewV0Namespace(bytes.Repeat([]byte{0xa}, 10)) + namespaceB := gosquare.MustNewV0Namespace(bytes.Repeat([]byte{0xb}, 10)) - blobA, err := NewBlob(share.ShareVersionZero, namespaceA, []byte("dataA"), nil) + blobA, err := NewBlob(gosquare.ShareVersionZero, namespaceA, []byte("dataA"), nil) require.NoError(t, err) - blobB, err := NewBlob(share.ShareVersionZero, namespaceB, []byte("dataB"), nil) + blobB, err := NewBlob(gosquare.ShareVersionZero, namespaceB, []byte("dataB"), nil) require.NoError(t, err) got := ToAppBlobs(blobA, blobB) - assert.Equal(t, []*share.Blob{blobA.Blob, blobB.Blob}, got) + assert.Equal(t, []*gosquare.Blob{blobA.Blob, blobB.Blob}, got) } diff --git a/blob/parser.go b/blob/parser.go index d693b3a8c3..ad452329d2 100644 --- a/blob/parser.go +++ b/blob/parser.go @@ -6,7 +6,7 @@ import ( "github.com/celestiaorg/go-square/merkle" "github.com/celestiaorg/go-square/v2/inclusion" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) // parser helps to collect shares and transform them into a blob. @@ -17,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 []share.Share + shares []gosquare.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 []share.Share) ([]share.Share, error) { +func (p *parser) set(index int, shrs []gosquare.Share) ([]gosquare.Share, error) { if len(shrs) == 0 { return nil, errEmptyShares } @@ -40,14 +40,14 @@ func (p *parser) set(index int, shrs []share.Share) ([]share.Share, error) { // `+=` as index could be updated in `skipPadding` p.index += index length := shrs[0].SequenceLen() - p.length = share.SparseSharesNeeded(length) + p.length = gosquare.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 []share.Share) (shrs []share.Share, isComplete bool) { +func (p *parser) addShares(shares []gosquare.Share) (shrs []gosquare.Share, isComplete bool) { index := -1 for i, sh := range shares { p.shares = append(p.shares, sh) @@ -75,7 +75,7 @@ func (p *parser) parse() (*Blob, error) { return nil, fmt.Errorf("invalid shares amount. want:%d, have:%d", p.length, len(p.shares)) } - blobs, err := share.ParseBlobs(p.shares) + blobs, err := gosquare.ParseBlobs(p.shares) if err != nil { return nil, err } @@ -98,7 +98,7 @@ func (p *parser) parse() (*Blob, error) { // 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 []share.Share) ([]share.Share, error) { +func (p *parser) skipPadding(shares []gosquare.Share) ([]gosquare.Share, error) { if len(shares) == 0 { return nil, errEmptyShares } diff --git a/blob/service.go b/blob/service.go index f95091d9d2..9ccf92825a 100644 --- a/blob/service.go +++ b/blob/service.go @@ -19,13 +19,13 @@ import ( "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" + gosquare "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/square/shwap" + "github.com/celestiaorg/celestia-node/share/shwap" "github.com/celestiaorg/celestia-node/state" ) @@ -45,7 +45,7 @@ type SubmitOptions = state.TxConfig // avoid a circular dependency between the blob and the state package, since the state package needs // the blob.Blob type for this signature. type Submitter interface { - SubmitPayForBlob(context.Context, []*share.Blob, *state.TxConfig) (*types.TxResponse, error) + SubmitPayForBlob(context.Context, []*gosquare.Blob, *state.TxConfig) (*types.TxResponse, error) } type Service struct { @@ -98,7 +98,7 @@ type SubscriptionResponse struct { // The channel will be closed when the context is canceled or the service is stopped. // Please note that no errors are returned: underlying operations are retried until successful. // Additionally, not reading from the returned channel will cause the stream to close after 16 messages. -func (s *Service) Subscribe(ctx context.Context, ns share.Namespace) (<-chan *SubscriptionResponse, error) { +func (s *Service) Subscribe(ctx context.Context, ns gosquare.Namespace) (<-chan *SubscriptionResponse, error) { if s.ctx == nil { return nil, fmt.Errorf("service has not been started") } @@ -132,7 +132,7 @@ func (s *Service) Subscribe(ctx context.Context, ns share.Namespace) (<-chan *Su var blobs []*Blob var err error for { - blobs, err = s.getAll(ctx, header, []share.Namespace{ns}) + blobs, err = s.getAll(ctx, header, []gosquare.Namespace{ns}) if ctx.Err() != nil { // context canceled, continuing would lead to unexpected missed heights for the client log.Debugw("blobsub: canceling subscription due to user ctx closing", "namespace", ns.ID()) @@ -169,18 +169,16 @@ 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([]*share.Blob, len(blobs)) + squareBlobs := make([]*gosquare.Blob, len(blobs)) for i := range blobs { namespace := blobs[i].Namespace() - if err := share.ValidateForData(namespace); err != nil { + if err := gosquare.ValidateForData(namespace); err != nil { return 0, err } - if !blobs[i].Namespace().IsUsableNamespace() { - return 0, fmt.Errorf("parity of tail padding namespaces %s are not allowed", namespace.ID()) - } - if blobs[i].Namespace().IsReserved() { - return 0, fmt.Errorf("reserved namespace %s is not allowed", namespace.ID()) + if !gosquare.IsBlobNamespace(namespace) { + return 0, fmt.Errorf("not allowed namespace %s were used to build the blob", namespace.ID()) } + squareBlobs[i] = blobs[i].Blob } @@ -198,7 +196,7 @@ func (s *Service) Submit(ctx context.Context, blobs []*Blob, txConfig *SubmitOpt func (s *Service) Get( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, commitment Commitment, ) (blob *Blob, err error) { ctx, span := tracer.Start(ctx, "get") @@ -224,7 +222,7 @@ func (s *Service) Get( func (s *Service) GetProof( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, commitment Commitment, ) (proof *Proof, err error) { ctx, span := tracer.Start(ctx, "get-proof") @@ -253,7 +251,7 @@ func (s *Service) GetProof( // the user will receive all found blobs along with a combined error message. // // All blobs will preserve the order of the namespaces that were requested. -func (s *Service) GetAll(ctx context.Context, height uint64, namespaces []share.Namespace) ([]*Blob, error) { +func (s *Service) GetAll(ctx context.Context, height uint64, namespaces []gosquare.Namespace) ([]*Blob, error) { header, err := s.headerGetter(ctx, height) if err != nil { return nil, err @@ -265,7 +263,7 @@ func (s *Service) GetAll(ctx context.Context, height uint64, namespaces []share. func (s *Service) getAll( ctx context.Context, header *header.ExtendedHeader, - namespaces []share.Namespace, + namespaces []gosquare.Namespace, ) ([]*Blob, error) { height := header.Height() var ( @@ -275,7 +273,7 @@ func (s *Service) getAll( ) for i, namespace := range namespaces { wg.Add(1) - go func(i int, namespace share.Namespace) { + go func(i int, namespace gosquare.Namespace) { log.Debugw("retrieving all blobs from", "namespace", namespace.String(), "height", height) defer wg.Done() @@ -304,7 +302,7 @@ func (s *Service) getAll( func (s *Service) Included( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, proof *Proof, commitment Commitment, ) (_ bool, err error) { @@ -339,7 +337,7 @@ func (s *Service) Included( func (s *Service) retrieve( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, sharesParser *parser, ) (_ *Blob, _ *Proof, err error) { log.Infow("requesting blob", @@ -383,7 +381,7 @@ func (s *Service) retrieve( attribute.Int64("eds-size", int64(len(header.DAH.RowRoots))))) var ( - appShares = make([]share.Share, 0) + appShares = make([]gosquare.Share, 0) proofs = make(Proof, 0) ) @@ -402,7 +400,7 @@ func (s *Service) retrieve( for { var ( isComplete bool - shrs []share.Share + shrs []gosquare.Share wasEmpty = sharesParser.isEmpty() ) @@ -473,7 +471,7 @@ func (s *Service) retrieve( // them to Blobs. func (s *Service) getBlobs( ctx context.Context, - namespace share.Namespace, + namespace gosquare.Namespace, header *header.ExtendedHeader, ) (_ []*Blob, err error) { ctx, span := tracer.Start(ctx, "get-blobs") @@ -499,7 +497,7 @@ func (s *Service) getBlobs( func (s *Service) GetCommitmentProof( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, shareCommitment []byte, ) (*CommitmentProof, error) { log.Debugw("proving share commitment", "height", height, "commitment", shareCommitment, "namespace", namespace) @@ -561,8 +559,8 @@ func (s *Service) GetCommitmentProof( func ProveCommitment( eds *rsmt2d.ExtendedDataSquare, - namespace share.Namespace, - blobShares []share.Share, + namespace gosquare.Namespace, + blobShares []gosquare.Share, ) (*CommitmentProof, error) { // find the blob shares in the EDS blobSharesStartIndex := -1 @@ -585,7 +583,7 @@ func ProveCommitment( sharesProof, err := pkgproof.NewShareInclusionProofFromEDS( eds, namespace, - share.NewRange(blobSharesStartIndex, blobSharesStartIndex+len(blobShares)), + gosquare.NewRange(blobSharesStartIndex, blobSharesStartIndex+len(blobShares)), ) if err != nil { return nil, err @@ -646,7 +644,7 @@ func ProveCommitment( // computeSubtreeRoots takes a set of shares and ranges and returns the corresponding subtree roots. // the offset is the number of shares that are before the subtree roots we're calculating. -func computeSubtreeRoots(shares []share.Share, ranges []nmt.LeafRange, offset int) ([][]byte, error) { +func computeSubtreeRoots(shares []gosquare.Share, ranges []nmt.LeafRange, offset int) ([][]byte, error) { if len(shares) == 0 { return nil, fmt.Errorf("cannot compute subtree roots for an empty shares list") } @@ -661,7 +659,7 @@ func computeSubtreeRoots(shares []share.Share, ranges []nmt.LeafRange, offset in tree := nmt.New( appconsts.NewBaseHashFunc(), nmt.IgnoreMaxNamespace(true), - nmt.NamespaceIDSize(share.NamespaceSize), + nmt.NamespaceIDSize(gosquare.NamespaceSize), ) for _, sh := range shares { leafData := make([]byte, 0) diff --git a/blob/service_test.go b/blob/service_test.go index 1114b84a97..c78b00c0fa 100644 --- a/blob/service_test.go +++ b/blob/service_test.go @@ -26,7 +26,7 @@ import ( 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" + gosquare "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/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" + "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" ) func TestBlobService_Get(t *testing.T) { @@ -94,7 +94,7 @@ func TestBlobService_Get(t *testing.T) { { name: "get all with the same namespace", doFn: func() (interface{}, error) { - return service.GetAll(ctx, 1, []share.Namespace{blobsWithSameNamespace[0].Namespace()}) + return service.GetAll(ctx, 1, []gosquare.Namespace{blobsWithSameNamespace[0].Namespace()}) }, expectedResult: func(res interface{}, err error) { require.NoError(t, err) @@ -123,7 +123,7 @@ func TestBlobService_Get(t *testing.T) { blobsWithDiffNamespaces[1].Commitment, ) require.NoError(t, err) - b23, err := service.GetAll(ctx, 1, []share.Namespace{blobsWithSameNamespace[0].Namespace()}) + b23, err := service.GetAll(ctx, 1, []gosquare.Namespace{blobsWithSameNamespace[0].Namespace()}) require.NoError(t, err) return []*Blob{b0, b1, b23[0], b23[1]}, nil }, @@ -159,10 +159,10 @@ func TestBlobService_Get(t *testing.T) { { name: "get all with different namespaces", doFn: func() (interface{}, error) { - nid, err := share.NewV0Namespace(tmrand.Bytes(7)) + nid, err := gosquare.NewV0Namespace(tmrand.Bytes(7)) require.NoError(t, err) b, err := service.GetAll(ctx, 1, - []share.Namespace{ + []gosquare.Namespace{ blobsWithDiffNamespaces[0].Namespace(), nid, blobsWithDiffNamespaces[1].Namespace(), }, @@ -236,13 +236,13 @@ func TestBlobService_Get(t *testing.T) { proof, ok := res.(*Proof) assert.True(t, ok) - verifyFn := func(t *testing.T, rawShares [][]byte, proof *Proof, namespace share.Namespace) { + verifyFn := func(t *testing.T, rawShares [][]byte, proof *Proof, namespace gosquare.Namespace) { for _, row := range header.DAH.RowRoots { to := 0 for _, p := range *proof { from := to to = p.End() - p.Start() + from - eq := p.VerifyInclusion(square.NewSHA256Hasher(), namespace.Bytes(), rawShares[from:to], row) + eq := p.VerifyInclusion(share.NewSHA256Hasher(), namespace.Bytes(), rawShares[from:to], row) if eq == true { return } @@ -253,7 +253,7 @@ func TestBlobService_Get(t *testing.T) { rawShares, err := BlobsToShares(blobsWithDiffNamespaces[1]) require.NoError(t, err) - verifyFn(t, share.ToBytes(rawShares), proof, blobsWithDiffNamespaces[1].Namespace()) + verifyFn(t, gosquare.ToBytes(rawShares), proof, blobsWithDiffNamespaces[1].Namespace()) }, }, { @@ -358,9 +358,9 @@ func TestBlobService_Get(t *testing.T) { { name: "empty result and err when blobs were not found ", doFn: func() (interface{}, error) { - nid, err := share.NewV0Namespace(tmrand.Bytes(squarens.NamespaceVersionZeroIDSize)) + nid, err := gosquare.NewV0Namespace(tmrand.Bytes(squarens.NamespaceVersionZeroIDSize)) require.NoError(t, err) - return service.GetAll(ctx, 1, []share.Namespace{nid}) + return service.GetAll(ctx, 1, []gosquare.Namespace{nid}) }, expectedResult: func(i interface{}, err error) { blobs, ok := i.([]*Blob) @@ -417,7 +417,7 @@ func TestBlobService_Get(t *testing.T) { GetSharesByNamespace(gomock.Any(), gomock.Any(), gomock.Any()). DoAndReturn( func( - ctx context.Context, h *header.ExtendedHeader, ns share.Namespace, + ctx context.Context, h *header.ExtendedHeader, ns gosquare.Namespace, ) (shwap.NamespaceData, error) { if ns.Equals(blobsWithDiffNamespaces[0].Namespace()) { return nil, errors.New("internal error") @@ -427,7 +427,7 @@ func TestBlobService_Get(t *testing.T) { service.shareGetter = getterWrapper return service.GetAll(ctx, 1, - []share.Namespace{ + []gosquare.Namespace{ blobsWithDiffNamespaces[0].Namespace(), blobsWithSameNamespace[0].Namespace(), }, @@ -465,16 +465,16 @@ func TestService_GetSingleBlobWithoutPadding(t *testing.T) { blobs, err := convertBlobs(appBlob...) require.NoError(t, err) - padding0, err := share.NamespacePaddingShare(blobs[0].Namespace(), share.ShareVersionZero) + padding0, err := gosquare.NamespacePaddingShare(blobs[0].Namespace(), gosquare.ShareVersionZero) require.NoError(t, err) - padding1, err := share.NamespacePaddingShare(blobs[1].Namespace(), share.ShareVersionZero) + padding1, err := gosquare.NamespacePaddingShare(blobs[1].Namespace(), gosquare.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([]share.Share, 0) + rawShares := make([]gosquare.Share, 0) rawShares = append(rawShares, append(rawShares0, padding0)...) rawShares = append(rawShares, append(rawShares1, padding1)...) service := createService(ctx, t, rawShares) @@ -543,10 +543,10 @@ func TestService_GetAllWithoutPadding(t *testing.T) { blobs, err := convertBlobs(appBlob...) require.NoError(t, err) - rawShares := make([]share.Share, 0) + rawShares := make([]gosquare.Share, 0) require.NoError(t, err) - padding, err := share.NamespacePaddingShare(blobs[0].Namespace(), share.ShareVersionZero) + padding, err := gosquare.NamespacePaddingShare(blobs[0].Namespace(), gosquare.ShareVersionZero) require.NoError(t, err) for i := 0; i < 2; i++ { @@ -567,7 +567,7 @@ func TestService_GetAllWithoutPadding(t *testing.T) { rawShares = append(rawShares, sh...) service := createService(ctx, t, rawShares) - newBlobs, err := service.GetAll(ctx, 1, []share.Namespace{blobs[0].Namespace()}) + newBlobs, err := service.GetAll(ctx, 1, []gosquare.Namespace{blobs[0].Namespace()}) require.NoError(t, err) assert.Equal(t, len(newBlobs), len(blobs)) @@ -590,13 +590,13 @@ func TestService_GetAllWithoutPadding(t *testing.T) { } func TestAllPaddingSharesInEDS(t *testing.T) { - nid, err := share.NewV0Namespace(tmrand.Bytes(7)) + nid, err := gosquare.NewV0Namespace(tmrand.Bytes(7)) require.NoError(t, err) - padding, err := share.NamespacePaddingShare(nid, share.ShareVersionZero) + padding, err := gosquare.NamespacePaddingShare(nid, gosquare.ShareVersionZero) require.NoError(t, err) - rawShares := make([]share.Share, 16) + rawShares := make([]gosquare.Share, 16) for i := 0; i < 16; i++ { rawShares[i] = padding } @@ -605,26 +605,26 @@ func TestAllPaddingSharesInEDS(t *testing.T) { t.Cleanup(cancel) service := createService(ctx, t, rawShares) - newBlobs, err := service.GetAll(ctx, 1, []share.Namespace{nid}) + newBlobs, err := service.GetAll(ctx, 1, []gosquare.Namespace{nid}) require.NoError(t, err) assert.Empty(t, newBlobs) } func TestSkipPaddingsAndRetrieveBlob(t *testing.T) { - nid := share.RandomBlobNamespace() - padding, err := share.NamespacePaddingShare(nid, share.ShareVersionZero) + nid := gosquare.RandomBlobNamespace() + padding, err := gosquare.NamespacePaddingShare(nid, gosquare.ShareVersionZero) require.NoError(t, err) - rawShares := make([]share.Share, 0, 64) + rawShares := make([]gosquare.Share, 0, 64) for i := 0; i < 58; i++ { rawShares = append(rawShares, padding) } - size := blobtest.RawBlobSize(share.FirstSparseShareContentSize * 6) - ns, err := share.NewNamespace(nid.Version(), nid.ID()) + size := blobtest.RawBlobSize(gosquare.FirstSparseShareContentSize * 6) + ns, err := gosquare.NewNamespace(nid.Version(), nid.ID()) require.NoError(t, err) data := tmrand.Bytes(size) - appBlob, err := share.NewBlob(ns, data, share.ShareVersionZero, nil) + appBlob, err := gosquare.NewBlob(ns, data, gosquare.ShareVersionZero, nil) require.NoError(t, err) blobs, err := convertBlobs(appBlob) @@ -638,7 +638,7 @@ func TestSkipPaddingsAndRetrieveBlob(t *testing.T) { t.Cleanup(cancel) service := createService(ctx, t, rawShares) - newBlob, err := service.GetAll(ctx, 1, []share.Namespace{nid}) + newBlob, err := service.GetAll(ctx, 1, []gosquare.Namespace{nid}) require.NoError(t, err) require.Len(t, newBlob, 1) require.True(t, newBlob[0].compareCommitments(blobs[0].Commitment)) @@ -674,7 +674,7 @@ func TestService_Subscribe(t *testing.T) { }) t.Run("subscription with no matching blobs", func(t *testing.T) { - ns, err := share.NewV0Namespace([]byte("nonexist")) + ns, err := gosquare.NewV0Namespace([]byte("nonexist")) require.NoError(t, err) subCh, err := service.Subscribe(ctx, ns) @@ -878,7 +878,7 @@ func createServiceWithSub(ctx context.Context, t testing.TB, blobs []*Blob) *Ser shareGetter := mock.NewMockGetter(ctrl) shareGetter.EXPECT().GetSharesByNamespace(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes(). - DoAndReturn(func(ctx context.Context, h *header.ExtendedHeader, ns share.Namespace) (shwap.NamespaceData, error) { + DoAndReturn(func(ctx context.Context, h *header.ExtendedHeader, ns gosquare.Namespace) (shwap.NamespaceData, error) { idx := int(h.Height()) - 1 accessor := &eds.Rsmt2D{ExtendedDataSquare: edsses[idx]} nd, err := eds.NamespaceData(ctx, accessor, ns) @@ -887,11 +887,11 @@ func createServiceWithSub(ctx context.Context, t testing.TB, blobs []*Blob) *Ser return NewService(nil, shareGetter, fn, fn2) } -func createService(ctx context.Context, t testing.TB, shares []share.Share) *Service { +func createService(ctx context.Context, t testing.TB, shares []gosquare.Share) *Service { odsSize := int(utils.SquareSize(len(shares))) square, err := rsmt2d.ComputeExtendedDataSquare( - share.ToBytes(shares), - square.DefaultRSMT2DCodec(), + gosquare.ToBytes(shares), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize))) require.NoError(t, err) @@ -899,12 +899,12 @@ func createService(ctx context.Context, t testing.TB, shares []share.Share) *Ser ctrl := gomock.NewController(t) shareGetter := mock.NewMockGetter(ctrl) shareGetter.EXPECT().GetSharesByNamespace(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes(). - DoAndReturn(func(ctx context.Context, h *header.ExtendedHeader, ns share.Namespace) (shwap.NamespaceData, error) { + DoAndReturn(func(ctx context.Context, h *header.ExtendedHeader, ns gosquare.Namespace) (shwap.NamespaceData, error) { nd, err := eds.NamespaceData(ctx, accessor, ns) return nd, err }) shareGetter.EXPECT().GetShare(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes(). - DoAndReturn(func(ctx context.Context, h *header.ExtendedHeader, row, col int) (share.Share, error) { + DoAndReturn(func(ctx context.Context, h *header.ExtendedHeader, row, col int) (gosquare.Share, error) { s, err := accessor.Sample(ctx, row, col) return s.Share, err }) @@ -995,8 +995,8 @@ func proveAndVerifyShareCommitments(t *testing.T, blobSize int) { func generateCommitmentProofFromBlock( t *testing.T, eds *rsmt2d.ExtendedDataSquare, - ns share.Namespace, - blob *share.Blob, + ns gosquare.Namespace, + blob *gosquare.Blob, dataRoot []byte, ) CommitmentProof { // create the blob from the data @@ -1025,7 +1025,7 @@ func generateCommitmentProofFromBlock( sharesProof, err := pkgproof.NewShareInclusionProofFromEDS( eds, ns, - share.NewRange(startShareIndex, startShareIndex+len(blobShares)), + gosquare.NewRange(startShareIndex, startShareIndex+len(blobShares)), ) require.NoError(t, err) require.NoError(t, sharesProof.Validate(dataRoot)) diff --git a/cmd/cel-shed/shwap.go b/cmd/cel-shed/shwap.go index 60a6d237ac..2d88e59ca9 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/square/shwap/p2p/bitswap" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/bitswap" ) func init() { diff --git a/cmd/util.go b/cmd/util.go index 16ff39d5d7..c2609b1266 100644 --- a/cmd/util.go +++ b/cmd/util.go @@ -11,7 +11,7 @@ import ( "github.com/spf13/cobra" flag "github.com/spf13/pflag" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/nodebuilder/core" "github.com/celestiaorg/celestia-node/nodebuilder/gateway" @@ -48,14 +48,14 @@ func PrintOutput(data interface{}, err error, formatData func(interface{}) inter // ParseV0Namespace parses a namespace from a base64 or hex string. The param // is expected to be the user-specified portion of a v0 namespace ID (i.e. the // last 10 bytes). -func ParseV0Namespace(param string) (share.Namespace, error) { +func ParseV0Namespace(param string) (gosquare.Namespace, error) { userBytes, err := DecodeToBytes(param) if err != nil { - return share.Namespace{}, err + return gosquare.Namespace{}, err } // if the namespace ID is <= 10 bytes, left pad it with 0s - return share.NewV0Namespace(userBytes) + return gosquare.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 97dc7cc83c..05f6226639 100644 --- a/cmd/util_test.go +++ b/cmd/util_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) func Test_parseNamespaceID(t *testing.T) { @@ -77,7 +77,7 @@ func Test_parseNamespaceID(t *testing.T) { } assert.NoError(t, err) - ns, err := share.NewNamespaceFromBytes(tc.want) + ns, err := gosquare.NewNamespaceFromBytes(tc.want) require.NoError(t, err) assert.Equal(t, ns, got) }) diff --git a/core/eds.go b/core/eds.go index b4d4fdfbcb..3104b70824 100644 --- a/core/eds.go +++ b/core/eds.go @@ -11,14 +11,14 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" "github.com/celestiaorg/go-square/shares" libSquare "github.com/celestiaorg/go-square/v2" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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/square" + "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/store" ) @@ -27,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 square.EmptyEDS(), nil + return share.EmptyEDS(), nil } // Construct the data square from the block's transactions - dataSquare, err := libSquare.Construct( + square, err := libSquare.Construct( data.Txs.ToSliceOfBytes(), appconsts.SquareSizeUpperBound(appVersion), appconsts.SubtreeRootThreshold(appVersion), @@ -39,7 +39,7 @@ func extendBlock(data types.Data, appVersion uint64, options ...nmt.Option) (*rs if err != nil { return nil, err } - return extendShares(share.ToBytes(dataSquare), options...) + return extendShares(gosquare.ToBytes(square), options...) } func extendShares(s [][]byte, options ...nmt.Option) (*rsmt2d.ExtendedDataSquare, error) { diff --git a/core/eds_test.go b/core/eds_test.go index ff4f6be808..3bed7ea94e 100644 --- a/core/eds_test.go +++ b/core/eds_test.go @@ -10,7 +10,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/app" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) // 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(square.EmptyEDS())) + require.True(t, eds.Equals(share.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(square.EmptyEDS())) + require.True(t, eds.Equals(share.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 := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) - assert.Equal(t, square.EmptyEDSRoots().Hash(), roots.Hash()) + assert.Equal(t, share.EmptyEDSRoots().Hash(), roots.Hash()) } diff --git a/core/exchange_test.go b/core/exchange_test.go index c7c1b6e3ab..c0b925b51d 100644 --- a/core/exchange_test.go +++ b/core/exchange_test.go @@ -14,7 +14,7 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/pruner" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" "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(square.EmptyEDSRoots()) { + if h.DAH.Equals(share.EmptyEDSRoots()) { continue } has, err = store.HasByHash(ctx, h.DAH.Hash()) @@ -147,7 +147,7 @@ func generateNonEmptyBlocks( fetcher *BlockFetcher, cfg *testnode.Config, cctx testnode.Context, -) []square.DataHash { +) []share.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([]square.DataHash, 0, 20) + hashes := make([]share.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(square.EmptyEDSDataHash(), b.Data.Hash()) { + if bytes.Equal(share.EmptyEDSDataHash(), b.Data.Hash()) { continue } - hashes = append(hashes, square.DataHash(b.Data.Hash())) + hashes = append(hashes, share.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 87c4378bb4..7b7eb3a7b7 100644 --- a/core/header_test.go +++ b/core/header_test.go @@ -13,7 +13,7 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) 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, square.EmptyEDSRoots(), headerExt.DAH) + assert.Equal(t, share.EmptyEDSRoots(), headerExt.DAH) } func TestMismatchedDataHash_ComputedRoot(t *testing.T) { diff --git a/core/listener.go b/core/listener.go index 694675d420..67e532d970 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/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share/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 3c67932104..b7d26fba36 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/square" + "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/store" ) @@ -43,7 +43,7 @@ func TestListenerWithNonEmptyBlocks(t *testing.T) { require.NoError(t, err) t.Cleanup(sub.Cancel) - empty := square.EmptyEDSRoots() + empty := share.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 54a52864cf..252c6e88c1 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/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" "github.com/celestiaorg/celestia-node/store" ) diff --git a/das/coordinator.go b/das/coordinator.go index c5ad1a668c..aff41bac8c 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/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share/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 3b5b7f793a..a94a9a4e6f 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/square" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/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: &square.AxisRoots{RowRoots: make([][]byte, 0)}, + DAH: &share.AxisRoots{RowRoots: make([][]byte, 0)}, }) } diff --git a/das/daser.go b/das/daser.go index cf8056ff95..2b0b84ba29 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/square" - "github.com/celestiaorg/celestia-node/square/eds/byzantine" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/byzantine" + "github.com/celestiaorg/celestia-node/share/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 square.Availability + da share.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 square.Availability, + da share.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 bf4516f40f..c67e5c06e2 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/square" - "github.com/celestiaorg/celestia-node/square/availability/mocks" - "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/availability/mocks" + "github.com/celestiaorg/celestia-node/share/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, square.Availability, and mock header.Subscriber. +// mockGetter, share.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: &square.AxisRoots{RowRoots: make([][]byte, 0)}, + DAH: &share.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: &square.AxisRoots{RowRoots: make([][]byte, 0)}, + DAH: &share.AxisRoots{RowRoots: make([][]byte, 0)}, }, nil } diff --git a/das/worker.go b/das/worker.go index 4da0acd89e..88ca387211 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/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share/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 50318efa09..0173e78efb 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, square.DataHash) (*share.Root, error) +func (s *Store) GetDAH(context.Context, share.DataHash) (*share.Root, error) ``` ##### `eds.Store.Get` diff --git a/header/headertest/fraud/testing.go b/header/headertest/fraud/testing.go index 0f3b8a11b5..546da7dd58 100644 --- a/header/headertest/fraud/testing.go +++ b/header/headertest/fraud/testing.go @@ -16,8 +16,8 @@ import ( "github.com/celestiaorg/celestia-node/header" "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/ipld" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/ipld" "github.com/celestiaorg/celestia-node/store" ) diff --git a/header/headertest/testing.go b/header/headertest/testing.go index 44d93c9db5..251592a9a5 100644 --- a/header/headertest/testing.go +++ b/header/headertest/testing.go @@ -23,7 +23,7 @@ import ( "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) // 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 := square.EmptyEDSRoots() + dah := share.EmptyEDSRoots() gen := RandRawHeader(s.t) @@ -152,7 +152,7 @@ func (s *TestSuite) NextHeader() *header.ExtendedHeader { return s.head } - dah := square.EmptyEDSRoots() + dah := share.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 := square.EmptyEDSRoots() + dah := share.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 := square.NewAxisRoots(eds) + roots, err := share.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 := square.NewAxisRoots(eds) + dah, err := share.NewAxisRoots(eds) require.NoError(t, err) gen.DataHash = dah.Hash() diff --git a/libs/edssser/edssser.go b/libs/edssser/edssser.go index 2c0ad624a4..dfb01e1756 100644 --- a/libs/edssser/edssser.go +++ b/libs/edssser/edssser.go @@ -9,8 +9,8 @@ import ( "testing" "time" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/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 - dataSquare := edstest.RandEDS(t, ss.config.EDSSize/2) - roots, err := square.NewAxisRoots(dataSquare) + square := edstest.RandEDS(t, ss.config.EDSSize/2) + roots, err := share.NewAxisRoots(square) if err != nil { return 0, err } now := time.Now() - err = ss.edsstore.PutODSQ4(ctx, roots, uint64(height), dataSquare) + err = ss.edsstore.PutODSQ4(ctx, roots, uint64(height), square) return time.Since(now), err } diff --git a/nodebuilder/blob/blob.go b/nodebuilder/blob/blob.go index 3d14a3487d..f89b58a29e 100644 --- a/nodebuilder/blob/blob.go +++ b/nodebuilder/blob/blob.go @@ -3,7 +3,7 @@ package blob import ( "context" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" ) @@ -19,7 +19,7 @@ type Module interface { // Uses default wallet registered on the Node. Submit(_ context.Context, _ []*blob.Blob, _ *blob.SubmitOptions) (height uint64, _ error) // Get retrieves the blob by commitment under the given namespace and height. - Get(_ context.Context, height uint64, _ share.Namespace, _ blob.Commitment) (*blob.Blob, error) + Get(_ context.Context, height uint64, _ gosquare.Namespace, _ blob.Commitment) (*blob.Blob, error) // GetAll returns all blobs under the given namespaces at the given height. // If all blobs were found without any errors, the user will receive a list of blobs. // If the BlobService couldn't find any blobs under the requested namespaces, @@ -29,21 +29,21 @@ type Module interface { // the user will receive all found blobs along with a combined error message. // // All blobs will preserve the order of the namespaces that were requested. - GetAll(_ context.Context, height uint64, _ []share.Namespace) ([]*blob.Blob, error) + GetAll(_ context.Context, height uint64, _ []gosquare.Namespace) ([]*blob.Blob, error) // GetProof retrieves proofs in the given namespaces at the given height by commitment. - GetProof(_ context.Context, height uint64, _ share.Namespace, _ blob.Commitment) (*blob.Proof, error) + GetProof(_ context.Context, height uint64, _ gosquare.Namespace, _ blob.Commitment) (*blob.Proof, error) // Included checks whether a blob's given commitment(Merkle subtree root) is included at // given height and under the namespace. - Included(_ context.Context, height uint64, _ share.Namespace, _ *blob.Proof, _ blob.Commitment) (bool, error) + Included(_ context.Context, height uint64, _ gosquare.Namespace, _ *blob.Proof, _ blob.Commitment) (bool, error) // GetCommitmentProof generates a commitment proof for a share commitment. GetCommitmentProof( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, shareCommitment []byte, ) (*blob.CommitmentProof, error) // Subscribe to published blobs from the given namespace as they are included. - Subscribe(_ context.Context, _ share.Namespace) (<-chan *blob.SubscriptionResponse, error) + Subscribe(_ context.Context, _ gosquare.Namespace) (<-chan *blob.SubscriptionResponse, error) } type API struct { @@ -56,36 +56,36 @@ type API struct { Get func( context.Context, uint64, - share.Namespace, + gosquare.Namespace, blob.Commitment, ) (*blob.Blob, error) `perm:"read"` GetAll func( context.Context, uint64, - []share.Namespace, + []gosquare.Namespace, ) ([]*blob.Blob, error) `perm:"read"` GetProof func( context.Context, uint64, - share.Namespace, + gosquare.Namespace, blob.Commitment, ) (*blob.Proof, error) `perm:"read"` Included func( context.Context, uint64, - share.Namespace, + gosquare.Namespace, *blob.Proof, blob.Commitment, ) (bool, error) `perm:"read"` GetCommitmentProof func( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, shareCommitment []byte, ) (*blob.CommitmentProof, error) `perm:"read"` Subscribe func( context.Context, - share.Namespace, + gosquare.Namespace, ) (<-chan *blob.SubscriptionResponse, error) `perm:"read"` } } @@ -97,20 +97,20 @@ func (api *API) Submit(ctx context.Context, blobs []*blob.Blob, options *blob.Su func (api *API) Get( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, commitment blob.Commitment, ) (*blob.Blob, error) { return api.Internal.Get(ctx, height, namespace, commitment) } -func (api *API) GetAll(ctx context.Context, height uint64, namespaces []share.Namespace) ([]*blob.Blob, error) { +func (api *API) GetAll(ctx context.Context, height uint64, namespaces []gosquare.Namespace) ([]*blob.Blob, error) { return api.Internal.GetAll(ctx, height, namespaces) } func (api *API) GetProof( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, commitment blob.Commitment, ) (*blob.Proof, error) { return api.Internal.GetProof(ctx, height, namespace, commitment) @@ -119,7 +119,7 @@ func (api *API) GetProof( func (api *API) GetCommitmentProof( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, shareCommitment []byte, ) (*blob.CommitmentProof, error) { return api.Internal.GetCommitmentProof(ctx, height, namespace, shareCommitment) @@ -128,7 +128,7 @@ func (api *API) GetCommitmentProof( func (api *API) Included( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, proof *blob.Proof, commitment blob.Commitment, ) (bool, error) { @@ -137,7 +137,7 @@ func (api *API) Included( func (api *API) Subscribe( ctx context.Context, - namespace share.Namespace, + namespace gosquare.Namespace, ) (<-chan *blob.SubscriptionResponse, error) { return api.Internal.Subscribe(ctx, namespace) } diff --git a/nodebuilder/blob/cmd/blob.go b/nodebuilder/blob/cmd/blob.go index 527ac9b2d7..2be5df5c0c 100644 --- a/nodebuilder/blob/cmd/blob.go +++ b/nodebuilder/blob/cmd/blob.go @@ -11,7 +11,7 @@ import ( "github.com/spf13/cobra" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" cmdnode "github.com/celestiaorg/celestia-node/cmd" @@ -106,7 +106,7 @@ var getAllCmd = &cobra.Command{ return fmt.Errorf("error parsing a namespace: %w", err) } - blobs, err := client.Blob.GetAll(cmd.Context(), height, []share.Namespace{namespace}) + blobs, err := client.Blob.GetAll(cmd.Context(), height, []gosquare.Namespace{namespace}) return cmdnode.PrintOutput(blobs, err, formatData(args[1])) }, } diff --git a/nodebuilder/blob/module.go b/nodebuilder/blob/module.go index d62624adf8..cf07ed3732 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/square/shwap" + "github.com/celestiaorg/celestia-node/share/shwap" ) func ConstructModule() fx.Option { diff --git a/nodebuilder/core/module.go b/nodebuilder/core/module.go index f186d724c2..441907ce32 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/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" "github.com/celestiaorg/celestia-node/store" ) diff --git a/nodebuilder/da/service.go b/nodebuilder/da/service.go index b9a87a629c..ed8e5054b2 100644 --- a/nodebuilder/da/service.go +++ b/nodebuilder/da/service.go @@ -11,7 +11,7 @@ import ( "github.com/rollkit/go-da" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" "github.com/celestiaorg/celestia-node/header" @@ -68,7 +68,7 @@ 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) - namespace, err := share.NewNamespaceFromBytes(ns) + namespace, err := gosquare.NewNamespaceFromBytes(ns) if err != nil { return nil, err } @@ -85,14 +85,14 @@ func (s *Service) Get(ctx context.Context, ids []da.ID, ns da.Namespace) ([]da.B // 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) + ns, err := gosquare.NewNamespaceFromBytes(namespace) if err != nil { return nil, err } var ids []da.ID //nolint:prealloc log.Debugw("getting ids", "height", height, "namespace", ns) - blobs, err := s.blobServ.GetAll(ctx, height, []share.Namespace{ns}) + blobs, err := s.blobServ.GetAll(ctx, height, []gosquare.Namespace{ns}) log.Debugw("got ids", "height", height, "namespace", ns) if err != nil { if strings.Contains(err.Error(), blob.ErrBlobNotFound.Error()) { @@ -114,7 +114,7 @@ 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) + ns, err := gosquare.NewNamespaceFromBytes(namespace) if err != nil { return nil, err } @@ -213,7 +213,7 @@ func (s *Service) blobsAndCommitments( blobs := make([]*blob.Blob, 0, len(daBlobs)) commitments := make([]da.Commitment, 0, len(daBlobs)) for _, daBlob := range daBlobs { - ns, err := share.NewNamespaceFromBytes(namespace) + ns, err := gosquare.NewNamespaceFromBytes(namespace) if err != nil { return nil, nil, err } @@ -247,7 +247,7 @@ func (s *Service) Validate( proofs[i] = blobProof } for i, id := range ids { - ns, err := share.NewNamespaceFromBytes(namespace) + ns, err := gosquare.NewNamespaceFromBytes(namespace) if err != nil { return nil, err } diff --git a/nodebuilder/das/constructors.go b/nodebuilder/das/constructors.go index c3c7602740..8d6f9d1168 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/square" - "github.com/celestiaorg/celestia-node/square/eds/byzantine" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/byzantine" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" ) var _ Module = (*daserStub)(nil) @@ -39,7 +39,7 @@ func newDaserStub() Module { } func newDASer( - da square.Availability, + da share.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 e5cf07272e..d5e0461f01 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/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/share/eds/byzantine" ) var defaultProofUnmarshaler proofRegistry diff --git a/nodebuilder/header/constructors.go b/nodebuilder/header/constructors.go index 04e36d27ec..23947a8338 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/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/share/eds/byzantine" ) // newP2PExchange constructs a new Exchange for headers. diff --git a/nodebuilder/node_test.go b/nodebuilder/node_test.go index 91c057b69c..8155d7e081 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/square" + "github.com/celestiaorg/celestia-node/share" ) 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, square.EmptyEDSRoots()) + eh := headertest.RandExtendedHeaderWithRoot(t, share.EmptyEDSRoots()) err = node.ShareServ.SharesAvailable(ctx, eh) require.NoError(t, err) diff --git a/nodebuilder/p2p/module.go b/nodebuilder/p2p/module.go index 8c819373ae..9538ce03a5 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/square/ipld" + "github.com/celestiaorg/celestia-node/share/ipld" ) var log = logging.Logger("module/p2p") diff --git a/nodebuilder/p2p/routing.go b/nodebuilder/p2p/routing.go index 65a8a17da2..53f5377524 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/square/shwap/p2p/discovery" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/discovery" ) func newDHT( diff --git a/nodebuilder/share/bitswap.go b/nodebuilder/share/bitswap.go index 26784689ff..9316075dfe 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/square/shwap/p2p/bitswap" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/bitswap" "github.com/celestiaorg/celestia-node/store" ) diff --git a/nodebuilder/share/cmd/share.go b/nodebuilder/share/cmd/share.go index 8ec42a510a..b4abbabc52 100644 --- a/nodebuilder/share/cmd/share.go +++ b/nodebuilder/share/cmd/share.go @@ -8,7 +8,7 @@ import ( "github.com/spf13/cobra" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" rpc "github.com/celestiaorg/celestia-node/api/rpc/client" cmdnode "github.com/celestiaorg/celestia-node/cmd" @@ -123,7 +123,7 @@ var getShare = &cobra.Command{ s, err := client.Share.GetShare(cmd.Context(), eh, int(row), int(col)) formatter := func(data interface{}) interface{} { - sh, ok := data.(share.Share) + sh, ok := data.(gosquare.Share) if !ok { return data } diff --git a/nodebuilder/share/config.go b/nodebuilder/share/config.go index 00af197a83..6cf18332bc 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/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/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/store" ) diff --git a/nodebuilder/share/constructors.go b/nodebuilder/share/constructors.go index 6637ffac24..62e37477e6 100644 --- a/nodebuilder/share/constructors.go +++ b/nodebuilder/share/constructors.go @@ -7,15 +7,15 @@ import ( headerServ "github.com/celestiaorg/celestia-node/nodebuilder/header" "github.com/celestiaorg/celestia-node/pruner" - "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/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/store" ) -func newShareModule(getter shwap.Getter, avail square.Availability, header headerServ.Module) Module { +func newShareModule(getter shwap.Getter, avail share.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 1498be402a..e2d201757a 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/square" + share0 "github.com/celestiaorg/go-square/v2/share" rsmt2d "github.com/celestiaorg/rsmt2d" gomock "github.com/golang/mock/gomock" ) @@ -69,10 +69,10 @@ func (mr *MockModuleMockRecorder) GetRange(arg0, arg1, arg2, arg3 interface{}) * } // GetShare mocks base method. -func (m *MockModule) GetShare(arg0 context.Context, arg1 *header.ExtendedHeader, arg2, arg3 int) ([]byte, error) { +func (m *MockModule) GetShare(arg0 context.Context, arg1 *header.ExtendedHeader, arg2, arg3 int) (share0.Share, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetShare", arg0, arg1, arg2, arg3) - ret0, _ := ret[0].([]byte) + ret0, _ := ret[0].(share0.Share) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/nodebuilder/share/module.go b/nodebuilder/share/module.go index ac73a681e3..f02b4632b5 100644 --- a/nodebuilder/share/module.go +++ b/nodebuilder/share/module.go @@ -12,15 +12,15 @@ 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/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/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/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/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/store" ) @@ -233,14 +233,14 @@ func availabilityComponents(tp node.Type, cfg *Config) fx.Option { return la.Close(ctx) }), )), - fx.Provide(func(avail *light.ShareAvailability) square.Availability { + fx.Provide(func(avail *light.ShareAvailability) share.Availability { return avail }), ) case node.Bridge, node.Full: return fx.Options( fx.Provide(full.NewShareAvailability), - fx.Provide(func(avail *full.ShareAvailability) square.Availability { + fx.Provide(func(avail *full.ShareAvailability) share.Availability { return avail }), ) diff --git a/nodebuilder/share/opts.go b/nodebuilder/share/opts.go index 0510c1f11b..cfea26dbb4 100644 --- a/nodebuilder/share/opts.go +++ b/nodebuilder/share/opts.go @@ -3,11 +3,11 @@ package share import ( "errors" - "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/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/store" ) diff --git a/nodebuilder/share/p2p_constructors.go b/nodebuilder/share/p2p_constructors.go index 2e8ad55b1f..62a2948845 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/square/shwap/p2p/discovery" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/peers" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" + "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" ) const ( diff --git a/nodebuilder/share/share.go b/nodebuilder/share/share.go index 00d32d8890..d39381f6b8 100644 --- a/nodebuilder/share/share.go +++ b/nodebuilder/share/share.go @@ -5,15 +5,15 @@ import ( "github.com/tendermint/tendermint/types" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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/square" - "github.com/celestiaorg/celestia-node/square/eds" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/shwap" ) var _ Module = (*API)(nil) @@ -21,14 +21,14 @@ var _ Module = (*API)(nil) // GetRangeResult wraps the return value of the GetRange endpoint // because Json-RPC doesn't support more than two return values. type GetRangeResult struct { - Shares []share.Share + Shares []gosquare.Share Proof *types.ShareProof } // Module provides access to any data square or block share on the network. // // All Get methods provided on Module follow the following flow: -// 1. Check local storage for the requested Share. +// 1. Check local storage for the requested gosquare. // 2. If exists // * Load from disk // * Return @@ -46,13 +46,13 @@ type Module interface { // ExtendedHeader are available on the Network. SharesAvailable(context.Context, *header.ExtendedHeader) error // GetShare gets a Share by coordinates in EDS. - GetShare(ctx context.Context, header *header.ExtendedHeader, row, col int) (share.Share, error) + GetShare(ctx context.Context, header *header.ExtendedHeader, row, col int) (gosquare.Share, error) // GetEDS gets the full EDS identified by the given extended header. GetEDS(ctx context.Context, header *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) // GetSharesByNamespace gets all shares from an EDS within the given namespace. // Shares are returned in a row-by-row order if the namespace spans multiple rows. GetSharesByNamespace( - ctx context.Context, header *header.ExtendedHeader, namespace share.Namespace, + ctx context.Context, header *header.ExtendedHeader, namespace gosquare.Namespace, ) (NamespacedShares, error) // GetRange gets a list of shares and their corresponding proof. GetRange(ctx context.Context, height uint64, start, end int) (*GetRangeResult, error) @@ -67,7 +67,7 @@ type API struct { ctx context.Context, header *header.ExtendedHeader, row, col int, - ) (share.Share, error) `perm:"read"` + ) (gosquare.Share, error) `perm:"read"` GetEDS func( ctx context.Context, header *header.ExtendedHeader, @@ -75,7 +75,7 @@ type API struct { GetSharesByNamespace func( ctx context.Context, header *header.ExtendedHeader, - namespace share.Namespace, + namespace gosquare.Namespace, ) (NamespacedShares, error) `perm:"read"` GetRange func( ctx context.Context, @@ -89,7 +89,7 @@ func (api *API) SharesAvailable(ctx context.Context, header *header.ExtendedHead return api.Internal.SharesAvailable(ctx, header) } -func (api *API) GetShare(ctx context.Context, header *header.ExtendedHeader, row, col int) (share.Share, error) { +func (api *API) GetShare(ctx context.Context, header *header.ExtendedHeader, row, col int) (gosquare.Share, error) { return api.Internal.GetShare(ctx, header, row, col) } @@ -104,14 +104,14 @@ func (api *API) GetRange(ctx context.Context, height uint64, start, end int) (*G func (api *API) GetSharesByNamespace( ctx context.Context, header *header.ExtendedHeader, - namespace share.Namespace, + namespace gosquare.Namespace, ) (NamespacedShares, error) { return api.Internal.GetSharesByNamespace(ctx, header, namespace) } type module struct { shwap.Getter - square.Availability + share.Availability hs headerServ.Module } @@ -134,7 +134,7 @@ func (m module) GetRange(ctx context.Context, height uint64, start, end int) (*G return nil, err } - shares, err := share.FromBytes(extendedDataSquare.FlattenedODS()[start:end]) + shares, err := gosquare.FromBytes(extendedDataSquare.FlattenedODS()[start:end]) if err != nil { return nil, err } @@ -147,7 +147,7 @@ func (m module) GetRange(ctx context.Context, height uint64, start, end int) (*G func (m module) GetSharesByNamespace( ctx context.Context, header *header.ExtendedHeader, - namespace share.Namespace, + namespace gosquare.Namespace, ) (NamespacedShares, error) { nd, err := m.Getter.GetSharesByNamespace(ctx, header, namespace) if err != nil { @@ -157,19 +157,19 @@ func (m module) GetSharesByNamespace( } // NamespacedShares represents all shares with proofs within a specific namespace of an EDS. -// This is a copy of the share.NamespacedShares type, that is used to avoid breaking changes +// This is a copy of the gosquare.NamespacedShares type, that is used to avoid breaking changes // in the API. type NamespacedShares []NamespacedRow // NamespacedRow represents all shares with proofs within a specific namespace of a single EDS row. type NamespacedRow struct { - Shares []share.Share `json:"shares"` - Proof *nmt.Proof `json:"proof"` + Shares []gosquare.Share `json:"shares"` + Proof *nmt.Proof `json:"proof"` } // Flatten returns the concatenated slice of all NamespacedRow shares. -func (ns NamespacedShares) Flatten() []share.Share { - var shares []share.Share +func (ns NamespacedShares) Flatten() []gosquare.Share { + var shares []gosquare.Share for _, row := range ns { shares = append(shares, row.Shares...) } diff --git a/nodebuilder/state/core.go b/nodebuilder/state/core.go index f377fe4c6a..39ab732368 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/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/share/eds/byzantine" "github.com/celestiaorg/celestia-node/state" ) diff --git a/nodebuilder/state/state.go b/nodebuilder/state/state.go index 49568f26c0..0339970bea 100644 --- a/nodebuilder/state/state.go +++ b/nodebuilder/state/state.go @@ -5,7 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/state" ) @@ -39,7 +39,7 @@ type Module interface { // SubmitPayForBlob builds, signs and submits a PayForBlob transaction. SubmitPayForBlob( ctx context.Context, - blobs []*share.Blob, + blobs []*gosquare.Blob, config *state.TxConfig, ) (*state.TxResponse, error) // CancelUnbondingDelegation cancels a user's pending undelegation from a validator. @@ -115,7 +115,7 @@ type API struct { ) (*state.TxResponse, error) `perm:"write"` SubmitPayForBlob func( ctx context.Context, - blobs []*share.Blob, + blobs []*gosquare.Blob, config *state.TxConfig, ) (*state.TxResponse, error) `perm:"write"` CancelUnbondingDelegation func( @@ -189,7 +189,7 @@ func (api *API) Transfer( func (api *API) SubmitPayForBlob( ctx context.Context, - blobs []*share.Blob, + blobs []*gosquare.Blob, config *state.TxConfig, ) (*state.TxResponse, error) { return api.Internal.SubmitPayForBlob(ctx, blobs, config) diff --git a/nodebuilder/state/stub.go b/nodebuilder/state/stub.go index bd26068a52..fb8a1402f2 100644 --- a/nodebuilder/state/stub.go +++ b/nodebuilder/state/stub.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/state" ) @@ -44,7 +44,7 @@ func (s stubbedStateModule) Transfer( func (s stubbedStateModule) SubmitPayForBlob( context.Context, - []*share.Blob, + []*gosquare.Blob, *state.TxConfig, ) (*state.TxResponse, error) { return nil, ErrNoStateAccess diff --git a/nodebuilder/store.go b/nodebuilder/store.go index e778e9924e..61048c41b3 100644 --- a/nodebuilder/store.go +++ b/nodebuilder/store.go @@ -17,7 +17,7 @@ import ( dsbadger "github.com/ipfs/go-ds-badger4" "github.com/mitchellh/go-homedir" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/libs/keystore" nodemod "github.com/celestiaorg/celestia-node/nodebuilder/node" @@ -276,10 +276,10 @@ func dataPath(base string) string { func constraintBadgerConfig() *dsbadger.Options { opts := dsbadger.DefaultOptions // this must be copied // ValueLog: - // 2mib default => share.Size - makes sure headers and samples are stored in value log + // 2mib default => gosquare.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.ShareSize + opts.ValueThreshold = gosquare.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/blob_test.go b/nodebuilder/tests/blob_test.go index 590aed2166..ba949a7aa4 100644 --- a/nodebuilder/tests/blob_test.go +++ b/nodebuilder/tests/blob_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" "github.com/celestiaorg/celestia-node/blob/blobtest" @@ -87,7 +87,7 @@ func TestBlobModule(t *testing.T) { doFn: func(t *testing.T) { // https://github.com/celestiaorg/celestia-node/issues/2915 time.Sleep(time.Second) - newBlobs, err := fullClient.Blob.GetAll(ctx, height, []share.Namespace{blobs[0].Namespace()}) + newBlobs, err := fullClient.Blob.GetAll(ctx, height, []gosquare.Namespace{blobs[0].Namespace()}) require.NoError(t, err) require.Len(t, newBlobs, len(appBlobs0)) require.True(t, bytes.Equal(blobs[0].Commitment, newBlobs[0].Commitment)) @@ -126,7 +126,7 @@ func TestBlobModule(t *testing.T) { require.Error(t, err) require.ErrorContains(t, err, blob.ErrBlobNotFound.Error()) - blobs, err := fullClient.Blob.GetAll(ctx, height, []share.Namespace{newBlob.Namespace()}) + blobs, err := fullClient.Blob.GetAll(ctx, height, []gosquare.Namespace{newBlob.Namespace()}) require.NoError(t, err) assert.Empty(t, blobs) }, @@ -203,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 *share.Blob) (nodeBlob *blob.Blob, err error) { +func convert(squareBlob *gosquare.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 63961e379f..77708e7c49 100644 --- a/nodebuilder/tests/da_test.go +++ b/nodebuilder/tests/da_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/require" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" "github.com/celestiaorg/celestia-node/blob/blobtest" @@ -27,7 +27,7 @@ func TestDaModule(t *testing.T) { t.Cleanup(cancel) sw := swamp.NewSwamp(t, swamp.WithBlockTime(time.Second)) - namespace, err := share.NewV0Namespace([]byte("namespace")) + namespace, err := gosquare.NewV0Namespace([]byte("namespace")) require.NoError(t, err) require.False(t, namespace.IsReserved()) diff --git a/nodebuilder/tests/fraud_test.go b/nodebuilder/tests/fraud_test.go index f3ec37c157..524b306ac0 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/square/eds/byzantine" + "github.com/celestiaorg/celestia-node/share/eds/byzantine" "github.com/celestiaorg/celestia-node/store" ) diff --git a/nodebuilder/tests/nd_test.go b/nodebuilder/tests/nd_test.go index a7c6e35ffa..04cac8195b 100644 --- a/nodebuilder/tests/nd_test.go +++ b/nodebuilder/tests/nd_test.go @@ -12,16 +12,16 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/fx" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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/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/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/store" ) @@ -68,8 +68,8 @@ func TestShrexNDFromLights(t *testing.T) { reqCtx, cancel := context.WithTimeout(ctx, time.Second*5) // ensure to fetch random namespace (not the reserved namespace) - namespace := h.DAH.RowRoots[1][:share.NamespaceSize] - ns, err := share.NewNamespaceFromBytes(namespace) + namespace := h.DAH.RowRoots[1][:gosquare.NamespaceSize] + ns, err := gosquare.NewNamespaceFromBytes(namespace) require.NoError(t, err) expected, err := bridgeClient.Share.GetSharesByNamespace(reqCtx, h, ns) @@ -144,8 +144,8 @@ func TestShrexNDFromLightsWithBadFulls(t *testing.T) { reqCtx, cancel := context.WithTimeout(ctx, time.Second*5) // ensure to fetch random namespace (not the reserved namespace) - namespace := h.DAH.RowRoots[1][:share.NamespaceSize] - ns, err := share.NewNamespaceFromBytes(namespace) + namespace := h.DAH.RowRoots[1][:gosquare.NamespaceSize] + ns, err := gosquare.NewNamespaceFromBytes(namespace) expected, err := bridgeClient.Share.GetSharesByNamespace(reqCtx, h, ns) require.NoError(t, err) require.True(t, len(expected[0].Shares) > 0) diff --git a/nodebuilder/tests/prune_test.go b/nodebuilder/tests/prune_test.go index 14b26a219d..047981102c 100644 --- a/nodebuilder/tests/prune_test.go +++ b/nodebuilder/tests/prune_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/fx" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/blob" "github.com/celestiaorg/celestia-node/libs/fxutil" @@ -22,11 +22,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/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" + "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" ) // TestArchivalBlobSync tests whether a LN is able to sync historical blobs from @@ -118,7 +118,7 @@ func TestArchivalBlobSync(t *testing.T) { type archivalBlob struct { blob *blob.Blob height uint64 - root square.DataHash + root share.DataHash } archivalBlobs := make([]*archivalBlob, 0) @@ -127,7 +127,7 @@ func TestArchivalBlobSync(t *testing.T) { eh, err := archivalFN.HeaderServ.GetByHeight(ctx, uint64(i)) require.NoError(t, err) - if bytes.Equal(eh.DataHash, square.EmptyEDSRoots().Hash()) { + if bytes.Equal(eh.DataHash, share.EmptyEDSRoots().Hash()) { i++ continue } @@ -135,7 +135,7 @@ func TestArchivalBlobSync(t *testing.T) { shr, err := archivalFN.ShareServ.GetShare(ctx, eh, 2, 2) require.NoError(t, err) - blobs, err := archivalFN.BlobServ.GetAll(ctx, uint64(i), []share.Namespace{shr.Namespace()}) + blobs, err := archivalFN.BlobServ.GetAll(ctx, uint64(i), []gosquare.Namespace{shr.Namespace()}) require.NoError(t, err) archivalBlobs = append(archivalBlobs, &archivalBlob{ diff --git a/nodebuilder/tests/reconstruct_test.go b/nodebuilder/tests/reconstruct_test.go index f5360395cb..70bcca05be 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/square/availability/light" - "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/share/availability/light" + "github.com/celestiaorg/celestia-node/share/eds" ) /* diff --git a/nodebuilder/tests/sync_test.go b/nodebuilder/tests/sync_test.go index 90baabd218..780619146c 100644 --- a/nodebuilder/tests/sync_test.go +++ b/nodebuilder/tests/sync_test.go @@ -77,7 +77,7 @@ func TestSyncAgainstBridge_NonEmptyChain(t *testing.T) { assert.EqualValues(t, h.Commit.BlockID.Hash, sw.GetCoreBlockHashByHeight(ctx, numBlocks)) // check that the light node has also sampled over the block at height 20 - err = lightClient.Share.SharesAvailable(ctx, h) + err = lightClient.gosquare.SharesAvailable(ctx, h) assert.NoError(t, err) // wait until the entire chain (up to network head) has been sampled @@ -97,7 +97,7 @@ func TestSyncAgainstBridge_NonEmptyChain(t *testing.T) { assert.EqualValues(t, h.Commit.BlockID.Hash, sw.GetCoreBlockHashByHeight(ctx, numBlocks)) // check to ensure the full node can sync the 20th block's data - err = fullClient.Share.SharesAvailable(ctx, h) + err = fullClient.gosquare.SharesAvailable(ctx, h) assert.NoError(t, err) // wait for full node to sync up the blocks from genesis -> network head. @@ -167,7 +167,7 @@ func TestSyncAgainstBridge_EmptyChain(t *testing.T) { assert.EqualValues(t, h.Commit.BlockID.Hash, sw.GetCoreBlockHashByHeight(ctx, numBlocks)) // check that the light node has also sampled over the block at height 20 - err = lightClient.Share.SharesAvailable(ctx, h) + err = lightClient.gosquare.SharesAvailable(ctx, h) assert.NoError(t, err) // wait until the entire chain (up to network head) has been sampled @@ -187,7 +187,7 @@ func TestSyncAgainstBridge_EmptyChain(t *testing.T) { assert.EqualValues(t, h.Commit.BlockID.Hash, sw.GetCoreBlockHashByHeight(ctx, numBlocks)) // check to ensure the full node can sync the 20th block's data - err = fullClient.Share.SharesAvailable(ctx, h) + err = fullClient.gosquare.SharesAvailable(ctx, h) assert.NoError(t, err) // wait for full node to sync up the blocks from genesis -> network head. diff --git a/pruner/light/pruner.go b/pruner/light/pruner.go index bc0e1732ad..5739cd8cee 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/square" - "github.com/celestiaorg/celestia-node/square/ipld" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/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 square.DataHash(dah.Hash()).IsEmptyEDS() { + if share.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 *square.AxisRoots) datastore.Key { +func rootKey(root *share.AxisRoots) datastore.Key { return datastore.NewKey(root.String()) } diff --git a/square/availability.go b/share/availability.go similarity index 97% rename from square/availability.go rename to share/availability.go index fe2f29bea0..3373a62276 100644 --- a/square/availability.go +++ b/share/availability.go @@ -1,4 +1,4 @@ -package square +package share import ( "context" diff --git a/square/availability/full/availability.go b/share/availability/full/availability.go similarity index 83% rename from square/availability/full/availability.go rename to share/availability/full/availability.go index af6106cc27..32d889ff67 100644 --- a/square/availability/full/availability.go +++ b/share/availability/full/availability.go @@ -10,17 +10,17 @@ 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/square" - "github.com/celestiaorg/celestia-node/square/eds/byzantine" - "github.com/celestiaorg/celestia-node/square/shwap" + "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/store" ) var log = logging.Logger("share/full") -// ShareAvailability implements square.Availability using the full data square +// ShareAvailability implements share.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. +// to download enough shares to fully reconstruct the data share. type ShareAvailability struct { store *store.Store getter shwap.Getter @@ -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 square.DataHash(dah.Hash()).IsEmptyEDS() { - err := fa.store.PutODSQ4(ctx, dah, header.Height(), square.EmptyEDS()) + if share.DataHash(dah.Hash()).IsEmptyEDS() { + err := fa.store.PutODSQ4(ctx, dah, header.Height(), share.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 square.ErrNotAvailable + return share.ErrNotAvailable } return err } diff --git a/square/availability/full/availability_test.go b/share/availability/full/availability_test.go similarity index 86% rename from square/availability/full/availability_test.go rename to share/availability/full/availability_test.go index 4a03cace50..95f8bda533 100644 --- a/square/availability/full/availability_test.go +++ b/share/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/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/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/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 := square.NewAxisRoots(eds) + roots, err := share.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 := square.NewAxisRoots(eds) + roots, err := share.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 := square.NewAxisRoots(eds) + roots, err := share.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, square.ErrNotAvailable) + require.ErrorIs(t, err, share.ErrNotAvailable) } } diff --git a/square/availability/full/reconstruction_test.go b/share/availability/full/reconstruction_test.go similarity index 96% rename from square/availability/full/reconstruction_test.go rename to share/availability/full/reconstruction_test.go index e52b75d127..179a458d36 100644 --- a/square/availability/full/reconstruction_test.go +++ b/share/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/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" +// "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" //) // // 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, square.ErrNotAvailable) +// require.ErrorIs(t, err, share.ErrNotAvailable) // cancelErr() // // // but after they connect diff --git a/square/availability/full/testing.go b/share/availability/full/testing.go similarity index 63% rename from square/availability/full/testing.go rename to share/availability/full/testing.go index fae51c53ca..d4e7ee4f0c 100644 --- a/square/availability/full/testing.go +++ b/share/availability/full/testing.go @@ -10,24 +10,24 @@ package full // "github.com/ipfs/go-datastore" // "github.com/stretchr/testify/require" // -// "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" +// "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" //) // -//// 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) (square.Getter, *square.AxisRoots) { +//// GetterWithRandSquare provides a gosquare.Getter filled with 'n' NMT +//// trees of 'n' random shares, essentially storing a whole share. +//func GetterWithRandSquare(t *testing.T, n int) (share.Getter, *share.AxisRoots) { // bServ := ipld.NewMemBlockservice() // getter := shwap.NewIPLDGetter(bServ) // return getter, availability_test.RandFillBS(t, n, bServ) //} // //// RandNode creates a Full Node filled with a random block of the given size. -//func RandNode(dn *availability_test.TestDagNet, squareSize int) (*availability_test.TestNode, *square.AxisRoots) { +//func RandNode(dn *availability_test.TestDagNet, squareSize int) (*availability_test.TestNode, *share.AxisRoots) { // nd := Node(dn) // return nd, availability_test.RandFillBS(dn.T, squareSize, nd.BlockService) //} @@ -40,7 +40,7 @@ package full // return nd //} // -//func TestAvailability(t *testing.T, getter square.Getter) *ShareAvailability { +//func TestAvailability(t *testing.T, getter share.Getter) *ShareAvailability { // params := discovery.DefaultParameters() // params.AdvertiseInterval = time.Second // params.PeersLimit = 10 diff --git a/square/availability/light/availability.go b/share/availability/light/availability.go similarity index 91% rename from square/availability/light/availability.go rename to share/availability/light/availability.go index 1154c6a435..5b1e144de0 100644 --- a/square/availability/light/availability.go +++ b/share/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/square" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap" ) var ( @@ -21,7 +21,7 @@ var ( writeBatchSize = 2048 ) -// ShareAvailability implements square.Availability using Data Availability Sampling technique. +// ShareAvailability implements share.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 square.DataHash(dah.Hash()).IsEmptyEDS() { + if share.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 - // square.ErrNotAvailable + // share.ErrNotAvailable return ctx.Err() } @@ -144,12 +144,12 @@ func (la *ShareAvailability) SharesAvailable(ctx context.Context, header *header "root", dah.String(), "failed_samples", failedSamples, ) - return square.ErrNotAvailable + return share.ErrNotAvailable } return nil } -func rootKey(root *square.AxisRoots) datastore.Key { +func rootKey(root *share.AxisRoots) datastore.Key { return datastore.NewKey(root.String()) } diff --git a/square/availability/light/availability_test.go b/share/availability/light/availability_test.go similarity index 83% rename from square/availability/light/availability_test.go rename to share/availability/light/availability_test.go index f2bd6d420f..190aa2f7a6 100644 --- a/square/availability/light/availability_test.go +++ b/share/availability/light/availability_test.go @@ -10,16 +10,16 @@ import ( "github.com/ipfs/go-datastore" "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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/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" + "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" ) func TestSharesAvailableCaches(t *testing.T) { @@ -27,7 +27,7 @@ func TestSharesAvailableCaches(t *testing.T) { defer cancel() eds := edstest.RandEDS(t, 16) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) eh := headertest.RandExtendedHeaderWithRoot(t, roots) @@ -35,11 +35,11 @@ func TestSharesAvailableCaches(t *testing.T) { getter.EXPECT(). GetShare(gomock.Any(), eh, gomock.Any(), gomock.Any()). DoAndReturn( - func(_ context.Context, _ *header.ExtendedHeader, row, col int) (share.Share, error) { + func(_ context.Context, _ *header.ExtendedHeader, row, col int) (gosquare.Share, error) { rawSh := eds.GetCell(uint(row), uint(col)) - sh, err := share.NewShare(rawSh) + sh, err := gosquare.NewShare(rawSh) if err != nil { - return share.Share{}, err + return gosquare.Share{}, err } return *sh, nil }). @@ -72,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(share.Share{}, shrex.ErrNotFound). + Return(gosquare.Share{}, shrex.ErrNotFound). AnyTimes() ds := datastore.NewMapDatastore() @@ -84,7 +84,7 @@ func TestSharesAvailableHitsCache(t *testing.T) { // store doesn't actually have the eds err := avail.SharesAvailable(ctx, eh) - require.ErrorIs(t, err, square.ErrNotAvailable) + require.ErrorIs(t, err, share.ErrNotAvailable) // put success result in cache err = avail.ds.Put(ctx, rootKey(roots), []byte{}) @@ -104,7 +104,7 @@ func TestSharesAvailableEmptyRoot(t *testing.T) { avail := NewShareAvailability(getter, ds) // request for empty eds - eh := headertest.RandExtendedHeaderWithRoot(t, square.EmptyEDSRoots()) + eh := headertest.RandExtendedHeaderWithRoot(t, share.EmptyEDSRoots()) err := avail.SharesAvailable(ctx, eh) require.NoError(t, err) } @@ -119,17 +119,17 @@ func TestSharesAvailableFailed(t *testing.T) { // create new eds, that is not available by getter eds := edstest.RandEDS(t, 16) - roots, err := square.NewAxisRoots(eds) + roots, err := share.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(share.Share{}, shrex.ErrNotFound). + Return(gosquare.Share{}, shrex.ErrNotFound). AnyTimes() err = avail.SharesAvailable(ctx, eh) - require.ErrorIs(t, err, square.ErrNotAvailable) + require.ErrorIs(t, err, share.ErrNotAvailable) // cache should have failed results now result, err := avail.ds.Get(ctx, rootKey(roots)) @@ -175,15 +175,15 @@ func (m onceGetter) AddSamples(samples []Sample) { } } -func (m onceGetter) GetShare(_ context.Context, _ *header.ExtendedHeader, row, col int) (share.Share, error) { +func (m onceGetter) GetShare(_ context.Context, _ *header.ExtendedHeader, row, col int) (gosquare.Share, error) { m.Lock() defer m.Unlock() s := Sample{Row: uint16(row), Col: uint16(col)} if _, ok := m.available[s]; ok { delete(m.available, s) - return share.Share{}, nil + return gosquare.Share{}, nil } - return share.Share{}, square.ErrNotAvailable + return gosquare.Share{}, share.ErrNotAvailable } func (m onceGetter) GetEDS(_ context.Context, _ *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) { @@ -193,7 +193,7 @@ func (m onceGetter) GetEDS(_ context.Context, _ *header.ExtendedHeader) (*rsmt2d func (m onceGetter) GetSharesByNamespace( _ context.Context, _ *header.ExtendedHeader, - _ share.Namespace, + _ gosquare.Namespace, ) (shwap.NamespaceData, error) { panic("not implemented") } diff --git a/square/availability/light/options.go b/share/availability/light/options.go similarity index 100% rename from square/availability/light/options.go rename to share/availability/light/options.go diff --git a/square/availability/light/sample.go b/share/availability/light/sample.go similarity index 98% rename from square/availability/light/sample.go rename to share/availability/light/sample.go index c8061cdb1e..c3021b2e1f 100644 --- a/square/availability/light/sample.go +++ b/share/availability/light/sample.go @@ -8,7 +8,7 @@ import ( "math/big" ) -// Sample is a point in 2D space over square. +// Sample is a point in 2D space over share. type Sample struct { Row, Col uint16 } diff --git a/square/availability/light/sample_test.go b/share/availability/light/sample_test.go similarity index 100% rename from square/availability/light/sample_test.go rename to share/availability/light/sample_test.go diff --git a/square/availability/light/testing.go b/share/availability/light/testing.go similarity index 70% rename from square/availability/light/testing.go rename to share/availability/light/testing.go index 224e2425a3..a777a6ac9e 100644 --- a/square/availability/light/testing.go +++ b/share/availability/light/testing.go @@ -13,15 +13,15 @@ package light // // "github.com/celestiaorg/celestia-node/header" // "github.com/celestiaorg/celestia-node/header/headertest" -// "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" +// "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" //) // -//// 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, *header.ExtendedHeader) { +//// GetterWithRandSquare provides a gosquare.Getter filled with 'n' NMT trees of 'n' random shares, +//// essentially storing a whole share. +// func GetterWithRandSquare(t *testing.T, n int) (gosquare.Getter, *header.ExtendedHeader) { // bServ := ipld.NewMemBlockservice() // getter := getters.NewIPLDGetter(bServ) // root := availability_test.RandFillBS(t, n, bServ) @@ -31,16 +31,16 @@ package light // return getter, eh //} // -//// EmptyGetter provides an unfilled share.Getter with corresponding blockservice.BlockService than +//// EmptyGetter provides an unfilled gosquare.Getter with corresponding blockservice.BlockService than //// can be filled by the test. -// func EmptyGetter() (share.Getter, blockservice.BlockService) { +// func EmptyGetter() (gosquare.Getter, blockservice.BlockService) { // bServ := ipld.NewMemBlockservice() // getter := getters.NewIPLDGetter(bServ) // return getter, bServ //} // //// 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, *square.AxisRoots) { +// func RandNode(dn *availability_test.TestDagNet, squareSize int) (*availability_test.TestNode, *share.AxisRoots) { // nd := Node(dn) // return nd, availability_test.RandFillBS(dn.T, squareSize, nd.BlockService) //} @@ -53,7 +53,7 @@ package light // return nd //} // -// func TestAvailability(getter share.Getter) *ShareAvailability { +// func TestAvailability(getter gosquare.Getter) *ShareAvailability { // ds := datastore.NewMapDatastore() // return NewShareAvailability(getter, ds) //} @@ -84,15 +84,15 @@ package light // } //} // -// func (m onceGetter) GetShare(_ context.Context, _ *header.ExtendedHeader, row, col int) (share.Share, error) { +// func (m onceGetter) GetShare(_ context.Context, _ *header.ExtendedHeader, row, col int) (gosquare.Share, error) { // m.Lock() // defer m.Unlock() // s := Sample{Row: uint16(row), Col: uint16(col)} // if _, ok := m.available[s]; ok { // delete(m.available, s) -// return share.Share{}, nil +// return gosquare.Share{}, nil // } -// return share.Share{}, square.ErrNotAvailable +// return gosquare.Share{}, share.ErrNotAvailable //} // // func (m onceGetter) GetEDS(_ context.Context, _ *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) { @@ -102,7 +102,7 @@ package light // func (m onceGetter) GetSharesByNamespace( // _ context.Context, // _ *header.ExtendedHeader, -// _ share.Namespace, -// ) (share.NamespacedShares, error) { +// _ gosquare.Namespace, +// ) (gosquare.NamespacedShares, error) { // panic("not implemented") // } diff --git a/square/availability/mocks/availability.go b/share/availability/mocks/availability.go similarity index 100% rename from square/availability/mocks/availability.go rename to share/availability/mocks/availability.go diff --git a/square/availability/test/testing.go b/share/availability/test/testing.go similarity index 92% rename from square/availability/test/testing.go rename to share/availability/test/testing.go index 6296290c4c..1db8a5433b 100644 --- a/square/availability/test/testing.go +++ b/share/availability/test/testing.go @@ -17,24 +17,24 @@ import ( mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/ipld" + "github.com/celestiaorg/celestia-node/share/shwap" ) // RandFillBS fills the given BlockService with a random block of a given size. -func RandFillBS(t *testing.T, n int, bServ blockservice.BlockService) *square.AxisRoots { - shares := share.RandShares(n * n) +func RandFillBS(t *testing.T, n int, bServ blockservice.BlockService) *share.AxisRoots { + shares := gosquare.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) *square.AxisRoots { +func FillBS(t *testing.T, bServ blockservice.BlockService, shares []gosquare.Share) *share.AxisRoots { eds, err := ipld.AddShares(context.TODO(), shares, bServ) require.NoError(t, err) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) return roots } @@ -42,7 +42,7 @@ func FillBS(t *testing.T, bServ blockservice.BlockService, shares []share.Share) type TestNode struct { net *TestDagNet shwap.Getter - square.Availability + share.Availability blockservice.BlockService host.Host } diff --git a/square/doc.go b/share/doc.go similarity index 88% rename from square/doc.go rename to share/doc.go index c28ee5cdab..90dea3f243 100644 --- a/square/doc.go +++ b/share/doc.go @@ -1,5 +1,5 @@ /* -Package square contains logic related to the retrieval and random sampling of shares of +package share 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 square +package share diff --git a/square/eds/accessor.go b/share/eds/accessor.go similarity index 72% rename from square/eds/accessor.go rename to share/eds/accessor.go index a290d2aed0..4dc4732a1e 100644 --- a/square/eds/accessor.go +++ b/share/eds/accessor.go @@ -4,24 +4,24 @@ import ( "context" "io" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap" ) // EmptyAccessor is an accessor of an empty EDS block. -var EmptyAccessor = &Rsmt2D{ExtendedDataSquare: square.EmptyEDS()} +var EmptyAccessor = &Rsmt2D{ExtendedDataSquare: share.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) (square.DataHash, error) - // AxisRoots returns square.AxisRoots (DataAvailabilityHeader) of the Accessor. - AxisRoots(ctx context.Context) (*square.AxisRoots, error) + DataHash(ctx context.Context) (share.DataHash, error) + // AxisRoots returns share.AxisRoots (DataAvailabilityHeader) of the Accessor. + AxisRoots(ctx context.Context) (*share.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. @@ -30,9 +30,9 @@ type Accessor interface { // implementation. Implementations should indicate the side in the returned AxisHalf. AxisHalf(ctx context.Context, axisType rsmt2d.Axis, axisIdx int) (AxisHalf, error) // RowNamespaceData returns data for the given namespace and row index. - RowNamespaceData(ctx context.Context, namespace share.Namespace, rowIdx int) (shwap.RowNamespaceData, error) + RowNamespaceData(ctx context.Context, namespace gosquare.Namespace, rowIdx int) (shwap.RowNamespaceData, error) // Shares returns data (ODS) shares extracted from the Accessor. - Shares(ctx context.Context) ([]share.Share, error) + Shares(ctx context.Context) ([]gosquare.Share, error) } // AccessorStreamer is an interface that groups Accessor and Streamer interfaces. diff --git a/square/eds/axis_half.go b/share/eds/axis_half.go similarity index 62% rename from square/eds/axis_half.go rename to share/eds/axis_half.go index d5ef406be8..37ad7dede6 100644 --- a/square/eds/axis_half.go +++ b/share/eds/axis_half.go @@ -3,17 +3,17 @@ package eds import ( "fmt" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap" ) -var codec = square.DefaultRSMT2DCodec() +var codec = share.DefaultRSMT2DCodec() // AxisHalf represents a half of data for a row or column in the EDS. type AxisHalf struct { - Shares []share.Share + Shares []gosquare.Share // IsParity indicates whether the half is parity or data. IsParity bool } @@ -28,7 +28,7 @@ func (a AxisHalf) ToRow() shwap.Row { } // Extended returns full axis shares from half axis shares. -func (a AxisHalf) Extended() ([]share.Share, error) { +func (a AxisHalf) Extended() ([]gosquare.Share, error) { if a.IsParity { return reconstructShares(a.Shares) } @@ -36,42 +36,42 @@ func (a AxisHalf) Extended() ([]share.Share, error) { } // extendShares constructs full axis shares from original half axis shares. -func extendShares(original []share.Share) ([]share.Share, error) { +func extendShares(original []gosquare.Share) ([]gosquare.Share, error) { if len(original) == 0 { return nil, fmt.Errorf("original shares are empty") } - parity, err := codec.Encode(share.ToBytes(original)) + parity, err := codec.Encode(gosquare.ToBytes(original)) if err != nil { return nil, fmt.Errorf("encoding: %w", err) } - parityShrs, err := share.FromBytes(parity) + parityShrs, err := gosquare.FromBytes(parity) if err != nil { return nil, err } sqLen := len(original) * 2 - shares := make([]share.Share, sqLen) + shares := make([]gosquare.Share, sqLen) copy(shares, original) copy(shares[sqLen/2:], parityShrs) return shares, nil } -func reconstructShares(parity []share.Share) ([]share.Share, error) { +func reconstructShares(parity []gosquare.Share) ([]gosquare.Share, error) { if len(parity) == 0 { return nil, fmt.Errorf("parity shares are empty") } sqLen := len(parity) * 2 - shares := make([]share.Share, sqLen) + shares := make([]gosquare.Share, sqLen) for i := sqLen / 2; i < sqLen; i++ { shares[i] = parity[i-sqLen/2] } - shrs, err := codec.Decode(share.ToBytes(shares)) + shrs, err := codec.Decode(gosquare.ToBytes(shares)) if err != nil { return nil, fmt.Errorf("reconstructing: %w", err) } - return share.FromBytes(shrs) + return gosquare.FromBytes(shrs) } diff --git a/square/eds/axis_half_test.go b/share/eds/axis_half_test.go similarity index 84% rename from square/eds/axis_half_test.go rename to share/eds/axis_half_test.go index 6974080523..77165eabce 100644 --- a/square/eds/axis_half_test.go +++ b/share/eds/axis_half_test.go @@ -5,11 +5,11 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) func TestExtendAxisHalf(t *testing.T) { - shares := share.RandShares(16) + shares := gosquare.RandShares(16) original := AxisHalf{ Shares: shares, diff --git a/square/eds/byzantine/bad_encoding.go b/share/eds/byzantine/bad_encoding.go similarity index 97% rename from square/eds/byzantine/bad_encoding.go rename to share/eds/byzantine/bad_encoding.go index 8687e7ce1f..8b4586d83c 100644 --- a/square/eds/byzantine/bad_encoding.go +++ b/share/eds/byzantine/bad_encoding.go @@ -10,8 +10,8 @@ import ( "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" - "github.com/celestiaorg/celestia-node/square" - pb "github.com/celestiaorg/celestia-node/square/eds/byzantine/pb" + "github.com/celestiaorg/celestia-node/share" + pb "github.com/celestiaorg/celestia-node/share/eds/byzantine/pb" ) const ( @@ -152,7 +152,7 @@ func (p *BadEncodingProof) Validate(hdr *header.ExtendedHeader) error { // Since p.Shares should contain all the shares from either a row or a // column, it should exactly match the number of row roots. In this // context, the number of row roots is the width of the extended data - // square. + // share. log.Infof("%s: %s (%d >= %d)", invalidProofPrefix, errIncorrectAmountOfShares, int(p.Index), width, ) @@ -191,7 +191,7 @@ func (p *BadEncodingProof) Validate(hdr *header.ExtendedHeader) error { shares[index] = shr.Share.ToBytes() } - codec := square.DefaultRSMT2DCodec() + codec := share.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/square/eds/byzantine/bad_encoding_test.go b/share/eds/byzantine/bad_encoding_test.go similarity index 92% rename from square/eds/byzantine/bad_encoding_test.go rename to share/eds/byzantine/bad_encoding_test.go index c226b2a5cb..4a849aaaa0 100644 --- a/square/eds/byzantine/bad_encoding_test.go +++ b/share/eds/byzantine/bad_encoding_test.go @@ -14,14 +14,14 @@ import ( core "github.com/tendermint/tendermint/types" "github.com/celestiaorg/celestia-app/v3/test/util/malicious" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/ipld" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/ipld" ) func TestBEFP_Validate(t *testing.T) { @@ -30,7 +30,7 @@ func TestBEFP_Validate(t *testing.T) { bServ := ipld.NewMemBlockservice() byzSquare := edstest.RandByzantineEDS(t, 16) - roots, err := square.NewAxisRoots(byzSquare) + roots, err := share.NewAxisRoots(byzSquare) require.NoError(t, err) err = ipld.ImportEDS(ctx, byzSquare, bServ) require.NoError(t, err) @@ -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 := square.NewAxisRoots(validSquare) + validRoots, err := share.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 := share.RandShares(2) + sh := gosquare.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 := share.RandShares(squareSize * squareSize) + shares := gosquare.RandShares(squareSize * squareSize) eds, err := ipld.AddShares(ctx, shares, bServ) require.NoError(t, err) - roots, err := square.NewAxisRoots(eds) + roots, err := share.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, - square.DefaultRSMT2DCodec(), + share.DefaultRSMT2DCodec(), malicious.NewConstructor(uint64(size), nmt.NodeVisitor(batchAddr.Visit)), ) require.NoError(t, err, "failure to recompute the extended data square") - roots, err := square.NewAxisRoots(eds) + roots, err := share.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(square.NewSHA256Hasher(), share.NamespaceSize, true) + nh := nmt.NewNmtHasher(share.NewSHA256Hasher(), gosquare.NamespaceSize, true) nh.Reset() return nh }) @@ -265,7 +265,7 @@ func newNamespacedBlockService() *namespacedBlockService { Codec: sha256NamespaceFlagged, MhType: sha256NamespaceFlagged, // equals to NmtHasher.Size() - MhLength: square.NewSHA256Hasher().Size() + 2*share.NamespaceSize, + MhLength: share.NewSHA256Hasher().Size() + 2*gosquare.NamespaceSize, } return bs } diff --git a/square/eds/byzantine/byzantine.go b/share/eds/byzantine/byzantine.go similarity index 87% rename from square/eds/byzantine/byzantine.go rename to share/eds/byzantine/byzantine.go index 80f015529c..cd0c54b9fc 100644 --- a/square/eds/byzantine/byzantine.go +++ b/share/eds/byzantine/byzantine.go @@ -6,18 +6,18 @@ import ( "github.com/ipfs/boxo/blockstore" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/ipld" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/ipld" ) // ErrByzantine is a thrown when recovered data square is not correct // (merkle proofs do not match parity erasure-coding data). // // It is converted from rsmt2d.ByzantineRow/Col + -// Merkle Proof for each share. +// Merkle Proof for each gosquare. type ErrByzantine struct { Index uint32 Shares []*ShareWithProof @@ -33,7 +33,7 @@ func (e *ErrByzantine) Error() string { func NewErrByzantine( ctx context.Context, bStore blockstore.Blockstore, - roots *square.AxisRoots, + roots *share.AxisRoots, errByz *rsmt2d.ErrByzantineData, ) error { sharesWithProof := make([]*ShareWithProof, len(errByz.Shares)) @@ -43,7 +43,7 @@ func NewErrByzantine( if len(shr) == 0 { continue } - sh, err := share.NewShare(shr) + sh, err := gosquare.NewShare(shr) if err != nil { log.Warn("failed to create share", "index", index, "err", err) continue diff --git a/square/eds/byzantine/pb/share.pb.go b/share/eds/byzantine/pb/share.pb.go similarity index 87% rename from square/eds/byzantine/pb/share.pb.go rename to share/eds/byzantine/pb/share.pb.go index d31b409560..af79d48b13 100644 --- a/square/eds/byzantine/pb/share.pb.go +++ b/share/eds/byzantine/pb/share.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: square/eds/byzantine/pb/share.proto +// source: share/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_5c467604cd602917, []int{0} + return fileDescriptor_d28ce8f160a920d1, []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_5c467604cd602917, []int{0} + return fileDescriptor_d28ce8f160a920d1, []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_5c467604cd602917, []int{1} + return fileDescriptor_d28ce8f160a920d1, []int{1} } func (m *BadEncoding) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -191,31 +191,31 @@ func init() { } func init() { - 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, + 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, } func (m *Share) Marshal() (dAtA []byte, err error) { diff --git a/square/eds/byzantine/pb/share.proto b/share/eds/byzantine/pb/share.proto similarity index 100% rename from square/eds/byzantine/pb/share.proto rename to share/eds/byzantine/pb/share.proto diff --git a/square/eds/byzantine/share_proof.go b/share/eds/byzantine/share_proof.go similarity index 84% rename from square/eds/byzantine/share_proof.go rename to share/eds/byzantine/share_proof.go index 5d94159a0a..51cf4b9793 100644 --- a/square/eds/byzantine/share_proof.go +++ b/share/eds/byzantine/share_proof.go @@ -7,14 +7,14 @@ import ( "github.com/ipfs/boxo/blockservice" logging "github.com/ipfs/go-log/v2" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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/square" - pb "github.com/celestiaorg/celestia-node/square/eds/byzantine/pb" - "github.com/celestiaorg/celestia-node/square/ipld" + "github.com/celestiaorg/celestia-node/share" + pb "github.com/celestiaorg/celestia-node/share/eds/byzantine/pb" + "github.com/celestiaorg/celestia-node/share/ipld" ) var log = logging.Logger("share/byzantine") @@ -22,7 +22,7 @@ var log = logging.Logger("share/byzantine") // ShareWithProof contains data with corresponding Merkle Proof type ShareWithProof struct { // Share is a full data including namespace - share.Share + gosquare.Share // Proof is a Merkle Proof of current share Proof *nmt.Proof // Axis is a proof axis @@ -30,7 +30,7 @@ type ShareWithProof struct { } // Validate validates inclusion of the share under the given root CID. -func (s *ShareWithProof) Validate(roots *square.AxisRoots, axisType rsmt2d.Axis, axisIdx, shrIdx int) bool { +func (s *ShareWithProof) Validate(roots *share.AxisRoots, axisType rsmt2d.Axis, axisIdx, shrIdx int) bool { var rootHash []byte switch axisType { case rsmt2d.Row: @@ -41,12 +41,12 @@ func (s *ShareWithProof) Validate(roots *square.AxisRoots, axisType rsmt2d.Axis, edsSize := len(roots.RowRoots) isParity := shrIdx >= edsSize/2 || axisIdx >= edsSize/2 - namespace := share.ParitySharesNamespace + namespace := gosquare.ParitySharesNamespace if !isParity { namespace = s.Share.Namespace() } return s.Proof.VerifyInclusion( - square.NewSHA256Hasher(), + share.NewSHA256Hasher(), namespace.Bytes(), [][]byte{s.Share.ToBytes()}, rootHash, @@ -70,13 +70,13 @@ func (s *ShareWithProof) ShareWithProofToProto() *pb.Share { } } -// GetShareWithProof attempts to get a share with proof for the given share. It first tries to get +// GetShareWithProof attempts to get a share with proof for the given gosquare. It first tries to get // a row proof and if that fails or proof is invalid, it tries to get a column proof. func GetShareWithProof( ctx context.Context, bGetter blockservice.BlockGetter, - roots *square.AxisRoots, - share share.Share, + roots *share.AxisRoots, + share gosquare.Share, axisType rsmt2d.Axis, axisIdx, shrIdx int, ) (*ShareWithProof, error) { if axisType == rsmt2d.Col { @@ -121,7 +121,7 @@ func ProtoToShare(protoShares []*pb.Share) ([]*ShareWithProof, error) { continue } proof := ProtoToProof(protoSh.Proof) - sh, err := share.NewShare(protoSh.Data) + sh, err := gosquare.NewShare(protoSh.Data) if err != nil { return nil, err } @@ -143,7 +143,7 @@ func ProtoToProof(protoProof *nmt_pb.Proof) nmt.Proof { ) } -func rootHashForCoordinates(r *square.AxisRoots, axisType rsmt2d.Axis, x, y int) []byte { +func rootHashForCoordinates(r *share.AxisRoots, axisType rsmt2d.Axis, x, y int) []byte { if axisType == rsmt2d.Row { return r.RowRoots[y] } diff --git a/square/eds/close_once.go b/share/eds/close_once.go similarity index 80% rename from square/eds/close_once.go rename to share/eds/close_once.go index 13b2df177b..773eea2be9 100644 --- a/square/eds/close_once.go +++ b/share/eds/close_once.go @@ -6,11 +6,11 @@ import ( "io" "sync/atomic" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap" ) var _ AccessorStreamer = (*closeOnce)(nil) @@ -43,14 +43,14 @@ func (c *closeOnce) Size(ctx context.Context) int { return c.f.Size(ctx) } -func (c *closeOnce) DataHash(ctx context.Context) (square.DataHash, error) { +func (c *closeOnce) DataHash(ctx context.Context) (share.DataHash, error) { if c.closed.Load() { return nil, errAccessorClosed } return c.f.DataHash(ctx) } -func (c *closeOnce) AxisRoots(ctx context.Context) (*square.AxisRoots, error) { +func (c *closeOnce) AxisRoots(ctx context.Context) (*share.AxisRoots, error) { if c.closed.Load() { return nil, errAccessorClosed } @@ -77,7 +77,7 @@ func (c *closeOnce) AxisHalf( func (c *closeOnce) RowNamespaceData( ctx context.Context, - namespace share.Namespace, + namespace gosquare.Namespace, rowIdx int, ) (shwap.RowNamespaceData, error) { if c.closed.Load() { @@ -86,7 +86,7 @@ func (c *closeOnce) RowNamespaceData( return c.f.RowNamespaceData(ctx, namespace, rowIdx) } -func (c *closeOnce) Shares(ctx context.Context) ([]share.Share, error) { +func (c *closeOnce) Shares(ctx context.Context) ([]gosquare.Share, error) { if c.closed.Load() { return nil, errAccessorClosed } diff --git a/square/eds/close_once_test.go b/share/eds/close_once_test.go similarity index 72% rename from square/eds/close_once_test.go rename to share/eds/close_once_test.go index 58da79d840..cc41954ef5 100644 --- a/square/eds/close_once_test.go +++ b/share/eds/close_once_test.go @@ -8,11 +8,11 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap" ) func TestWithClosedOnce(t *testing.T) { @@ -24,7 +24,7 @@ func TestWithClosedOnce(t *testing.T) { require.NoError(t, err) _, err = closedOnce.AxisHalf(ctx, rsmt2d.Row, 0) require.NoError(t, err) - _, err = closedOnce.RowNamespaceData(ctx, share.Namespace{}, 0) + _, err = closedOnce.RowNamespaceData(ctx, gosquare.Namespace{}, 0) require.NoError(t, err) _, err = closedOnce.Shares(ctx) require.NoError(t, err) @@ -37,7 +37,7 @@ func TestWithClosedOnce(t *testing.T) { require.ErrorIs(t, err, errAccessorClosed) _, err = closedOnce.AxisHalf(ctx, rsmt2d.Row, 0) require.ErrorIs(t, err, errAccessorClosed) - _, err = closedOnce.RowNamespaceData(ctx, share.Namespace{}, 0) + _, err = closedOnce.RowNamespaceData(ctx, gosquare.Namespace{}, 0) require.ErrorIs(t, err, errAccessorClosed) _, err = closedOnce.Shares(ctx) require.ErrorIs(t, err, errAccessorClosed) @@ -51,12 +51,12 @@ func (s *stubEdsAccessorCloser) Size(context.Context) int { return 0 } -func (s *stubEdsAccessorCloser) DataHash(context.Context) (square.DataHash, error) { - return square.DataHash{}, nil +func (s *stubEdsAccessorCloser) DataHash(context.Context) (share.DataHash, error) { + return share.DataHash{}, nil } -func (s *stubEdsAccessorCloser) AxisRoots(context.Context) (*square.AxisRoots, error) { - return &square.AxisRoots{}, nil +func (s *stubEdsAccessorCloser) AxisRoots(context.Context) (*share.AxisRoots, error) { + return &share.AxisRoots{}, nil } func (s *stubEdsAccessorCloser) Sample(context.Context, int, int) (shwap.Sample, error) { @@ -69,13 +69,13 @@ func (s *stubEdsAccessorCloser) AxisHalf(context.Context, rsmt2d.Axis, int) (Axi func (s *stubEdsAccessorCloser) RowNamespaceData( context.Context, - share.Namespace, + gosquare.Namespace, int, ) (shwap.RowNamespaceData, error) { return shwap.RowNamespaceData{}, nil } -func (s *stubEdsAccessorCloser) Shares(context.Context) ([]share.Share, error) { +func (s *stubEdsAccessorCloser) Shares(context.Context) ([]gosquare.Share, error) { return nil, nil } diff --git a/square/eds/edstest/testing.go b/share/eds/edstest/testing.go similarity index 78% rename from square/eds/edstest/testing.go rename to share/eds/edstest/testing.go index 8eb11409bb..a3e84073b6 100644 --- a/square/eds/edstest/testing.go +++ b/share/eds/edstest/testing.go @@ -18,11 +18,11 @@ import ( blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" appshares "github.com/celestiaorg/go-square/shares" libSquare "github.com/celestiaorg/go-square/square" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) const ( @@ -33,22 +33,22 @@ const ( func RandByzantineEDS(t testing.TB, odsSize int, options ...nmt.Option) *rsmt2d.ExtendedDataSquare { eds := RandEDS(t, odsSize) shares := eds.Flattened() - copy(shares[0][share.NamespaceSize:], shares[1][share.NamespaceSize:]) // corrupting eds + copy(shares[0][gosquare.NamespaceSize:], shares[1][gosquare.NamespaceSize:]) // corrupting eds eds, err := rsmt2d.ImportExtendedDataSquare( shares, - square.DefaultRSMT2DCodec(), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize), options...), ) require.NoError(t, err, "failure to recompute the extended data square") return eds } -// RandEDS generates EDS filled with the random data with the given size for original square. +// RandEDS generates EDS filled with the random data with the given size for original share. func RandEDS(t testing.TB, odsSize int) *rsmt2d.ExtendedDataSquare { - shares := share.RandShares(odsSize * odsSize) + shares := gosquare.RandShares(odsSize * odsSize) eds, err := rsmt2d.ComputeExtendedDataSquare( - share.ToBytes(shares), - square.DefaultRSMT2DCodec(), + gosquare.ToBytes(shares), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize)), ) require.NoError(t, err, "failure to recompute the extended data square") @@ -57,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 := share.RandShares(odsSize * odsSize) + shares := gosquare.RandShares(odsSize * odsSize) for i := len(shares) - padding; i < len(shares); i++ { - paddingShare := share.TailPaddingShare() + paddingShare := gosquare.TailPaddingShare() shares[i] = paddingShare } eds, err := rsmt2d.ComputeExtendedDataSquare( - share.ToBytes(shares), - square.DefaultRSMT2DCodec(), + gosquare.ToBytes(shares), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize)), ) require.NoError(t, err, "failure to recompute the extended data square") @@ -76,23 +76,23 @@ func RandEDSWithTailPadding(t testing.TB, odsSize, padding int) *rsmt2d.Extended // namespacedAmount of shares with the given namespace. func RandEDSWithNamespace( t testing.TB, - namespace share.Namespace, + namespace gosquare.Namespace, namespacedAmount, odsSize int, -) (*rsmt2d.ExtendedDataSquare, *square.AxisRoots) { - shares := share.RandSharesWithNamespace(namespace, namespacedAmount, odsSize*odsSize) +) (*rsmt2d.ExtendedDataSquare, *share.AxisRoots) { + shares := gosquare.RandSharesWithNamespace(namespace, namespacedAmount, odsSize*odsSize) eds, err := rsmt2d.ComputeExtendedDataSquare( - share.ToBytes(shares), - square.DefaultRSMT2DCodec(), + gosquare.ToBytes(shares), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(odsSize)), ) require.NoError(t, err, "failure to recompute the extended data square") - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) return eds, roots } -// RandomAxisRoots generates random square.AxisRoots for the given eds size. -func RandomAxisRoots(t testing.TB, edsSize int) *square.AxisRoots { +// RandomAxisRoots generates random share.AxisRoots for the given eds size. +func RandomAxisRoots(t testing.TB, edsSize int) *share.AxisRoots { roots := make([][]byte, edsSize*2) for i := range roots { root := make([]byte, edsSize) @@ -103,7 +103,7 @@ func RandomAxisRoots(t testing.TB, edsSize int) *square.AxisRoots { rows := roots[:edsSize] cols := roots[edsSize:] - return &square.AxisRoots{ + return &share.AxisRoots{ RowRoots: rows, ColumnRoots: cols, } @@ -116,8 +116,8 @@ func GenerateTestBlock( blobSize, numberOfTransactions int, ) ( []*blobtypes.MsgPayForBlobs, - []*share.Blob, - []share.Namespace, + []*gosquare.Blob, + []gosquare.Namespace, *rsmt2d.ExtendedDataSquare, coretypes.Txs, *da.DataAvailabilityHeader, @@ -131,7 +131,7 @@ func GenerateTestBlock( txs := make(coretypes.Txs, 0) txs = append(txs, coreTxs...) - dataSquare, err := libSquare.Construct( + square, err := libSquare.Construct( txs.ToSliceOfBytes(), appconsts.SquareSizeUpperBound(appconsts.LatestVersion), appconsts.SubtreeRootThreshold(appconsts.LatestVersion), @@ -139,7 +139,7 @@ func GenerateTestBlock( require.NoError(t, err) // erasure the data square which we use to create the data root. - eds, err := da.ExtendShares(appshares.ToBytes(dataSquare)) + eds, err := da.ExtendShares(appshares.ToBytes(square)) require.NoError(t, err) // create the new data root by creating the data availability header (merkle @@ -157,10 +157,10 @@ func GenerateTestBlock( func createTestBlobTransactions( t *testing.T, numberOfTransactions, size int, -) ([]share.Namespace, []*blobtypes.MsgPayForBlobs, []*share.Blob, []coretypes.Tx) { - nss := make([]share.Namespace, 0) +) ([]gosquare.Namespace, []*blobtypes.MsgPayForBlobs, []*gosquare.Blob, []coretypes.Tx) { + nss := make([]gosquare.Namespace, 0) msgs := make([]*blobtypes.MsgPayForBlobs, 0) - blobs := make([]*share.Blob, 0) + blobs := make([]*gosquare.Blob, 0) coreTxs := make([]coretypes.Tx, 0) config := encoding.MakeConfig(app.ModuleEncodingRegisters...) keyring := testfactory.TestKeyring(config.Codec, accountName) @@ -185,11 +185,11 @@ func createTestBlobTransaction( t *testing.T, signer *user.Signer, size int, -) (share.Namespace, *blobtypes.MsgPayForBlobs, *share.Blob, coretypes.Tx) { - ns := share.RandomBlobNamespace() +) (gosquare.Namespace, *blobtypes.MsgPayForBlobs, *gosquare.Blob, coretypes.Tx) { + ns := gosquare.RandomBlobNamespace() account := signer.Account(accountName) msg, b := blobfactory.RandMsgPayForBlobsWithNamespaceAndSigner(account.Address().String(), ns, size) - cTx, _, err := signer.CreatePayForBlobs(accountName, []*share.Blob{b}) + cTx, _, err := signer.CreatePayForBlobs(accountName, []*gosquare.Blob{b}) require.NoError(t, err) return ns, msg, b, cTx } diff --git a/square/eds/nd.go b/share/eds/nd.go similarity index 75% rename from square/eds/nd.go rename to share/eds/nd.go index 1ba186e083..6215493c68 100644 --- a/square/eds/nd.go +++ b/share/eds/nd.go @@ -4,10 +4,10 @@ import ( "context" "fmt" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap" ) // NamespaceData extracts shares for a specific namespace from an EDS, considering @@ -16,13 +16,13 @@ import ( func NamespaceData( ctx context.Context, eds Accessor, - namespace share.Namespace, + namespace gosquare.Namespace, ) (shwap.NamespaceData, error) { roots, err := eds.AxisRoots(ctx) if err != nil { return nil, fmt.Errorf("failed to get AxisRoots: %w", err) } - rowIdxs := square.RowsWithNamespace(roots, namespace) + rowIdxs := share.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/square/eds/nd_test.go b/share/eds/nd_test.go similarity index 81% rename from square/eds/nd_test.go rename to share/eds/nd_test.go index dba512a644..63c1883bf2 100644 --- a/square/eds/nd_test.go +++ b/share/eds/nd_test.go @@ -7,9 +7,9 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/share/eds/edstest" ) func TestNamespaceData(t *testing.T) { @@ -18,7 +18,7 @@ func TestNamespaceData(t *testing.T) { const odsSize = 8 sharesAmount := odsSize * odsSize - namespace := share.RandomNamespace() + namespace := gosquare.RandomNamespace() for amount := 1; amount < sharesAmount; amount++ { eds, root := edstest.RandEDSWithNamespace(t, namespace, amount, odsSize) rsmt2d := &Rsmt2D{ExtendedDataSquare: eds} diff --git a/square/eds/proof.go b/share/eds/proof.go similarity index 94% rename from square/eds/proof.go rename to share/eds/proof.go index 2e9d8912cc..d649ed7772 100644 --- a/square/eds/proof.go +++ b/share/eds/proof.go @@ -7,7 +7,7 @@ import ( "github.com/tendermint/tendermint/types" pkgproof "github.com/celestiaorg/celestia-app/v3/pkg/proof" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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 := share.FromBytes(eds.FlattenedODS()) + odsShares, err := gosquare.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, share.NewRange(start, end)) + proof, err := pkgproof.NewShareInclusionProofFromEDS(eds, nID, gosquare.NewRange(start, end)) if err != nil { return nil, err } diff --git a/square/eds/proofs_cache.go b/share/eds/proofs_cache.go similarity index 92% rename from square/eds/proofs_cache.go rename to share/eds/proofs_cache.go index 6f28240a11..32af960ff6 100644 --- a/square/eds/proofs_cache.go +++ b/share/eds/proofs_cache.go @@ -13,13 +13,13 @@ import ( "github.com/ipfs/go-cid" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/ipld" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/ipld" + "github.com/celestiaorg/celestia-node/share/shwap" ) var _ AccessorStreamer = (*proofsCache)(nil) @@ -34,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[square.DataHash] + dataHash atomic.Pointer[share.DataHash] // rootsCache caches the axis roots - rootsCache atomic.Pointer[square.AxisRoots] + rootsCache atomic.Pointer[share.AxisRoots] // axisCacheLock protects proofCache axisCacheLock sync.RWMutex // axisCache caches the axis Shares and proofs. Index in the slice corresponds to the axis type. @@ -51,11 +51,11 @@ type proofsCache struct { type axisWithProofs struct { half AxisHalf // shares are the extended axis Shares - shares []share.Share + shares []gosquare.Share // root caches the root of the tree. It will be set only when proofs are calculated root []byte // proofs are stored in a blockservice.BlockGetter by their CID. It will be set only when proofs - // are calculated and will be used to get the proof for a specific share. BlockGetter is used to + // are calculated and will be used to get the proof for a specific gosquare. BlockGetter is used to // reuse ipld based proof generation logic, which traverses the tree from the root to the leafs and // collects the nodes on the path. This is temporary and will be replaced with a more efficient // proof caching mechanism in nmt package, once it is implemented. @@ -84,7 +84,7 @@ func (c *proofsCache) Size(ctx context.Context) int { return int(size) } -func (c *proofsCache) DataHash(ctx context.Context) (square.DataHash, error) { +func (c *proofsCache) DataHash(ctx context.Context) (share.DataHash, error) { dataHash := c.dataHash.Load() if dataHash != nil { return *dataHash, nil @@ -97,7 +97,7 @@ func (c *proofsCache) DataHash(ctx context.Context) (square.DataHash, error) { return loaded, nil } -func (c *proofsCache) AxisRoots(ctx context.Context) (*square.AxisRoots, error) { +func (c *proofsCache) AxisRoots(ctx context.Context) (*share.AxisRoots, error) { roots := c.rootsCache.Load() if roots != nil { return roots, nil @@ -213,7 +213,7 @@ func (c *proofsCache) AxisHalf(ctx context.Context, axisType rsmt2d.Axis, axisId func (c *proofsCache) RowNamespaceData( ctx context.Context, - namespace share.Namespace, + namespace gosquare.Namespace, rowIdx int, ) (shwap.RowNamespaceData, error) { ax, err := c.axisWithProofs(ctx, rsmt2d.Row, rowIdx) @@ -232,9 +232,9 @@ func (c *proofsCache) RowNamespaceData( }, nil } -func (c *proofsCache) Shares(ctx context.Context) ([]share.Share, error) { +func (c *proofsCache) Shares(ctx context.Context) ([]gosquare.Share, error) { odsSize := c.Size(ctx) / 2 - shares := make([]share.Share, 0, odsSize*odsSize) + shares := make([]gosquare.Share, 0, odsSize*odsSize) for i := 0; i < c.Size(ctx)/2; i++ { ax, err := c.AxisHalf(ctx, rsmt2d.Row, i) if err != nil { @@ -265,7 +265,7 @@ func (c *proofsCache) Close() error { return c.inner.Close() } -func (c *proofsCache) axisShares(ctx context.Context, axisType rsmt2d.Axis, axisIdx int) ([]share.Share, error) { +func (c *proofsCache) axisShares(ctx context.Context, axisType rsmt2d.Axis, axisIdx int) ([]gosquare.Share, error) { ax, ok := c.getAxisFromCache(axisType, axisIdx) if ok && len(ax.shares) != 0 { return ax.shares, nil diff --git a/square/eds/proofs_cache_test.go b/share/eds/proofs_cache_test.go similarity index 100% rename from square/eds/proofs_cache_test.go rename to share/eds/proofs_cache_test.go diff --git a/square/eds/read.go b/share/eds/read.go similarity index 77% rename from square/eds/read.go rename to share/eds/read.go index 0090a7c1a9..38afba4199 100644 --- a/square/eds/read.go +++ b/share/eds/read.go @@ -7,15 +7,15 @@ import ( "fmt" "io" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) // ReadAccessor reads up EDS out of the io.Reader until io.EOF and provides. -func ReadAccessor(ctx context.Context, reader io.Reader, root *square.AxisRoots) (*Rsmt2D, error) { +func ReadAccessor(ctx context.Context, reader io.Reader, root *share.AxisRoots) (*Rsmt2D, error) { odsSize := len(root.RowRoots) / 2 - shares, err := ReadShares(reader, share.ShareSize, odsSize) + shares, err := ReadShares(reader, gosquare.ShareSize, odsSize) if err != nil { return nil, fmt.Errorf("failed to read eds from ods bytes: %w", err) } @@ -41,22 +41,22 @@ func ReadAccessor(ctx context.Context, reader io.Reader, root *square.AxisRoots) // ReadShares reads shares from the provided io.Reader until EOF. If EOF is reached, the remaining shares // are populated as tail padding shares. Provided reader must contain shares in row-major order. -func ReadShares(r io.Reader, shareSize, odsSize int) ([]share.Share, error) { - shares := make([]share.Share, odsSize*odsSize) +func ReadShares(r io.Reader, shareSize, odsSize int) ([]gosquare.Share, error) { + shares := make([]gosquare.Share, odsSize*odsSize) var total int for i := range shares { shr := make([]byte, shareSize) n, err := io.ReadFull(r, shr) if errors.Is(err, io.EOF) { for ; i < len(shares); i++ { - shares[i] = share.TailPaddingShare() + shares[i] = gosquare.TailPaddingShare() } return shares, nil } if err != nil { return nil, fmt.Errorf("reading shares: %w, bytes read: %v", err, total+n) } - newShare, err := share.NewShare(shr) + newShare, err := gosquare.NewShare(shr) if err != nil { return nil, err } diff --git a/square/eds/retriever.go b/share/eds/retriever.go similarity index 94% rename from square/eds/retriever.go rename to share/eds/retriever.go index 53b79aacd7..d8111289af 100644 --- a/square/eds/retriever.go +++ b/share/eds/retriever.go @@ -16,13 +16,13 @@ import ( "go.opentelemetry.io/otel/trace" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/byzantine" - "github.com/celestiaorg/celestia-node/square/ipld" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/byzantine" + "github.com/celestiaorg/celestia-node/share/ipld" ) var ( @@ -41,7 +41,7 @@ var ( // ---- ---- // // Retriever randomly picks one of the data square quadrants and tries to request them one by one -// until it is able to reconstruct the whole square. +// until it is able to reconstruct the whole share. type Retriever struct { bServ blockservice.BlockService } @@ -57,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 *square.AxisRoots) (*rsmt2d.ExtendedDataSquare, error) { +func (r *Retriever) Retrieve(ctx context.Context, roots *share.AxisRoots) (*rsmt2d.ExtendedDataSquare, error) { ctx, cancel := context.WithCancel(ctx) defer cancel() // cancels all the ongoing requests if reconstruction succeeds early @@ -107,7 +107,7 @@ func (r *Retriever) Retrieve(ctx context.Context, roots *square.AxisRoots) (*rsm // quadrant request retries. Also, provides an API // to reconstruct the block once enough shares are fetched. type retrievalSession struct { - roots *square.AxisRoots + roots *share.AxisRoots bget blockservice.BlockGetter adder *ipld.NmtNodeAdder @@ -125,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 *square.AxisRoots) (*retrievalSession, error) { +func (r *Retriever) newSession(ctx context.Context, roots *share.AxisRoots) (*retrievalSession, error) { size := len(roots.RowRoots) adder := ipld.NewNmtNodeAdder(ctx, r.bServ, ipld.MaxSizeBatchOption(size)) @@ -143,7 +143,7 @@ func (r *Retriever) newSession(ctx context.Context, roots *square.AxisRoots) (*r return &tree } - square, err := rsmt2d.NewExtendedDataSquare(square.DefaultRSMT2DCodec(), treeFn, uint(size), share.ShareSize) + square, err := rsmt2d.NewExtendedDataSquare(share.DefaultRSMT2DCodec(), treeFn, uint(size), gosquare.ShareSize) if err != nil { return nil, err } @@ -283,7 +283,7 @@ func (rs *retrievalSession) doRequest(ctx context.Context, q *quadrant) { 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. + // in the share. // NOTE-2: We may never actually fetch shares from the network *twice*. // Once a share is downloaded from the network it may be cached on the IPLD(blockservice) level. // diff --git a/square/eds/retriever_no_race_test.go b/share/eds/retriever_no_race_test.go similarity index 72% rename from square/eds/retriever_no_race_test.go rename to share/eds/retriever_no_race_test.go index 43165a0bce..b27d9c5264 100644 --- a/square/eds/retriever_no_race_test.go +++ b/share/eds/retriever_no_race_test.go @@ -10,14 +10,14 @@ import ( "github.com/stretchr/testify/require" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" - "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" + "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" ) func TestRetriever_ByzantineError(t *testing.T) { @@ -31,13 +31,13 @@ func TestRetriever_ByzantineError(t *testing.T) { require.NoError(t, err) // corrupt shares so that eds erasure coding does not match - copy(shares[14][share.NamespaceSize:], shares[15][share.NamespaceSize:]) + copy(shares[14][gosquare.NamespaceSize:], shares[15][gosquare.NamespaceSize:]) // import corrupted eds batchAdder := ipld.NewNmtNodeAdder(ctx, bserv, ipld.MaxSizeBatchOption(width*2)) attackerEDS, err := rsmt2d.ImportExtendedDataSquare( shares, - square.DefaultRSMT2DCodec(), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(width), nmt.NodeVisitor(batchAdder.Visit)), ) @@ -46,7 +46,7 @@ func TestRetriever_ByzantineError(t *testing.T) { require.NoError(t, err) // ensure we rcv an error - roots, err := square.NewAxisRoots(attackerEDS) + roots, err := share.NewAxisRoots(attackerEDS) require.NoError(t, err) r := NewRetriever(bserv) _, err = r.Retrieve(ctx, roots) diff --git a/square/eds/retriever_quadrant.go b/share/eds/retriever_quadrant.go similarity index 92% rename from square/eds/retriever_quadrant.go rename to share/eds/retriever_quadrant.go index 6450926948..0b5bffb311 100644 --- a/square/eds/retriever_quadrant.go +++ b/share/eds/retriever_quadrant.go @@ -8,8 +8,8 @@ import ( "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/ipld" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/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 *square.AxisRoots) []*quadrant { +func newQuadrants(roots *share.AxisRoots) []*quadrant { // combine all the roots into one slice, so they can be easily accessible by index daRoots := [][][]byte{ roots.RowRoots, @@ -87,7 +87,7 @@ func newQuadrants(roots *square.AxisRoots) []*quadrant { return quadrants } -// pos calculates position of a share in a data square. +// pos calculates position of a share in a data share. func (q *quadrant) pos(rootIdx, cellIdx int) (int, int) { cellIdx += len(q.roots) * q.x rootIdx += len(q.roots) * q.y diff --git a/square/eds/retriever_test.go b/share/eds/retriever_test.go similarity index 92% rename from square/eds/retriever_test.go rename to share/eds/retriever_test.go index 1fd2c4632f..69980dcfc1 100644 --- a/square/eds/retriever_test.go +++ b/share/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" + gosquare "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/square" - "github.com/celestiaorg/celestia-node/square/eds/byzantine" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/ipld" + "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" ) 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)", square.MaxSquareSize}, + {"128x128(max)", share.MaxSquareSize}, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { // generate EDS - shares := share.RandShares(tc.squareSize * tc.squareSize) + shares := gosquare.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 := square.NewAxisRoots(in) + roots, err := share.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 := share.RandShares(squareSize * squareSize) + shares := gosquare.RandShares(squareSize * squareSize) in, err := ipld.AddShares(ctx, shares, bServ) require.NoError(t, err) - roots, err := square.NewAxisRoots(in) + roots, err := share.NewAxisRoots(in) require.NoError(t, err) ses, err := r.newSession(ctx, roots) require.NoError(t, err) diff --git a/square/eds/rsmt2d.go b/share/eds/rsmt2d.go similarity index 78% rename from square/eds/rsmt2d.go rename to share/eds/rsmt2d.go index 0dfc044498..39e2973a38 100644 --- a/square/eds/rsmt2d.go +++ b/share/eds/rsmt2d.go @@ -6,11 +6,11 @@ import ( "io" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap" ) var _ AccessorStreamer = (*Rsmt2D)(nil) @@ -20,23 +20,23 @@ type Rsmt2D struct { *rsmt2d.ExtendedDataSquare } -// Size returns the size of the Extended Data Square. +// Size returns the size of the Extended Data share. func (eds *Rsmt2D) Size(context.Context) int { return int(eds.Width()) } // DataHash returns data hash of the Accessor. -func (eds *Rsmt2D) DataHash(context.Context) (square.DataHash, error) { - roots, err := square.NewAxisRoots(eds.ExtendedDataSquare) +func (eds *Rsmt2D) DataHash(context.Context) (share.DataHash, error) { + roots, err := share.NewAxisRoots(eds.ExtendedDataSquare) if err != nil { - return square.DataHash{}, fmt.Errorf("while creating data root: %w", err) + return share.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) (*square.AxisRoots, error) { - roots, err := square.NewAxisRoots(eds.ExtendedDataSquare) +func (eds *Rsmt2D) AxisRoots(context.Context) (*share.AxisRoots, error) { + roots, err := share.NewAxisRoots(eds.ExtendedDataSquare) if err != nil { return nil, fmt.Errorf("while creating axis roots: %w", err) } @@ -100,7 +100,7 @@ func (eds *Rsmt2D) AxisHalf(_ context.Context, axisType rsmt2d.Axis, axisIdx int // side. func (eds *Rsmt2D) HalfRow(idx int, side shwap.RowSide) (shwap.Row, error) { shares := eds.ExtendedDataSquare.Row(uint(idx)) - sh, err := share.FromBytes(shares) + sh, err := gosquare.FromBytes(shares) if err != nil { return shwap.Row{}, fmt.Errorf("while converting shares from bytes: %w", err) } @@ -110,11 +110,11 @@ func (eds *Rsmt2D) HalfRow(idx int, side shwap.RowSide) (shwap.Row, error) { // RowNamespaceData returns data for the given namespace and row index. func (eds *Rsmt2D) RowNamespaceData( _ context.Context, - namespace share.Namespace, + namespace gosquare.Namespace, rowIdx int, ) (shwap.RowNamespaceData, error) { shares := eds.Row(uint(rowIdx)) - sh, err := share.FromBytes(shares) + sh, err := gosquare.FromBytes(shares) if err != nil { return shwap.RowNamespaceData{}, fmt.Errorf("while converting shares from bytes: %w", err) } @@ -123,8 +123,8 @@ func (eds *Rsmt2D) RowNamespaceData( // 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 share.FromBytes(eds.ExtendedDataSquare.FlattenedODS()) +func (eds *Rsmt2D) Shares(_ context.Context) ([]gosquare.Share, error) { + return gosquare.FromBytes(eds.ExtendedDataSquare.FlattenedODS()) } func (eds *Rsmt2D) Close() error { @@ -142,9 +142,9 @@ func (eds *Rsmt2D) Reader() (io.Reader, error) { } // Rsmt2DFromShares constructs an Extended Data Square from shares. -func Rsmt2DFromShares(shares []share.Share, odsSize int) (*Rsmt2D, error) { +func Rsmt2DFromShares(shares []gosquare.Share, odsSize int) (*Rsmt2D, error) { treeFn := wrapper.NewConstructor(uint64(odsSize)) - eds, err := rsmt2d.ComputeExtendedDataSquare(share.ToBytes(shares), square.DefaultRSMT2DCodec(), treeFn) + eds, err := rsmt2d.ComputeExtendedDataSquare(gosquare.ToBytes(shares), share.DefaultRSMT2DCodec(), treeFn) if err != nil { return &Rsmt2D{}, fmt.Errorf("computing extended data square: %w", err) } @@ -152,13 +152,13 @@ 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, error) { +func getAxis(eds *rsmt2d.ExtendedDataSquare, axisType rsmt2d.Axis, axisIdx int) ([]gosquare.Share, error) { switch axisType { case rsmt2d.Row: - sh, err := share.FromBytes(eds.Row(uint(axisIdx))) + sh, err := gosquare.FromBytes(eds.Row(uint(axisIdx))) return sh, err case rsmt2d.Col: - sh, err := share.FromBytes(eds.Col(uint(axisIdx))) + sh, err := gosquare.FromBytes(eds.Col(uint(axisIdx))) return sh, err default: panic("unknown axis") diff --git a/square/eds/rsmt2d_test.go b/share/eds/rsmt2d_test.go similarity index 83% rename from square/eds/rsmt2d_test.go rename to share/eds/rsmt2d_test.go index 58ee60211c..fa76b03a09 100644 --- a/square/eds/rsmt2d_test.go +++ b/share/eds/rsmt2d_test.go @@ -7,12 +7,12 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "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/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/shwap" ) func TestRsmt2dAccessor(t *testing.T) { @@ -43,7 +43,7 @@ func TestRsmt2dHalfRow(t *testing.T) { want := eds.Row(uint(rowIdx)) shares, err := row.Shares() require.NoError(t, err) - require.Equal(t, want, share.ToBytes(shares)) + require.Equal(t, want, gosquare.ToBytes(shares)) } } } @@ -70,9 +70,9 @@ func TestRsmt2dSampleForProofAxis(t *testing.T) { } } -func randRsmt2dAccsessor(t *testing.T, size int) (Rsmt2D, *square.AxisRoots) { +func randRsmt2dAccsessor(t *testing.T, size int) (Rsmt2D, *share.AxisRoots) { eds := edstest.RandEDS(t, size) - root, err := square.NewAxisRoots(eds) + root, err := share.NewAxisRoots(eds) require.NoError(t, err) return Rsmt2D{ExtendedDataSquare: eds}, root } diff --git a/square/eds/share_reader.go b/share/eds/share_reader.go similarity index 100% rename from square/eds/share_reader.go rename to share/eds/share_reader.go diff --git a/square/eds/share_reader_test.go b/share/eds/share_reader_test.go similarity index 86% rename from square/eds/share_reader_test.go rename to share/eds/share_reader_test.go index cb4e6d19ff..165cc25f42 100644 --- a/square/eds/share_reader_test.go +++ b/share/eds/share_reader_test.go @@ -8,9 +8,9 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/share/eds/edstest" ) func TestShareReader(t *testing.T) { @@ -24,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.ShareSize) + expected := make([]byte, 0, odsSize*odsSize*gosquare.ShareSize) for _, share := range eds.FlattenedODS() { expected = append(expected, share...) } diff --git a/square/eds/testing.go b/share/eds/testing.go similarity index 92% rename from square/eds/testing.go rename to share/eds/testing.go index f7a1bf0f89..b6b448a075 100644 --- a/square/eds/testing.go +++ b/share/eds/testing.go @@ -10,13 +10,13 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" - "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/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/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"] = square.EmptyEDS() + testEDSes["EmptyODS"] = share.EmptyEDS() return testEDSes } @@ -110,12 +110,12 @@ func testAccessorDataHash( ) { acc := createAccessor(t, eds) - expected, err := square.NewAxisRoots(eds) + expected, err := share.NewAxisRoots(eds) require.NoError(t, err) datahash, err := acc.DataHash(ctx) require.NoError(t, err) - require.Equal(t, square.DataHash(expected.Hash()), datahash) + require.Equal(t, share.DataHash(expected.Hash()), datahash) } func testAccessorAxisRoots( @@ -126,7 +126,7 @@ func testAccessorAxisRoots( ) { acc := createAccessor(t, eds) - expected, err := square.NewAxisRoots(eds) + expected, err := share.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 := square.NewAxisRoots(eds) + roots, err := share.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 := square.NewAxisRoots(eds) + roots, err := share.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 := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) wg := sync.WaitGroup{} @@ -194,7 +194,7 @@ func testSample( ctx context.Context, t *testing.T, acc Accessor, - roots *square.AxisRoots, + roots *share.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 := share.RandomNamespace() + namespace := gosquare.RandomNamespace() // test with different amount of shares for amount := 1; amount < sharesAmount; amount++ { // select random amount of shares, but not less than 1 @@ -250,18 +250,18 @@ func testAccessorRowNamespaceData( t.Parallel() // generate EDS with random data and some Shares with the same namespace eds := edstest.RandEDS(t, odsSize) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) // loop over first half of the rows, because the second half is parity and does not contain // namespaced shares 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) - ns, err := share.NewNamespaceFromBytes(maxNs) + maxNs := nmt.MaxNamespace(root, gosquare.NamespaceSize) + ns, err := gosquare.NewNamespaceFromBytes(maxNs) require.NoError(t, err) - absentNs, err := share.AddInt(ns, -1) + absentNs, err := gosquare.AddInt(ns, -1) require.NoError(t, err) acc := createAccessor(t, eds) @@ -294,7 +294,7 @@ func testAccessorAxisHalf( require.NoError(t, err) require.Len(t, half.Shares, odsSize) - var expected []share.Share + var expected []gosquare.Share if half.IsParity { expected, err = getAxis(eds, axisType, axisIdx) require.NoError(t, err) @@ -322,7 +322,7 @@ func testAccessorAxisHalf( require.NoError(t, err) require.Len(t, half.Shares, odsSize) - var expected []share.Share + var expected []gosquare.Share if half.IsParity { expected, err = getAxis(eds, axisType, idx) require.NoError(t, err) @@ -357,7 +357,7 @@ func testAccessorShares( shares, err := acc.Shares(ctx) require.NoError(t, err) expected := eds.FlattenedODS() - sh, err := share.FromBytes(expected) + sh, err := gosquare.FromBytes(expected) require.NoError(t, err) require.Equal(t, sh, shares) }() @@ -390,7 +390,7 @@ func testReader(ctx context.Context, t *testing.T, eds *rsmt2d.ExtendedDataSquar reader, err := as.Reader() require.NoError(t, err) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) actual, err := ReadAccessor(ctx, reader, roots) diff --git a/square/eds/validation.go b/share/eds/validation.go similarity index 92% rename from square/eds/validation.go rename to share/eds/validation.go index c8d7c632f7..eca404ab99 100644 --- a/square/eds/validation.go +++ b/share/eds/validation.go @@ -6,10 +6,10 @@ import ( "fmt" "sync/atomic" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share/shwap" ) var _ Accessor = validation{} @@ -56,7 +56,7 @@ func (f validation) AxisHalf(ctx context.Context, axisType rsmt2d.Axis, axisIdx func (f validation) RowNamespaceData( ctx context.Context, - namespace share.Namespace, + namespace gosquare.Namespace, rowIdx int, ) (shwap.RowNamespaceData, error) { _, err := shwap.NewRowNamespaceDataID(1, rowIdx, namespace, f.Size(ctx)) diff --git a/square/eds/validation_test.go b/share/eds/validation_test.go similarity index 92% rename from square/eds/validation_test.go rename to share/eds/validation_test.go index 0d0b3bf42e..f5ac0d5588 100644 --- a/square/eds/validation_test.go +++ b/share/eds/validation_test.go @@ -7,11 +7,11 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/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 := share.RandomNamespace() + ns := gosquare.RandomNamespace() _, err := validation.RowNamespaceData(context.Background(), ns, tt.rowIdx) if tt.expectFail { require.ErrorIs(t, err, shwap.ErrInvalidID) diff --git a/square/empty.go b/share/empty.go similarity index 82% rename from square/empty.go rename to share/empty.go index b683715a3e..ce82915180 100644 --- a/square/empty.go +++ b/share/empty.go @@ -1,4 +1,4 @@ -package square +package share import ( "bytes" @@ -6,7 +6,7 @@ import ( "sync" "github.com/celestiaorg/celestia-app/v3/pkg/da" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" ) @@ -22,14 +22,14 @@ func EmptyEDSRoots() *AxisRoots { return emptyBlockRoots } -// EmptyEDS returns the EDS of the empty block data square. +// EmptyEDS returns the EDS of the empty block data share. func EmptyEDS() *rsmt2d.ExtendedDataSquare { initEmpty() return emptyBlockEDS } // EmptyBlockShares returns the shares of the empty block. -func EmptyBlockShares() []share.Share { +func EmptyBlockShares() []gosquare.Share { initEmpty() return emptyBlockShares } @@ -39,7 +39,7 @@ var ( emptyBlockDataHash DataHash emptyBlockRoots *AxisRoots emptyBlockEDS *rsmt2d.ExtendedDataSquare - emptyBlockShares []share.Share + emptyBlockShares []gosquare.Share ) // initEmpty enables lazy initialization for constant empty block data. @@ -49,8 +49,8 @@ func initEmpty() { func computeEmpty() { // compute empty block EDS and DAH for it - result := share.TailPaddingShares(share.MinShareCount) - rawEmptyBlockShares := share.ToBytes(result) + result := gosquare.TailPaddingShares(gosquare.MinShareCount) + rawEmptyBlockShares := gosquare.ToBytes(result) eds, err := da.ExtendShares(rawEmptyBlockShares) if err != nil { @@ -69,7 +69,7 @@ func computeEmpty() { } sh := eds.FlattenedODS() - emptyBlockShares, err = share.FromBytes(sh) + emptyBlockShares, err = gosquare.FromBytes(sh) if err != nil { panic(fmt.Errorf("failed to create shares: %w", err)) } diff --git a/square/ipld/add.go b/share/ipld/add.go similarity index 91% rename from square/ipld/add.go rename to share/ipld/add.go index f200f28309..8a182bce2f 100644 --- a/square/ipld/add.go +++ b/share/ipld/add.go @@ -7,19 +7,19 @@ import ( "github.com/ipfs/boxo/blockservice" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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/square" + "github.com/celestiaorg/celestia-node/share" ) // AddShares erasures and extends shares to blockservice.BlockService using the provided // ipld.NodeAdder. func AddShares( ctx context.Context, - shares []share.Share, + shares []gosquare.Share, adder blockservice.BlockService, ) (*rsmt2d.ExtendedDataSquare, error) { if len(shares) == 0 { @@ -31,8 +31,8 @@ func AddShares( // create the nmt wrapper to generate row and col commitments // recompute the eds eds, err := rsmt2d.ComputeExtendedDataSquare( - share.ToBytes(shares), - square.DefaultRSMT2DCodec(), + gosquare.ToBytes(shares), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(squareSize), nmt.NodeVisitor(batchAdder.Visit)), ) @@ -64,7 +64,7 @@ func ImportShares( // recompute the eds eds, err := rsmt2d.ImportExtendedDataSquare( shares, - square.DefaultRSMT2DCodec(), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(squareSize/2), nmt.NodeVisitor(batchAdder.Visit)), ) diff --git a/square/ipld/blockserv.go b/share/ipld/blockserv.go similarity index 100% rename from square/ipld/blockserv.go rename to share/ipld/blockserv.go diff --git a/square/ipld/delete.go b/share/ipld/delete.go similarity index 100% rename from square/ipld/delete.go rename to share/ipld/delete.go diff --git a/square/ipld/delete_test.go b/share/ipld/delete_test.go similarity index 95% rename from square/ipld/delete_test.go rename to share/ipld/delete_test.go index e6953ba5f3..ff879a10b8 100644 --- a/square/ipld/delete_test.go +++ b/share/ipld/delete_test.go @@ -12,7 +12,7 @@ import ( "github.com/ipfs/go-datastore/sync" "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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 := share.RandShares(size * size) + shares := gosquare.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 := share.RandShares(size * size) + shares := gosquare.RandShares(size * size) eds, err := AddShares(ctx, shares, full) require.NoError(t, err) diff --git a/square/ipld/get.go b/share/ipld/get.go similarity index 97% rename from square/ipld/get.go rename to share/ipld/get.go index a5769adf40..9e85f7ccc9 100644 --- a/square/ipld/get.go +++ b/share/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/square" + "github.com/celestiaorg/celestia-node/share" ) // 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 = square.MaxSquareSize * square.MaxSquareSize / 2 * NumConcurrentSquares +var NumWorkersLimit = share.MaxSquareSize * share.MaxSquareSize / 2 * NumConcurrentSquares // NumConcurrentSquares limits the amount of squares that are fetched // concurrently/simultaneously. diff --git a/square/ipld/get_shares.go b/share/ipld/get_shares.go similarity index 79% rename from square/ipld/get_shares.go rename to share/ipld/get_shares.go index 5872daeb41..172a576834 100644 --- a/square/ipld/get_shares.go +++ b/share/ipld/get_shares.go @@ -7,7 +7,7 @@ import ( "github.com/ipfs/go-cid" format "github.com/ipfs/go-ipld-format" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" ) @@ -18,15 +18,15 @@ func GetShare( rootCid cid.Cid, leafIndex int, totalLeafs int, // this corresponds to the extended square width -) (share.Share, error) { +) (gosquare.Share, error) { nd, err := GetLeaf(ctx, bGetter, rootCid, leafIndex, totalLeafs) if err != nil { - return share.Share{}, err + return gosquare.Share{}, err } - sh, err := share.NewShare(nd.RawData()[share.NamespaceSize:]) + sh, err := gosquare.NewShare(nd.RawData()[gosquare.NamespaceSize:]) if err != nil { - return share.Share{}, err + return gosquare.Share{}, err } return *sh, nil } @@ -36,7 +36,7 @@ func GetShare( // (got all shares) or on context cancellation. 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, leaf.RawData()[share.NamespaceSize:]) + put(i, leaf.RawData()[gosquare.NamespaceSize:]) } GetLeaves(ctx, bg, root, shares, putNode) } @@ -48,9 +48,9 @@ func GetSharesByNamespace( ctx context.Context, bGetter blockservice.BlockGetter, root []byte, - namespace share.Namespace, + namespace gosquare.Namespace, maxShares int, -) ([]share.Share, *nmt.Proof, error) { +) ([]gosquare.Share, *nmt.Proof, error) { rootCid := MustCidFromNamespacedSha256(root) data := NewNamespaceData(maxShares, namespace, WithLeaves(), WithProofs()) err := data.CollectLeavesByNamespace(ctx, bGetter, rootCid) @@ -63,10 +63,10 @@ func GetSharesByNamespace( return nil, data.Proof(), nil } - shares := make([]share.Share, len(leaves)) + shares := make([]gosquare.Share, len(leaves)) for i, leaf := range leaves { if leaf != nil { - sh, err := share.NewShare(leaf.RawData()[share.NamespaceSize:]) + sh, err := gosquare.NewShare(leaf.RawData()[gosquare.NamespaceSize:]) if err != nil { return nil, nil, err } diff --git a/square/ipld/get_shares_test.go b/share/ipld/get_shares_test.go similarity index 87% rename from square/ipld/get_shares_test.go rename to share/ipld/get_shares_test.go index 75399d77bf..2c17790c36 100644 --- a/square/ipld/get_shares_test.go +++ b/share/ipld/get_shares_test.go @@ -15,12 +15,12 @@ import ( "github.com/stretchr/testify/require" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/libs/utils" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" ) func TestGetShare(t *testing.T) { @@ -31,7 +31,7 @@ func TestGetShare(t *testing.T) { bServ := NewMemBlockservice() // generate random shares for the nmt - shares := share.RandShares(size * size) + shares := gosquare.RandShares(size * size) eds, err := AddShares(ctx, shares, bServ) require.NoError(t, err) @@ -53,12 +53,12 @@ func TestBlockRecovery(t *testing.T) { extendedShareCount := extendedSquareWidth * extendedSquareWidth // generate test data - quarterShares := share.RandShares(shareCount) - allShares := share.RandShares(shareCount) + quarterShares := gosquare.RandShares(shareCount) + allShares := gosquare.RandShares(shareCount) testCases := []struct { name string - shares []share.Share + shares []gosquare.Share expectErr bool errString string d int // number of shares to delete @@ -73,8 +73,8 @@ func TestBlockRecovery(t *testing.T) { squareSize := utils.SquareSize(len(tc.shares)) testEds, err := rsmt2d.ComputeExtendedDataSquare( - share.ToBytes(tc.shares), - square.DefaultRSMT2DCodec(), + gosquare.ToBytes(tc.shares), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(squareSize), ) require.NoError(t, err) @@ -91,7 +91,7 @@ func TestBlockRecovery(t *testing.T) { rdata := removeRandShares(flat, tc.d) testEds, err = rsmt2d.ImportExtendedDataSquare( rdata, - square.DefaultRSMT2DCodec(), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(squareSize), ) require.NoError(t, err) @@ -104,7 +104,7 @@ func TestBlockRecovery(t *testing.T) { } assert.NoError(t, err) - reds, err := rsmt2d.ImportExtendedDataSquare(rdata, square.DefaultRSMT2DCodec(), wrapper.NewConstructor(squareSize)) + reds, err := rsmt2d.ImportExtendedDataSquare(rdata, share.DefaultRSMT2DCodec(), wrapper.NewConstructor(squareSize)) require.NoError(t, err) // check that the squares are equal assert.Equal(t, testEds.Flattened(), reds.Flattened()) @@ -114,18 +114,18 @@ func TestBlockRecovery(t *testing.T) { func Test_ConvertEDStoShares(t *testing.T) { squareWidth := 16 - shares := share.RandShares(squareWidth * squareWidth) + shares := gosquare.RandShares(squareWidth * squareWidth) // compute extended square testEds, err := rsmt2d.ComputeExtendedDataSquare( - share.ToBytes(shares), - square.DefaultRSMT2DCodec(), + gosquare.ToBytes(shares), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(squareWidth)), ) require.NoError(t, err) resshares := testEds.FlattenedODS() - require.Equal(t, share.ToBytes(shares), resshares) + require.Equal(t, gosquare.ToBytes(shares), resshares) } // removes d shares from data @@ -149,10 +149,10 @@ func TestGetSharesByNamespace(t *testing.T) { bServ := NewMemBlockservice() tests := []struct { - rawData []share.Share + rawData []gosquare.Share }{ - {rawData: share.RandShares(4)}, - {rawData: share.RandShares(16)}, + {rawData: gosquare.RandShares(4)}, + {rawData: gosquare.RandShares(16)}, } for i, tt := range tests { @@ -167,7 +167,7 @@ func TestGetSharesByNamespace(t *testing.T) { eds, err := AddShares(ctx, tt.rawData, bServ) require.NoError(t, err) - var shares []share.Share + var shares []gosquare.Share rowRoots, err := eds.RowRoots() require.NoError(t, err) for _, row := range rowRoots { @@ -193,7 +193,7 @@ func TestCollectLeavesByNamespace_IncompleteData(t *testing.T) { t.Cleanup(cancel) bServ := NewMemBlockservice() - shares := share.RandShares(16) + shares := gosquare.RandShares(16) // set all shares to the same namespace id namespace := shares[0].Namespace() @@ -237,7 +237,7 @@ func TestCollectLeavesByNamespace_AbsentNamespaceId(t *testing.T) { t.Cleanup(cancel) bServ := NewMemBlockservice() - shares := share.RandShares(1024) + shares := gosquare.RandShares(1024) // set all shares to the same namespace namespaces, err := randomNamespaces(5) @@ -259,8 +259,8 @@ func TestCollectLeavesByNamespace_AbsentNamespaceId(t *testing.T) { tests := []struct { name string - data []share.Share - missingNamespace share.Namespace + data []gosquare.Share + missingNamespace gosquare.Namespace isAbsence bool }{ {name: "Namespace less than the minimum namespace in data", data: shares, missingNamespace: minNamespace}, @@ -282,7 +282,7 @@ func TestCollectLeavesByNamespace_MultipleRowsContainingSameNamespaceId(t *testi t.Cleanup(cancel) bServ := NewMemBlockservice() - shares := share.RandShares(16) + shares := gosquare.RandShares(16) // set all shares to the same namespace and data but the last one namespace := shares[0].Namespace() @@ -314,7 +314,7 @@ func TestCollectLeavesByNamespace_MultipleRowsContainingSameNamespaceId(t *testi for _, node := range leaves { // test that the data returned by collectLeavesByNamespace for nid // matches the commonNamespaceData that was copied across almost all data - sh, err := share.NewShare(node.RawData()[share.NamespaceSize:]) + sh, err := gosquare.NewShare(node.RawData()[gosquare.NamespaceSize:]) require.NoError(t, err) assert.Equal(t, commonNamespaceData, *sh) } @@ -327,11 +327,11 @@ func TestGetSharesWithProofsByNamespace(t *testing.T) { bServ := NewMemBlockservice() tests := []struct { - rawData []share.Share + rawData []gosquare.Share }{ - {rawData: share.RandShares(4)}, - {rawData: share.RandShares(16)}, - {rawData: share.RandShares(64)}, + {rawData: gosquare.RandShares(4)}, + {rawData: gosquare.RandShares(16)}, + {rawData: gosquare.RandShares(64)}, } for i, tt := range tests { @@ -357,7 +357,7 @@ func TestGetSharesWithProofsByNamespace(t *testing.T) { eds, err := AddShares(ctx, tt.rawData, bServ) require.NoError(t, err) - var shares []share.Share + var shares []gosquare.Share rowRoots, err := eds.RowRoots() require.NoError(t, err) for _, row := range rowRoots { @@ -380,7 +380,7 @@ func TestGetSharesWithProofsByNamespace(t *testing.T) { // verify namespace verified := proof.VerifyNamespace( - square.NewSHA256Hasher(), + share.NewSHA256Hasher(), namespace.Bytes(), leaves, row) @@ -388,9 +388,9 @@ func TestGetSharesWithProofsByNamespace(t *testing.T) { // verify inclusion verified = proof.VerifyInclusion( - square.NewSHA256Hasher(), + share.NewSHA256Hasher(), namespace.Bytes(), - share.ToBytes(rowShares), + gosquare.ToBytes(rowShares), row) require.True(t, verified) } @@ -426,7 +426,7 @@ func TestBatchSize(t *testing.T) { randEds := edstest.RandEDS(t, tt.origWidth) - shrs, err := share.FromBytes(randEds.FlattenedODS()) + shrs, err := gosquare.FromBytes(randEds.FlattenedODS()) require.NoError(t, err) _, err = AddShares(ctx, shrs, bs) require.NoError(t, err) @@ -449,7 +449,7 @@ func assertNoRowContainsNID( t *testing.T, bServ blockservice.BlockService, eds *rsmt2d.ExtendedDataSquare, - namespace share.Namespace, + namespace gosquare.Namespace, isAbsent bool, ) { rowRoots, err := eds.RowRoots() @@ -482,7 +482,7 @@ func assertNoRowContainsNID( // if no error returned, check absence proof foundAbsenceRows++ - verified := data.Proof().VerifyNamespace(square.NewSHA256Hasher(), namespace.Bytes(), nil, rowRoot) + verified := data.Proof().VerifyNamespace(share.NewSHA256Hasher(), namespace.Bytes(), nil, rowRoot) require.True(t, verified) } @@ -493,10 +493,10 @@ func assertNoRowContainsNID( } } -func randomNamespaces(total int) ([]share.Namespace, error) { - namespaces := make([]share.Namespace, total) +func randomNamespaces(total int) ([]gosquare.Namespace, error) { + namespaces := make([]gosquare.Namespace, total) for i := range namespaces { - namespaces[i] = share.RandomNamespace() + namespaces[i] = gosquare.RandomNamespace() } sort.Slice(namespaces, func(i, j int) bool { return namespaces[i].IsLessThan(namespaces[j]) }) return namespaces, nil diff --git a/square/ipld/namespace_data.go b/share/ipld/namespace_data.go similarity index 96% rename from square/ipld/namespace_data.go rename to share/ipld/namespace_data.go index 2c2ddaf3df..194b14dddd 100644 --- a/square/ipld/namespace_data.go +++ b/share/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" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share/shwap" ) var ErrNamespaceOutsideRange = shwap.ErrNamespaceOutsideRange @@ -46,13 +46,13 @@ type NamespaceData struct { bounds fetchedBounds maxShares int - namespace share.Namespace + namespace gosquare.Namespace isAbsentNamespace atomic.Bool absenceProofLeaf ipld.Node } -func NewNamespaceData(maxShares int, namespace share.Namespace, options ...Option) *NamespaceData { +func NewNamespaceData(maxShares int, namespace gosquare.Namespace, options ...Option) *NamespaceData { data := &NamespaceData{ maxShares: maxShares, namespace: namespace, @@ -71,7 +71,7 @@ func NewNamespaceData(maxShares int, namespace share.Namespace, options ...Optio } func (n *NamespaceData) validate(rootCid cid.Cid) error { - if err := share.ValidateUserNamespace(n.namespace.Version(), n.namespace.ID()); err != nil { + if err := gosquare.ValidateUserNamespace(n.namespace.Version(), n.namespace.ID()); err != nil { return err } diff --git a/square/ipld/nmt.go b/share/ipld/nmt.go similarity index 92% rename from square/ipld/nmt.go rename to share/ipld/nmt.go index c96c081168..4dad93df36 100644 --- a/square/ipld/nmt.go +++ b/share/ipld/nmt.go @@ -16,10 +16,10 @@ import ( mh "github.com/multiformats/go-multihash" mhcore "github.com/multiformats/go-multihash/core" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) var log = logging.Logger("ipld") @@ -36,13 +36,13 @@ const ( sha256NamespaceFlagged = 0x7701 // NmtHashSize is the size of a digest created by an NMT in bytes. - NmtHashSize = 2*share.NamespaceSize + sha256.Size + NmtHashSize = 2*gosquare.NamespaceSize + sha256.Size // InnerNodeSize is the size of data in inner nodes. InnerNodeSize = NmtHashSize * 2 // LeafNodeSize is the size of data in leaf nodes. - LeafNodeSize = share.NamespaceSize + share.ShareSize + LeafNodeSize = gosquare.NamespaceSize + gosquare.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(square.NewSHA256Hasher(), share.NamespaceSize, true) + nh := nmt.NewNmtHasher(share.NewSHA256Hasher(), gosquare.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 *square.AxisRoots, row, col int) (cid.Cid, int) { +func Translate(roots *share.AxisRoots, row, col int) (cid.Cid, int) { if rand.Intn(2) == 0 { //nolint:gosec return MustCidFromNamespacedSha256(roots.ColumnRoots[col]), row } diff --git a/square/ipld/nmt_adder.go b/share/ipld/nmt_adder.go similarity index 100% rename from square/ipld/nmt_adder.go rename to share/ipld/nmt_adder.go diff --git a/square/ipld/nmt_test.go b/share/ipld/nmt_test.go similarity index 85% rename from square/ipld/nmt_test.go rename to share/ipld/nmt_test.go index a2133492c8..040c68ec1d 100644 --- a/square/ipld/nmt_test.go +++ b/share/ipld/nmt_test.go @@ -9,8 +9,8 @@ import ( "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/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 := square.NewAxisRoots(tt.eds) + roots, err := share.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/square/ipld/proof_collector.go b/share/ipld/proof_collector.go similarity index 100% rename from square/ipld/proof_collector.go rename to share/ipld/proof_collector.go diff --git a/square/ipld/proofs.go b/share/ipld/proofs.go similarity index 100% rename from square/ipld/proofs.go rename to share/ipld/proofs.go diff --git a/square/ipld/proofs_test.go b/share/ipld/proofs_test.go similarity index 81% rename from square/ipld/proofs_test.go rename to share/ipld/proofs_test.go index ca28499b82..d7185d886e 100644 --- a/square/ipld/proofs_test.go +++ b/share/ipld/proofs_test.go @@ -7,11 +7,11 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap" ) func TestGetProof(t *testing.T) { @@ -21,11 +21,11 @@ func TestGetProof(t *testing.T) { defer cancel() bServ := NewMemBlockservice() - shares := share.RandShares(width * width) + shares := gosquare.RandShares(width * width) in, err := AddShares(ctx, shares, bServ) require.NoError(t, err) - axisRoots, err := square.NewAxisRoots(in) + axisRoots, err := share.NewAxisRoots(in) require.NoError(t, err) for _, proofType := range []rsmt2d.Axis{rsmt2d.Row, rsmt2d.Col} { @@ -45,7 +45,7 @@ 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:]) + sh, err := gosquare.NewShare(node.RawData()[gosquare.NamespaceSize:]) require.NoError(t, err) sample := shwap.Sample{ Share: *sh, diff --git a/square/ipld/test_helpers.go b/share/ipld/test_helpers.go similarity index 100% rename from square/ipld/test_helpers.go rename to share/ipld/test_helpers.go diff --git a/square/ipld/utils.go b/share/ipld/utils.go similarity index 51% rename from square/ipld/utils.go rename to share/ipld/utils.go index 1333dddd78..62acc24961 100644 --- a/square/ipld/utils.go +++ b/share/ipld/utils.go @@ -3,14 +3,14 @@ package ipld import ( "github.com/ipfs/go-cid" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) -// FilterRootByNamespace returns the row roots from the given square.AxisRoots that contain the +// FilterRootByNamespace returns the row roots from the given share.AxisRoots that contain the // namespace. -func FilterRootByNamespace(root *square.AxisRoots, namespace share.Namespace) []cid.Cid { +func FilterRootByNamespace(root *share.AxisRoots, namespace gosquare.Namespace) []cid.Cid { rowRootCIDs := make([]cid.Cid, 0, len(root.RowRoots)) for _, row := range root.RowRoots { if !namespace.IsOutsideRange(row, row) { diff --git a/square/root.go b/share/root.go similarity index 89% rename from square/root.go rename to share/root.go index f4c1045662..b0c2357a52 100644 --- a/square/root.go +++ b/share/root.go @@ -1,4 +1,4 @@ -package square +package share import ( "bytes" @@ -8,7 +8,7 @@ import ( "hash" "github.com/celestiaorg/celestia-app/v3/pkg/da" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" ) @@ -20,7 +20,7 @@ const ( ) // AxisRoots represents root commitment to multiple Shares. -// In practice, it is a commitment to all the Data in a square. +// In practice, it is a commitment to all the Data in a share. type AxisRoots = da.DataAvailabilityHeader // DataHash is a representation of the AxisRoots hash. @@ -48,7 +48,7 @@ func NewSHA256Hasher() hash.Hash { } // NewAxisRoots generates AxisRoots(DataAvailabilityHeader) using the -// provided extended data square. +// provided extended data share. func NewAxisRoots(eds *rsmt2d.ExtendedDataSquare) (*AxisRoots, error) { dah, err := da.NewDataAvailabilityHeader(eds) if err != nil { @@ -59,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 share.Namespace) (idxs []int) { +func RowsWithNamespace(root *AxisRoots, namespace gosquare.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/share/share.go similarity index 89% rename from square/share.go rename to share/share.go index 696a6bc948..3fb654a1a0 100644 --- a/square/share.go +++ b/share/share.go @@ -1,8 +1,8 @@ -package square +package share import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" ) @@ -17,7 +17,7 @@ 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 + gosquare.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 @@ -27,7 +27,7 @@ type ShareWithProof struct { //nolint: revive // 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 + namespace := gosquare.ParitySharesNamespace if !isParity { namespace = s.Share.Namespace() } diff --git a/square/shwap/eds.go b/share/shwap/eds.go similarity index 68% rename from square/shwap/eds.go rename to share/shwap/eds.go index 2d856c5317..8ea8665507 100644 --- a/square/shwap/eds.go +++ b/share/shwap/eds.go @@ -1,6 +1,6 @@ package shwap -// EDSName is the name identifier for the Extended Data Square. +// EDSName is the name identifier for the Extended Data share. const EDSName = "eds_v0" // NOTE: There is no EDS container as it's already defined by rsmt2d and eds.Accessor interface. diff --git a/square/shwap/eds_id.go b/share/shwap/eds_id.go similarity index 100% rename from square/shwap/eds_id.go rename to share/shwap/eds_id.go diff --git a/square/shwap/eds_id_test.go b/share/shwap/eds_id_test.go similarity index 100% rename from square/shwap/eds_id_test.go rename to share/shwap/eds_id_test.go diff --git a/square/shwap/getter.go b/share/shwap/getter.go similarity index 89% rename from square/shwap/getter.go rename to share/shwap/getter.go index dfbe36432e..fbb1050e63 100644 --- a/square/shwap/getter.go +++ b/share/shwap/getter.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/header" @@ -30,7 +30,7 @@ var ( //go:generate mockgen -destination=getters/mock/getter.go -package=mock . Getter type Getter interface { // GetShare gets a Share by coordinates in EDS. - GetShare(ctx context.Context, header *header.ExtendedHeader, row, col int) (share.Share, error) + GetShare(ctx context.Context, header *header.ExtendedHeader, row, col int) (gosquare.Share, error) // GetEDS gets the full EDS identified by the given extended header. GetEDS(context.Context, *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) @@ -40,5 +40,5 @@ type Getter interface { // Inclusion of returned data could be verified using Verify method on NamespacedShares. // If no shares are found for target namespace non-inclusion could be also verified by calling // Verify method. - GetSharesByNamespace(context.Context, *header.ExtendedHeader, share.Namespace) (NamespaceData, error) + GetSharesByNamespace(context.Context, *header.ExtendedHeader, gosquare.Namespace) (NamespaceData, error) } diff --git a/square/shwap/getters/cascade.go b/share/shwap/getters/cascade.go similarity index 93% rename from square/shwap/getters/cascade.go rename to share/shwap/getters/cascade.go index 5aeddafd30..80736198e6 100644 --- a/square/shwap/getters/cascade.go +++ b/share/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" + gosquare "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/square/eds/byzantine" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share/eds/byzantine" + "github.com/celestiaorg/celestia-node/share/shwap" ) var ( @@ -44,7 +44,7 @@ func NewCascadeGetter(getters []shwap.Getter) *CascadeGetter { // GetShare gets a share from any of registered shwap.Getters in cascading order. func (cg *CascadeGetter) GetShare( ctx context.Context, header *header.ExtendedHeader, row, col int, -) (share.Share, error) { +) (gosquare.Share, error) { ctx, span := tracer.Start(ctx, "cascade/get-share", trace.WithAttributes( attribute.Int("row", row), attribute.Int("col", col), @@ -55,9 +55,9 @@ func (cg *CascadeGetter) GetShare( if row >= upperBound || col >= upperBound { err := shwap.ErrOutOfBounds span.RecordError(err) - return share.Share{}, err + return gosquare.Share{}, err } - get := func(ctx context.Context, get shwap.Getter) (share.Share, error) { + get := func(ctx context.Context, get shwap.Getter) (gosquare.Share, error) { return get.GetShare(ctx, header, row, col) } @@ -83,7 +83,7 @@ func (cg *CascadeGetter) GetEDS( func (cg *CascadeGetter) GetSharesByNamespace( ctx context.Context, header *header.ExtendedHeader, - namespace share.Namespace, + namespace gosquare.Namespace, ) (shwap.NamespaceData, error) { ctx, span := tracer.Start(ctx, "cascade/get-shares-by-namespace", trace.WithAttributes( attribute.String("namespace", namespace.String()), diff --git a/square/shwap/getters/cascade_test.go b/share/shwap/getters/cascade_test.go similarity index 97% rename from square/shwap/getters/cascade_test.go rename to share/shwap/getters/cascade_test.go index 0012780fbf..a23568006f 100644 --- a/square/shwap/getters/cascade_test.go +++ b/share/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/square/shwap" - "github.com/celestiaorg/celestia-node/square/shwap/getters/mock" + "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/share/shwap/getters/mock" ) func TestCascadeGetter(t *testing.T) { diff --git a/square/shwap/getters/mock/getter.go b/share/shwap/getters/mock/getter.go similarity index 98% rename from square/shwap/getters/mock/getter.go rename to share/shwap/getters/mock/getter.go index 5eb7be8ef6..41146b3a73 100644 --- a/square/shwap/getters/mock/getter.go +++ b/share/shwap/getters/mock/getter.go @@ -9,7 +9,7 @@ import ( reflect "reflect" header "github.com/celestiaorg/celestia-node/header" - shwap "github.com/celestiaorg/celestia-node/square/shwap" + shwap "github.com/celestiaorg/celestia-node/share/shwap" share "github.com/celestiaorg/go-square/v2/share" rsmt2d "github.com/celestiaorg/rsmt2d" gomock "github.com/golang/mock/gomock" diff --git a/square/shwap/getters/testing.go b/share/shwap/getters/testing.go similarity index 79% rename from square/shwap/getters/testing.go rename to share/shwap/getters/testing.go index a9eb55d034..55a5580a90 100644 --- a/square/shwap/getters/testing.go +++ b/share/shwap/getters/testing.go @@ -8,20 +8,20 @@ import ( "github.com/stretchr/testify/require" "github.com/celestiaorg/celestia-app/v3/pkg/da" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/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 := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) eh := headertest.RandExtendedHeaderWithRoot(t, roots) require.NoError(t, err) return &SingleEDSGetter{ @@ -40,15 +40,15 @@ func (seg *SingleEDSGetter) GetShare( _ context.Context, header *header.ExtendedHeader, row, col int, -) (share.Share, error) { +) (gosquare.Share, error) { err := seg.checkRoots(header.DAH) if err != nil { - return share.Share{}, err + return gosquare.Share{}, err } rawSh := seg.EDS.GetCell(uint(row), uint(col)) - sh, err := share.NewShare(rawSh) + sh, err := gosquare.NewShare(rawSh) if err != nil { - return share.Share{}, err + return gosquare.Share{}, err } return *sh, nil } @@ -66,12 +66,12 @@ func (seg *SingleEDSGetter) GetEDS( } // GetSharesByNamespace returns NamespacedShares from a kept EDS if the correct root is given. -func (seg *SingleEDSGetter) GetSharesByNamespace(context.Context, *header.ExtendedHeader, share.Namespace, +func (seg *SingleEDSGetter) GetSharesByNamespace(context.Context, *header.ExtendedHeader, gosquare.Namespace, ) (shwap.NamespaceData, error) { panic("SingleEDSGetter: GetSharesByNamespace is not implemented") } -func (seg *SingleEDSGetter) checkRoots(roots *square.AxisRoots) error { +func (seg *SingleEDSGetter) checkRoots(roots *share.AxisRoots) error { dah, err := da.NewDataAvailabilityHeader(seg.EDS) if err != nil { return err diff --git a/square/shwap/namespace_data.go b/share/shwap/namespace_data.go similarity index 85% rename from square/shwap/namespace_data.go rename to share/shwap/namespace_data.go index 730d4e1c41..b98c210656 100644 --- a/square/shwap/namespace_data.go +++ b/share/shwap/namespace_data.go @@ -5,9 +5,9 @@ import ( "fmt" "io" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) // NamespaceDataName is the name identifier for the namespace data container. @@ -20,8 +20,8 @@ const NamespaceDataName = "nd_v0" type NamespaceData []RowNamespaceData // Flatten combines all shares from all rows within the namespace into a single slice. -func (nd NamespaceData) Flatten() []share.Share { - var shares []share.Share +func (nd NamespaceData) Flatten() []gosquare.Share { + var shares []gosquare.Share for _, row := range nd { shares = append(shares, row.Shares...) } @@ -29,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 *square.AxisRoots, namespace share.Namespace) error { - rowIdxs := square.RowsWithNamespace(root, namespace) +func (nd NamespaceData) Verify(root *share.AxisRoots, namespace gosquare.Namespace) error { + rowIdxs := share.RowsWithNamespace(root, namespace) if len(rowIdxs) != len(nd) { return fmt.Errorf("expected %d rows, found %d rows", len(rowIdxs), len(nd)) } diff --git a/square/shwap/namespace_data_id.go b/share/shwap/namespace_data_id.go similarity index 90% rename from square/shwap/namespace_data_id.go rename to share/shwap/namespace_data_id.go index 1488e41ba3..3e4b288c3f 100644 --- a/square/shwap/namespace_data_id.go +++ b/share/shwap/namespace_data_id.go @@ -4,24 +4,24 @@ import ( "fmt" "io" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) // NamespaceDataIDSize defines the total size of a NamespaceDataID in bytes, combining the // size of a EdsID and the size of a Namespace. -const NamespaceDataIDSize = EdsIDSize + share.NamespaceSize +const NamespaceDataIDSize = EdsIDSize + gosquare.NamespaceSize // NamespaceDataID filters the data in the EDS by a specific namespace. type NamespaceDataID struct { // Embedding EdsID to include the block height. EdsID // DataNamespace will be used to identify the data within the EDS. - DataNamespace share.Namespace + DataNamespace gosquare.Namespace } // NewNamespaceDataID creates a new NamespaceDataID with the specified parameters. It // validates the namespace and returns an error if it is invalid. -func NewNamespaceDataID(height uint64, namespace share.Namespace) (NamespaceDataID, error) { +func NewNamespaceDataID(height uint64, namespace gosquare.Namespace) (NamespaceDataID, error) { ndid := NamespaceDataID{ EdsID: EdsID{ Height: height, @@ -48,7 +48,7 @@ func NamespaceDataIDFromBinary(data []byte) (NamespaceDataID, error) { return NamespaceDataID{}, fmt.Errorf("error unmarshaling EDSID: %w", err) } - ns, err := share.NewNamespaceFromBytes(data[EdsIDSize:]) + ns, err := gosquare.NewNamespaceFromBytes(data[EdsIDSize:]) if err != nil { return NamespaceDataID{}, fmt.Errorf("error unmarshaling namespace: %w", err) } @@ -112,7 +112,7 @@ func (ndid NamespaceDataID) Validate() error { return fmt.Errorf("validating RowID: %w", err) } - if err := share.ValidateForData(ndid.DataNamespace); err != nil { + if err := gosquare.ValidateForData(ndid.DataNamespace); err != nil { return fmt.Errorf("%w: validating DataNamespace: %w", ErrInvalidID, err) } return nil diff --git a/square/shwap/namespace_data_id_test.go b/share/shwap/namespace_data_id_test.go similarity index 88% rename from square/shwap/namespace_data_id_test.go rename to share/shwap/namespace_data_id_test.go index daab44cdcf..c978db85a4 100644 --- a/square/shwap/namespace_data_id_test.go +++ b/share/shwap/namespace_data_id_test.go @@ -7,11 +7,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) func TestNamespaceDataID(t *testing.T) { - ns := share.RandomNamespace() + ns := gosquare.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 := share.RandomNamespace() + ns := gosquare.RandomNamespace() id, err := NewNamespaceDataID(1, ns) require.NoError(t, err) diff --git a/square/shwap/p2p/bitswap/bitswap.go b/share/shwap/p2p/bitswap/bitswap.go similarity index 100% rename from square/shwap/p2p/bitswap/bitswap.go rename to share/shwap/p2p/bitswap/bitswap.go diff --git a/square/shwap/p2p/bitswap/block.go b/share/shwap/p2p/bitswap/block.go similarity index 89% rename from square/shwap/p2p/bitswap/block.go rename to share/shwap/p2p/bitswap/block.go index d42697722c..940afb5bc2 100644 --- a/square/shwap/p2p/bitswap/block.go +++ b/share/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/square" - "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/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(*square.AxisRoots) UnmarshalFn + UnmarshalFn(*share.AxisRoots) UnmarshalFn } // UnmarshalFn is a closure produced by a Block that unmarshalls and validates diff --git a/square/shwap/p2p/bitswap/block_fetch.go b/share/shwap/p2p/bitswap/block_fetch.go similarity index 98% rename from square/shwap/p2p/bitswap/block_fetch.go rename to share/shwap/p2p/bitswap/block_fetch.go index 55011cbc82..7d7dcd1c90 100644 --- a/square/shwap/p2p/bitswap/block_fetch.go +++ b/share/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/square" + "github.com/celestiaorg/celestia-node/share" ) // 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 *square.AxisRoots, + root *share.AxisRoots, blks []Block, opts ...FetchOption, ) error { @@ -62,7 +62,7 @@ func Fetch( func fetch( ctx context.Context, exchg exchange.Interface, - root *square.AxisRoots, + root *share.AxisRoots, blks []Block, opts ...FetchOption, ) error { diff --git a/square/shwap/p2p/bitswap/block_fetch_test.go b/share/shwap/p2p/bitswap/block_fetch_test.go similarity index 98% rename from square/shwap/p2p/bitswap/block_fetch_test.go rename to share/shwap/p2p/bitswap/block_fetch_test.go index 872a8f8a66..6642801efe 100644 --- a/square/shwap/p2p/bitswap/block_fetch_test.go +++ b/share/shwap/p2p/bitswap/block_fetch_test.go @@ -20,7 +20,7 @@ import ( "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/share/eds" ) func TestFetch_Options(t *testing.T) { diff --git a/square/shwap/p2p/bitswap/block_proto.go b/share/shwap/p2p/bitswap/block_proto.go similarity index 92% rename from square/shwap/p2p/bitswap/block_proto.go rename to share/shwap/p2p/bitswap/block_proto.go index 6ab0243abf..8cab645705 100644 --- a/square/shwap/p2p/bitswap/block_proto.go +++ b/share/shwap/p2p/bitswap/block_proto.go @@ -5,7 +5,7 @@ import ( "github.com/ipfs/go-cid" - bitswappb "github.com/celestiaorg/celestia-node/square/shwap/p2p/bitswap/pb" + bitswappb "github.com/celestiaorg/celestia-node/share/shwap/p2p/bitswap/pb" ) // marshalProto wraps the given Block in composition protobuf and marshals it. diff --git a/square/shwap/p2p/bitswap/block_registry.go b/share/shwap/p2p/bitswap/block_registry.go similarity index 100% rename from square/shwap/p2p/bitswap/block_registry.go rename to share/shwap/p2p/bitswap/block_registry.go diff --git a/square/shwap/p2p/bitswap/block_store.go b/share/shwap/p2p/bitswap/block_store.go similarity index 98% rename from square/shwap/p2p/bitswap/block_store.go rename to share/shwap/p2p/bitswap/block_store.go index 69fa072d61..b1a5f1554e 100644 --- a/square/shwap/p2p/bitswap/block_store.go +++ b/share/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/square/eds" + "github.com/celestiaorg/celestia-node/share/eds" "github.com/celestiaorg/celestia-node/store" ) diff --git a/square/shwap/p2p/bitswap/block_test.go b/share/shwap/p2p/bitswap/block_test.go similarity index 92% rename from square/shwap/p2p/bitswap/block_test.go rename to share/shwap/p2p/bitswap/block_test.go index e953eb0546..39bb55bc14 100644 --- a/square/shwap/p2p/bitswap/block_test.go +++ b/share/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/square" - "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds" ) const ( @@ -103,7 +103,7 @@ func (t *testBlock) Marshal() ([]byte, error) { return t.data, nil } -func (t *testBlock) UnmarshalFn(*square.AxisRoots) UnmarshalFn { +func (t *testBlock) UnmarshalFn(*share.AxisRoots) UnmarshalFn { return func(bytes, _ []byte) error { t.data = bytes time.Sleep(time.Millisecond * 1) diff --git a/square/shwap/p2p/bitswap/cid.go b/share/shwap/p2p/bitswap/cid.go similarity index 100% rename from square/shwap/p2p/bitswap/cid.go rename to share/shwap/p2p/bitswap/cid.go diff --git a/square/shwap/p2p/bitswap/getter.go b/share/shwap/p2p/bitswap/getter.go similarity index 90% rename from square/shwap/p2p/bitswap/getter.go rename to share/shwap/p2p/bitswap/getter.go index a346032b3e..86ce510cb6 100644 --- a/square/shwap/p2p/bitswap/getter.go +++ b/share/shwap/p2p/bitswap/getter.go @@ -12,18 +12,18 @@ import ( "go.opentelemetry.io/otel/trace" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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/square" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap" ) var tracer = otel.Tracer("shwap/bitswap") -// Getter implements share.Getter. +// Getter implements gosquare.Getter. type Getter struct { exchange exchange.SessionExchange bstore blockstore.Blockstore @@ -72,7 +72,7 @@ func (g *Getter) GetShares( ctx context.Context, hdr *header.ExtendedHeader, rowIdxs, colIdxs []int, -) ([]share.Share, error) { +) ([]gosquare.Share, error) { if len(rowIdxs) != len(colIdxs) { return nil, fmt.Errorf("row indecies and col indices must be same length") } @@ -104,7 +104,7 @@ func (g *Getter) GetShares( return nil, err } - shares := make([]share.Share, len(blks)) + shares := make([]gosquare.Share, len(blks)) for i, blk := range blks { shares[i] = blk.(*SampleBlock).Container.Share } @@ -118,14 +118,14 @@ func (g *Getter) GetShare( ctx context.Context, hdr *header.ExtendedHeader, row, col int, -) (share.Share, error) { +) (gosquare.Share, error) { shrs, err := g.GetShares(ctx, hdr, []int{row}, []int{col}) if err != nil { - return share.Share{}, err + return gosquare.Share{}, err } if len(shrs) != 1 { - return share.Share{}, fmt.Errorf("expected 1 share row, got %d", len(shrs)) + return gosquare.Share{}, fmt.Errorf("expected 1 share row, got %d", len(shrs)) } return shrs[0], nil @@ -185,16 +185,16 @@ func (g *Getter) GetEDS( func (g *Getter) GetSharesByNamespace( ctx context.Context, hdr *header.ExtendedHeader, - ns share.Namespace, + ns gosquare.Namespace, ) (shwap.NamespaceData, error) { - if err := share.ValidateForData(ns); err != nil { + if err := gosquare.ValidateForData(ns); err != nil { return nil, err } ctx, span := tracer.Start(ctx, "get-shares-by-namespace") defer span.End() - rowIdxs := square.RowsWithNamespace(hdr.DAH, ns) + rowIdxs := share.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)) @@ -242,8 +242,8 @@ 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 *square.AxisRoots, rows []shwap.Row) (*rsmt2d.ExtendedDataSquare, error) { - shrs := make([]share.Share, len(roots.RowRoots)*len(roots.RowRoots)) +func edsFromRows(roots *share.AxisRoots, rows []shwap.Row) (*rsmt2d.ExtendedDataSquare, error) { + shrs := make([]gosquare.Share, len(roots.RowRoots)*len(roots.RowRoots)) for i, row := range rows { rowShrs, err := row.Shares() if err != nil { @@ -256,8 +256,8 @@ func edsFromRows(roots *square.AxisRoots, rows []shwap.Row) (*rsmt2d.ExtendedDat } square, err := rsmt2d.ImportExtendedDataSquare( - share.ToBytes(shrs), - square.DefaultRSMT2DCodec(), + gosquare.ToBytes(shrs), + share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(len(roots.RowRoots)/2)), ) if err != nil { diff --git a/square/shwap/p2p/bitswap/getter_test.go b/share/shwap/p2p/bitswap/getter_test.go similarity index 57% rename from square/shwap/p2p/bitswap/getter_test.go rename to share/shwap/p2p/bitswap/getter_test.go index 64365ed7f2..e543e0f76f 100644 --- a/square/shwap/p2p/bitswap/getter_test.go +++ b/share/shwap/p2p/bitswap/getter_test.go @@ -5,21 +5,21 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/shwap" ) func TestEDSFromRows(t *testing.T) { edsIn := edstest.RandEDS(t, 8) - roots, err := square.NewAxisRoots(edsIn) + roots, err := share.NewAxisRoots(edsIn) require.NoError(t, err) rows := make([]shwap.Row, edsIn.Width()/2) for i := range edsIn.Width() / 2 { - rowShrs, err := share.FromBytes(edsIn.Row(i)[:edsIn.Width()/2]) + rowShrs, err := gosquare.FromBytes(edsIn.Row(i)[:edsIn.Width()/2]) require.NoError(t, err) rows[i] = shwap.NewRow(rowShrs, shwap.Left) } diff --git a/square/shwap/p2p/bitswap/pb/bitswap.pb.go b/share/shwap/p2p/bitswap/pb/bitswap.pb.go similarity index 85% rename from square/shwap/p2p/bitswap/pb/bitswap.pb.go rename to share/shwap/p2p/bitswap/pb/bitswap.pb.go index e1f425c41b..a84077e9ef 100644 --- a/square/shwap/p2p/bitswap/pb/bitswap.pb.go +++ b/share/shwap/p2p/bitswap/pb/bitswap.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: square/shwap/p2p/bitswap/pb/bitswap.proto +// source: share/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_98329a1d35a94c34, []int{0} + return fileDescriptor_09fd4e2ff1d5ce94, []int{0} } func (m *Block) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -79,22 +79,22 @@ func init() { } func init() { - proto.RegisterFile("square/shwap/p2p/bitswap/pb/bitswap.proto", fileDescriptor_98329a1d35a94c34) + proto.RegisterFile("share/shwap/p2p/bitswap/pb/bitswap.proto", fileDescriptor_09fd4e2ff1d5ce94) } -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, +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, } func (m *Block) Marshal() (dAtA []byte, err error) { diff --git a/square/shwap/p2p/bitswap/pb/bitswap.proto b/share/shwap/p2p/bitswap/pb/bitswap.proto similarity index 70% rename from square/shwap/p2p/bitswap/pb/bitswap.proto rename to share/shwap/p2p/bitswap/pb/bitswap.proto index b620e98b60..3ba19aa49c 100644 --- a/square/shwap/p2p/bitswap/pb/bitswap.proto +++ b/share/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/square/shwap/p2p/bitswap/pb"; +option go_package = "github.com/celestiaorg/celestia-node/share/shwap/p2p/bitswap/pb"; message Block { bytes cid = 1; diff --git a/square/shwap/p2p/bitswap/row_block.go b/share/shwap/p2p/bitswap/row_block.go similarity index 90% rename from square/shwap/p2p/bitswap/row_block.go rename to share/shwap/p2p/bitswap/row_block.go index cfc57dc765..4763f63954 100644 --- a/square/shwap/p2p/bitswap/row_block.go +++ b/share/shwap/p2p/bitswap/row_block.go @@ -8,10 +8,10 @@ import ( "github.com/celestiaorg/rsmt2d" - "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" + "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" ) const ( @@ -96,7 +96,7 @@ func (rb *RowBlock) Populate(ctx context.Context, eds eds.Accessor) error { return nil } -func (rb *RowBlock) UnmarshalFn(root *square.AxisRoots) UnmarshalFn { +func (rb *RowBlock) UnmarshalFn(root *share.AxisRoots) UnmarshalFn { return func(cntrData, idData []byte) error { if !rb.Container.IsEmpty() { return nil diff --git a/square/shwap/p2p/bitswap/row_block_test.go b/share/shwap/p2p/bitswap/row_block_test.go similarity index 82% rename from square/shwap/p2p/bitswap/row_block_test.go rename to share/shwap/p2p/bitswap/row_block_test.go index 9b48338957..f609683da5 100644 --- a/square/shwap/p2p/bitswap/row_block_test.go +++ b/share/shwap/p2p/bitswap/row_block_test.go @@ -7,8 +7,8 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/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 := square.NewAxisRoots(eds) + root, err := share.NewAxisRoots(eds) require.NoError(t, err) exchange := newExchangeOverEDS(ctx, t, eds) diff --git a/square/shwap/p2p/bitswap/row_namespace_data_block.go b/share/shwap/p2p/bitswap/row_namespace_data_block.go similarity index 89% rename from square/shwap/p2p/bitswap/row_namespace_data_block.go rename to share/shwap/p2p/bitswap/row_namespace_data_block.go index 76778b0f53..704ad3f616 100644 --- a/square/shwap/p2p/bitswap/row_namespace_data_block.go +++ b/share/shwap/p2p/bitswap/row_namespace_data_block.go @@ -6,12 +6,12 @@ import ( "github.com/ipfs/go-cid" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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" + "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" ) const ( @@ -44,7 +44,7 @@ type RowNamespaceDataBlock struct { func NewEmptyRowNamespaceDataBlock( height uint64, rowIdx int, - namespace share.Namespace, + namespace gosquare.Namespace, edsSize int, ) (*RowNamespaceDataBlock, error) { id, err := shwap.NewRowNamespaceDataID(height, rowIdx, namespace, edsSize) @@ -102,7 +102,7 @@ func (rndb *RowNamespaceDataBlock) Populate(ctx context.Context, eds eds.Accesso return nil } -func (rndb *RowNamespaceDataBlock) UnmarshalFn(root *square.AxisRoots) UnmarshalFn { +func (rndb *RowNamespaceDataBlock) UnmarshalFn(root *share.AxisRoots) UnmarshalFn { return func(cntrData, idData []byte) error { if !rndb.Container.IsEmpty() { return nil diff --git a/square/shwap/p2p/bitswap/row_namespace_data_block_test.go b/share/shwap/p2p/bitswap/row_namespace_data_block_test.go similarity index 76% rename from square/shwap/p2p/bitswap/row_namespace_data_block_test.go rename to share/shwap/p2p/bitswap/row_namespace_data_block_test.go index fecf5494ca..552c0d31fe 100644 --- a/square/shwap/p2p/bitswap/row_namespace_data_block_test.go +++ b/share/shwap/p2p/bitswap/row_namespace_data_block_test.go @@ -7,21 +7,21 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" ) func TestRowNamespaceData_FetchRoundtrip(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() - namespace := share.RandomNamespace() + namespace := gosquare.RandomNamespace() eds, root := edstest.RandEDSWithNamespace(t, namespace, 64, 16) exchange := newExchangeOverEDS(ctx, t, eds) - rowIdxs := square.RowsWithNamespace(root, namespace) + rowIdxs := share.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/square/shwap/p2p/bitswap/sample_block.go b/share/shwap/p2p/bitswap/sample_block.go similarity index 90% rename from square/shwap/p2p/bitswap/sample_block.go rename to share/shwap/p2p/bitswap/sample_block.go index d7e7fdd884..062369c0be 100644 --- a/square/shwap/p2p/bitswap/sample_block.go +++ b/share/shwap/p2p/bitswap/sample_block.go @@ -6,10 +6,10 @@ import ( "github.com/ipfs/go-cid" - "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" + "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" ) const ( @@ -95,7 +95,7 @@ func (sb *SampleBlock) Populate(ctx context.Context, eds eds.Accessor) error { return nil } -func (sb *SampleBlock) UnmarshalFn(root *square.AxisRoots) UnmarshalFn { +func (sb *SampleBlock) UnmarshalFn(root *share.AxisRoots) UnmarshalFn { return func(cntrData, idData []byte) error { if !sb.Container.IsEmpty() { return nil diff --git a/square/shwap/p2p/bitswap/sample_block_test.go b/share/shwap/p2p/bitswap/sample_block_test.go similarity index 85% rename from square/shwap/p2p/bitswap/sample_block_test.go rename to share/shwap/p2p/bitswap/sample_block_test.go index ec7364e71f..2a28e7e4c9 100644 --- a/square/shwap/p2p/bitswap/sample_block_test.go +++ b/share/shwap/p2p/bitswap/sample_block_test.go @@ -7,8 +7,8 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/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 := square.NewAxisRoots(eds) + root, err := share.NewAxisRoots(eds) require.NoError(t, err) exchange := newExchangeOverEDS(ctx, t, eds) diff --git a/square/shwap/p2p/discovery/backoff.go b/share/shwap/p2p/discovery/backoff.go similarity index 100% rename from square/shwap/p2p/discovery/backoff.go rename to share/shwap/p2p/discovery/backoff.go diff --git a/square/shwap/p2p/discovery/backoff_test.go b/share/shwap/p2p/discovery/backoff_test.go similarity index 100% rename from square/shwap/p2p/discovery/backoff_test.go rename to share/shwap/p2p/discovery/backoff_test.go diff --git a/square/shwap/p2p/discovery/dht.go b/share/shwap/p2p/discovery/dht.go similarity index 100% rename from square/shwap/p2p/discovery/dht.go rename to share/shwap/p2p/discovery/dht.go diff --git a/square/shwap/p2p/discovery/discovery.go b/share/shwap/p2p/discovery/discovery.go similarity index 100% rename from square/shwap/p2p/discovery/discovery.go rename to share/shwap/p2p/discovery/discovery.go diff --git a/square/shwap/p2p/discovery/discovery_test.go b/share/shwap/p2p/discovery/discovery_test.go similarity index 100% rename from square/shwap/p2p/discovery/discovery_test.go rename to share/shwap/p2p/discovery/discovery_test.go diff --git a/square/shwap/p2p/discovery/metrics.go b/share/shwap/p2p/discovery/metrics.go similarity index 100% rename from square/shwap/p2p/discovery/metrics.go rename to share/shwap/p2p/discovery/metrics.go diff --git a/square/shwap/p2p/discovery/options.go b/share/shwap/p2p/discovery/options.go similarity index 100% rename from square/shwap/p2p/discovery/options.go rename to share/shwap/p2p/discovery/options.go diff --git a/square/shwap/p2p/discovery/set.go b/share/shwap/p2p/discovery/set.go similarity index 100% rename from square/shwap/p2p/discovery/set.go rename to share/shwap/p2p/discovery/set.go diff --git a/square/shwap/p2p/discovery/set_test.go b/share/shwap/p2p/discovery/set_test.go similarity index 100% rename from square/shwap/p2p/discovery/set_test.go rename to share/shwap/p2p/discovery/set_test.go diff --git a/square/shwap/p2p/shrex/doc.go b/share/shwap/p2p/shrex/doc.go similarity index 94% rename from square/shwap/p2p/shrex/doc.go rename to share/shwap/p2p/shrex/doc.go index 9654532842..fee7a07c93 100644 --- a/square/shwap/p2p/shrex/doc.go +++ b/share/shwap/p2p/shrex/doc.go @@ -8,7 +8,7 @@ // // - shrexeds: a request/response protocol that is used to request extended data square shares from peers. // This protocol exchanges the original data square in between the client and server, and it's up to the -// receiver to compute the extended data square. +// receiver to compute the extended data share. // // This package also defines a peer manager that is used to manage network peers that can be used to exchange // shares. The peer manager is primarily responsible for providing peers to request shares from, diff --git a/square/shwap/p2p/shrex/error.go b/share/shwap/p2p/shrex/error.go similarity index 100% rename from square/shwap/p2p/shrex/error.go rename to share/shwap/p2p/shrex/error.go diff --git a/square/shwap/p2p/shrex/error_test.go b/share/shwap/p2p/shrex/error_test.go similarity index 100% rename from square/shwap/p2p/shrex/error_test.go rename to share/shwap/p2p/shrex/error_test.go diff --git a/square/shwap/p2p/shrex/errors.go b/share/shwap/p2p/shrex/errors.go similarity index 100% rename from square/shwap/p2p/shrex/errors.go rename to share/shwap/p2p/shrex/errors.go diff --git a/square/shwap/p2p/shrex/metrics.go b/share/shwap/p2p/shrex/metrics.go similarity index 100% rename from square/shwap/p2p/shrex/metrics.go rename to share/shwap/p2p/shrex/metrics.go diff --git a/square/shwap/p2p/shrex/middleware.go b/share/shwap/p2p/shrex/middleware.go similarity index 100% rename from square/shwap/p2p/shrex/middleware.go rename to share/shwap/p2p/shrex/middleware.go diff --git a/square/shwap/p2p/shrex/params.go b/share/shwap/p2p/shrex/params.go similarity index 100% rename from square/shwap/p2p/shrex/params.go rename to share/shwap/p2p/shrex/params.go diff --git a/square/shwap/p2p/shrex/pb/shrex.pb.go b/share/shwap/p2p/shrex/pb/shrex.pb.go similarity index 81% rename from square/shwap/p2p/shrex/pb/shrex.pb.go rename to share/shwap/p2p/shrex/pb/shrex.pb.go index 48171b5135..88322b1985 100644 --- a/square/shwap/p2p/shrex/pb/shrex.pb.go +++ b/share/shwap/p2p/shrex/pb/shrex.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: square/shwap/p2p/shrex/pb/shrex.proto +// source: share/shwap/p2p/shrex/pb/shrex.proto package pb @@ -50,7 +50,7 @@ func (x Status) String() string { } func (Status) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_ade548694c6c6a45, []int{0} + return fileDescriptor_68dfd78ade756110, []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_ade548694c6c6a45, []int{0} + return fileDescriptor_68dfd78ade756110, []int{0} } func (m *Response) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -103,25 +103,25 @@ func init() { } func init() { - proto.RegisterFile("square/shwap/p2p/shrex/pb/shrex.proto", fileDescriptor_ade548694c6c6a45) + proto.RegisterFile("share/shwap/p2p/shrex/pb/shrex.proto", fileDescriptor_68dfd78ade756110) } -var fileDescriptor_ade548694c6c6a45 = []byte{ +var fileDescriptor_68dfd78ade756110 = []byte{ // 218 bytes of a gzipped FileDescriptorProto - 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, + 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, } func (m *Response) Marshal() (dAtA []byte, err error) { diff --git a/square/shwap/p2p/shrex/pb/shrex.proto b/share/shwap/p2p/shrex/pb/shrex.proto similarity index 69% rename from square/shwap/p2p/shrex/pb/shrex.proto rename to share/shwap/p2p/shrex/pb/shrex.proto index 0dac0f433b..7b3a57227d 100644 --- a/square/shwap/p2p/shrex/pb/shrex.proto +++ b/share/shwap/p2p/shrex/pb/shrex.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -option go_package = "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/pb"; +option go_package = "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/pb"; enum Status { INVALID = 0; diff --git a/square/shwap/p2p/shrex/peers/doc.go b/share/shwap/p2p/shrex/peers/doc.go similarity index 100% rename from square/shwap/p2p/shrex/peers/doc.go rename to share/shwap/p2p/shrex/peers/doc.go diff --git a/square/shwap/p2p/shrex/peers/manager.go b/share/shwap/p2p/shrex/peers/manager.go similarity index 97% rename from square/shwap/p2p/shrex/peers/manager.go rename to share/shwap/p2p/shrex/peers/manager.go index 9c77496932..857c5ee937 100644 --- a/square/shwap/p2p/shrex/peers/manager.go +++ b/share/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/square" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/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 square.DataHash, height uint64, +func (m *Manager) Peer(ctx context.Context, datahash share.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 square.DataHash, + datahash share.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 square.DataHash, peerID peer.ID, source peerSource) DoneFunc { +func (m *Manager) doneFunc(datahash share.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 square.DataHash) bool { +func (m *Manager) isBlacklistedHash(hash share.DataHash) bool { m.lock.Lock() defer m.lock.Unlock() return m.blacklistedHashes[hash.String()] diff --git a/square/shwap/p2p/shrex/peers/manager_test.go b/share/shwap/p2p/shrex/peers/manager_test.go similarity index 97% rename from square/shwap/p2p/shrex/peers/manager_test.go rename to share/shwap/p2p/shrex/peers/manager_test.go index 3dbf242841..c18a2c340c 100644 --- a/square/shwap/p2p/shrex/peers/manager_test.go +++ b/share/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/square" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/discovery" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub" + "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" ) 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: square.DataHash("datahash1datahash1datahash1datahash1datahash1"), + DataHash: share.DataHash("datahash1datahash1datahash1datahash1datahash1"), Height: 2, } manager.Validate(ctx, peerID, msg) // create validated pool - validDataHash := square.DataHash("datahash2") + validDataHash := share.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: square.DataHash("datahash"), + DataHash: share.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: square.DataHash("datahash"), + DataHash: share.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: square.DataHash("datahash"), + DataHash: share.DataHash("datahash"), Height: h.Height() - storedPoolsAmount - 3, } result := manager.Validate(ctx, "peer", msg) diff --git a/square/shwap/p2p/shrex/peers/metrics.go b/share/shwap/p2p/shrex/peers/metrics.go similarity index 99% rename from square/shwap/p2p/shrex/peers/metrics.go rename to share/shwap/p2p/shrex/peers/metrics.go index 67bdb5caf0..d401d6a4fc 100644 --- a/square/shwap/p2p/shrex/peers/metrics.go +++ b/share/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/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" ) const ( diff --git a/square/shwap/p2p/shrex/peers/options.go b/share/shwap/p2p/shrex/peers/options.go similarity index 97% rename from square/shwap/p2p/shrex/peers/options.go rename to share/shwap/p2p/shrex/peers/options.go index 7a4a5e10cf..e268550853 100644 --- a/square/shwap/p2p/shrex/peers/options.go +++ b/share/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/square/shwap/p2p/shrex/shrexsub" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub" ) type Parameters struct { diff --git a/square/shwap/p2p/shrex/peers/pool.go b/share/shwap/p2p/shrex/peers/pool.go similarity index 100% rename from square/shwap/p2p/shrex/peers/pool.go rename to share/shwap/p2p/shrex/peers/pool.go diff --git a/square/shwap/p2p/shrex/peers/pool_test.go b/share/shwap/p2p/shrex/peers/pool_test.go similarity index 100% rename from square/shwap/p2p/shrex/peers/pool_test.go rename to share/shwap/p2p/shrex/peers/pool_test.go diff --git a/square/shwap/p2p/shrex/peers/timedqueue.go b/share/shwap/p2p/shrex/peers/timedqueue.go similarity index 100% rename from square/shwap/p2p/shrex/peers/timedqueue.go rename to share/shwap/p2p/shrex/peers/timedqueue.go diff --git a/square/shwap/p2p/shrex/peers/timedqueue_test.go b/share/shwap/p2p/shrex/peers/timedqueue_test.go similarity index 100% rename from square/shwap/p2p/shrex/peers/timedqueue_test.go rename to share/shwap/p2p/shrex/peers/timedqueue_test.go diff --git a/square/shwap/p2p/shrex/recovery.go b/share/shwap/p2p/shrex/recovery.go similarity index 100% rename from square/shwap/p2p/shrex/recovery.go rename to share/shwap/p2p/shrex/recovery.go diff --git a/square/shwap/p2p/shrex/shrex_getter/shrex.go b/share/shwap/p2p/shrex/shrex_getter/shrex.go similarity index 90% rename from square/shwap/p2p/shrex/shrex_getter/shrex.go rename to share/shwap/p2p/shrex/shrex_getter/shrex.go index 099d62272e..c87b6990a5 100644 --- a/square/shwap/p2p/shrex/shrex_getter/shrex.go +++ b/share/shwap/p2p/shrex/shrex_getter/shrex.go @@ -13,18 +13,18 @@ import ( "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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/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" + "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" ) var ( @@ -91,7 +91,7 @@ func (sg *Getter) WithMetrics() error { return nil } -// Getter is a share.Getter that uses the shrex/eds and shrex/nd protocol to retrieve shares. +// Getter is a gosquare.Getter that uses the shrex/eds and shrex/nd protocol to retrieve shares. type Getter struct { edsClient *shrexeds.Client ndClient *shrexnd.Client @@ -146,8 +146,8 @@ func (sg *Getter) Stop(ctx context.Context) error { return sg.archivalPeerManager.Stop(ctx) } -func (sg *Getter) GetShare(context.Context, *header.ExtendedHeader, int, int) (share.Share, error) { - return share.Share{}, fmt.Errorf("getter/shrex: GetShare %w", shwap.ErrOperationNotSupported) +func (sg *Getter) GetShare(context.Context, *header.ExtendedHeader, int, int) (gosquare.Share, error) { + return gosquare.Share{}, fmt.Errorf("getter/shrex: GetShare %w", shwap.ErrOperationNotSupported) } func (sg *Getter) GetEDS(ctx context.Context, header *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) { @@ -158,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(square.EmptyEDSRoots()) { - return square.EmptyEDS(), nil + if header.DAH.Equals(share.EmptyEDSRoots()) { + return share.EmptyEDS(), nil } var attempt int @@ -217,9 +217,9 @@ func (sg *Getter) GetEDS(ctx context.Context, header *header.ExtendedHeader) (*r func (sg *Getter) GetSharesByNamespace( ctx context.Context, header *header.ExtendedHeader, - namespace share.Namespace, + namespace gosquare.Namespace, ) (shwap.NamespaceData, error) { - if err := share.ValidateForData(namespace); err != nil { + if err := gosquare.ValidateForData(namespace); err != nil { return nil, err } var ( @@ -235,7 +235,7 @@ func (sg *Getter) GetSharesByNamespace( // verify that the namespace could exist inside the roots before starting network requests dah := header.DAH - rowIdxs := square.RowsWithNamespace(dah, namespace) + rowIdxs := share.RowsWithNamespace(dah, namespace) if len(rowIdxs) == 0 { return shwap.NamespaceData{}, nil } diff --git a/square/shwap/p2p/shrex/shrex_getter/shrex_test.go b/share/shwap/p2p/shrex/shrex_getter/shrex_test.go similarity index 87% rename from square/shwap/p2p/shrex/shrex_getter/shrex_test.go rename to share/shwap/p2p/shrex/shrex_getter/shrex_test.go index 908ac7f2bd..69c22dced2 100644 --- a/square/shwap/p2p/shrex/shrex_getter/shrex_test.go +++ b/share/shwap/p2p/shrex/shrex_getter/shrex_test.go @@ -17,7 +17,7 @@ import ( "github.com/stretchr/testify/require" libhead "github.com/celestiaorg/go-header" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" @@ -25,13 +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/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/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/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/store" ) @@ -71,7 +71,7 @@ func TestShrexGetter(t *testing.T) { // generate test data size := 64 - namespace := share.RandomNamespace() + namespace := gosquare.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 := share.AddInt(maxNamespace, -1) + nID, err := gosquare.AddInt(maxNamespace, -1) require.NoError(t, err) // check for namespace to be between max and min namespace in root - require.Len(t, square.RowsWithNamespace(roots, nID), 1) + require.Len(t, share.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 = share.AddInt(maxNamespace, 1) + nID, err = gosquare.AddInt(maxNamespace, 1) require.NoError(t, err) // check for namespace to be not in root - require.Len(t, square.RowsWithNamespace(roots, nID), 0) + require.Len(t, share.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 := share.AddInt(maxNamespace, 1) + namespace, err := gosquare.AddInt(maxNamespace, 1) require.NoError(t, err) // check for namespace to be not in root - require.Len(t, square.RowsWithNamespace(roots, namespace), 0) + require.Len(t, share.RowsWithNamespace(roots, namespace), 0) emptyShares, err := getter.GetSharesByNamespace(ctx, eh, namespace) require.NoError(t, err) @@ -277,12 +277,12 @@ func newStore(t *testing.T) (*store.Store, error) { return store.NewStore(store.DefaultParameters(), t.TempDir()) } -func generateTestEDS(t *testing.T) (*rsmt2d.ExtendedDataSquare, *square.AxisRoots, share.Namespace) { +func generateTestEDS(t *testing.T) (*rsmt2d.ExtendedDataSquare, *share.AxisRoots, gosquare.Namespace) { eds := edstest.RandEDS(t, 4) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) - max := nmt.MaxNamespace(roots.RowRoots[(len(roots.RowRoots))/2-1], share.NamespaceSize) - ns, err := share.NewNamespaceFromBytes(max) + max := nmt.MaxNamespace(roots.RowRoots[(len(roots.RowRoots))/2-1], gosquare.NamespaceSize) + ns, err := gosquare.NewNamespaceFromBytes(max) require.NoError(t, err) return eds, roots, ns } @@ -351,21 +351,21 @@ func newEDSClientServer( // addToNamespace adds arbitrary int value to namespace, treating namespace as big-endian // implementation of int -func addToNamespace(namespace share.Namespace, val int) (share.Namespace, error) { +func addToNamespace(namespace gosquare.Namespace, val int) (gosquare.Namespace, error) { if val == 0 { return namespace, nil } // Convert the input integer to a byte slice and add it to result slice - result := make([]byte, namespace.Len()) + result := make([]byte, gosquare.NamespaceSize) if val > 0 { - binary.BigEndian.PutUint64(result[namespace.Len()-8:], uint64(val)) + binary.BigEndian.PutUint64(result[gosquare.NamespaceSize-8:], uint64(val)) } else { - binary.BigEndian.PutUint64(result[namespace.Len()-8:], uint64(-val)) + binary.BigEndian.PutUint64(result[gosquare.NamespaceSize-8:], uint64(-val)) } // Perform addition byte by byte var carry int - for i := namespace.Len() - 1; i >= 0; i-- { + for i := gosquare.NamespaceSize - 1; i >= 0; i-- { var sum int if val > 0 { sum = int(namespace.Bytes()[i]) + int(result[i]) + carry @@ -389,8 +389,8 @@ func addToNamespace(namespace share.Namespace, val int) (share.Namespace, error) // Handle any remaining carry if carry != 0 { - return share.Namespace{}, errors.New("namespace overflow") + return gosquare.Namespace{}, errors.New("namespace overflow") } - return share.NewNamespaceFromBytes(result) + return gosquare.NewNamespaceFromBytes(result) } diff --git a/square/shwap/p2p/shrex/shrexeds/client.go b/share/shwap/p2p/shrex/shrexeds/client.go similarity index 93% rename from square/shwap/p2p/shrex/shrexeds/client.go rename to share/shwap/p2p/shrex/shrexeds/client.go index 88038f568b..5239c407f9 100644 --- a/square/shwap/p2p/shrex/shrexeds/client.go +++ b/share/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/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" + "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" ) // 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 *square.AxisRoots, + root *share.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 *square.AxisRoots, + root *share.AxisRoots, height uint64, to peer.ID, ) (*rsmt2d.ExtendedDataSquare, error) { diff --git a/square/shwap/p2p/shrex/shrexeds/doc.go b/share/shwap/p2p/shrex/shrexeds/doc.go similarity index 98% rename from square/shwap/p2p/shrex/shrexeds/doc.go rename to share/shwap/p2p/shrex/shrexeds/doc.go index 6bad3061f9..8272bd8470 100644 --- a/square/shwap/p2p/shrex/shrexeds/doc.go +++ b/share/shwap/p2p/shrex/shrexeds/doc.go @@ -3,7 +3,7 @@ // // This protocol is a request/response protocol that allows for sending requests for extended data squares by data root // to the peers in the network and receiving a response containing the original data square(s), which is used -// to recompute the extended data square. +// to recompute the extended data share. // // The streams are established using the protocol ID: // diff --git a/square/shwap/p2p/shrex/shrexeds/exchange_test.go b/share/shwap/p2p/shrex/shrexeds/exchange_test.go similarity index 90% rename from square/shwap/p2p/shrex/shrexeds/exchange_test.go rename to share/shwap/p2p/shrex/shrexeds/exchange_test.go index 76e3e2e2ee..89e1dafa1c 100644 --- a/square/shwap/p2p/shrex/shrexeds/exchange_test.go +++ b/share/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/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/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/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 := square.NewAxisRoots(eds) + roots, err := share.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 := square.NewAxisRoots(eds) + roots, err := share.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 := square.EmptyEDSRoots() + emptyRoot := share.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 := square.NewAxisRoots(eds) + roots, err := share.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 := square.EmptyEDSRoots() + emptyRoot := share.EmptyEDSRoots() for i := 0; i < rateLimit; i++ { go func(i int) { client.RequestEDS(ctx, emptyRoot, 1, server.host.ID()) //nolint:errcheck diff --git a/square/shwap/p2p/shrex/shrexeds/params.go b/share/shwap/p2p/shrex/shrexeds/params.go similarity index 90% rename from square/shwap/p2p/shrex/shrexeds/params.go rename to share/shwap/p2p/shrex/shrexeds/params.go index d3f46a1fd3..c5d76fecb2 100644 --- a/square/shwap/p2p/shrex/shrexeds/params.go +++ b/share/shwap/p2p/shrex/shrexeds/params.go @@ -5,8 +5,8 @@ import ( logging "github.com/ipfs/go-log/v2" - "github.com/celestiaorg/celestia-node/square/shwap" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" + "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" ) const protocolString = shrex.ProtocolString + shwap.EDSName diff --git a/square/shwap/p2p/shrex/shrexeds/server.go b/share/shwap/p2p/shrex/shrexeds/server.go similarity index 95% rename from square/shwap/p2p/shrex/shrexeds/server.go rename to share/shwap/p2p/shrex/shrexeds/server.go index 296acc6051..0367e7d82e 100644 --- a/square/shwap/p2p/shrex/shrexeds/server.go +++ b/share/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/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/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/store" ) diff --git a/square/shwap/p2p/shrex/shrexnd/client.go b/share/shwap/p2p/shrex/shrexnd/client.go similarity index 92% rename from square/shwap/p2p/shrex/shrexnd/client.go rename to share/shwap/p2p/shrex/shrexnd/client.go index b9fe86d14c..d5c1938f9f 100644 --- a/square/shwap/p2p/shrex/shrexnd/client.go +++ b/share/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" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/libs/utils" - "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/share/shwap" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" + shrexpb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/pb" ) // Client implements client side of shrex/nd protocol to obtain namespaced shares data from remote @@ -46,14 +46,14 @@ func NewClient(params *Parameters, host host.Host) (*Client, error) { } // RequestND requests namespaced data from the given peer. -// Returns NamespaceData with unverified inclusion proofs against the share.Root. +// Returns NamespaceData with unverified inclusion proofs against the gosquare.Root. func (c *Client) RequestND( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, peer peer.ID, ) (shwap.NamespaceData, error) { - if err := share.ValidateForData(namespace); err != nil { + if err := gosquare.ValidateForData(namespace); err != nil { return nil, err } @@ -83,7 +83,7 @@ func (c *Client) RequestND( func (c *Client) doRequest( ctx context.Context, height uint64, - namespace share.Namespace, + namespace gosquare.Namespace, peerID peer.ID, ) (shwap.NamespaceData, error) { streamOpenCtx, cancel := context.WithTimeout(ctx, c.params.ServerReadTimeout) diff --git a/square/shwap/p2p/shrex/shrexnd/doc.go b/share/shwap/p2p/shrex/shrexnd/doc.go similarity index 91% rename from square/shwap/p2p/shrex/shrexnd/doc.go rename to share/shwap/p2p/shrex/shrexnd/doc.go index 74ba7397e8..251a86dcb0 100644 --- a/square/shwap/p2p/shrex/shrexnd/doc.go +++ b/share/shwap/p2p/shrex/shrexnd/doc.go @@ -22,7 +22,7 @@ // // data, err := client.RequestND(ctx, dataRoot, peerID, namespaceID) // -// where data is of type [share.NamespacedShares] +// where data is of type [gosquare.NamespacedShares] // // To use a shrexnd server to respond to requests from peers, you must first create a new `shrexnd.Server` instance by: // @@ -31,7 +31,7 @@ // // server, err := shrexnd.NewServer(params, host, store, storeShareGetter) // -// where store is of type [share.Store] and storeShareGetter is of type [share.Getter] +// where store is of type [gosquare.Store] and storeShareGetter is of type [gosquare.Getter] // // 2. Start the server by calling `Start` on the server: // diff --git a/square/shwap/p2p/shrex/shrexnd/exchange_test.go b/share/shwap/p2p/shrex/shrexnd/exchange_test.go similarity index 85% rename from square/shwap/p2p/shrex/shrexnd/exchange_test.go rename to share/shwap/p2p/shrex/shrexnd/exchange_test.go index ea2e07eb06..5414d781e5 100644 --- a/square/shwap/p2p/shrex/shrexnd/exchange_test.go +++ b/share/shwap/p2p/shrex/shrexnd/exchange_test.go @@ -12,11 +12,11 @@ import ( mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" "github.com/celestiaorg/celestia-node/store" ) @@ -33,7 +33,7 @@ func TestExchange_RequestND_NotFound(t *testing.T) { ctx, cancel := context.WithTimeout(ctx, time.Second) t.Cleanup(cancel) - namespace := share.RandomNamespace() + namespace := gosquare.RandomNamespace() height := height.Add(1) _, err := client.RequestND(ctx, height, namespace, server.host.ID()) require.ErrorIs(t, err, shrex.ErrNotFound) @@ -44,14 +44,14 @@ func TestExchange_RequestND_NotFound(t *testing.T) { t.Cleanup(cancel) eds := edstest.RandEDS(t, 4) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) height := height.Add(1) err = edsStore.PutODSQ4(ctx, roots, height, eds) require.NoError(t, err) - namespace := share.RandomNamespace() + namespace := gosquare.RandomNamespace() emptyShares, err := client.RequestND(ctx, height, namespace, server.host.ID()) require.NoError(t, err) require.Empty(t, emptyShares.Flatten()) @@ -95,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, share.RandomNamespace(), server.host.ID()) //nolint:errcheck + client.RequestND(ctx, 1, gosquare.RandomNamespace(), server.host.ID()) //nolint:errcheck }(i) } // wait until all server slots are taken wg.Wait() - _, err = client.RequestND(ctx, 1, share.RandomNamespace(), server.host.ID()) + _, err = client.RequestND(ctx, 1, gosquare.RandomNamespace(), server.host.ID()) require.ErrorIs(t, err, shrex.ErrRateLimited) }) } diff --git a/square/shwap/p2p/shrex/shrexnd/params.go b/share/shwap/p2p/shrex/shrexnd/params.go similarity index 87% rename from square/shwap/p2p/shrex/shrexnd/params.go rename to share/shwap/p2p/shrex/shrexnd/params.go index 6003921c1e..5544ae6b27 100644 --- a/square/shwap/p2p/shrex/shrexnd/params.go +++ b/share/shwap/p2p/shrex/shrexnd/params.go @@ -5,8 +5,8 @@ import ( logging "github.com/ipfs/go-log/v2" - "github.com/celestiaorg/celestia-node/square/shwap" - "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex" + "github.com/celestiaorg/celestia-node/share/shwap" + "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex" ) const protocolString = shrex.ProtocolString + shwap.NamespaceDataName diff --git a/square/shwap/p2p/shrex/shrexnd/server.go b/share/shwap/p2p/shrex/shrexnd/server.go similarity index 96% rename from square/shwap/p2p/shrex/shrexnd/server.go rename to share/shwap/p2p/shrex/shrexnd/server.go index 20a7098b74..0193c91ae1 100644 --- a/square/shwap/p2p/shrex/shrexnd/server.go +++ b/share/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/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/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/store" ) diff --git a/square/shwap/p2p/shrex/shrexsub/doc.go b/share/shwap/p2p/shrex/shrexsub/doc.go similarity index 97% rename from square/shwap/p2p/shrex/shrexsub/doc.go rename to share/shwap/p2p/shrex/shrexsub/doc.go index 95d08361a2..3ca4919581 100644 --- a/square/shwap/p2p/shrex/shrexsub/doc.go +++ b/share/shwap/p2p/shrex/shrexsub/doc.go @@ -28,7 +28,7 @@ // // where `notification` is of type [shrexsub.Notification]. // -// and `DataHash` is the hash of the share that you want to broadcast, and `Height` is the height of the share. +// and `DataHash` is the hash of the share that you want to broadcast, and `Height` is the height of the gosquare. // // You can also subscribe to the pubsub topic by: // diff --git a/square/shwap/p2p/shrex/shrexsub/pb/notification.pb.go b/share/shwap/p2p/shrex/shrexsub/pb/notification.pb.go similarity index 83% rename from square/shwap/p2p/shrex/shrexsub/pb/notification.pb.go rename to share/shwap/p2p/shrex/shrexsub/pb/notification.pb.go index a04cbc56ac..939e4774e3 100644 --- a/square/shwap/p2p/shrex/shrexsub/pb/notification.pb.go +++ b/share/shwap/p2p/shrex/shrexsub/pb/notification.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: square/shwap/p2p/shrex/shrexsub/pb/notification.proto +// source: share/shwap/p2p/shrex/shrexsub/pb/notification.proto -package share_p2p_shrex_sub +package gosquare_p2p_shrex_sub import ( fmt "fmt" @@ -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_3a5bf8ca81a1e1ac, []int{0} + return fileDescriptor_c16b670e7e556100, []int{0} } func (m *RecentEDSNotification) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -75,27 +75,27 @@ func (m *RecentEDSNotification) GetDataHash() []byte { } func init() { - proto.RegisterType((*RecentEDSNotification)(nil), "share.p2p.shrex.sub.RecentEDSNotification") + proto.RegisterType((*RecentEDSNotification)(nil), "gosquare.p2p.shrex.sub.RecentEDSNotification") } func init() { - proto.RegisterFile("square/shwap/p2p/shrex/shrexsub/pb/notification.proto", fileDescriptor_3a5bf8ca81a1e1ac) + proto.RegisterFile("share/shwap/p2p/shrex/shrexsub/pb/notification.proto", fileDescriptor_c16b670e7e556100) } -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, +var fileDescriptor_c16b670e7e556100 = []byte{ + // 189 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, 0x62, 0xe9, 0xf9, + 0xc5, 0x85, 0xa5, 0x89, 0x45, 0xa9, 0x7a, 0x05, 0x46, 0x05, 0x7a, 0x60, 0xc5, 0x7a, 0xc5, 0xa5, + 0x49, 0x4a, 0x3e, 0x5c, 0xa2, 0x41, 0xa9, 0xc9, 0xa9, 0x79, 0x25, 0xae, 0x2e, 0xc1, 0x7e, 0x48, + 0xda, 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, 0x9d, 0x61, 0x0c, + 0x08, 0x00, 0x00, 0xff, 0xff, 0xa9, 0x5f, 0xae, 0x6a, 0xbe, 0x00, 0x00, 0x00, } func (m *RecentEDSNotification) Marshal() (dAtA []byte, err error) { diff --git a/square/shwap/p2p/shrex/shrexsub/pb/notification.proto b/share/shwap/p2p/shrex/shrexsub/pb/notification.proto similarity index 75% rename from square/shwap/p2p/shrex/shrexsub/pb/notification.proto rename to share/shwap/p2p/shrex/shrexsub/pb/notification.proto index d96cf3369e..c2aa88b70f 100644 --- a/square/shwap/p2p/shrex/shrexsub/pb/notification.proto +++ b/share/shwap/p2p/shrex/shrexsub/pb/notification.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -package share.p2p.shrex.sub; +package gosquare.p2p.shrex.sub; message RecentEDSNotification { uint64 height = 1; diff --git a/square/shwap/p2p/shrex/shrexsub/pubsub.go b/share/shwap/p2p/shrex/shrexsub/pubsub.go similarity index 96% rename from square/shwap/p2p/shrex/shrexsub/pubsub.go rename to share/shwap/p2p/shrex/shrexsub/pubsub.go index f2f49233a3..d1861cfe12 100644 --- a/square/shwap/p2p/shrex/shrexsub/pubsub.go +++ b/share/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/square" - pb "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub/pb" + "github.com/celestiaorg/celestia-node/share" + pb "github.com/celestiaorg/celestia-node/share/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 square.DataHash + DataHash share.DataHash Height uint64 } diff --git a/square/shwap/p2p/shrex/shrexsub/pubsub_test.go b/share/shwap/p2p/shrex/shrexsub/pubsub_test.go similarity index 97% rename from square/shwap/p2p/shrex/shrexsub/pubsub_test.go rename to share/shwap/p2p/shrex/shrexsub/pubsub_test.go index ecaf8519e5..59602da29b 100644 --- a/square/shwap/p2p/shrex/shrexsub/pubsub_test.go +++ b/share/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/square/shwap/p2p/shrex/shrexsub/pb" + pb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub/pb" ) func TestPubSub(t *testing.T) { diff --git a/square/shwap/p2p/shrex/shrexsub/subscription.go b/share/shwap/p2p/shrex/shrexsub/subscription.go similarity index 94% rename from square/shwap/p2p/shrex/shrexsub/subscription.go rename to share/shwap/p2p/shrex/shrexsub/subscription.go index d65928e2c3..5021f090c2 100644 --- a/square/shwap/p2p/shrex/shrexsub/subscription.go +++ b/share/shwap/p2p/shrex/shrexsub/subscription.go @@ -6,7 +6,7 @@ import ( pubsub "github.com/libp2p/go-libp2p-pubsub" - pb "github.com/celestiaorg/celestia-node/square/shwap/p2p/shrex/shrexsub/pb" + pb "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexsub/pb" ) // Subscription is a wrapper over pubsub.Subscription that handles diff --git a/square/shwap/pb/shwap.pb.go b/share/shwap/pb/shwap.pb.go similarity index 89% rename from square/shwap/pb/shwap.pb.go rename to share/shwap/pb/shwap.pb.go index 12a158882e..000bf78ca7 100644 --- a/square/shwap/pb/shwap.pb.go +++ b/share/shwap/pb/shwap.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: square/shwap/pb/shwap.proto +// source: share/shwap/pb/shwap.proto package pb @@ -45,7 +45,7 @@ func (x AxisType) String() string { } func (AxisType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_d53f2247170ec31c, []int{0} + return fileDescriptor_9431653f3c9f0bcb, []int{0} } type Row_HalfSide int32 @@ -70,7 +70,7 @@ func (x Row_HalfSide) String() string { } func (Row_HalfSide) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_d53f2247170ec31c, []int{0, 0} + return fileDescriptor_9431653f3c9f0bcb, []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_d53f2247170ec31c, []int{0} + return fileDescriptor_9431653f3c9f0bcb, []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_d53f2247170ec31c, []int{1} + return fileDescriptor_9431653f3c9f0bcb, []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_d53f2247170ec31c, []int{2} + return fileDescriptor_9431653f3c9f0bcb, []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_d53f2247170ec31c, []int{3} + return fileDescriptor_9431653f3c9f0bcb, []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("square/shwap/pb/shwap.proto", fileDescriptor_d53f2247170ec31c) } +func init() { proto.RegisterFile("share/shwap/pb/shwap.proto", fileDescriptor_9431653f3c9f0bcb) } -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, +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, } func (m *Row) Marshal() (dAtA []byte, err error) { diff --git a/square/shwap/pb/shwap.proto b/share/shwap/pb/shwap.proto similarity index 89% rename from square/shwap/pb/shwap.proto rename to share/shwap/pb/shwap.proto index 444844f055..d7daea568a 100644 --- a/square/shwap/pb/shwap.proto +++ b/share/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/square/shwap/pb"; +option go_package = "github.com/celestiaorg/celestia-node/share/shwap/pb"; import "pb/proof.proto"; // celestiaorg/nmt/pb/proof.proto diff --git a/square/shwap/row.go b/share/shwap/row.go similarity index 80% rename from square/shwap/row.go rename to share/shwap/row.go index b4298c27ab..013dd3d2bf 100644 --- a/square/shwap/row.go +++ b/share/shwap/row.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap/pb" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap/pb" ) // RowName is the name identifier for the row container. @@ -24,12 +24,12 @@ const ( // Row represents a portion of a row in an EDS, either left or right half. type Row struct { - halfShares []share.Share // halfShares holds the shares of either the left or right half of a row. - side RowSide // side indicates whether the row half is left or right. + halfShares []gosquare.Share // halfShares holds the shares of either the left or right half of a row. + side RowSide // side indicates whether the row half is left or right. } // NewRow creates a new Row with the specified shares and side. -func NewRow(halfShares []share.Share, side RowSide) Row { +func NewRow(halfShares []gosquare.Share, side RowSide) Row { return Row{ halfShares: halfShares, side: side, @@ -38,8 +38,8 @@ func NewRow(halfShares []share.Share, side RowSide) Row { // RowFromShares constructs a new Row from an Extended Data Square based on the specified index and // side. -func RowFromShares(shares []share.Share, side RowSide) Row { - var halfShares []share.Share +func RowFromShares(shares []gosquare.Share, side RowSide) Row { + var halfShares []gosquare.Share if side == Right { halfShares = shares[len(shares)/2:] // Take the right half of the shares. } else { @@ -63,8 +63,8 @@ func RowFromProto(r *pb.Row) (Row, error) { // Shares reconstructs the complete row shares from the half provided, using RSMT2D for data // recovery if needed. -func (r Row) Shares() ([]share.Share, error) { - shares := make([]share.Share, len(r.halfShares)*2) +func (r Row) Shares() ([]gosquare.Share, error) { + shares := make([]gosquare.Share, len(r.halfShares)*2) offset := 0 if r.side == Right { offset = len(r.halfShares) // Position the halfShares in the second half if it's the right side. @@ -73,11 +73,11 @@ func (r Row) Shares() ([]share.Share, error) { shares[i+offset] = share } - rowShares, err := square.DefaultRSMT2DCodec().Decode(share.ToBytes(shares)) + rowShares, err := share.DefaultRSMT2DCodec().Decode(gosquare.ToBytes(shares)) if err != nil { return nil, err } - return share.FromBytes(rowShares) + return gosquare.FromBytes(rowShares) } // ToProto converts the Row to its protobuf representation. @@ -95,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 *square.AxisRoots, idx int) error { +func (r Row) Verify(roots *share.AxisRoots, idx int) error { if len(r.halfShares) == 0 { return fmt.Errorf("empty half row") } @@ -115,7 +115,7 @@ func (r Row) Verify(roots *square.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 *square.AxisRoots, idx int) error { +func (r Row) verifyInclusion(roots *share.AxisRoots, idx int) error { shrs, err := r.Shares() if err != nil { return fmt.Errorf("while extending shares: %w", err) diff --git a/square/shwap/row_id.go b/share/shwap/row_id.go similarity index 99% rename from square/shwap/row_id.go rename to share/shwap/row_id.go index acc0495ef4..169458fcbb 100644 --- a/square/shwap/row_id.go +++ b/share/shwap/row_id.go @@ -14,7 +14,7 @@ const RowIDSize = EdsIDSize + 2 // with the row's index. type RowID struct { EdsID // Embedding EdsID to include the block height in RowID. - RowIndex int // RowIndex specifies the position of the row within the data square. + RowIndex int // RowIndex specifies the position of the row within the data share. } // NewRowID creates a new RowID with the specified block height, row index, and EDS size. diff --git a/square/shwap/row_id_test.go b/share/shwap/row_id_test.go similarity index 100% rename from square/shwap/row_id_test.go rename to share/shwap/row_id_test.go diff --git a/square/shwap/row_namespace_data.go b/share/shwap/row_namespace_data.go similarity index 90% rename from square/shwap/row_namespace_data.go rename to share/shwap/row_namespace_data.go index 761652ebff..294e0b4a9e 100644 --- a/square/shwap/row_namespace_data.go +++ b/share/shwap/row_namespace_data.go @@ -8,12 +8,12 @@ import ( "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" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" nmt_pb "github.com/celestiaorg/nmt/pb" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/shwap/pb" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap/pb" ) // RowNamespaceDataName is the name identifier for the row namespace data container. @@ -26,21 +26,21 @@ var ErrNamespaceOutsideRange = errors.New("target namespace is outside of namesp // RowNamespaceData holds shares and their corresponding proof for a single row within a namespace. type RowNamespaceData struct { - Shares []share.Share `json:"shares"` // Shares within the namespace. - Proof *nmt.Proof `json:"proof"` // Proof of the shares' inclusion in the namespace. + Shares []gosquare.Share `json:"shares"` // Shares within the namespace. + Proof *nmt.Proof `json:"proof"` // Proof of the shares' inclusion in the namespace. } // RowNamespaceDataFromShares extracts and constructs a RowNamespaceData from shares within the // specified namespace. func RowNamespaceDataFromShares( - shares []share.Share, - namespace share.Namespace, + shares []gosquare.Share, + namespace gosquare.Namespace, rowIndex int, ) (RowNamespaceData, error) { tree := wrapper.NewErasuredNamespacedMerkleTree(uint64(len(shares)/2), uint(rowIndex)) nmtTree := nmt.New( appconsts.NewBaseHashFunc(), - nmt.NamespaceIDSize(share.NamespaceSize), + nmt.NamespaceIDSize(gosquare.NamespaceSize), nmt.IgnoreMaxNamespace(true), ) tree.SetTree(nmtTree) @@ -85,7 +85,7 @@ func RowNamespaceDataFromShares( }, nil } - namespacedShares := make([]share.Share, count) + namespacedShares := make([]gosquare.Share, count) copy(namespacedShares, shares[from:from+count]) proof, err := tree.ProveRange(from, from+count) @@ -150,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 *square.AxisRoots, namespace share.Namespace, rowIdx int) error { +func (rnd RowNamespaceData) Verify(roots *share.AxisRoots, namespace gosquare.Namespace, rowIdx int) error { if rnd.Proof == nil || rnd.Proof.IsEmptyProof() { return fmt.Errorf("nil proof") } @@ -174,7 +174,7 @@ func (rnd RowNamespaceData) Verify(roots *square.AxisRoots, namespace share.Name } // verifyInclusion checks the inclusion of the row's shares in the provided root using NMT. -func (rnd RowNamespaceData) verifyInclusion(rowRoot []byte, namespace share.Namespace) bool { +func (rnd RowNamespaceData) verifyInclusion(rowRoot []byte, namespace gosquare.Namespace) bool { leaves := make([][]byte, 0, len(rnd.Shares)) for _, sh := range rnd.Shares { namespaceBytes := sh.Namespace().Bytes() @@ -185,7 +185,7 @@ func (rnd RowNamespaceData) verifyInclusion(rowRoot []byte, namespace share.Name } return rnd.Proof.VerifyNamespace( - square.NewSHA256Hasher(), + share.NewSHA256Hasher(), namespace.Bytes(), leaves, rowRoot, diff --git a/square/shwap/row_namespace_data_id.go b/share/shwap/row_namespace_data_id.go similarity index 88% rename from square/shwap/row_namespace_data_id.go rename to share/shwap/row_namespace_data_id.go index cdada45b03..f0f20e58b9 100644 --- a/square/shwap/row_namespace_data_id.go +++ b/share/shwap/row_namespace_data_id.go @@ -4,18 +4,18 @@ import ( "fmt" "io" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) // RowNamespaceDataIDSize defines the total size of a RowNamespaceDataID in bytes, combining the // size of a RowID and the size of a Namespace. -const RowNamespaceDataIDSize = RowIDSize + share.NamespaceSize +const RowNamespaceDataIDSize = RowIDSize + gosquare.NamespaceSize // RowNamespaceDataID uniquely identifies a piece of namespaced data within a row of an Extended // Data Square (EDS). type RowNamespaceDataID struct { - RowID // Embedded RowID representing the specific row in the EDS. - DataNamespace share.Namespace // DataNamespace is a string representation of the namespace to facilitate comparisons. + RowID // Embedded RowID representing the specific row in the EDS. + DataNamespace gosquare.Namespace // DataNamespace is a string representation of the namespace to facilitate comparisons. } // NewRowNamespaceDataID creates a new RowNamespaceDataID with the specified parameters. It @@ -23,7 +23,7 @@ type RowNamespaceDataID struct { func NewRowNamespaceDataID( height uint64, rowIdx int, - namespace share.Namespace, + namespace gosquare.Namespace, edsSize int, ) (RowNamespaceDataID, error) { did := RowNamespaceDataID{ @@ -55,7 +55,7 @@ func RowNamespaceDataIDFromBinary(data []byte) (RowNamespaceDataID, error) { return RowNamespaceDataID{}, fmt.Errorf("unmarshaling RowID: %w", err) } - ns, err := share.NewNamespaceFromBytes(data[RowIDSize:]) + ns, err := gosquare.NewNamespaceFromBytes(data[RowIDSize:]) rndid := RowNamespaceDataID{ RowID: rid, DataNamespace: ns, @@ -123,7 +123,7 @@ func (rndid RowNamespaceDataID) Validate() error { if err := rndid.RowID.Validate(); err != nil { return fmt.Errorf("validating RowID: %w", err) } - if err := share.ValidateForData(rndid.DataNamespace); err != nil { + if err := gosquare.ValidateForData(rndid.DataNamespace); err != nil { return fmt.Errorf("%w: validating DataNamespace: %w", ErrInvalidID, err) } diff --git a/square/shwap/row_namespace_data_id_test.go b/share/shwap/row_namespace_data_id_test.go similarity index 89% rename from square/shwap/row_namespace_data_id_test.go rename to share/shwap/row_namespace_data_id_test.go index 658072c58a..c59e34753f 100644 --- a/square/shwap/row_namespace_data_id_test.go +++ b/share/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/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" ) func TestRowNamespaceDataID(t *testing.T) { edsSize := 4 - ns := share.RandomNamespace() + ns := gosquare.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 := share.RandomNamespace() + ns := gosquare.RandomNamespace() id, err := NewRowNamespaceDataID(1, 1, ns, edsSize) require.NoError(t, err) diff --git a/square/shwap/row_namespace_data_test.go b/share/shwap/row_namespace_data_test.go similarity index 71% rename from square/shwap/row_namespace_data_test.go rename to share/shwap/row_namespace_data_test.go index b120919d13..ec922e98ca 100644 --- a/square/shwap/row_namespace_data_test.go +++ b/share/shwap/row_namespace_data_test.go @@ -9,28 +9,28 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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" + "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" ) func TestNamespacedRowFromShares(t *testing.T) { const odsSize = 8 - minNamespace, err := share.NewV0Namespace(slices.Concat(bytes.Repeat([]byte{0}, 8), []byte{1, 0})) + minNamespace, err := gosquare.NewV0Namespace(slices.Concat(bytes.Repeat([]byte{0}, 8), []byte{1, 0})) require.NoError(t, err) - err = share.ValidateForData(minNamespace) + err = gosquare.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)) + shares := gosquare.RandSharesWithNamespace(minNamespace, namespacedAmount, odsSize) + parity, err := share.DefaultRSMT2DCodec().Encode(gosquare.ToBytes(shares)) require.NoError(t, err) - paritySh, err := share.FromBytes(parity) + paritySh, err := gosquare.FromBytes(parity) require.NoError(t, err) extended := slices.Concat(shares, paritySh) @@ -46,15 +46,15 @@ func TestNamespacedRowFromShares(t *testing.T) { // // const odsSize = 8 // // Test absent namespace -// shares := share.RandShares( odsSize) -// absentNs, err := square.GetNamespace(shares[0]).AddInt(1) +// shares := gosquare.RandShares( odsSize) +// absentNs, err := share.GetNamespace(shares[0]).AddInt(1) // require.NoError(t, err) // -// parity, err := square.DefaultRSMT2DCodec().Encode(shares) +// parity, err := share.DefaultRSMT2DCodec().Encode(shares) // require.NoError(t, err) // extended := slices.Concat(shares, parity) // -// shrs, err := share.FromBytes(extended) +// shrs, err := gosquare.FromBytes(extended) // require.NoError(t, err) // // nr, err := shwap.RowNamespaceDataFromShares(shrs, absentNs, 0) @@ -77,7 +77,7 @@ func TestNamespacedRowFromShares(t *testing.T) { // require.NoError(t, err) // require.True(t, len(nd) > 0) // -// rowIdxs := square.RowsWithNamespace(root, namespace) +// rowIdxs := share.RowsWithNamespace(root, namespace) // require.Len(t, nd, len(rowIdxs)) // // for i, rowIdx := range rowIdxs { @@ -92,7 +92,7 @@ func TestNamespacedRowProtoEncoding(t *testing.T) { t.Cleanup(cancel) const odsSize = 8 - namespace := share.RandomNamespace() + namespace := gosquare.RandomNamespace() randEDS, _ := edstest.RandEDSWithNamespace(t, namespace, odsSize, odsSize) rsmt2d := &eds.Rsmt2D{ExtendedDataSquare: randEDS} nd, err := eds.NamespaceData(ctx, rsmt2d, namespace) diff --git a/square/shwap/row_test.go b/share/shwap/row_test.go similarity index 80% rename from square/shwap/row_test.go rename to share/shwap/row_test.go index 9bb9aded59..e2936ab245 100644 --- a/square/shwap/row_test.go +++ b/share/shwap/row_test.go @@ -5,10 +5,10 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" ) func TestRowFromShares(t *testing.T) { @@ -18,14 +18,14 @@ func TestRowFromShares(t *testing.T) { for rowIdx := 0; rowIdx < odsSize*2; rowIdx++ { for _, side := range []RowSide{Left, Right} { shrs := eds.Row(uint(rowIdx)) - shares, err := share.FromBytes(shrs) + shares, err := gosquare.FromBytes(shrs) require.NoError(t, err) row := RowFromShares(shares, side) extended, err := row.Shares() require.NoError(t, err) require.Equal(t, shares, extended) - var half []share.Share + var half []gosquare.Share if side == Right { half = shares[odsSize:] } else { @@ -40,13 +40,13 @@ func TestRowFromShares(t *testing.T) { func TestRowValidate(t *testing.T) { const odsSize = 8 eds := edstest.RandEDS(t, odsSize) - root, err := square.NewAxisRoots(eds) + root, err := share.NewAxisRoots(eds) require.NoError(t, err) for rowIdx := 0; rowIdx < odsSize*2; rowIdx++ { for _, side := range []RowSide{Left, Right} { shrs := eds.Row(uint(rowIdx)) - shares, err := share.FromBytes(shrs) + shares, err := gosquare.FromBytes(shrs) require.NoError(t, err) row := RowFromShares(shares, side) @@ -60,10 +60,10 @@ 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 := square.NewAxisRoots(eds) + root, err := share.NewAxisRoots(eds) require.NoError(t, err) shrs := eds.Row(0) - shares, err := share.FromBytes(shrs) + shares, err := gosquare.FromBytes(shrs) require.NoError(t, err) row := RowFromShares(shares, Left) @@ -73,9 +73,9 @@ func TestRowValidateNegativeCases(t *testing.T) { require.Error(t, err, "should error on invalid row side") // Test with invalid shares (more shares than expected) - incorrectShares := make([]share.Share, (eds.Width()/2)+1) // Adding an extra share + incorrectShares := make([]gosquare.Share, (eds.Width()/2)+1) // Adding an extra share for i := range incorrectShares { - shr, err := share.NewShare(eds.GetCell(uint(i), 0)) + shr, err := gosquare.NewShare(eds.GetCell(uint(i), 0)) require.NoError(t, err) incorrectShares[i] = *shr } @@ -84,7 +84,7 @@ func TestRowValidateNegativeCases(t *testing.T) { require.Error(t, err, "should error on incorrect number of shares") // Test with empty shares - emptyRow := Row{halfShares: []share.Share{}, side: Left} + emptyRow := Row{halfShares: []gosquare.Share{}, side: Left} err = emptyRow.Verify(root, 0) require.Error(t, err, "should error on empty halfShares") @@ -101,7 +101,7 @@ func TestRowProtoEncoding(t *testing.T) { for rowIdx := 0; rowIdx < odsSize*2; rowIdx++ { for _, side := range []RowSide{Left, Right} { shrs := eds.Row(uint(rowIdx)) - shares, err := share.FromBytes(shrs) + shares, err := gosquare.FromBytes(shrs) require.NoError(t, err) row := RowFromShares(shares, side) @@ -118,10 +118,10 @@ func TestRowProtoEncoding(t *testing.T) { func BenchmarkRowValidate(b *testing.B) { const odsSize = 32 eds := edstest.RandEDS(b, odsSize) - root, err := square.NewAxisRoots(eds) + root, err := share.NewAxisRoots(eds) require.NoError(b, err) shrs := eds.Row(0) - shares, err := share.FromBytes(shrs) + shares, err := gosquare.FromBytes(shrs) require.NoError(b, err) row := RowFromShares(shares, Left) diff --git a/square/shwap/sample.go b/share/shwap/sample.go similarity index 75% rename from square/shwap/sample.go rename to share/shwap/sample.go index 2e24918e0a..dd9e7cc1f9 100644 --- a/square/shwap/sample.go +++ b/share/shwap/sample.go @@ -5,13 +5,13 @@ import ( "fmt" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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/square" - "github.com/celestiaorg/celestia-node/square/shwap/pb" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/shwap/pb" ) // SampleName is the name identifier for the sample container. @@ -22,16 +22,16 @@ const SampleName = "sample_v0" var ErrFailedVerification = errors.New("failed to verify inclusion") // Sample represents a data share along with its Merkle proof, used to validate the share's -// inclusion in a data square. +// inclusion in a data share. type Sample struct { - share.Share // Embeds the Share which includes the data with namespace. - Proof *nmt.Proof // Proof is the Merkle Proof validating the share's inclusion. - ProofType rsmt2d.Axis // ProofType indicates whether the proof is against a row or a column. + gosquare.Share // Embeds the Share which includes the data with namespace. + Proof *nmt.Proof // Proof is the Merkle Proof validating the share's inclusion. + ProofType rsmt2d.Axis // ProofType indicates whether the proof is against a row or a column. } // SampleFromShares creates a Sample from a list of shares, using the specified proof type and // the share index to be included in the sample. -func SampleFromShares(shares []share.Share, proofType rsmt2d.Axis, axisIdx, shrIdx int) (Sample, error) { +func SampleFromShares(shares []gosquare.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.ToBytes()) @@ -95,7 +95,7 @@ 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 *square.AxisRoots, rowIdx, colIdx int) error { +func (s Sample) Verify(roots *share.AxisRoots, rowIdx, colIdx int) error { if s.Proof == nil || s.Proof.IsEmptyProof() { return errors.New("nil proof") } @@ -109,26 +109,26 @@ func (s Sample) Verify(roots *square.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 *square.AxisRoots, rowIdx, colIdx int) bool { +func (s Sample) verifyInclusion(roots *share.AxisRoots, rowIdx, colIdx int) bool { size := len(roots.RowRoots) namespace := inclusionNamespace(s.Share, rowIdx, colIdx, size) - rootHash := square.RootHashForCoordinates(roots, s.ProofType, uint(rowIdx), uint(colIdx)) + rootHash := share.RootHashForCoordinates(roots, s.ProofType, uint(rowIdx), uint(colIdx)) return s.Proof.VerifyInclusion( - square.NewSHA256Hasher(), + share.NewSHA256Hasher(), namespace.Bytes(), [][]byte{s.Share.ToBytes()}, rootHash, ) } -// inclusionNamespace returns the namespace for the share based on its position in the square. +// inclusionNamespace returns the namespace for the share based on its position in the share. // Shares from extended part of the square are considered parity shares. It means that -// parity shares are located outside of first quadrant of the square. According to the nmt +// parity shares are located outside of first quadrant of the share. According to the nmt // specification, the parity shares are prefixed with the namespace of the parity shares. -func inclusionNamespace(sh share.Share, rowIdx, colIdx, squareSize int) share.Namespace { +func inclusionNamespace(sh gosquare.Share, rowIdx, colIdx, squareSize int) gosquare.Namespace { isParity := colIdx >= squareSize/2 || rowIdx >= squareSize/2 if isParity { - return share.ParitySharesNamespace + return gosquare.ParitySharesNamespace } return sh.Namespace() } diff --git a/square/shwap/sample_id.go b/share/shwap/sample_id.go similarity index 100% rename from square/shwap/sample_id.go rename to share/shwap/sample_id.go diff --git a/square/shwap/sample_id_test.go b/share/shwap/sample_id_test.go similarity index 100% rename from square/shwap/sample_id_test.go rename to share/shwap/sample_id_test.go diff --git a/square/shwap/sample_test.go b/share/shwap/sample_test.go similarity index 87% rename from square/shwap/sample_test.go rename to share/shwap/sample_test.go index a2b4aa1e53..031bec7834 100644 --- a/square/shwap/sample_test.go +++ b/share/shwap/sample_test.go @@ -6,19 +6,19 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "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" + "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" ) func TestSampleValidate(t *testing.T) { const odsSize = 8 randEDS := edstest.RandEDS(t, odsSize) - root, err := square.NewAxisRoots(randEDS) + root, err := share.NewAxisRoots(randEDS) require.NoError(t, err) inMem := eds.Rsmt2D{ExtendedDataSquare: randEDS} @@ -38,7 +38,7 @@ func TestSampleValidate(t *testing.T) { func TestSampleNegativeVerifyInclusion(t *testing.T) { const odsSize = 8 randEDS := edstest.RandEDS(t, odsSize) - root, err := square.NewAxisRoots(randEDS) + root, err := share.NewAxisRoots(randEDS) require.NoError(t, err) inMem := eds.Rsmt2D{ExtendedDataSquare: randEDS} @@ -54,7 +54,7 @@ func TestSampleNegativeVerifyInclusion(t *testing.T) { // Corrupt the share b := sample.Share.ToBytes() b[0] ^= 0xFF - shr, err := share.NewShare(b) + shr, err := gosquare.NewShare(b) require.NoError(t, err) sample.Share = *shr err = sample.Verify(root, 0, 0) @@ -100,7 +100,7 @@ func TestSampleProtoEncoding(t *testing.T) { func BenchmarkSampleValidate(b *testing.B) { const odsSize = 32 randEDS := edstest.RandEDS(b, odsSize) - root, err := square.NewAxisRoots(randEDS) + root, err := share.NewAxisRoots(randEDS) require.NoError(b, err) inMem := eds.Rsmt2D{ExtendedDataSquare: randEDS} sample, err := inMem.SampleForProofAxis(0, 0, rsmt2d.Row) diff --git a/square/shwap/share.go b/share/shwap/share.go similarity index 70% rename from square/shwap/share.go rename to share/shwap/share.go index 76b68e0eff..f10048636e 100644 --- a/square/shwap/share.go +++ b/share/shwap/share.go @@ -3,21 +3,21 @@ package shwap import ( "fmt" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/celestia-node/square/shwap/pb" + "github.com/celestiaorg/celestia-node/share/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, error) { +func ShareFromProto(s *pb.Share) (gosquare.Share, error) { if s == nil { - return share.Share{}, nil + return gosquare.Share{}, nil } - sh, err := share.NewShare(s.Data) + sh, err := gosquare.NewShare(s.Data) if err != nil { - return share.Share{}, err + return gosquare.Share{}, err } return *sh, err } @@ -25,7 +25,7 @@ func ShareFromProto(s *pb.Share) (share.Share, error) { // SharesToProto converts a slice of Shares from the application's internal representation to a // slice of protobuf Share objects. This function allocates memory for the protobuf objects and // copies data from the input slice. -func SharesToProto(shrs []share.Share) []*pb.Share { +func SharesToProto(shrs []gosquare.Share) []*pb.Share { protoShares := make([]*pb.Share, len(shrs)) for i, shr := range shrs { protoShares[i] = &pb.Share{Data: shr.ToBytes()} @@ -35,8 +35,8 @@ func SharesToProto(shrs []share.Share) []*pb.Share { // 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, error) { - shares := make([]share.Share, len(shrs)) +func SharesFromProto(shrs []*pb.Share) ([]gosquare.Share, error) { + shares := make([]gosquare.Share, len(shrs)) var err error for i, shr := range shrs { shares[i], err = ShareFromProto(shr) diff --git a/square/namespace.go b/square/namespace.go deleted file mode 100644 index 65c5a0390c..0000000000 --- a/square/namespace.go +++ /dev/null @@ -1,233 +0,0 @@ -package square - -import ( - "bytes" - "encoding/binary" - "encoding/hex" - "errors" - "fmt" - - appns "github.com/celestiaorg/go-square/namespace" - "github.com/celestiaorg/go-square/v2/share" - "github.com/celestiaorg/nmt/namespace" -) - -// NamespaceSize is a system-wide size for NMT namespaces. -const NamespaceSize = appns.NamespaceSize - -// Various reserved namespaces. -var ( - // MaxPrimaryReservedNamespace is the highest primary reserved namespace. - // Namespaces lower than this are reserved for protocol use. - MaxPrimaryReservedNamespace = Namespace(appns.MaxPrimaryReservedNamespace.Bytes()) - // MinSecondaryReservedNamespace is the lowest secondary reserved namespace - // reserved for protocol use. Namespaces higher than this are reserved for - // protocol use. - MinSecondaryReservedNamespace = Namespace(appns.MinSecondaryReservedNamespace.Bytes()) - ParitySharesNamespace = Namespace(appns.ParitySharesNamespace.Bytes()) - TailPaddingNamespace = Namespace(appns.TailPaddingNamespace.Bytes()) - PrimaryReservedPaddingNamespace = Namespace(appns.PrimaryReservedPaddingNamespace.Bytes()) - TxNamespace = Namespace(appns.TxNamespace.Bytes()) - PayForBlobNamespace = Namespace(appns.PayForBlobNamespace.Bytes()) - ISRNamespace = Namespace(appns.IntermediateStateRootsNamespace.Bytes()) -) - -// Namespace represents namespace of a Share. -// Consists of version byte and namespace ID. -type Namespace []byte - -// NewBlobNamespaceV0 takes a variable size byte slice and creates a valid version 0 Blob Namespace. -// The byte slice must be <= 10 bytes. -// If it is less than 10 bytes, it will be left padded to size 10 with 0s. -// Use predefined namespaces above, if non-blob namespace is needed. -func NewBlobNamespaceV0(id []byte) (Namespace, error) { - if len(id) == 0 || len(id) > appns.NamespaceVersionZeroIDSize { - return nil, fmt.Errorf( - "namespace id must be > 0 && <= %d, but it was %d bytes", appns.NamespaceVersionZeroIDSize, len(id)) - } - - n := make(Namespace, NamespaceSize) - // version and zero padding are already set as zero, - // so simply copying subNID to the end is enough to comply the V0 spec - copy(n[len(n)-len(id):], id) - return n, n.ValidateForBlob() -} - -// NamespaceFromBytes converts bytes into Namespace and validates it. -func NamespaceFromBytes(b []byte) (Namespace, error) { - n := Namespace(b) - return n, n.Validate() -} - -// Version reports version of the Namespace. -func (n Namespace) Version() byte { - return n[appns.NamespaceVersionSize-1] -} - -// ID reports ID of the Namespace. -func (n Namespace) ID() namespace.ID { - return namespace.ID(n[appns.NamespaceVersionSize:]) -} - -// ToNMT converts the whole Namespace(both Version and ID parts) into NMT's namespace.ID -// NOTE: Once https://github.com/celestiaorg/nmt/issues/206 is closed Namespace should become NNT's -// type. -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() (share.Namespace, error) { - return share.NewNamespace(n.Version(), n.ID()) -} - -// Len reports the total length of the namespace. -func (n Namespace) Len() int { - return len(n) -} - -// String stringifies the Namespace. -func (n Namespace) String() string { - return hex.EncodeToString(n) -} - -// Equals compares two Namespaces. -func (n Namespace) Equals(target Namespace) bool { - return bytes.Equal(n, target) -} - -// Validate checks if the namespace is correct. -func (n Namespace) Validate() error { - if n.Len() != NamespaceSize { - return fmt.Errorf("invalid namespace length: expected %d, got %d", NamespaceSize, n.Len()) - } - if n.Version() != appns.NamespaceVersionZero && n.Version() != appns.NamespaceVersionMax { - return fmt.Errorf("invalid namespace version %v", n.Version()) - } - if len(n.ID()) != appns.NamespaceIDSize { - return fmt.Errorf("invalid namespace id length: expected %d, got %d", appns.NamespaceIDSize, n.ID().Size()) - } - if n.Version() == appns.NamespaceVersionZero && !bytes.HasPrefix(n.ID(), appns.NamespaceVersionZeroPrefix) { - return fmt.Errorf("invalid namespace id: expect %d leading zeroes", len(appns.NamespaceVersionZeroPrefix)) - } - return nil -} - -// ValidateForData checks if the Namespace is of real/useful data. -func (n Namespace) ValidateForData() error { - if err := n.Validate(); err != nil { - return err - } - if n.Equals(ParitySharesNamespace) || n.Equals(TailPaddingNamespace) { - return fmt.Errorf("invalid data namespace(%s): parity and tail padding namespace are forbidden", n) - } - if n.Version() != appns.NamespaceVersionZero { - return fmt.Errorf("invalid data namespace(%s): only version 0 is supported", n) - } - return nil -} - -// ValidateForBlob checks if the Namespace is valid blob namespace. -func (n Namespace) ValidateForBlob() error { - if err := n.ValidateForData(); err != nil { - return err - } - if bytes.Compare(n, MaxPrimaryReservedNamespace) < 1 { - return fmt.Errorf("invalid blob namespace(%s): reserved namespaces are forbidden", n) - } - if bytes.Compare(n, MinSecondaryReservedNamespace) > -1 { - return fmt.Errorf("invalid blob namespace(%s): reserved namespaces are forbidden", n) - } - return nil -} - -// IsAboveMax checks if the namespace is above the maximum namespace of the given hash. -func (n Namespace) IsAboveMax(nodeHash []byte) bool { - return !n.IsLessOrEqual(nodeHash[n.Len() : n.Len()*2]) -} - -// IsBelowMin checks if the target namespace is below the minimum namespace of the given hash. -func (n Namespace) IsBelowMin(nodeHash []byte) bool { - return n.IsLess(nodeHash[:n.Len()]) -} - -// IsOutsideRange checks if the namespace is outside the min-max range of the given hashes. -func (n Namespace) IsOutsideRange(leftNodeHash, rightNodeHash []byte) bool { - return n.IsBelowMin(leftNodeHash) || n.IsAboveMax(rightNodeHash) -} - -// Repeat copies the Namespace t times. -func (n Namespace) Repeat(t int) []Namespace { - ns := make([]Namespace, t) - for i := 0; i < t; i++ { - ns[i] = n - } - return ns -} - -// IsLess reports if the Namespace is less than the target. -func (n Namespace) IsLess(target Namespace) bool { - return bytes.Compare(n, target) == -1 -} - -// IsLessOrEqual reports if the Namespace is less than the target. -func (n Namespace) IsLessOrEqual(target Namespace) bool { - return bytes.Compare(n, target) < 1 -} - -// IsGreater reports if the Namespace is greater than the target. -func (n Namespace) IsGreater(target Namespace) bool { - return bytes.Compare(n, target) == 1 -} - -// IsGreaterOrEqualThan reports if the Namespace is greater or equal than the target. -func (n Namespace) IsGreaterOrEqualThan(target Namespace) bool { - return bytes.Compare(n, target) > -1 -} - -// AddInt adds arbitrary int value to namespace, treating namespace as big-endian -// implementation of int -func (n Namespace) AddInt(val int) (Namespace, error) { - if val == 0 { - return n, nil - } - // Convert the input integer to a byte slice and add it to result slice - result := make([]byte, len(n)) - if val > 0 { - binary.BigEndian.PutUint64(result[len(n)-8:], uint64(val)) - } else { - binary.BigEndian.PutUint64(result[len(n)-8:], uint64(-val)) - } - - // Perform addition byte by byte - var carry int - for i := len(n) - 1; i >= 0; i-- { - var sum int - if val > 0 { - sum = int(n[i]) + int(result[i]) + carry - } else { - sum = int(n[i]) - int(result[i]) + carry - } - - switch { - case sum > 255: - carry = 1 - sum -= 256 - case sum < 0: - carry = -1 - sum += 256 - default: - carry = 0 - } - - result[i] = uint8(sum) - } - - // Handle any remaining carry - if carry != 0 { - return nil, errors.New("namespace overflow") - } - - return result, nil -} diff --git a/state/core_access.go b/state/core_access.go index c768a89c9d..4fbeb52326 100644 --- a/state/core_access.go +++ b/state/core_access.go @@ -27,7 +27,7 @@ import ( 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/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/header" ) @@ -201,7 +201,7 @@ func (ca *CoreAccessor) cancelCtx() { // TxResponse. The user can specify additional options that can bee applied to the Tx. func (ca *CoreAccessor) SubmitPayForBlob( ctx context.Context, - appblobs []*share.Blob, + appblobs []*gosquare.Blob, cfg *TxConfig, ) (*TxResponse, error) { if len(appblobs) == 0 { diff --git a/state/core_access_test.go b/state/core_access_test.go index f44057bbea..684d1963ac 100644 --- a/state/core_access_test.go +++ b/state/core_access_test.go @@ -19,7 +19,7 @@ import ( "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" + gosquare "github.com/celestiaorg/go-square/v2/share" ) func TestSubmitPayForBlob(t *testing.T) { @@ -32,31 +32,31 @@ func TestSubmitPayForBlob(t *testing.T) { _ = ca.Stop(ctx) }) - ns, err := share.NewV0Namespace([]byte("namespace")) + ns, err := gosquare.NewV0Namespace([]byte("namespace")) require.NoError(t, err) require.False(t, ns.IsReserved()) require.NoError(t, err) - blobbyTheBlob, err := share.NewV0Blob(ns, []byte("data")) + blobbyTheBlob, err := gosquare.NewV0Blob(ns, []byte("data")) require.NoError(t, err) testcases := []struct { name string - blobs []*share.Blob + blobs []*gosquare.Blob gasPrice float64 gasLim uint64 expErr error }{ { name: "empty blobs", - blobs: []*share.Blob{}, + blobs: []*gosquare.Blob{}, gasPrice: DefaultGasPrice, gasLim: 0, expErr: errors.New("state: no blobs provided"), }, { name: "good blob with user provided gas and fees", - blobs: []*share.Blob{blobbyTheBlob}, + blobs: []*gosquare.Blob{blobbyTheBlob}, gasPrice: 0.005, gasLim: apptypes.DefaultEstimateGas([]uint32{uint32(blobbyTheBlob.DataLen())}), expErr: nil, diff --git a/store/cache/accessor_cache.go b/store/cache/accessor_cache.go index 2b99bfee13..893c73b7a9 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/square/eds" + "github.com/celestiaorg/celestia-node/share/eds" ) const defaultCloseTimeout = time.Minute diff --git a/store/cache/accessor_cache_test.go b/store/cache/accessor_cache_test.go index 16fd7d1a7d..d1847dd6da 100644 --- a/store/cache/accessor_cache_test.go +++ b/store/cache/accessor_cache_test.go @@ -11,12 +11,12 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "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/share" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/shwap" ) func TestAccessorCache(t *testing.T) { @@ -307,11 +307,11 @@ func (m *mockAccessor) Size(context.Context) int { panic("implement me") } -func (m *mockAccessor) DataHash(context.Context) (square.DataHash, error) { +func (m *mockAccessor) DataHash(context.Context) (share.DataHash, error) { panic("implement me") } -func (m *mockAccessor) AxisRoots(context.Context) (*square.AxisRoots, error) { +func (m *mockAccessor) AxisRoots(context.Context) (*share.AxisRoots, error) { panic("implement me") } @@ -323,11 +323,11 @@ func (m *mockAccessor) AxisHalf(context.Context, rsmt2d.Axis, int) (eds.AxisHalf panic("implement me") } -func (m *mockAccessor) RowNamespaceData(context.Context, share.Namespace, int) (shwap.RowNamespaceData, error) { +func (m *mockAccessor) RowNamespaceData(context.Context, gosquare.Namespace, int) (shwap.RowNamespaceData, error) { panic("implement me") } -func (m *mockAccessor) Shares(context.Context) ([]share.Share, error) { +func (m *mockAccessor) Shares(context.Context) ([]gosquare.Share, error) { panic("implement me") } diff --git a/store/cache/cache.go b/store/cache/cache.go index 6e5438913a..10e7dffcb3 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/square/eds" + "github.com/celestiaorg/celestia-node/share/eds" ) var ( diff --git a/store/cache/doublecache.go b/store/cache/doublecache.go index f06bd06fe7..d0fb2c47b9 100644 --- a/store/cache/doublecache.go +++ b/store/cache/doublecache.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/share/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 5be2eef20b..ad98c4d98d 100644 --- a/store/cache/noop.go +++ b/store/cache/noop.go @@ -4,12 +4,12 @@ import ( "context" "io" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "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/share" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/shwap" ) var _ Cache = (*NoopCache)(nil) @@ -51,12 +51,12 @@ func (n NoopFile) Size(context.Context) int { return 0 } -func (n NoopFile) DataHash(context.Context) (square.DataHash, error) { - return square.DataHash{}, nil +func (n NoopFile) DataHash(context.Context) (share.DataHash, error) { + return share.DataHash{}, nil } -func (n NoopFile) AxisRoots(context.Context) (*square.AxisRoots, error) { - return &square.AxisRoots{}, nil +func (n NoopFile) AxisRoots(context.Context) (*share.AxisRoots, error) { + return &share.AxisRoots{}, nil } func (n NoopFile) Sample(context.Context, int, int) (shwap.Sample, error) { @@ -67,12 +67,12 @@ func (n NoopFile) AxisHalf(context.Context, rsmt2d.Axis, int) (eds.AxisHalf, err return eds.AxisHalf{}, nil } -func (n NoopFile) RowNamespaceData(context.Context, share.Namespace, int) (shwap.RowNamespaceData, error) { +func (n NoopFile) RowNamespaceData(context.Context, gosquare.Namespace, int) (shwap.RowNamespaceData, error) { return shwap.RowNamespaceData{}, nil } -func (n NoopFile) Shares(context.Context) ([]share.Share, error) { - return []share.Share{}, nil +func (n NoopFile) Shares(context.Context) ([]gosquare.Share, error) { + return []gosquare.Share{}, nil } func (n NoopFile) Close() error { diff --git a/store/file/codec_test.go b/store/file/codec_test.go index 0ab9b7c5bb..7a0489e4d5 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/go-square/v2/share" + gosquare "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 := share.RandShares(size / 2) - copy(shards, share.ToBytes(original)) + original := gosquare.RandShares(size / 2) + copy(shards, gosquare.ToBytes(original)) if fillParity { // fill with parity empty Shares for j := len(original); j < len(shards); j++ { - shards[j] = make([]byte, share.ShareSize) + shards[j] = make([]byte, gosquare.ShareSize) } } return shards diff --git a/store/file/header.go b/store/file/header.go index bb5f891870..7c2d8c7924 100644 --- a/store/file/header.go +++ b/store/file/header.go @@ -5,7 +5,7 @@ import ( "fmt" "io" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) // 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 square.DataHash + datahash share.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 square.AxisRootSize * h.SquareSize() * 2 + return share.AxisRootSize * h.SquareSize() * 2 } func (h *headerV0) OffsetWithRoots() int { diff --git a/store/file/ods.go b/store/file/ods.go index fd6285971a..8747298129 100644 --- a/store/file/ods.go +++ b/store/file/ods.go @@ -9,12 +9,12 @@ import ( "os" "sync" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "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/share" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/shwap" ) var _ eds.AccessorStreamer = (*ODS)(nil) @@ -34,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 dataSquare + ods square // 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. @@ -46,7 +46,7 @@ type ODS struct { // It may leave partially written file if any of the writes fail. func CreateODS( path string, - roots *square.AxisRoots, + roots *share.AxisRoots, eds *rsmt2d.ExtendedDataSquare, ) error { mod := os.O_RDWR | os.O_CREATE | os.O_EXCL // ensure we fail if already exist @@ -57,7 +57,7 @@ func CreateODS( hdr := &headerV0{ fileVersion: fileV0, - shareSize: share.ShareSize, + shareSize: gosquare.ShareSize, squareSize: uint16(eds.Width()), datahash: roots.Hash(), } @@ -71,7 +71,7 @@ func CreateODS( } // writeQ4File full ODS content into OS File. -func writeODSFile(f *os.File, axisRoots *square.AxisRoots, eds *rsmt2d.ExtendedDataSquare, hdr *headerV0) error { +func writeODSFile(f *os.File, axisRoots *share.AxisRoots, eds *rsmt2d.ExtendedDataSquare, hdr *headerV0) error { // buffering gives us ~4x speed up buf := bufio.NewWriterSize(f, writeBufferSize) @@ -96,16 +96,16 @@ func writeODSFile(f *os.File, axisRoots *square.AxisRoots, eds *rsmt2d.ExtendedD // writeODS writes the first quadrant(ODS) of the square to the writer. It writes the quadrant in // row-major order. Write finishes once all the shares are written or on the first instance of tail -// padding share. Tail padding share are constant and aren't stored. +// padding gosquare. Tail padding share are constant and aren't stored. 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 - ns, err := share.NewNamespace(shr[share.VersionIndex], shr[share.VersionIndex:share.NamespaceIDSize]) + ns, err := gosquare.NewNamespace(shr[gosquare.VersionIndex], shr[gosquare.VersionIndex:gosquare.NamespaceIDSize]) if err != nil { return fmt.Errorf("creating namespace: %w", err) } - if ns.Equals(share.TailPaddingNamespace) { + if ns.Equals(gosquare.TailPaddingNamespace) { return nil } @@ -119,7 +119,7 @@ func writeODS(w io.Writer, eds *rsmt2d.ExtendedDataSquare) error { } // writeAxisRoots writes RowRoots followed by ColumnRoots. -func writeAxisRoots(w io.Writer, roots *square.AxisRoots) error { +func writeAxisRoots(w io.Writer, roots *share.AxisRoots) error { for _, root := range roots.RowRoots { if _, err := w.Write(root); err != nil { return fmt.Errorf("writing row roots: %w", err) @@ -167,13 +167,13 @@ func (o *ODS) size() int { } // DataHash returns root hash of Accessor's underlying EDS. -func (o *ODS) DataHash(context.Context) (square.DataHash, error) { +func (o *ODS) DataHash(context.Context) (share.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) (*square.AxisRoots, error) { +func (o *ODS) AxisRoots(context.Context) (*share.AxisRoots, error) { roots := make([]byte, o.hdr.RootsSize()) n, err := o.fl.ReadAt(roots, int64(o.hdr.Size())) if err != nil { @@ -185,10 +185,10 @@ func (o *ODS) AxisRoots(context.Context) (*square.AxisRoots, error) { rowRoots := make([][]byte, o.size()) colRoots := make([][]byte, o.size()) for i := 0; i < o.size(); i++ { - rowRoots[i] = roots[i*square.AxisRootSize : (i+1)*square.AxisRootSize] - colRoots[i] = roots[(o.size()+i)*square.AxisRootSize : (o.size()+i+1)*square.AxisRootSize] + rowRoots[i] = roots[i*share.AxisRootSize : (i+1)*share.AxisRootSize] + colRoots[i] = roots[(o.size()+i)*share.AxisRootSize : (o.size()+i+1)*share.AxisRootSize] } - axisRoots := &square.AxisRoots{ + axisRoots := &share.AxisRoots{ RowRoots: rowRoots, ColumnRoots: colRoots, } @@ -228,7 +228,7 @@ func (o *ODS) Sample(ctx context.Context, rowIdx, colIdx int) (shwap.Sample, err // implementation. Implementations should indicate the side in the returned AxisHalf. func (o *ODS) AxisHalf(_ context.Context, axisType rsmt2d.Axis, axisIdx int) (eds.AxisHalf, error) { // Read the axis from the file if the axis is a row and from the top half of the square, or if the - // axis is a column and from the left half of the square. + // axis is a column and from the left half of the share. if axisIdx < o.size()/2 { half, err := o.readAxisHalf(axisType, axisIdx) if err != nil { @@ -253,7 +253,7 @@ func (o *ODS) AxisHalf(_ context.Context, axisType rsmt2d.Axis, axisIdx int) (ed // RowNamespaceData returns data for the given namespace and row index. func (o *ODS) RowNamespaceData( ctx context.Context, - namespace share.Namespace, + namespace gosquare.Namespace, rowIdx int, ) (shwap.RowNamespaceData, error) { shares, err := o.axis(ctx, rsmt2d.Row, rowIdx) @@ -264,7 +264,7 @@ func (o *ODS) RowNamespaceData( } // Shares returns data shares extracted from the Accessor. -func (o *ODS) Shares(context.Context) ([]share.Share, error) { +func (o *ODS) Shares(context.Context) ([]gosquare.Share, error) { ods, err := o.readODS() if err != nil { return nil, err @@ -288,7 +288,7 @@ func (o *ODS) Reader() (io.Reader, error) { return reader, nil } -func (o *ODS) axis(ctx context.Context, axisType rsmt2d.Axis, axisIdx int) ([]share.Share, error) { +func (o *ODS) axis(ctx context.Context, axisType rsmt2d.Axis, axisIdx int) ([]gosquare.Share, error) { half, err := o.AxisHalf(ctx, axisType, axisIdx) if err != nil { return nil, err @@ -321,7 +321,7 @@ func (o *ODS) readAxisHalf(axisType rsmt2d.Axis, axisIdx int) (eds.AxisHalf, err }, nil } -func (o *ODS) readODS() (dataSquare, error) { +func (o *ODS) readODS() (square, error) { if !o.disableCache { o.lock.RLock() ods := o.ods @@ -351,7 +351,7 @@ func (o *ODS) readODS() (dataSquare, error) { return ods, nil } -func readAxisHalf(r io.ReaderAt, axisTp rsmt2d.Axis, axisIdx int, hdr *headerV0, offset int) ([]share.Share, error) { +func readAxisHalf(r io.ReaderAt, axisTp rsmt2d.Axis, axisIdx int, hdr *headerV0, offset int) ([]gosquare.Share, error) { switch axisTp { case rsmt2d.Row: return readRowHalf(r, axisIdx, hdr, offset) @@ -364,12 +364,12 @@ func readAxisHalf(r io.ReaderAt, axisTp rsmt2d.Axis, axisIdx int, hdr *headerV0, // readRowHalf reads specific Row half from the file in a single IO operation. // If some or all shares are missing, tail padding shares are returned instead. -func readRowHalf(r io.ReaderAt, rowIdx int, hdr *headerV0, offset int) ([]share.Share, error) { +func readRowHalf(r io.ReaderAt, rowIdx int, hdr *headerV0, offset int) ([]gosquare.Share, error) { odsLn := hdr.SquareSize() / 2 rowOffset := rowIdx * odsLn * hdr.ShareSize() offset += rowOffset - shares := make([]share.Share, odsLn) + shares := make([]gosquare.Share, odsLn) axsData := make([]byte, odsLn*hdr.ShareSize()) n, err := r.ReadAt(axsData, int64(offset)) if err != nil && !errors.Is(err, io.EOF) { @@ -382,10 +382,10 @@ 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.TailPaddingShare() + shares[i] = gosquare.TailPaddingShare() continue } - sh, err := share.NewShare(axsData[i*hdr.ShareSize() : (i+1)*hdr.ShareSize()]) + sh, err := gosquare.NewShare(axsData[i*hdr.ShareSize() : (i+1)*hdr.ShareSize()]) if err != nil { return nil, err } @@ -396,9 +396,9 @@ func readRowHalf(r io.ReaderAt, rowIdx int, hdr *headerV0, offset int) ([]share. // readColHalf reads specific Col half from the file in a single IO operation. // If some or all shares are missing, tail padding shares are returned instead. -func readColHalf(r io.ReaderAt, colIdx int, hdr *headerV0, offset int) ([]share.Share, error) { +func readColHalf(r io.ReaderAt, colIdx int, hdr *headerV0, offset int) ([]gosquare.Share, error) { odsLn := hdr.SquareSize() / 2 - shares := make([]share.Share, odsLn) + shares := make([]gosquare.Share, odsLn) for i := range shares { pos := colIdx + i*odsLn offset := offset + pos*hdr.ShareSize() @@ -413,12 +413,12 @@ 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.TailPaddingShare() + shares[i] = gosquare.TailPaddingShare() } return shares, nil } - sh, err := share.NewShare(shr) + sh, err := gosquare.NewShare(shr) if err != nil { return nil, err } diff --git a/store/file/ods_q4.go b/store/file/ods_q4.go index e6b4cae8e3..9760e96c93 100644 --- a/store/file/ods_q4.go +++ b/store/file/ods_q4.go @@ -9,12 +9,12 @@ import ( "sync" "sync/atomic" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "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/share" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/shwap" ) var _ eds.AccessorStreamer = (*ODSQ4)(nil) @@ -37,7 +37,7 @@ type ODSQ4 struct { // CreateODSQ4 creates ODS and Q4 files under the given FS paths. func CreateODSQ4( pathODS, pathQ4 string, - roots *square.AxisRoots, + roots *share.AxisRoots, eds *rsmt2d.ExtendedDataSquare, ) error { errCh := make(chan error) @@ -103,11 +103,11 @@ func (odsq4 *ODSQ4) Size(ctx context.Context) int { return odsq4.ods.Size(ctx) } -func (odsq4 *ODSQ4) DataHash(ctx context.Context) (square.DataHash, error) { +func (odsq4 *ODSQ4) DataHash(ctx context.Context) (share.DataHash, error) { return odsq4.ods.DataHash(ctx) } -func (odsq4 *ODSQ4) AxisRoots(ctx context.Context) (*square.AxisRoots, error) { +func (odsq4 *ODSQ4) AxisRoots(ctx context.Context) (*share.AxisRoots, error) { return odsq4.ods.AxisRoots(ctx) } @@ -138,7 +138,7 @@ func (odsq4 *ODSQ4) AxisHalf(ctx context.Context, axisType rsmt2d.Axis, axisIdx } func (odsq4 *ODSQ4) RowNamespaceData(ctx context.Context, - namespace share.Namespace, + namespace gosquare.Namespace, rowIdx int, ) (shwap.RowNamespaceData, error) { half, err := odsq4.AxisHalf(ctx, rsmt2d.Row, rowIdx) @@ -152,7 +152,7 @@ func (odsq4 *ODSQ4) RowNamespaceData(ctx context.Context, return shwap.RowNamespaceDataFromShares(shares, namespace, rowIdx) } -func (odsq4 *ODSQ4) Shares(ctx context.Context) ([]share.Share, error) { +func (odsq4 *ODSQ4) Shares(ctx context.Context) ([]gosquare.Share, error) { return odsq4.ods.Shares(ctx) } diff --git a/store/file/ods_q4_test.go b/store/file/ods_q4_test.go index 24476f4d4b..20ccf3c48c 100644 --- a/store/file/ods_q4_test.go +++ b/store/file/ods_q4_test.go @@ -9,12 +9,12 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/rand" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "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/share" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/eds/edstest" ) func TestCreateODSQ4File(t *testing.T) { @@ -27,7 +27,7 @@ func TestCreateODSQ4File(t *testing.T) { shares, err := odsq4.Shares(ctx) require.NoError(t, err) expected := edsIn.FlattenedODS() - require.Equal(t, expected, share.ToBytes(shares)) + require.Equal(t, expected, gosquare.ToBytes(shares)) require.NoError(t, odsq4.Close()) } @@ -90,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 := square.NewAxisRoots(eds) + roots, err := share.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 dbd1485dfa..ef671d2d02 100644 --- a/store/file/ods_test.go +++ b/store/file/ods_test.go @@ -9,12 +9,12 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/rand" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "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/share" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/eds/edstest" ) func TestCreateODSFile(t *testing.T) { @@ -23,18 +23,18 @@ func TestCreateODSFile(t *testing.T) { edsIn := edstest.RandEDS(t, 8) f := createODSFile(t, edsIn) - readRoots, err := square.NewAxisRoots(edsIn) + readRoots, err := share.NewAxisRoots(edsIn) require.NoError(t, err) shares, err := f.Shares(ctx) require.NoError(t, err) expected := edsIn.FlattenedODS() - require.Equal(t, expected, share.ToBytes(shares)) + require.Equal(t, expected, gosquare.ToBytes(shares)) roots, err := f.AxisRoots(ctx) require.NoError(t, err) - require.Equal(t, square.DataHash(roots.Hash()), f.hdr.datahash) + require.Equal(t, share.DataHash(roots.Hash()), f.hdr.datahash) require.True(t, roots.Equals(readRoots)) require.NoError(t, f.Close()) } @@ -48,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, share.ToBytes(row)) + require.Equal(t, original, gosquare.ToBytes(row)) } } @@ -160,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 := square.NewAxisRoots(eds) + roots, err := share.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 139ed28806..cb310128fa 100644 --- a/store/file/q4.go +++ b/store/file/q4.go @@ -9,10 +9,10 @@ import ( "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/share/eds" ) -// q4 stores the fourth quadrant of the square. +// q4 stores the fourth quadrant of the share. type q4 struct { hdr *headerV0 file *os.File diff --git a/store/file/square.go b/store/file/square.go index a12cf41c03..5e9eb53786 100644 --- a/store/file/square.go +++ b/store/file/square.go @@ -6,32 +6,32 @@ import ( "golang.org/x/sync/errgroup" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/share/eds" ) -type dataSquare [][]share.Share +type square [][]gosquare.Share -// readSquare reads Shares from the reader and returns a square. It assumes that the reader is +// readSquare reads Shares from the reader and returns a share. 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) (dataSquare, error) { +func readSquare(r io.Reader, shareSize, edsSize int) (square, error) { odsLn := edsSize / 2 shares, err := eds.ReadShares(r, shareSize, odsLn) if err != nil { return nil, fmt.Errorf("reading shares: %w", err) } - square := make(dataSquare, odsLn) + square := make(square, odsLn) for i := range square { square[i] = shares[i*odsLn : (i+1)*odsLn] } return square, nil } -func (s dataSquare) reader() (io.Reader, error) { +func (s square) reader() (io.Reader, error) { if s == nil { return nil, fmt.Errorf("ods file not cached") } @@ -42,19 +42,19 @@ func (s dataSquare) reader() (io.Reader, error) { return reader, nil } -func (s dataSquare) size() int { +func (s square) size() int { return len(s) } -func (s dataSquare) shares() ([]share.Share, error) { - shares := make([]share.Share, 0, s.size()*s.size()) +func (s square) shares() ([]gosquare.Share, error) { + shares := make([]gosquare.Share, 0, s.size()*s.size()) for _, row := range s { shares = append(shares, row...) } return shares, nil } -func (s dataSquare) axisHalf(axisType rsmt2d.Axis, axisIdx int) (eds.AxisHalf, error) { +func (s square) axisHalf(axisType rsmt2d.Axis, axisIdx int) (eds.AxisHalf, error) { if s == nil { return eds.AxisHalf{}, fmt.Errorf("square is nil") } @@ -73,7 +73,7 @@ func (s dataSquare) axisHalf(axisType rsmt2d.Axis, axisIdx int) (eds.AxisHalf, e } // construct half column from row ordered square - col := make([]share.Share, s.size()) + col := make([]gosquare.Share, s.size()) for i := 0; i < s.size(); i++ { col[i] = s[i][axisIdx] } @@ -83,11 +83,11 @@ func (s dataSquare) axisHalf(axisType rsmt2d.Axis, axisIdx int) (eds.AxisHalf, e }, nil } -func (s dataSquare) computeAxisHalf( +func (s square) computeAxisHalf( axisType rsmt2d.Axis, axisIdx int, ) (eds.AxisHalf, error) { - shares := make([]share.Share, s.size()) + shares := make([]gosquare.Share, s.size()) // extend opposite half of the square while collecting Shares for the first half of required axis g := errgroup.Group{} @@ -106,9 +106,9 @@ func (s dataSquare) computeAxisHalf( shards := make([][]byte, s.size()*2) if half.IsParity { - copy(shards[s.size():], share.ToBytes(half.Shares)) + copy(shards[s.size():], gosquare.ToBytes(half.Shares)) } else { - copy(shards, share.ToBytes(half.Shares)) + copy(shards, gosquare.ToBytes(half.Shares)) } target := make([]bool, s.size()*2) @@ -119,7 +119,7 @@ func (s dataSquare) computeAxisHalf( return fmt.Errorf("reconstruct some: %w", err) } - shard, err := share.NewShare(shards[axisIdx]) + shard, err := gosquare.NewShare(shards[axisIdx]) if err != nil { return fmt.Errorf("creating share: %w", err) } diff --git a/store/getter.go b/store/getter.go index e436aa0489..96b9d37d10 100644 --- a/store/getter.go +++ b/store/getter.go @@ -5,13 +5,13 @@ import ( "errors" "fmt" - "github.com/celestiaorg/go-square/v2/share" + gosquare "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/square/eds" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share/eds" + "github.com/celestiaorg/celestia-node/share/shwap" ) var _ shwap.Getter = (*Getter)(nil) @@ -24,13 +24,13 @@ func NewGetter(store *Store) *Getter { return &Getter{store: store} } -func (g *Getter) GetShare(ctx context.Context, h *header.ExtendedHeader, row, col int) (share.Share, error) { +func (g *Getter) GetShare(ctx context.Context, h *header.ExtendedHeader, row, col int) (gosquare.Share, error) { acc, err := g.store.GetByHeight(ctx, h.Height()) if err != nil { if errors.Is(err, ErrNotFound) { - return share.Share{}, shwap.ErrNotFound + return gosquare.Share{}, shwap.ErrNotFound } - return share.Share{}, fmt.Errorf("get accessor from store:%w", err) + return gosquare.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 share.Share{}, fmt.Errorf("get sample from accessor:%w", err) + return gosquare.Share{}, fmt.Errorf("get sample from accessor:%w", err) } return sample.Share, nil } @@ -71,7 +71,7 @@ func (g *Getter) GetEDS(ctx context.Context, h *header.ExtendedHeader) (*rsmt2d. func (g *Getter) GetSharesByNamespace( ctx context.Context, h *header.ExtendedHeader, - ns share.Namespace, + ns gosquare.Namespace, ) (shwap.NamespaceData, error) { acc, err := g.store.GetByHeight(ctx, h.Height()) if err != nil { diff --git a/store/getter_test.go b/store/getter_test.go index 5693e2cc57..9d6defea45 100644 --- a/store/getter_test.go +++ b/store/getter_test.go @@ -7,11 +7,11 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-node/header/headertest" - "github.com/celestiaorg/celestia-node/square/eds/edstest" - "github.com/celestiaorg/celestia-node/square/shwap" + "github.com/celestiaorg/celestia-node/share/eds/edstest" + "github.com/celestiaorg/celestia-node/share/shwap" ) func TestStoreGetter(t *testing.T) { @@ -67,7 +67,7 @@ func TestStoreGetter(t *testing.T) { }) t.Run("GetSharesByNamespace", func(t *testing.T) { - ns := share.RandomNamespace() + ns := gosquare.RandomNamespace() eds, roots := edstest.RandEDSWithNamespace(t, ns, 8, 16) eh := headertest.RandExtendedHeaderWithRoot(t, roots) height := height.Add(1) @@ -80,7 +80,7 @@ func TestStoreGetter(t *testing.T) { require.NoError(t, shares.Verify(eh.DAH, ns)) // namespace not found - randNamespace := share.RandomNamespace() + randNamespace := gosquare.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 8f97135b93..632f198bb3 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/square" - "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/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 *square.AxisRoots, + roots *share.AxisRoots, height uint64, square *rsmt2d.ExtendedDataSquare, ) error { @@ -101,7 +101,7 @@ func (s *Store) PutODSQ4( func (s *Store) PutODS( ctx context.Context, - roots *square.AxisRoots, + roots *share.AxisRoots, height uint64, square *rsmt2d.ExtendedDataSquare, ) error { @@ -110,12 +110,12 @@ func (s *Store) PutODS( func (s *Store) put( ctx context.Context, - roots *square.AxisRoots, + roots *share.AxisRoots, height uint64, - dataSquare *rsmt2d.ExtendedDataSquare, + square *rsmt2d.ExtendedDataSquare, writeQ4 bool, ) error { - datahash := square.DataHash(roots.Hash()) + datahash := share.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: dataSquare} + accessor := &eds.Rsmt2D{ExtendedDataSquare: square} 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(dataSquare, roots, height) + exists, err = s.createODSQ4File(square, roots, height) } else { - exists, err = s.createODSFile(dataSquare, roots, height) + exists, err = s.createODSFile(square, roots, height) } if exists { @@ -152,17 +152,17 @@ func (s *Store) put( return nil } if err != nil { - s.metrics.observePut(ctx, time.Since(tNow), dataSquare.Width(), writeQ4, true) + s.metrics.observePut(ctx, time.Since(tNow), square.Width(), writeQ4, true) return fmt.Errorf("creating file: %w", err) } - s.metrics.observePut(ctx, time.Since(tNow), dataSquare.Width(), writeQ4, false) + s.metrics.observePut(ctx, time.Since(tNow), square.Width(), writeQ4, false) return nil } func (s *Store) createODSQ4File( square *rsmt2d.ExtendedDataSquare, - roots *square.AxisRoots, + roots *share.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 *square.AxisRoots, + roots *share.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 square.DataHash, height uint64) error { +func (s *Store) linkHeight(datahash share.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 square.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(square.EmptyEDSDataHash(), odsFileExt) - pathQ4 := s.hashToPath(square.EmptyEDSDataHash(), q4FileExt) + pathOds := s.hashToPath(share.EmptyEDSDataHash(), odsFileExt) + pathQ4 := s.hashToPath(share.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, square.EmptyEDSRoots(), eds.EmptyAccessor.ExtendedDataSquare) + err = file.CreateODSQ4(pathOds, pathQ4, share.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 square.DataHash) (eds.AccessorStreamer, error) { +func (s *Store) GetByHash(ctx context.Context, datahash share.DataHash) (eds.AccessorStreamer, error) { if datahash.IsEmptyEDS() { return eds.EmptyAccessor, nil } @@ -274,7 +274,7 @@ func (s *Store) GetByHash(ctx context.Context, datahash square.DataHash) (eds.Ac return f, err } -func (s *Store) getByHash(ctx context.Context, datahash square.DataHash) (eds.AccessorStreamer, error) { +func (s *Store) getByHash(ctx context.Context, datahash share.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 square.DataHash) (bool, error) { +func (s *Store) HasByHash(ctx context.Context, datahash share.DataHash) (bool, error) { if datahash.IsEmptyEDS() { return true, nil } @@ -338,7 +338,7 @@ func (s *Store) HasByHash(ctx context.Context, datahash square.DataHash) (bool, return exist, err } -func (s *Store) hasByHash(datahash square.DataHash) (bool, error) { +func (s *Store) hasByHash(datahash share.DataHash) (bool, error) { // For now, we assume that if ODS exists, the Q4 exists as well. path := s.hashToPath(datahash, odsFileExt) return exists(path) @@ -365,7 +365,7 @@ func (s *Store) hasByHeight(height uint64) (bool, error) { return exists(pathODS) } -func (s *Store) RemoveODSQ4(ctx context.Context, height uint64, datahash square.DataHash) error { +func (s *Store) RemoveODSQ4(ctx context.Context, height uint64, datahash share.DataHash) error { lock := s.stripLock.byHashAndHeight(datahash, height) lock.lock() defer lock.unlock() @@ -376,7 +376,7 @@ func (s *Store) RemoveODSQ4(ctx context.Context, height uint64, datahash square. return err } -func (s *Store) removeODSQ4(height uint64, datahash square.DataHash) error { +func (s *Store) removeODSQ4(height uint64, datahash share.DataHash) error { if err := s.removeODS(height, datahash); err != nil { return fmt.Errorf("removing ODS: %w", err) } @@ -386,7 +386,7 @@ func (s *Store) removeODSQ4(height uint64, datahash square.DataHash) error { return nil } -func (s *Store) removeODS(height uint64, datahash square.DataHash) error { +func (s *Store) removeODS(height uint64, datahash share.DataHash) error { if err := s.cache.Remove(height); err != nil { return fmt.Errorf("removing from cache: %w", err) } @@ -408,7 +408,7 @@ func (s *Store) removeODS(height uint64, datahash square.DataHash) error { return nil } -func (s *Store) RemoveQ4(ctx context.Context, height uint64, datahash square.DataHash) error { +func (s *Store) RemoveQ4(ctx context.Context, height uint64, datahash share.DataHash) error { lock := s.stripLock.byHashAndHeight(datahash, height) lock.lock() defer lock.unlock() @@ -419,7 +419,7 @@ func (s *Store) RemoveQ4(ctx context.Context, height uint64, datahash square.Dat return err } -func (s *Store) removeQ4(height uint64, datahash square.DataHash) error { +func (s *Store) removeQ4(height uint64, datahash share.DataHash) error { // if datahash is empty, we don't need to remove the Q4 file if datahash.IsEmptyEDS() { return nil @@ -437,7 +437,7 @@ func (s *Store) removeQ4(height uint64, datahash square.DataHash) error { return nil } -func (s *Store) hashToPath(datahash square.DataHash, ext string) string { +func (s *Store) hashToPath(datahash share.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 a9d5e4882d..9e552312fd 100644 --- a/store/store_cache.go +++ b/store/store_cache.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/celestiaorg/celestia-node/square/eds" + "github.com/celestiaorg/celestia-node/share/eds" "github.com/celestiaorg/celestia-node/store/cache" ) diff --git a/store/store_test.go b/store/store_test.go index 6e25f2512b..0d3f040187 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -10,11 +10,11 @@ import ( "github.com/stretchr/testify/require" - "github.com/celestiaorg/go-square/v2/share" + gosquare "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" - "github.com/celestiaorg/celestia-node/square" - "github.com/celestiaorg/celestia-node/square/eds/edstest" + "github.com/celestiaorg/celestia-node/share" + "github.com/celestiaorg/celestia-node/share/eds/edstest" "github.com/celestiaorg/celestia-node/store/cache" ) @@ -68,7 +68,7 @@ func TestEDSStore(t *testing.T) { require.NoError(t, err) require.NoError(t, f.Close()) expected := eds.FlattenedODS() - require.Equal(t, expected, share.ToBytes(fromFile)) + require.Equal(t, expected, gosquare.ToBytes(fromFile)) }) t.Run("Second Put should be noop", func(t *testing.T) { @@ -106,7 +106,7 @@ func TestEDSStore(t *testing.T) { require.NoError(t, err) require.NoError(t, f.Close()) expected := eds.FlattenedODS() - require.Equal(t, expected, share.ToBytes(fromFile)) + require.Equal(t, expected, gosquare.ToBytes(fromFile)) }) t.Run("GetByHash", func(t *testing.T) { @@ -124,7 +124,7 @@ func TestEDSStore(t *testing.T) { require.NoError(t, err) require.NoError(t, f.Close()) expected := eds.FlattenedODS() - require.Equal(t, expected, share.ToBytes(fromFile)) + require.Equal(t, expected, gosquare.ToBytes(fromFile)) }) t.Run("Does not exist", func(t *testing.T) { @@ -148,8 +148,8 @@ func TestEDSStore(t *testing.T) { require.NoError(t, err) height := height.Add(1) - hash := square.EmptyEDSDataHash() - err = edsStore.PutODSQ4(ctx, square.EmptyEDSRoots(), height, square.EmptyEDS()) + hash := share.EmptyEDSDataHash() + err = edsStore.PutODSQ4(ctx, share.EmptyEDSRoots(), height, share.EmptyEDS()) require.NoError(t, err) ensureAmountFileAndLinks(t, dir, 0, 1) @@ -174,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, square.DataHash{0x01, 0x02}) + err = edsStore.RemoveODSQ4(ctx, missingHeight, share.DataHash{0x01, 0x02}) require.NoError(t, err) eds, roots := randomEDS(t) @@ -210,8 +210,8 @@ func TestEDSStore(t *testing.T) { require.NoError(t, err) height := height.Add(1) - hash := square.EmptyEDSDataHash() - err = edsStore.PutODSQ4(ctx, square.EmptyEDSRoots(), height, square.EmptyEDS()) + hash := share.EmptyEDSDataHash() + err = edsStore.PutODSQ4(ctx, share.EmptyEDSRoots(), height, share.EmptyEDS()) require.NoError(t, err) // empty file is not counted as a file ensureAmountFileAndLinks(t, dir, 0, 1) @@ -256,8 +256,8 @@ func TestEDSStore(t *testing.T) { }) t.Run("empty EDS returned by hash", func(t *testing.T) { - eds := square.EmptyEDS() - roots, err := square.NewAxisRoots(eds) + eds := share.EmptyEDS() + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) // assert that the empty file exists @@ -274,8 +274,8 @@ func TestEDSStore(t *testing.T) { }) t.Run("empty EDS returned by height", func(t *testing.T) { - eds := square.EmptyEDS() - roots, err := square.NewAxisRoots(eds) + eds := share.EmptyEDS() + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) height := height.Add(1) @@ -301,8 +301,8 @@ func TestEDSStore(t *testing.T) { edsStore, err := NewStore(DefaultParameters(), dir) require.NoError(t, err) - eds := square.EmptyEDS() - roots, err := square.NewAxisRoots(eds) + eds := share.EmptyEDS() + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) from, to := 10, 20 @@ -343,7 +343,7 @@ func BenchmarkStore(b *testing.B) { b.Cleanup(cancel) eds := edstest.RandEDS(b, 128) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(b, err) // BenchmarkStore/put_128-16 186 6623266 ns/op @@ -394,9 +394,9 @@ func BenchmarkStore(b *testing.B) { }) } -func randomEDS(t testing.TB) (*rsmt2d.ExtendedDataSquare, *square.AxisRoots) { +func randomEDS(t testing.TB) (*rsmt2d.ExtendedDataSquare, *share.AxisRoots) { eds := edstest.RandEDS(t, 4) - roots, err := square.NewAxisRoots(eds) + roots, err := share.NewAxisRoots(eds) require.NoError(t, err) return eds, roots @@ -422,7 +422,7 @@ func hasByHashAndHeight( t testing.TB, store *Store, ctx context.Context, - hash square.DataHash, + hash share.DataHash, height uint64, hasByHash, hasByHeight bool, ) { diff --git a/store/striplock.go b/store/striplock.go index eb23facab2..4738453c77 100644 --- a/store/striplock.go +++ b/store/striplock.go @@ -3,7 +3,7 @@ package store import ( "sync" - "github.com/celestiaorg/celestia-node/square" + "github.com/celestiaorg/celestia-node/share" ) // 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 square.DataHash) *sync.RWMutex { +func (l *striplock) byHash(datahash share.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 square.DataHash, height uint64) *multiLock { +func (l *striplock) byHashAndHeight(datahash share.DataHash, height uint64) *multiLock { return &multiLock{[]*sync.RWMutex{l.byHash(datahash), l.byHeight(height)}} }